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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(sheet): cell related facade api (#4032)
Dushusir545dc8261a0f
diff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.tsindex 2c836e8dcc..27fe0883d2 100644--- a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts+++ b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts@@ -194,3 +194,39 @@ test('diff sheet default style rendering', async () => {await page.waitForTimeout(2000);await browser.close();});++test('diff facade sheet hooks', async () => {+ const browser = await chromium.launch({+ headless: !!isCI, // Set to false to see the browser window+ });+ const context = await browser.newContext({+ viewport: { width: 1280, height: 1280 },+ deviceScaleFactor: 2, // Set your desired DPR+ });+ const page = await context.newPage();+ await page.goto('http://localhost:3000/sheets/');+ await page.waitForTimeout(2000);++ await page.evaluate(() => window.E2EControllerAPI.loadDefaultStyleSheet());+ await page.waitForTimeout(2000);++ await page.evaluate(() => window.univerAPI.getSheetHooks().onCellRender([{+ drawWith: (ctx, info) => {+ const { row, col } = info;+ // Update to any cell location you want+ if (row === 1 && col === 2) {+ const { primaryWithCoord } = info;+ const { startX, startY } = primaryWithCoord;+ ctx.fillText('Univer', startX, startY + 10);+ }+ },+ }]));+ await page.evaluate(() => window.univerAPI.getActiveWorkbook().getActiveSheet().refreshCanvas());++ const filename = generateSnapshotName('facade-sheet-hooks');+ const screenshot = await page.locator(SHEET_MAIN_CANVAS_ID).screenshot();+ await expect(screenshot).toMatchSnapshot(filename, { maxDiffPixels: 5 });++ await page.waitForTimeout(2000);+ await browser.close();+});diff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-chromium-linux.pngnew file mode 100644index 0000000000..a4e95c5df0Binary files /dev/null and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-ci-chromium-linux.pngnew file mode 100644index 0000000000..189dc7c486Binary files /dev/null and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-ci-chromium-linux.png differdiff --git a/packages/facade/src/apis/everything.ts b/packages/facade/src/apis/everything.tsindex f156f67788..5623dfc604 100644--- a/packages/facade/src/apis/everything.ts+++ b/packages/facade/src/apis/everything.ts@@ -29,8 +29,8 @@ import '@univerjs/sheets-thread-comment/facade';export { FHooks, FUniver } from '@univerjs/core';export { FFormula } from '@univerjs/engine-formula/facade';+export { FSheetHooks } from '@univerjs/sheets/facade';export { FPermission, FRange, FSelection, FWorkbook, FWorksheet } from '@univerjs/sheets/facade';export { FDataValidation, FDataValidationBuilder } from '@univerjs/sheets-data-validation/facade';export { FFilter } from '@univerjs/sheets-filter/facade';export { FThreadComment } from '@univerjs/sheets-thread-comment/facade';-export { FSheetHooks } from '@univerjs/sheets-ui/facade';diff --git a/packages/facade/src/apis/sheets/__tests__/create-worksheet-test-bed.ts b/packages/facade/src/apis/sheets/__tests__/create-worksheet-test-bed.tsindex 3364f46b6e..2fd756ddeb 100644--- a/packages/facade/src/apis/sheets/__tests__/create-worksheet-test-bed.ts+++ b/packages/facade/src/apis/sheets/__tests__/create-worksheet-test-bed.ts@@ -17,6 +17,7 @@/* eslint-disable max-lines-per-function */import type { Dependency, IWorkbookData, UnitModel } from '@univerjs/core';+import type { IRender } from '@univerjs/engine-render';import {ILogService,Inject,@@ -116,6 +117,13 @@ export interface ITestBed {injector: Injector;}+class RenderManagerServiceTestBed extends RenderManagerService {+ override createRender(unitId: string): IRender {+ const renderer = this._createRender(unitId, new Engine(100, 100));+ return renderer;+ }+}+export function createWorksheetTestBed(workbookData?: IWorkbookData, dependencies?: Dependency[]): ITestBed {const univer = new Univer();const injector = univer.__getInjector();@@ -146,7 +154,7 @@ export function createWorksheetTestBed(workbookData?: IWorkbookData, dependencieinjector.add([IFunctionService, { useClass: FunctionService }]);injector.add([ISocketService, { useClass: WebSocketService }]);injector.add([IRenderingEngine, { useFactory: () => new Engine() }]);- injector.add([IRenderManagerService, { useClass: RenderManagerService }]);+ injector.add([IRenderManagerService, { useClass: RenderManagerServiceTestBed }]);injector.add([ISheetSelectionRenderService, { useClass: SheetSelectionRenderService }]);injector.add([SheetsRenderService]);injector.add([IShortcutService, { useClass: ShortcutService }]);@@ -189,6 +197,10 @@ export function createWorksheetTestBed(workbookData?: IWorkbookData, dependenciedependencies?.forEach((d) => injector.add(d));}++ override onReady(): void {+ this._injector.get(SheetsRenderService);+ }}// load i18ndiff --git a/packages/facade/src/apis/sheets/__tests__/f-worksheet.spec.ts b/packages/facade/src/apis/sheets/__tests__/f-worksheet.spec.tsindex 3cb9c24a2d..adf3d1672f 100644--- a/packages/facade/src/apis/sheets/__tests__/f-worksheet.spec.ts+++ b/packages/facade/src/apis/sheets/__tests__/f-worksheet.spec.ts@@ -544,4 +544,9 @@ describe('Test FWorksheet', () => {expect(activeSheet?.getFrozenRows()).toBe(21);expect(activeSheet?.getFrozenColumns()).toBe(9);});++ it('Worksheet refreshCanvas', async () => {+ const activeSheet = univerAPI.getActiveWorkbook()?.getActiveSheet();+ activeSheet?.refreshCanvas();+ });});diff --git a/packages/sheets-ui/src/facade/__tests__/create-test-bed.ts b/packages/sheets-ui/src/facade/__tests__/create-test-bed.tsnew file mode 100644index 0000000000..523cdab519--- /dev/null+++ b/packages/sheets-ui/src/facade/__tests__/create-test-bed.ts@@ -0,0 +1,157 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { Dependency, IWorkbookData, UnitModel } from '@univerjs/core';+import type { IRender } from '@univerjs/engine-render';+import {+ FUniver,+ ILogService,+ Inject,+ Injector,+ IUniverInstanceService,+ LocaleType,+ LogLevel,+ Plugin,+ ThemeService,+ Univer,+ UniverInstanceType } from '@univerjs/core';+import { LexerTreeBuilder } from '@univerjs/engine-formula';+import { Engine, IRenderingEngine, IRenderManagerService, RenderManagerService } from '@univerjs/engine-render';+import {+ SheetInterceptorService,+} from '@univerjs/sheets';++import '../f-sheet-hooks';++function getTestWorkbookDataDemo(): IWorkbookData {+ return {+ id: 'test',+ appVersion: '3.0.0-alpha',+ sheets: {+ sheet1: {+ id: 'sheet1',+ name: 'sheet1',+ cellData: {+ 0: {+ 3: {+ f: '=SUM(A1)',+ si: '3e4r5t',+ },+ },+ 1: {+ 3: {+ f: '=SUM(A2)',+ si: 'OSPtzm',+ },+ },+ 2: {+ 3: {+ si: 'OSPtzm',+ },+ },+ 3: {+ 3: {+ si: 'OSPtzm',+ },+ },+ },+ rowCount: 100,+ columnCount: 100,+ },+ },+ locale: LocaleType.ZH_CN,+ name: '',+ sheetOrder: [],+ styles: {},+ resources: [+ {+ name: 'SHEET_CONDITIONAL_FORMATTING_PLUGIN',+ data: '{"sheet-0011":[{"cfId":"AEGZdW8C","ranges":[{"startRow":2,"startColumn":1,"endRow":11,"endColumn":5,"startAbsoluteRefType":0,"endAbsoluteRefType":0,"rangeType":0}],"rule":{"type":"highlightCell","subType":"text","operator":"containsText","style":{"cl":{"rgb":"#2f56ef"},"bg":{"rgb":"#e8ecfc"}},"value":""},"stopIfTrue":false},{"cfId":"4ICEXdJj","ranges":[{"startRow":2,"startColumn":1,"endRow":11,"endColumn":5,"startAbsoluteRefType":0,"endAbsoluteRefType":0,"rangeType":0}],"rule":{"type":"highlightCell","subType":"text","operator":"containsText","style":{"cl":{"rgb":"#2f56ef"},"bg":{"rgb":"#e8ecfc"}},"value":""},"stopIfTrue":false},{"cfId":"geCv018z","ranges":[{"startRow":2,"startColumn":1,"endRow":11,"endColumn":5,"startAbsoluteRefType":0,"endAbsoluteRefType":0,"rangeType":0}],"rule":{"type":"highlightCell","subType":"text","operator":"containsText","style":{"cl":{"rgb":"#2f56ef"},"bg":{"rgb":"#e8ecfc"}},"value":""},"stopIfTrue":false}]}',+ },+ ],+ };+}++export interface ITestBed {+ univer: Univer;+ get: Injector['get'];+ sheet: UnitModel<IWorkbookData>;+ univerAPI: FUniver;+ injector: Injector;+}++class RenderManagerServiceTestBed extends RenderManagerService {+ override createRender(unitId: string): IRender {+ const renderer = this._createRender(unitId, new Engine(100, 100));+ return renderer;+ }+}++export function createFacadeTestBed(workbookData?: IWorkbookData, dependencies?: Dependency[]): ITestBed {+ const univer = new Univer();+ const injector = univer.__getInjector();++ class TestPlugin extends Plugin {+ static override pluginName = 'test-plugin';+ static override type = UniverInstanceType.UNIVER_SHEET;++ constructor(+ _config: undefined,+ @Inject(Injector) override readonly _injector: Injector+ ) {+ super();+ }++ override onStarting(): void {+ const injector = this._injector;+ injector.add([SheetInterceptorService]);+ injector.add([IRenderingEngine, { useFactory: () => new Engine() }]);+ injector.add([IRenderManagerService, { useClass: RenderManagerServiceTestBed }]);+ injector.add([LexerTreeBuilder]);++ dependencies?.forEach((d) => injector.add(d));++ this._injector.get(SheetInterceptorService);+ }+ }++ // load theme service+ const themeService = injector.get(ThemeService);+ themeService.setTheme({ colorBlack: '#35322b' });++ // register builtin plugins+ // note that UI plugins are not registered here, because the unit test environment does not have a UI+ univer.registerPlugin(TestPlugin);++ const sheet = univer.createUnit<IWorkbookData, UnitModel<IWorkbookData>>(UniverInstanceType.UNIVER_SHEET, workbookData || getTestWorkbookDataDemo());+ const univerInstanceService = injector.get(IUniverInstanceService);+ univerInstanceService.focusUnit('test');++ // set log level+ const logService = injector.get(ILogService);+ logService.setLogLevel(LogLevel.SILENT); // NOTE: change this to `LogLevel.VERBOSE` to debug tests via logs++ // init data validation+ const univerAPI = FUniver.newAPI(injector);++ return {+ univer,+ get: injector.get.bind(injector),+ sheet,+ univerAPI,+ injector,+ };+}diff --git a/packages/facade/src/apis/sheets/__tests__/f-sheet-hooks.spec.ts b/packages/sheets-ui/src/facade/__tests__/f-sheet-hooks.spec.tssimilarity index 71%rename from packages/facade/src/apis/sheets/__tests__/f-sheet-hooks.spec.tsrename to packages/sheets-ui/src/facade/__tests__/f-sheet-hooks.spec.tsindex 39cefa0628..d442ae7d45 100644--- a/packages/facade/src/apis/sheets/__tests__/f-sheet-hooks.spec.ts+++ b/packages/sheets-ui/src/facade/__tests__/f-sheet-hooks.spec.ts@@ -15,15 +15,27 @@*/import type { ICellData, Injector, IStyleData, Nullable, Workbook } from '@univerjs/core';-import type { IDragCellPosition, IHoverCellPosition } from '@univerjs/sheets-ui';+import type { IDragCellPosition } from '../../services/drag-manager.service';+import type { IEditorBridgeServiceVisibleParam } from '../../services/editor-bridge.service';+import type { IHoverCellPosition } from '../../services/hover-manager.service';+import { ICommandService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';-import { SetHorizontalTextAlignCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetStyleCommand, SetTextWrapCommand, SetVerticalTextAlignCommand } from '@univerjs/sheets';+import { DocSelectionManagerService } from '@univerjs/docs';-import { DragManagerService, HoverManagerService } from '@univerjs/sheets-ui';+import { EditorService, IEditorService } from '@univerjs/docs-ui';+import { DeviceInputEventType } from '@univerjs/engine-render';+import { IRefSelectionsService, RefSelectionsService, SetHorizontalTextAlignCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetStyleCommand, SetTextWrapCommand, SetVerticalTextAlignCommand } from '@univerjs/sheets';+import { FSheetHooks } from '@univerjs/sheets/facade';+import { KeyCode } from '@univerjs/ui';import { Subject } from 'rxjs';import { beforeEach, describe, expect, it } from 'vitest';-import { createFacadeTestBed } from '../../__tests__/create-test-bed';-import { FSheetHooks } from '../../everything';+import { SetCellEditVisibleOperation } from '../../commands/operations/cell-edit.operation';+import { DragManagerService } from '../../services/drag-manager.service';+import { EditorBridgeService, IEditorBridgeService } from '../../services/editor-bridge.service';+import { HoverManagerService } from '../../services/hover-manager.service';++import { createFacadeTestBed } from './create-test-bed';+import '../f-sheet-hooks';class MockDataTransfer implements DataTransfer {effectAllowed: 'none' | 'copy' | 'link' | 'move' | 'all' | 'copyLink' | 'copyMove' | 'linkMove' | 'uninitialized';@@ -95,6 +107,10 @@ describe('Test FSheetHooks', () => {const testBed = createFacadeTestBed(undefined, [[HoverManagerService, { useValue: mockHoverManagerService }],[DragManagerService, { useValue: mockDragManagerService }],+ [IEditorBridgeService, { useClass: EditorBridgeService }],+ [IEditorService, { useClass: EditorService }],+ [DocSelectionManagerService],+ [IRefSelectionsService, { useClass: RefSelectionsService }],]);get = testBed.get;injector = testBed.injector;@@ -108,6 +124,9 @@ describe('Test FSheetHooks', () => {commandService.registerCommand(SetHorizontalTextAlignCommand);commandService.registerCommand(SetTextWrapCommand);+ // onCellEditBefore+ commandService.registerCommand(SetCellEditVisibleOperation);+getValueByPosition = (startRow: number,startColumn: number,@@ -183,4 +202,50 @@ describe('Test FSheetHooks', () => {const subUnitId = worksheet.getSheetId();dragEndCell$.next({ location: { workbook, worksheet, unitId, subUnitId, row: 0, col: 0 }, position: { startX: 0, endX: 1, startY: 0, endY: 1 }, dataTransfer: new MockDataTransfer() });});++ it('Test onCellRender', () => {+ sheetHooks.onCellRender([{+ drawWith: (ctx, info, skeleton, spreadsheets) => {+ const { row, col } = info;+ // Update to any cell location you want+ if (row === 1 && col === 1) {+ const { primaryWithCoord } = info;+ const { startX, startY } = primaryWithCoord;+ ctx.fillText('✅', startX, startY + 10);++ expect(info.unitId).toEqual(workbook.getUnitId());+ expect(info.subUnitId).toEqual(workbook.getActiveSheet().getSheetId());+ }+ },+ }]);+ });++ it('Test onBeforeCellEdit', () => {+ const commandParams: IEditorBridgeServiceVisibleParam = {+ visible: true,+ eventType: DeviceInputEventType.Dblclick,+ unitId: workbook.getUnitId(),+ };++ sheetHooks.onBeforeCellEdit((params) => {+ expect(params).toEqual(commandParams);+ });++ commandService.executeCommand(SetCellEditVisibleOperation.id, commandParams);+ });++ it('Test onAfterCellEdit', () => {+ const commandParams: IEditorBridgeServiceVisibleParam = {+ visible: false,+ eventType: DeviceInputEventType.Keyboard,+ unitId: workbook.getUnitId(),+ keycode: KeyCode.ENTER,+ };++ sheetHooks.onAfterCellEdit((params) => {+ expect(params).toEqual(commandParams);+ });++ commandService.executeCommand(SetCellEditVisibleOperation.id, commandParams);+ });});diff --git a/packages/sheets-ui/src/facade/f-sheet-hooks.ts b/packages/sheets-ui/src/facade/f-sheet-hooks.tsindex 07662a40af..d25980d436 100644--- a/packages/sheets-ui/src/facade/f-sheet-hooks.ts+++ b/packages/sheets-ui/src/facade/f-sheet-hooks.ts@@ -14,53 +14,120 @@* limitations under the License.*/-import type { IDisposable, Nullable } from '@univerjs/core';-import type { IDragCellPosition, IHoverCellPosition } from '@univerjs/sheets-ui';-import { Inject, Injector, toDisposable } from '@univerjs/core';-import { DragManagerService, HoverManagerService } from '@univerjs/sheets-ui';--export class FSheetHooks {- constructor(- @Inject(Injector) private readonly _injector: Injector,- @Inject(HoverManagerService) private readonly _hoverManagerService: HoverManagerService,- @Inject(DragManagerService) private readonly _dragManagerService: DragManagerService- ) {- // empty- }+import type { ICellCustomRender, IDisposable, Nullable } from '@univerjs/core';+import type { IDragCellPosition, IEditorBridgeServiceVisibleParam, IHoverCellPosition } from '@univerjs/sheets-ui';+import { ICommandService, InterceptorEffectEnum, toDisposable } from '@univerjs/core';+import { InterceptCellContentPriority, INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';+import { FSheetHooks } from '@univerjs/sheets/facade';+import { DragManagerService, HoverManagerService, SetCellEditVisibleOperation } from '@univerjs/sheets-ui';+interface IFSheetHooksUIMixin {/*** The onCellPointerMove event is fired when a pointer changes coordinates.* @param callback Callback function that will be called when the event is fired* @returns A disposable object that can be used to unsubscribe from the event*/- onCellPointerMove(callback: (cellPos: Nullable<IHoverCellPosition>) => void): IDisposable {- return toDisposable(this._hoverManagerService.currentPosition$.subscribe(callback));- }+ onCellPointerMove(callback: (cellPos: Nullable<IHoverCellPosition>) => void): IDisposable;/*** The onCellPointerOver event is fired when a pointer is moved into a cell's hit test boundaries.* @param callback Callback function that will be called when the event is fired* @returns A disposable object that can be used to unsubscribe from the event*/- onCellPointerOver(callback: (cellPos: Nullable<IHoverCellPosition>) => void): IDisposable {- return toDisposable(this._hoverManagerService.currentCell$.subscribe(callback));- }+ onCellPointerOver(callback: (cellPos: Nullable<IHoverCellPosition>) => void): IDisposable;/*** The onCellDragOver event is fired when an element or text selection is being dragged into a cell's hit test boundaries.* @param callback Callback function that will be called when the event is fired* @returns A disposable object that can be used to unsubscribe from the event*/- onCellDragOver(callback: (cellPos: Nullable<IDragCellPosition>) => void): IDisposable {- return toDisposable(this._dragManagerService.currentCell$.subscribe(callback));- }+ onCellDragOver(callback: (cellPos: Nullable<IDragCellPosition>) => void): IDisposable;/*** The onCellDrop event is fired when an element or text selection is being dropped on the cell.* @param callback Callback function that will be called when the event is fired* @returns A disposable object that can be used to unsubscribe from the event*/- onCellDrop(callback: (cellPos: Nullable<IDragCellPosition>) => void): IDisposable {- return toDisposable(this._dragManagerService.endCell$.subscribe(callback));+ onCellDrop(callback: (cellPos: Nullable<IDragCellPosition>) => void): IDisposable;++ /**+ * The onCellRender event is fired when a cell is rendered.+ * @param customRender Custom render function+ * @param effect The effect of the interceptor+ * @param priority The priority of the interceptor+ * @returns A disposable object that can be used to unsubscribe from the event+ */+ onCellRender(customRender: Nullable<ICellCustomRender[]>, effect?: InterceptorEffectEnum, priority?: number): IDisposable;++ /**+ * The onBeforeCellEdit event is fired before a cell is edited.+ * @param callback Callback function that will be called when the event is fired+ * @returns A disposable object that can be used to unsubscribe from the event+ */+ onBeforeCellEdit(callback: (params: IEditorBridgeServiceVisibleParam) => void): IDisposable;++ /**+ * The onAfterCellEdit event is fired after a cell is edited.+ * @param callback Callback function that will be called when the event is fired+ * @returns A disposable object that can be used to unsubscribe from the event+ */+ onAfterCellEdit(callback: (params: IEditorBridgeServiceVisibleParam) => void): IDisposable;+}++class FSheetHooksUIMixin extends FSheetHooks implements IFSheetHooksUIMixin {+ override onCellPointerMove(callback: (cellPos: Nullable<IHoverCellPosition>) => void): IDisposable {+ return toDisposable(this._injector.get(HoverManagerService).currentPosition$.subscribe(callback));+ }++ override onCellPointerOver(callback: (cellPos: Nullable<IHoverCellPosition>) => void): IDisposable {+ return toDisposable(this._injector.get(HoverManagerService).currentCell$.subscribe(callback));+ }++ override onCellDragOver(callback: (cellPos: Nullable<IDragCellPosition>) => void): IDisposable {+ return toDisposable(this._injector.get(DragManagerService).currentCell$.subscribe(callback));+ }++ override onCellDrop(callback: (cellPos: Nullable<IDragCellPosition>) => void): IDisposable {+ return toDisposable(this._injector.get(DragManagerService).endCell$.subscribe(callback));}++ override onCellRender(customRender: Nullable<ICellCustomRender[]>, effect: InterceptorEffectEnum = InterceptorEffectEnum.Style, priority: number = InterceptCellContentPriority.DATA_VALIDATION): IDisposable {+ return this._injector.get(SheetInterceptorService).intercept(INTERCEPTOR_POINT.CELL_CONTENT, {+ effect,+ handler: (cell, pos, next) => {+ return next({+ ...cell,+ customRender: [+ ...(cell?.customRender || []),+ ...(customRender || []),+ ],+ });+ },+ priority,+ });+ }++ override onBeforeCellEdit(callback: (params: IEditorBridgeServiceVisibleParam) => void): IDisposable {+ return this._injector.get(ICommandService).beforeCommandExecuted((command) => {+ const params = command.params as IEditorBridgeServiceVisibleParam;+ if (command.id === SetCellEditVisibleOperation.id && params.visible) {+ callback(params);+ }+ });+ }++ override onAfterCellEdit(callback: (params: IEditorBridgeServiceVisibleParam) => void): IDisposable {+ return this._injector.get(ICommandService).onCommandExecuted((command) => {+ const params = command.params as IEditorBridgeServiceVisibleParam;+ if (command.id === SetCellEditVisibleOperation.id && !params.visible) {+ callback(params);+ }+ });+ }+}++FSheetHooks.extend(FSheetHooksUIMixin);+declare module '@univerjs/sheets/facade' {+ // eslint-disable-next-line ts/naming-convention+ interface FSheetHooks extends IFSheetHooksUIMixin {}}diff --git a/packages/sheets-ui/src/facade/f-univer.ts b/packages/sheets-ui/src/facade/f-univer.tsindex a0159c2eb8..5fc30a7dd7 100644--- a/packages/sheets-ui/src/facade/f-univer.ts+++ b/packages/sheets-ui/src/facade/f-univer.ts@@ -26,8 +26,8 @@ import type {} from '@univerjs/engine-render';import { FUniver, toDisposable } from '@univerjs/core';import { IRenderManagerService } from '@univerjs/engine-render';+import { FSheetHooks } from '@univerjs/sheets/facade';import { SHEET_VIEW_KEY } from '@univerjs/sheets-ui';-import '@univerjs/sheets/facade';interface IFUniverSheetsUIMixin {/**@@ -76,6 +76,13 @@ interface IFUniverSheetsUIMixin {* @returns {IDisposable} The disposable instance.*/registerSheetMainExtension(unitId: string, ...extensions: SheetExtension[]): IDisposable;++ /**+ * Get sheet hooks.+ *+ * @returns {FSheetHooks} FSheetHooks instance+ */+ getSheetHooks(): FSheetHooks;}export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMixin {@@ -144,7 +151,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMixconst renderManagerService = this._injector.get(IRenderManagerService);const render = renderManagerService.getRenderById(unitId);if (!render) {- throw new Error('Render not found');+ throw new Error(`Render Unit with unitId ${unitId} not found`);}const { components } = render;@@ -156,6 +163,15 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMixreturn renderComponent;}++ /**+ * Get sheet hooks.+ *+ * @returns {FSheetHooks} FSheetHooks instance+ */+ override getSheetHooks(): FSheetHooks {+ return this._injector.createInstance(FSheetHooks);+ }}FUniver.extend(FUniverSheetsUIMixin);diff --git a/packages/sheets-ui/src/facade/f-worksheet.ts b/packages/sheets-ui/src/facade/f-worksheet.tsnew file mode 100644index 0000000000..1e8323ec93--- /dev/null+++ b/packages/sheets-ui/src/facade/f-worksheet.ts@@ -0,0 +1,55 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { IRenderManagerService } from '@univerjs/engine-render';+import { FWorksheet } from '@univerjs/sheets/facade';+import { SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';++interface IFWorksheetSkeletonMixin {++ /**+ * Refresh the canvas.+ */+ refreshCanvas(): void;+}++class FWorksheetSkeletonMixin extends FWorksheet implements IFWorksheetSkeletonMixin {+ override refreshCanvas(): void {+ const renderManagerService = this._injector.get(IRenderManagerService);+ const unitId = this._fWorkbook.id;+ const render = renderManagerService.getRenderById(unitId);++ if (!render) {+ throw new Error(`Render Unit with unitId ${unitId} not found`);+ }++ render.with(SheetSkeletonManagerService).reCalculate();++ const mainComponent = render.mainComponent;++ if (!mainComponent) {+ throw new Error('Main component not found');+ }++ mainComponent.makeDirty();+ }+}++FWorksheet.extend(FWorksheetSkeletonMixin);+declare module '@univerjs/sheets/facade' {+ // eslint-disable-next-line ts/naming-convention+ interface FWorksheet extends IFWorksheetSkeletonMixin {}+}diff --git a/packages/sheets-ui/src/facade/index.ts b/packages/sheets-ui/src/facade/index.tsindex 209462782a..eb2ceaaef9 100644--- a/packages/sheets-ui/src/facade/index.ts+++ b/packages/sheets-ui/src/facade/index.ts@@ -16,7 +16,8 @@import './f-univer';import './f-workbook';+import './f-worksheet';import './f-permission';+import './f-sheet-hooks';export { type IFComponentKey, transformComponentKey } from './f-range';-export { FSheetHooks } from './f-sheet-hooks';diff --git a/packages/sheets/src/facade/f-sheet-hooks.ts b/packages/sheets/src/facade/f-sheet-hooks.tsnew file mode 100644index 0000000000..c0b70ea111--- /dev/null+++ b/packages/sheets/src/facade/f-sheet-hooks.ts@@ -0,0 +1,25 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { FBase, Inject, Injector } from '@univerjs/core';++export class FSheetHooks extends FBase {+ constructor(+ @Inject(Injector) protected readonly _injector: Injector+ ) {+ super();+ }+}diff --git a/packages/sheets/src/facade/index.ts b/packages/sheets/src/facade/index.tsindex 9f8159f7f1..c799d35b83 100644--- a/packages/sheets/src/facade/index.ts+++ b/packages/sheets/src/facade/index.ts@@ -20,5 +20,6 @@ export { FPermission } from './f-permission';export { FRange } from './f-range';export type { FontLine, FontStyle, FontWeight } from './f-range';export { FSelection } from './f-selection';+export { FSheetHooks } from './f-sheet-hooks';export { FWorkbook } from './f-workbook';export { FWorksheet } from './f-worksheet';