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
feat(sheets): add old sheets api (#4529)
#FF00006c6f2459e837
diff --git a/packages/sheets-ui/src/facade/f-workbook.ts b/packages/sheets-ui/src/facade/f-workbook.tsindex 802457224f..15af481a26 100644--- a/packages/sheets-ui/src/facade/f-workbook.ts+++ b/packages/sheets-ui/src/facade/f-workbook.ts@@ -15,13 +15,13 @@*/import type { IDisposable, Nullable } from '@univerjs/core';-import type { RenderManagerService } from '@univerjs/engine-render';-import type { ICellPosWithEvent, IEditorBridgeServiceVisibleParam, IHoverRichTextInfo, IHoverRichTextPosition, IScrollState, SheetSelectionRenderService } from '@univerjs/sheets-ui';+import type { IMouseEvent, IPointerEvent, RenderManagerService } from '@univerjs/engine-render';+import type { ICellPosWithEvent, IDragCellPosition, IEditorBridgeServiceVisibleParam, IHoverRichTextInfo, IHoverRichTextPosition, IScrollState, SheetSelectionRenderService } from '@univerjs/sheets-ui';import type { ICellEventParam } from './f-event';import { awaitTime, ICommandService, ILogService, toDisposable } from '@univerjs/core';import { DeviceInputEventType, IRenderManagerService } from '@univerjs/engine-render';-import { HoverManagerService, ISheetSelectionRenderService, SetCellEditVisibleOperation, SheetScrollManagerService } from '@univerjs/sheets-ui';+import { DragManagerService, HoverManagerService, ISheetSelectionRenderService, SetCellEditVisibleOperation, SheetScrollManagerService } from '@univerjs/sheets-ui';import { FWorkbook } from '@univerjs/sheets/facade';import { type IDialogPartMethodOptions, IDialogService, type ISidebarMethodOptions, ISidebarService, KeyCode } from '@univerjs/ui';import { filter } from 'rxjs';@@ -53,6 +53,27 @@ export interface IFWorkbookSheetsUIMixin {*/onCellHover(callback: (cell: IHoverRichTextPosition) => void): IDisposable;+ /**+ * @deprecated use `univerAPI.addEvent(univerAPI.Event.CellPointerMove, () => {})` instead+ */+ onCellPointerMove(callback: (cell: ICellPosWithEvent, event: IPointerEvent | IMouseEvent) => void): IDisposable;+ /**+ * @deprecated use `univerAPI.addEvent(univerAPI.Event.CellPointerDown, () => {})` instead+ */+ onCellPointerDown(callback: (cell: ICellPosWithEvent) => void): IDisposable;+ /**+ * @deprecated use `univerAPI.addEvent(univerAPI.Event.CellPointerUp, () => {})` instead+ */+ onCellPointerUp(callback: (cell: ICellPosWithEvent) => void): IDisposable;+ /**+ * @deprecated use `univerAPI.addEvent(univerAPI.Event.DragOver, () => {})` instead+ */+ onDragOver(callback: (cell: IDragCellPosition) => void): IDisposable;+ /**+ * @deprecated use `univerAPI.addEvent(univerAPI.Event.Drop, () => {})` instead+ */+ onDrop(callback: (cell: IDragCellPosition) => void): IDisposable;+/*** Start the editing process* @returns A boolean value@@ -185,6 +206,53 @@ export class FWorkbookSheetsUIMixin extends FWorkbook implements IFWorkbookSheet);}+ override onCellPointerDown(callback: (cell: ICellPosWithEvent) => void): IDisposable {+ const hoverManagerService = this._injector.get(HoverManagerService);+ return toDisposable(+ hoverManagerService.currentPointerDownCell$.subscribe(callback)+ );+ }++ override onCellPointerUp(callback: (cell: ICellPosWithEvent) => void): IDisposable {+ const hoverManagerService = this._injector.get(HoverManagerService);+ return toDisposable(+ hoverManagerService.currentPointerUpCell$.subscribe(callback)+ );+ }++ override onCellPointerMove(callback: (cell: ICellPosWithEvent, event: IPointerEvent | IMouseEvent) => void): IDisposable {+ const hoverManagerService = this._injector.get(HoverManagerService);+ return toDisposable(+ hoverManagerService.currentCellPosWithEvent$+ .pipe(filter((cell) => !!cell))+ .subscribe((cell: ICellPosWithEvent) => {+ callback(cell, cell.event);+ })+ );+ }++ override onDragOver(callback: (cell: IDragCellPosition) => void): IDisposable {+ const dragManagerService = this._injector.get(DragManagerService);+ return toDisposable(+ dragManagerService.currentCell$+ .pipe(filter((cell) => !!cell))+ .subscribe((cell: IDragCellPosition) => {+ callback(cell);+ })+ );+ }++ override onDrop(callback: (cell: IDragCellPosition) => void): IDisposable {+ const dragManagerService = this._injector.get(DragManagerService);+ return toDisposable(+ dragManagerService.endCell$+ .pipe(filter((cell) => !!cell))+ .subscribe((cell: IDragCellPosition) => {+ callback(cell);+ })+ );+ }+override startEditing(): boolean {const commandService = this._injector.get(ICommandService);return commandService.syncExecuteCommand(SetCellEditVisibleOperation.id, {diff --git a/packages/sheets-ui/src/facade/f-worksheet.ts b/packages/sheets-ui/src/facade/f-worksheet.tsindex 2e30989a6b..35547e2091 100644--- a/packages/sheets-ui/src/facade/f-worksheet.ts+++ b/packages/sheets-ui/src/facade/f-worksheet.ts@@ -14,11 +14,11 @@* limitations under the License.*/-import type { IRange, Nullable } from '@univerjs/core';-import type { SpreadsheetSkeleton } from '@univerjs/engine-render';+import type { IDisposable, IRange, Nullable } from '@univerjs/core';+import type { RenderManagerService, SpreadsheetSkeleton } from '@univerjs/engine-render';-import type { IScrollState } from '@univerjs/sheets-ui';-import { ICommandService } from '@univerjs/core';+import type { IScrollState, IViewportScrollState } from '@univerjs/sheets-ui';+import { ICommandService, toDisposable } from '@univerjs/core';import { IRenderManagerService, SHEET_VIEWPORT_KEY, sheetContentViewportKeys } from '@univerjs/engine-render';import { ChangeZoomRatioCommand, SetWorksheetColAutoWidthCommand, SheetScrollManagerService, SheetSkeletonManagerService, SheetsScrollRenderController } from '@univerjs/sheets-ui';import { FWorksheet } from '@univerjs/sheets/facade';@@ -116,6 +116,11 @@ export interface IFWorksheetSkeletonMixin {*/setColumnAutoWidth(columnPosition: number, numColumn: number): FWorksheet;+ /**+ * @deprecated use `univerAPI.addEvent(univerAPI.Event.Scroll, () => {})` instead+ */+ onScroll(callback: (params: Nullable<IViewportScrollState>) => void): IDisposable;+}export class FWorksheetSkeletonMixin extends FWorksheet implements IFWorksheetSkeletonMixin {@@ -212,6 +217,19 @@ export class FWorksheetSkeletonMixin extends FWorksheet implements IFWorksheetSkreturn scrollState || emptyScrollState;}+ override onScroll(callback: (params: Nullable<IViewportScrollState>) => void): IDisposable {+ const unitId = this._workbook.getUnitId();+ const renderManagerService = this._injector.get(IRenderManagerService) as RenderManagerService;+ const scrollManagerService = renderManagerService.getRenderById(unitId)?.with(SheetScrollManagerService);+ if (scrollManagerService) {+ const sub = scrollManagerService.validViewportScrollInfo$.subscribe((params: Nullable<IViewportScrollState>) => {+ callback(params);+ });+ return toDisposable(sub);+ }+ return toDisposable(() => { });+ }+override getSkeleton(): Nullable<SpreadsheetSkeleton> {const service = this._injector.get(IRenderManagerService).getRenderById(this._workbook.getUnitId())?.with(SheetSkeletonManagerService);return service?.getWorksheetSkeleton(this._worksheet.getSheetId())?.skeleton;