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(facade): sheets event facade (#4485)
zhangwbd9da5d00511
diff --git a/packages/sheets-ui/src/facade/f-univer.ts b/packages/sheets-ui/src/facade/f-univer.tsindex b6e62dd8fb..83f5b52859 100644--- a/packages/sheets-ui/src/facade/f-univer.ts+++ b/packages/sheets-ui/src/facade/f-univer.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { DocumentDataModel, IDisposable, Injector, IRange, Nullable, Workbook } from '@univerjs/core';+import type { DocumentDataModel, IDisposable, Injector, Nullable } from '@univerjs/core';import type { IRichTextEditingMutationParams } from '@univerjs/docs';import type {IColumnsHeaderCfgParam,@@ -26,16 +26,15 @@ import type {SpreadsheetRowHeader,} from '@univerjs/engine-render';import type { IEditorBridgeServiceVisibleParam, ISheetPasteByShortKeyParams, IViewportScrollState } from '@univerjs/sheets-ui';-import type { FWorksheet } from '@univerjs/sheets/facade';-import type { IBeforeClipboardChangeParam, IBeforeClipboardPasteParam, IBeforeSheetEditEndEventParams, IBeforeSheetEditStartEventParams, ICellEventParam, IScrollEventParam, ISheetEditChangingEventParams, ISheetEditEndedEventParams, ISheetEditStartedEventParams } from './f-event';-import { CanceledError, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, FUniver, ICommandService, ILogService, IUniverInstanceService, LifecycleService, LifecycleStages, RichTextValue, toDisposable } from '@univerjs/core';+import type { IBeforeClipboardChangeParam, IBeforeClipboardPasteParam, IBeforeSheetEditEndEventParams, IBeforeSheetEditStartEventParams, ISheetEditChangingEventParams, ISheetEditEndedEventParams, ISheetEditStartedEventParams } from './f-event';+import { CanceledError, DisposableCollection, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, FUniver, ICommandService, ILogService, IUniverInstanceService, LifecycleService, LifecycleStages, RichTextValue, toDisposable, UniverInstanceType } from '@univerjs/core';import { RichTextEditingMutation } from '@univerjs/docs';import { IRenderManagerService } from '@univerjs/engine-render';-import { UniverType } from '@univerjs/protocol';-import { IEditorBridgeService, ISheetClipboardService, SetCellEditVisibleOperation, SHEET_VIEW_KEY, SheetPasteShortKeyCommand } from '@univerjs/sheets-ui';-import { FSheetHooks, FWorkbook } from '@univerjs/sheets/facade';+import { SheetsSelectionsService } from '@univerjs/sheets';+import { DragManagerService, HoverManagerService, IEditorBridgeService, ISheetClipboardService, SetCellEditVisibleOperation, SHEET_VIEW_KEY, SheetPasteShortKeyCommand, SheetScrollManagerService } from '@univerjs/sheets-ui';+import { FSheetHooks } from '@univerjs/sheets/facade';import { CopyCommand, CutCommand, HTML_CLIPBOARD_MIME_TYPE, IClipboardInterfaceService, KeyCode, PasteCommand, PLAIN_TEXT_CLIPBOARD_MIME_TYPE, supportClipboardAPI } from '@univerjs/ui';-import { combineLatest } from 'rxjs';+import { combineLatest, filter } from 'rxjs';export interface IFUniverSheetsUIMixin {/**@@ -217,95 +216,202 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMixconst unitId = unitM?.getUnitId();const renderManagerService = injector.get(IRenderManagerService);if (unitId) {- const lifeCycleService = this._injector.get(LifecycleService);-- let workbook: Nullable<FWorkbook>;- let worksheet: Nullable<FWorksheet>;-- const combined$ = combineLatest([lifeCycleService.lifecycle$, renderManagerService.created$]);- combined$.subscribe(([lifecycle, r]) => {- if (r.type === UniverType.UNIVER_SHEET) {- if (r.getRenderContext) {- const wb = r.getRenderContext()?.unit as Workbook;- if (wb) {- workbook = this._injector.createInstance(FWorkbook, wb);- }- }-- worksheet = workbook?.getActiveSheet();- }+ const lifeCycleService = injector.get(LifecycleService);++ const disposable = new DisposableCollection();+ const combined$ = combineLatest([+ renderManagerService.created$,+ lifeCycleService.lifecycle$,+ ]);+ const unitMap = new Map<string, IDisposable>();+ // eslint-disable-next-line max-lines-per-function+ this.disposeWithMe(lifeCycleService.lifecycle$.subscribe((lifecycle) => {if (lifecycle < LifecycleStages.Rendered) return;-- if (!workbook || !worksheet) return;- const baseParams = {- workbook,- worksheet,- };-- workbook.onScroll((params: Nullable<IViewportScrollState>) => {+ disposable.dispose();+ const hoverManagerService = injector.get(HoverManagerService);+ const dragManagerService = injector.get(DragManagerService);+ if (!hoverManagerService) return;+ disposable.add(+ hoverManagerService.currentClickedCell$+ .pipe(filter((cell) => !!cell))+ .subscribe((cell) => {+ if (!this._eventListend(this.Event.CellClicked)) return;+ const baseParams = this.getSheetTarget(cell.location.unitId, cell.location.subUnitId);+ if (!baseParams) return;+ this.fireEvent(this.Event.CellClicked, {+ ...baseParams,+ ...cell,+ row: cell.location.row,+ column: cell.location.col,+ });+ })+ );++ disposable.add(+ hoverManagerService.currentRichText$?.pipe(filter((cell) => !!cell))+ .subscribe((cell) => {+ if (!this._eventListend(this.Event.CellHover)) return;+ const baseParams = this.getSheetTarget(cell.unitId, cell.subUnitId);+ if (!baseParams) return;+ this.fireEvent(this.Event.CellHover, {+ ...baseParams,+ ...cell,+ row: cell.row,+ column: cell.col,+ });+ })+ );++ disposable.add(+ hoverManagerService.currentPointerDownCell$?.pipe(filter((cell) => !!cell))+ .subscribe((cell) => {+ if (!this._eventListend(this.Event.CellPointerDown)) return;+ const baseParams = this.getSheetTarget(cell.unitId, cell.subUnitId);+ if (!baseParams) return;+ this.fireEvent(this.Event.CellPointerDown, {+ ...baseParams,+ ...cell,+ row: cell.row,+ column: cell.col,+ });+ })+ );++ disposable.add(+ hoverManagerService.currentPointerUpCell$?.pipe(filter((cell) => !!cell))+ .subscribe((cell) => {+ if (!this._eventListend(this.Event.CellPointerUp)) return;+ const baseParams = this.getSheetTarget(cell.unitId, cell.subUnitId);+ if (!baseParams) return;+ this.fireEvent(this.Event.CellPointerUp, {+ ...baseParams,+ ...cell,+ row: cell.row,+ column: cell.col,+ });+ })+ );++ disposable.add(+ hoverManagerService.currentCellPosWithEvent$?.pipe(filter((cell) => !!cell))+ .subscribe((cell) => {+ if (!this._eventListend(this.Event.CellPointerMove)) return;+ const baseParams = this.getSheetTarget(cell.unitId, cell.subUnitId);+ if (!baseParams) return;+ this.fireEvent(this.Event.CellPointerMove, {+ ...baseParams,+ ...cell,+ row: cell.row,+ column: cell.col,+ });+ })+ );++ disposable.add(+ dragManagerService.currentCell$+ .pipe(filter((cell) => !!cell))+ .subscribe((cell) => {+ if (!this._eventListend(this.Event.DragOver)) return;+ const baseParams = this.getSheetTarget(cell.location.unitId, cell.location.subUnitId);+ if (!baseParams) return;+ this.fireEvent(this.Event.DragOver, {+ ...baseParams,+ ...cell,+ row: cell.location.row,+ column: cell.location.col,+ });+ })+ );++ disposable.add(+ dragManagerService.endCell$+ .pipe(filter((cell) => !!cell))+ .subscribe((cell) => {+ if (!this._eventListend(this.Event.Drop)) return;+ const baseParams = this.getSheetTarget(cell.location.unitId, cell.location.subUnitId);+ if (!baseParams) return;+ this.fireEvent(this.Event.Drop, {+ ...baseParams,+ ...cell,+ row: cell.location.row,+ column: cell.location.col,+ });+ })+ );+ }));++ this.disposeWithMe(disposable);++ this.disposeWithMe(combined$.subscribe(([created, lifecycle]) => {+ if (lifecycle < LifecycleStages.Rendered) return;+ if (created.type !== UniverInstanceType.UNIVER_SHEET) return;+ const disposable = new DisposableCollection();+ const workbook = this.getWorkbook(created.unitId);+ if (unitMap.get(created.unitId)) {+ unitMap.get(created.unitId)?.dispose();+ }+ unitMap.set(created.unitId, disposable);+ if (!workbook) return;+ const scrollManagerService = created.with(SheetScrollManagerService);+ disposable.add(scrollManagerService.validViewportScrollInfo$.subscribe((params: Nullable<IViewportScrollState>) => {+ if (!params) return;+ if (!this._eventListend(this.Event.Scroll)) return;this.fireEvent(this.Event.Scroll, {- scrollX: params?.viewportScrollX,- scrollY: params?.viewportScrollY,- ...baseParams,- } as IScrollEventParam);- });- workbook.onCellClick((cell) => {- this.fireEvent(this.Event.CellClicked, {- row: cell.location.row,- column: cell.location.col,- ...baseParams,- } as ICellEventParam);- });-- workbook.onDrop((cell) => {- this.fireEvent(this.Event.Drop, {- row: cell.location.row,- column: cell.location.col,- ...baseParams,+ workbook,+ worksheet: workbook.getActiveSheet(),+ ...params,});- });+ }));- workbook.onSelectionMoveStart((selections: IRange[]) => {+ const selectionService = created.with(SheetsSelectionsService);+ disposable.add(selectionService.selectionMoveStart$.subscribe((selections) => {+ if (!this._eventListend(this.Event.SelectionMoveStart)) return;this.fireEvent(this.Event.SelectionMoveStart, {- selections,- ...baseParams,- });- });-- workbook.onSelectionMoving((selections: IRange[]) => {- this.fireEvent(this.Event.SelectionMoving, {- selections,- ...baseParams,+ workbook,+ worksheet: workbook.getActiveSheet(),+ selections: selections?.map((s) => s.range) ?? [],});- });+ }));- workbook.onSelectionMoving((selections: IRange[]) => {+ disposable.add(selectionService.selectionMoving$.subscribe((selections) => {+ if (!this._eventListend(this.Event.SelectionMoving)) return;this.fireEvent(this.Event.SelectionMoving, {- selections,- ...baseParams,+ workbook,+ worksheet: workbook.getActiveSheet(),+ selections: selections?.map((s) => s.range) ?? [],});- });+ }));- workbook.onSelectionMoveEnd((selections: IRange[]) => {+ disposable.add(selectionService.selectionMoveEnd$.subscribe((selections) => {+ if (!this._eventListend(this.Event.SelectionMoveEnd)) return;this.fireEvent(this.Event.SelectionMoveEnd, {- selections,- ...baseParams,+ workbook,+ worksheet: workbook.getActiveSheet(),+ selections: selections?.map((s) => s.range) ?? [],});- });+ }));- workbook.onSelectionChanged((selections: IRange[]) => {+ disposable.add(selectionService.selectionChanged$.subscribe((selections) => {+ if (!this._eventListend(this.Event.SelectionChanged)) return;this.fireEvent(this.Event.SelectionChanged, {- selections,- ...baseParams,+ workbook,+ worksheet: workbook.getActiveSheet(),+ selections: selections?.map((s) => s.range) ?? [],});+ }));+ }));++ this.disposeWithMe(renderManagerService.disposed$.subscribe((unitId) => {+ unitMap.get(unitId)?.dispose();+ unitMap.delete(unitId);+ }));++ this.disposeWithMe(() => {+ unitMap.forEach((disposable) => {+ disposable.dispose();});});}-- // too late!- // univerInstanceService.unitAdded$.subscribe((p) => {- // console.log('univer ins add', p.getUnitId());- // });}override _initialize(injector: Injector): void {diff --git a/packages/sheets-ui/src/facade/f-workbook.ts b/packages/sheets-ui/src/facade/f-workbook.tsindex 8eadf17a57..802457224f 100644--- a/packages/sheets-ui/src/facade/f-workbook.ts+++ b/packages/sheets-ui/src/facade/f-workbook.ts@@ -14,19 +14,17 @@* limitations under the License.*/-import type { IDisposable, IRange, Nullable } from '@univerjs/core';-import type { IMouseEvent, IPointerEvent, RenderManagerService } from '@univerjs/engine-render';-import type { ICellPosWithEvent, IDragCellPosition, IEditorBridgeServiceVisibleParam, IHoverRichTextInfo, IHoverRichTextPosition, IScrollState, IViewportScrollState, SheetSelectionRenderService } from '@univerjs/sheets-ui';+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 { ICellEventParam, IFSheetsUIEventParamConfig, IScrollEventParam, ISheetUIEventBase } from './f-event';+import type { ICellEventParam } from './f-event';import { awaitTime, ICommandService, ILogService, toDisposable } from '@univerjs/core';import { DeviceInputEventType, IRenderManagerService } from '@univerjs/engine-render';-import { SheetsSelectionsService } from '@univerjs/sheets';-import { DragManagerService, HoverManagerService, ISheetSelectionRenderService, SetCellEditVisibleOperation, SheetScrollManagerService } from '@univerjs/sheets-ui';+import { 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';-import { CellFEventName } from './f-event';export interface IFWorkbookSheetsUIMixin {/**@@ -46,39 +44,15 @@ export interface IFWorkbookSheetsUIMixin {openDialog(dialog: IDialogPartMethodOptions): IDisposable;/**- * Subscribe to cell click events- * @param callback - The callback function to be called when a cell is clicked- * @returns A disposable object that can be used to unsubscribe from the event+ * @deprecated use `univerAPI.addEvent(univerAPI.Event.CellClick, () => {})` instead*/onCellClick(callback: (cell: IHoverRichTextInfo) => void): IDisposable;/**- * Subscribe cell hover events- * @param callback - The callback function to be called when a cell is hovered- * @returns A disposable object that can be used to unsubscribe from the event+ * @deprecated use `univerAPI.addEvent(univerAPI.Event.CellHover, () => {})` instead*/onCellHover(callback: (cell: IHoverRichTextPosition) => void): IDisposable;- /**- * Subscribe to pointer move events on workbook. Just like onCellHover, but with event information.- * @param {function(ICellPosWithEvent): any} callback The callback function accept cell location and event.- */- onCellPointerMove(callback: (cell: ICellPosWithEvent, event: IPointerEvent | IMouseEvent) => void): IDisposable;- /**- * Subscribe to cell pointer down events.- * @param {function(ICellPosWithEvent): any} callback The callback function accept cell location and event.- */- onCellPointerDown(callback: (cell: ICellPosWithEvent) => void): IDisposable;- /**- * Subscribe to cell pointer up events.- * @param {function(ICellPosWithEvent): any} callback The callback function accept cell location and event.- */- onCellPointerUp(callback: (cell: ICellPosWithEvent) => void): IDisposable;-- onDragOver(callback: (cell: IDragCellPosition) => void): IDisposable;-- onDrop(callback: (cell: IDragCellPosition) => void): IDisposable;-/*** Start the editing process* @returns A boolean value@@ -90,23 +64,19 @@ export interface IFWorkbookSheetsUIMixin {startEditing(): boolean;/**- * Use endEditingAsync as instead- * @deprecated- * End the editing process- * @async- * @param save - Whether to save the changes- * @returns A promise that resolves to a boolean value- * @example- * ``` ts- * univerAPI.getActiveWorkbook().endEditing(true);- * ```+ * @deprecated Use `endEditingAsync` as instead*/endEditing(save?: boolean): Promise<boolean>;/*** @async+ * End the editing process* @param {boolean} save - Whether to save the changes, default is true* @returns {Promise<boolean>} A promise that resolves to a boolean value+ * @example+ * ```ts+ * await univerAPI.getActiveWorkbook().endEditingAsync(false);+ * ```*/endEditingAsync(save?: boolean): Promise<boolean>;/*@@ -155,57 +125,6 @@ export interface IFWorkbookSheetsUIMixin {* ```*/showSelection(): FWorkbook;-- /**- * Invoked when scrolling the sheet.- * @param {function(Nullable<IViewportScrollState>): void} callback The scrolling callback function.- * @returns {IDisposable} The disposable object to remove the event listener.- * @example- * ``` ts- * univerAPI.getActiveWorkbook().onScroll((params) => {...})- * ```- */- onScroll(callback: (params: Nullable<IViewportScrollState>) => void): Nullable<IDisposable>;-- /**- * Invoked when the start a selection by mouse/pointer down event.- * @param callback- * @example- * ``` ts- * univerAPI.getActiveWorkbook().onSelectionMoveStart((params) => {...})- * ```- */- onSelectionMoveStart(callback: (params: IRange[]) => void): Nullable<IDisposable>;-- /**- * Invoked when moving cursor to adjust selection by mouse/pointer event.- * @param callback- * @example- * ``` ts- * univerAPI.getActiveWorkbook().onSelectionMoveMoving((params) => {...})- * ```- */- onSelectionMoving(callback: (params: IRange[]) => void): Nullable<IDisposable>;-- /**- * Invoked when end a selection by mouse/pointer up event.- * @param callback- * @example- * ``` ts- * univerAPI.getActiveWorkbook().onSelectionMoveEnd((params) => {...})- * ```- */- onSelectionMoveEnd(callback: (params: IRange[]) => void): Nullable<IDisposable>;-- /**- * Invoked when the selection is changed.- * @param callback- * @example- * ``` ts- * univerAPI.getActiveWorkbook().onSelectionChanged((params) => {...})- * ```- */- onSelectionChanged(callback: (params: IRange[]) => void): Nullable<IDisposable>;}export class FWorkbookSheetsUIMixin extends FWorkbook implements IFWorkbookSheetsUIMixin {@@ -236,113 +155,6 @@ export class FWorkbookSheetsUIMixin extends FWorkbook implements IFWorkbookSheetlogService.warn('[FWorkbook]', `${name} is deprecated. Please use the function of the same name on "FUniver".`);}- // eslint-disable-next-line max-lines-per-function- override addUIEvent(event: keyof IFSheetsUIEventParamConfig, _callback: (params: IFSheetsUIEventParamConfig[typeof event]) => void): IDisposable {- const worksheet = this.getActiveSheet();- const baseParams: ISheetUIEventBase = {- workbook: this,- worksheet,- };-- switch (event) {- case CellFEventName.CellClicked:- this.onCellClick((cell) => {- this.fireEvent(this.Event.CellClicked, {- row: cell.location.row,- column: cell.location.col,- ...baseParams,- } as ICellEventParam);- });- break;- case CellFEventName.CellPointerDown:- this.onCellPointerDown((cell) => {- this.fireEvent(this.Event.CellPointerDown, this.generateCellParams(cell));- });- break;- case CellFEventName.CellPointerUp:- this.onCellPointerUp((cell) => {- this.fireEvent(this.Event.CellPointerUp, this.generateCellParams(cell));- });- break;- case CellFEventName.CellPointerMove:- this.onCellPointerMove((cell) => {- this.fireEvent(this.Event.CellPointerMove, this.generateCellParams(cell));- });- break;- case CellFEventName.CellHover:- this.onCellHover((cell) => {- this.fireEvent(this.Event.CellHover, this.generateCellParams(cell));- });- break;- case CellFEventName.DragOver:- this.onDragOver((cell) => {- this.fireEvent(this.Event.DragOver, {- row: cell.location.row,- column: cell.location.col,- ...baseParams,- });- });- break;- case CellFEventName.Drop:- this.onDrop((cell) => {- this.fireEvent(this.Event.Drop, {- row: cell.location.row,- column: cell.location.col,- ...baseParams,- });- });- break;- case CellFEventName.Scroll:- this.onScroll((params: Nullable<IViewportScrollState>) => {- this.fireEvent(this.Event.Scroll, {- scrollX: params?.viewportScrollX,- scrollY: params?.viewportScrollY,- ...baseParams,- } as IScrollEventParam);- });- break;-- case CellFEventName.SelectionMoveStart:- this.onSelectionMoveStart((selections: IRange[]) => {- this.fireEvent(this.Event.SelectionMoveStart, {- selections,- ...baseParams,- });- });- break;-- case CellFEventName.SelectionMoving:- this.onSelectionMoving((selections: IRange[]) => {- this.fireEvent(this.Event.SelectionMoving, {- selections,- ...baseParams,- });- });- break;-- case CellFEventName.SelectionMoveEnd:- this.onSelectionMoveEnd((selections: IRange[]) => {- this.fireEvent(this.Event.SelectionMoveEnd, {- selections,- ...baseParams,- });- });- break;- case CellFEventName.SelectionChanged:- this.onSelectionChanged((selections: IRange[]) => {- this.fireEvent(this.Event.SelectionChanged, {- selections,- ...baseParams,- });- });- break;- }-- return toDisposable(() => {- //- });- }-generateCellParams(cell: IHoverRichTextPosition | ICellPosWithEvent): ICellEventParam {const worksheet = this.getActiveSheet();return {@@ -373,53 +185,6 @@ 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, {@@ -504,86 +269,6 @@ export class FWorkbookSheetsUIMixin extends FWorkbook implements IFWorkbookSheet}return this;}-- override onScroll(callback: (params: Nullable<IViewportScrollState>) => void): Nullable<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);- }- }-- override onSelectionMoveStart(callback: (selections: IRange[]) => void): Nullable<IDisposable> {- const unitId = this._workbook.getUnitId();- const renderManagerService = this._injector.get(IRenderManagerService) as RenderManagerService;- const selectionService = renderManagerService.getRenderById(unitId)?.with(SheetsSelectionsService);- if (selectionService) {- return toDisposable(- this._selectionManagerService.selectionMoveStart$.subscribe((selections) => {- if (!selections?.length) {- callback([]);- } else {- callback(selections!.map((s) => s.range));- }- })- );- }- }-- override onSelectionMoving(callback: (selections: IRange[]) => void): Nullable<IDisposable> {- const unitId = this._workbook.getUnitId();- const renderManagerService = this._injector.get(IRenderManagerService) as RenderManagerService;- const selectionService = renderManagerService.getRenderById(unitId)?.with(SheetsSelectionsService);- if (selectionService) {- return toDisposable(- this._selectionManagerService.selectionMoving$.subscribe((selections) => {- if (!selections?.length) {- callback([]);- } else {- callback(selections!.map((s) => s.range));- }- })- );- }- }-- override onSelectionMoveEnd(callback: (selections: IRange[]) => void): Nullable<IDisposable> {- const unitId = this._workbook.getUnitId();- const renderManagerService = this._injector.get(IRenderManagerService) as RenderManagerService;- const selectionService = renderManagerService.getRenderById(unitId)?.with(SheetsSelectionsService);- if (selectionService) {- return toDisposable(- this._selectionManagerService.selectionMoveEnd$.subscribe((selections) => {- if (!selections?.length) {- callback([]);- } else {- callback(selections!.map((s) => s.range));- }- })- );- }- }-- override onSelectionChanged(callback: (selections: IRange[]) => void): Nullable<IDisposable> {- const unitId = this._workbook.getUnitId();- const renderManagerService = this._injector.get(IRenderManagerService) as RenderManagerService;- const selectionService = renderManagerService.getRenderById(unitId)?.with(SheetsSelectionsService);- if (selectionService) {- return toDisposable(- this._selectionManagerService.selectionChanged$.subscribe((selections) => {- if (!selections?.length) {- callback([]);- } else {- callback(selections!.map((s) => s.range));- }- })- );- }- }}FWorkbook.extend(FWorkbookSheetsUIMixin);diff --git a/packages/sheets/src/facade/f-workbook.ts b/packages/sheets/src/facade/f-workbook.tsindex 4d831b2747..9d1d3bf3cf 100644--- a/packages/sheets/src/facade/f-workbook.ts+++ b/packages/sheets/src/facade/f-workbook.ts@@ -14,11 +14,11 @@* limitations under the License.*/-import type { CommandListener, CustomData, ICommandInfo, IDisposable, IEventParamConfig, IRange, IWorkbookData, LocaleType, Workbook } from '@univerjs/core';+import type { CommandListener, CustomData, ICommandInfo, IDisposable, IEventParamConfig, IRange, IWorkbookData, LocaleType, Registry, Workbook } from '@univerjs/core';import type { ISetDefinedNameMutationParam } from '@univerjs/engine-formula';import type { ISetSelectionsOperationParams, ISheetCommandSharedParams, RangeThemeStyle } from '@univerjs/sheets';import type { FontLine as _FontLine } from './f-range';-import { FBaseInitialable, FEnum, FEventName, ICommandService, ILogService, Inject, Injector, IPermissionService, IResourceLoaderService, IUniverInstanceService, LocaleService, mergeWorksheetSnapshotWithDefault, RedoCommand, Registry, toDisposable, UndoCommand, UniverInstanceType } from '@univerjs/core';+import { FBaseInitialable, ICommandService, ILogService, Inject, Injector, IPermissionService, IResourceLoaderService, IUniverInstanceService, LocaleService, mergeWorksheetSnapshotWithDefault, RedoCommand, toDisposable, UndoCommand, UniverInstanceType } from '@univerjs/core';import { IDefinedNamesService } from '@univerjs/engine-formula';import { CopySheetCommand, getPrimaryForRange, InsertSheetCommand, RegisterWorksheetRangeThemeStyleCommand, RemoveSheetCommand, SCOPE_WORKBOOK_VALUE_DEFINED_NAME, SetDefinedNameCommand, SetSelectionsOperation, SetWorksheetActiveOperation, SetWorksheetOrderCommand, SheetRangeThemeService, SheetsSelectionsService, UnregisterWorksheetRangeThemeStyleCommand, WorkbookEditablePermission } from '@univerjs/sheets';import { FDefinedName, FDefinedNameBuilder } from './f-defined-name';@@ -52,33 +52,6 @@ export class FWorkbook extends FBaseInitialable {private _eventRegistry: Map<string, Registry<(param: any) => void>> = new Map();- private _ensureEventRegistry(event: string): Registry<(param: any) => void> {- if (!this._eventRegistry.has(event)) {- this._eventRegistry.set(event, new Registry());- }-- return this._eventRegistry.get(event)!;- }-- /**- * Add an event listener- * @param event key of event- * @param callback callback when event triggered- * @returns {Disposable} The Disposable instance, for remove the listener- * @example- * ```ts- * univerAPI.addEvent(univerAPI.event.UnitCreated, (params) => {- * console.log('unit created', params);- * });- * ```- */- addEvent(event: keyof IEventParamConfig, callback: (params: IEventParamConfig[typeof event]) => void): IDisposable {- this._ensureEventRegistry(event).add(callback);- this.addUIEvent(event, callback);-- return toDisposable(() => this._ensureEventRegistry(event).delete(callback));- }-/*** Fire an event, used in internal only.* @param event {string} key of event@@ -97,21 +70,6 @@ export class FWorkbook extends FBaseInitialable {return params.cancel;}- addUIEvent(event: keyof IEventParamConfig, _callback: (params: IEventParamConfig[typeof event]) => void): void {- // implementation in sub class.- }-- get Enum(): FEnum {- return FEnum.get();- }-- /**- * @returns {FEventName} The event name.- */- get Event(): FEventName {- return FEventName.get();- }-/*** Get the id of the workbook.* @returns {string} The id of the workbook.diff --git a/packages/sheets/src/facade/f-worksheet.ts b/packages/sheets/src/facade/f-worksheet.tsindex 5f9414bbe2..6775f42651 100644--- a/packages/sheets/src/facade/f-worksheet.ts+++ b/packages/sheets/src/facade/f-worksheet.ts@@ -51,68 +51,6 @@ export class FWorksheet extends FBaseInitialable {return this._worksheet;}- // private _eventRegistry: Map<string, Registry<(param: any) => void>> = new Map();-- // private _ensureEventRegistry(event: string): Registry<(param: any) => void> {- // if (!this._eventRegistry.has(event)) {- // this._eventRegistry.set(event, new Registry());- // }-- // return this._eventRegistry.get(event)!;- // }-- // /**- // * Add an event listener- // * @param event key of event- // * @param callback callback when event triggered- // * @returns {Disposable} The Disposable instance, for remove the listener- // * @example- // * ```ts- // * univerAPI.addEvent(univerAPI.event.UnitCreated, (params) => {- // * console.log('unit created', params);- // * });- // * ```- // */- // addEvent(event: keyof IEventParamConfig, callback: (params: IEventParamConfig[typeof event]) => void): IDisposable {- // this._ensureEventRegistry(event).add(callback);- // this.addUIEvent(event, callback);-- // return toDisposable(() => this._ensureEventRegistry(event).delete(callback));- // }-- // addUIEvent(event: keyof IEventParamConfig, _callback: (params: IEventParamConfig[typeof event]) => void): void {- // // implementation in sub class.- // }-- // /**- // * Fire an event, used in internal only.- // * @param event {string} key of event- // * @param params {any} params of event- // * @returns {boolean} should cancel- // * @example- // * ```ts- // * this.fireEvent(univerAPI.event.UnitCreated, params);- // * ```- // */- // protected fireEvent<T extends keyof IEventParamConfig>(event: T, params: IEventParamConfig[T]): boolean | undefined {- // this._eventRegistry.get(event)?.getData().forEach((callback) => {- // callback(params);- // });-- // return params.cancel;- // }-- // get Enum(): FEnum {- // return FEnum.get();- // }-- // /**- // * @returns {FEventName} The event name.- // */- // get Event(): FEventName {- // return FEventName.get();- // }-/*** Returns the injector* @returns The injector