1515 */
1616
1717import type { IDisposable , Nullable } from '@univerjs/core' ;
18- import type { RenderManagerService } from '@univerjs/engine-render' ;
19- import type { ICellPosWithEvent , IEditorBridgeServiceVisibleParam , IHoverRichTextInfo , IHoverRichTextPosition , IScrollState , SheetSelectionRenderService } from '@univerjs/sheets-ui' ;
18+ import type { IMouseEvent , IPointerEvent , RenderManagerService } from '@univerjs/engine-render' ;
19+ import type { ICellPosWithEvent , IDragCellPosition , IEditorBridgeServiceVisibleParam , IHoverRichTextInfo , IHoverRichTextPosition , IScrollState , SheetSelectionRenderService } from '@univerjs/sheets-ui' ;
2020import { awaitTime , ICommandService , ILogService , toDisposable } from '@univerjs/core' ;
2121import { DeviceInputEventType , IRenderManagerService } from '@univerjs/engine-render' ;
22- import { HoverManagerService , ISheetSelectionRenderService , SetCellEditVisibleOperation , SheetScrollManagerService } from '@univerjs/sheets-ui' ;
22+ import { DragManagerService , HoverManagerService , ISheetSelectionRenderService , SetCellEditVisibleOperation , SheetScrollManagerService } from '@univerjs/sheets-ui' ;
2323import { FWorkbook } from '@univerjs/sheets/facade' ;
2424import { type IDialogPartMethodOptions , IDialogService , type ISidebarMethodOptions , ISidebarService , KeyCode } from '@univerjs/ui' ;
2525import { filter } from 'rxjs' ;
26+ import { CellFEventName , type ICellEventParam , type IFSheetsUIEventParamConfig , type IUIEventBase } from './f-event' ;
2627
2728export interface IFWorkbookSheetsUIMixin {
2829 /**
@@ -59,17 +60,21 @@ export interface IFWorkbookSheetsUIMixin {
5960 * Subscribe to pointer move events on workbook. Just like onCellHover, but with event information.
6061 * @param {function(ICellPosWithEvent): any } callback The callback function accept cell location and event.
6162 */
62- onPointerMove ( callback : ( cell : Nullable < ICellPosWithEvent > , buttons : number ) => void ) : IDisposable ;
63+ onCellPointerMove ( callback : ( cell : ICellPosWithEvent , event : IPointerEvent | IMouseEvent ) => void ) : IDisposable ;
6364 /**
6465 * Subscribe to cell pointer down events.
6566 * @param {function(ICellPosWithEvent): any } callback The callback function accept cell location and event.
6667 */
67- onCellPointerDown ( callback : ( cell : Nullable < ICellPosWithEvent > ) => void ) : IDisposable ;
68+ onCellPointerDown ( callback : ( cell : ICellPosWithEvent ) => void ) : IDisposable ;
6869 /**
6970 * Subscribe to cell pointer up events.
7071 * @param {function(ICellPosWithEvent): any } callback The callback function accept cell location and event.
7172 */
72- onCellPointerUp ( callback : ( cell : Nullable < ICellPosWithEvent > ) => void ) : IDisposable ;
73+ onCellPointerUp ( callback : ( cell : ICellPosWithEvent ) => void ) : IDisposable ;
74+
75+ onDragOver ( callback : ( cell : IDragCellPosition ) => void ) : IDisposable ;
76+
77+ onDrop ( callback : ( cell : IDragCellPosition ) => void ) : IDisposable ;
7378
7479 /**
7580 * Start the editing process
@@ -177,12 +182,85 @@ export class FWorkbookSheetsUIMixin extends FWorkbook implements IFWorkbookSheet
177182 logService . warn ( '[FWorkbook]' , `${ name } is deprecated. Please use the function of the same name on "FUniver".` ) ;
178183 }
179184
185+ override addUIEvent ( event : keyof IFSheetsUIEventParamConfig , _callback : ( params : IFSheetsUIEventParamConfig [ typeof event ] ) => void ) : IDisposable {
186+ const worksheet = this . getActiveSheet ( ) ;
187+ const baseParams : IUIEventBase = {
188+ workbook : this ,
189+ worksheet,
190+ } ;
191+
192+ switch ( event ) {
193+ case CellFEventName . CellClicked :
194+ this . onCellClick ( ( cell ) => {
195+ this . fireEvent ( this . Event . CellClicked , {
196+ row : cell . location . row ,
197+ column : cell . location . col ,
198+ ...baseParams ,
199+ } as ICellEventParam ) ;
200+ } ) ;
201+ break ;
202+ case CellFEventName . CellPointerDown :
203+ this . onCellPointerDown ( ( cell ) => {
204+ this . fireEvent ( this . Event . CellPointerDown , this . generateCellParams ( cell ) ) ;
205+ } ) ;
206+ break ;
207+ case CellFEventName . CellPointerUp :
208+ this . onCellPointerUp ( ( cell ) => {
209+ this . fireEvent ( this . Event . CellPointerUp , this . generateCellParams ( cell ) ) ;
210+ } ) ;
211+ break ;
212+ case CellFEventName . CellPointerMove :
213+ this . onCellPointerMove ( ( cell ) => {
214+ this . fireEvent ( this . Event . CellPointerMove , this . generateCellParams ( cell ) ) ;
215+ } ) ;
216+ break ;
217+ case CellFEventName . CellHover :
218+ this . onCellHover ( ( cell ) => {
219+ this . fireEvent ( this . Event . CellHover , this . generateCellParams ( cell ) ) ;
220+ } ) ;
221+ break ;
222+ case CellFEventName . DragOver :
223+ this . onDragOver ( ( cell ) => {
224+ this . fireEvent ( this . Event . DragOver , {
225+ row : cell . location . row ,
226+ column : cell . location . col ,
227+ ...baseParams ,
228+ } ) ;
229+ } ) ;
230+ break ;
231+ case CellFEventName . Drop :
232+ this . onDrop ( ( cell ) => {
233+ this . fireEvent ( this . Event . Drop , {
234+ row : cell . location . row ,
235+ column : cell . location . col ,
236+ ...baseParams ,
237+ } ) ;
238+ } ) ;
239+ }
240+
241+ return toDisposable ( ( ) => {
242+ //
243+ } ) ;
244+ }
245+
246+ generateCellParams ( cell : IHoverRichTextPosition | ICellPosWithEvent ) : ICellEventParam {
247+ const worksheet = this . getActiveSheet ( ) ;
248+ return {
249+ row : cell . row ,
250+ column : cell . col ,
251+ workbook : this ,
252+ worksheet,
253+ } ;
254+ }
255+
180256 override onCellClick ( callback : ( cell : IHoverRichTextInfo ) => void ) : IDisposable {
181257 const hoverManagerService = this . _injector . get ( HoverManagerService ) ;
182258 return toDisposable (
183259 hoverManagerService . currentClickedCell$
184260 . pipe ( filter ( ( cell ) => ! ! cell ) )
185- . subscribe ( callback )
261+ . subscribe ( ( cell ) => {
262+ callback ( cell ) ;
263+ } )
186264 ) ;
187265 }
188266
@@ -195,27 +273,49 @@ export class FWorkbookSheetsUIMixin extends FWorkbook implements IFWorkbookSheet
195273 ) ;
196274 }
197275
198- override onCellPointerDown ( callback : ( cell : Nullable < ICellPosWithEvent > ) => void ) : IDisposable {
276+ override onCellPointerDown ( callback : ( cell : ICellPosWithEvent ) => void ) : IDisposable {
199277 const hoverManagerService = this . _injector . get ( HoverManagerService ) ;
200278 return toDisposable (
201279 hoverManagerService . currentPointerDownCell$ . subscribe ( callback )
202280 ) ;
203281 }
204282
205- override onCellPointerUp ( callback : ( cell : Nullable < ICellPosWithEvent > ) => void ) : IDisposable {
283+ override onCellPointerUp ( callback : ( cell : ICellPosWithEvent ) => void ) : IDisposable {
206284 const hoverManagerService = this . _injector . get ( HoverManagerService ) ;
207285 return toDisposable (
208286 hoverManagerService . currentPointerUpCell$ . subscribe ( callback )
209287 ) ;
210288 }
211289
212- override onPointerMove ( callback : ( cell : Nullable < ICellPosWithEvent > , buttons : number ) => void ) : IDisposable {
290+ override onCellPointerMove ( callback : ( cell : ICellPosWithEvent , event : IPointerEvent | IMouseEvent ) => void ) : IDisposable {
213291 const hoverManagerService = this . _injector . get ( HoverManagerService ) ;
214292 return toDisposable (
215293 hoverManagerService . currentCellPosWithEvent$
216294 . pipe ( filter ( ( cell ) => ! ! cell ) )
217295 . subscribe ( ( cell : ICellPosWithEvent ) => {
218- callback ( cell , cell . event . buttons ) ;
296+ callback ( cell , cell . event ) ;
297+ } )
298+ ) ;
299+ }
300+
301+ override onDragOver ( callback : ( cell : IDragCellPosition ) => void ) : IDisposable {
302+ const dragManagerService = this . _injector . get ( DragManagerService ) ;
303+ return toDisposable (
304+ dragManagerService . currentCell$
305+ . pipe ( filter ( ( cell ) => ! ! cell ) )
306+ . subscribe ( ( cell : IDragCellPosition ) => {
307+ callback ( cell ) ;
308+ } )
309+ ) ;
310+ }
311+
312+ override onDrop ( callback : ( cell : IDragCellPosition ) => void ) : IDisposable {
313+ const dragManagerService = this . _injector . get ( DragManagerService ) ;
314+ return toDisposable (
315+ dragManagerService . endCell$
316+ . pipe ( filter ( ( cell ) => ! ! cell ) )
317+ . subscribe ( ( cell : IDragCellPosition ) => {
318+ callback ( cell ) ;
219319 } )
220320 ) ;
221321 }
0 commit comments