@@ -14,13 +14,13 @@ import {
14
14
TelemetryProvider ,
15
15
} from '@blocksuite/affine-shared/services' ;
16
16
import {
17
- autoScroll ,
18
17
captureEventTarget ,
19
18
type DropResult ,
20
19
getBlockComponentsExcludeSubtrees ,
21
20
getRectByBlockComponent ,
22
21
getScrollContainer ,
23
22
matchFlavours ,
23
+ requestThrottledConnectedFrame ,
24
24
SpecProvider ,
25
25
} from '@blocksuite/affine-shared/utils' ;
26
26
import {
@@ -61,10 +61,6 @@ export type DragBlockPayload = DragPayload<DragBlockEntity, DragFromBlockSuite>;
61
61
export class DragEventWatcher {
62
62
dropIndicator : null | DropIndicator = null ;
63
63
64
- lastDragPoint : Point | null = null ;
65
-
66
- rafID : number = 0 ;
67
-
68
64
get host ( ) {
69
65
return this . widget . host ;
70
66
}
@@ -122,23 +118,22 @@ export class DragEventWatcher {
122
118
123
119
private readonly _cleanup = ( ) => {
124
120
this . _clearDropIndicator ( ) ;
125
- this . clearRaf ( ) ;
126
121
this . widget . hide ( true ) ;
127
122
this . std . selection . setGroup ( 'gfx' , [ ] ) ;
128
123
} ;
129
124
130
- private readonly _onDragMove = (
131
- point : Point ,
132
- payload : DragBlockPayload ,
133
- dropPayload : DropPayload ,
134
- block : BlockComponent
135
- ) => {
136
- this . _createDropIndicator ( ) ;
137
- this . clearRaf ( ) ;
138
- this . rafID = requestAnimationFrame ( ( ) => {
139
- this . _updateDropIndicator ( point , payload , dropPayload , block , true ) ;
140
- } ) ;
141
- } ;
125
+ private readonly _onDragMove = requestThrottledConnectedFrame (
126
+ (
127
+ point : Point ,
128
+ payload : DragBlockPayload ,
129
+ dropPayload : DropPayload ,
130
+ block : BlockComponent
131
+ ) => {
132
+ this . _createDropIndicator ( ) ;
133
+ this . _updateDropIndicator ( point , payload , dropPayload , block ) ;
134
+ } ,
135
+ this . widget
136
+ ) ;
142
137
143
138
/**
144
139
* When dragging, should update indicator position and target drop block id
@@ -220,8 +215,7 @@ export class DragEventWatcher {
220
215
point : Point ,
221
216
dragPayload : DragBlockPayload ,
222
217
dropPayload : DropPayload ,
223
- dropBlock : BlockComponent ,
224
- shouldAutoScroll : boolean = false
218
+ dropBlock : BlockComponent
225
219
) => {
226
220
const closestNoteBlock = dropBlock && getParentNoteBlock ( dropBlock ) ;
227
221
@@ -245,37 +239,8 @@ export class DragEventWatcher {
245
239
}
246
240
247
241
this . lastDragPoint = point ;
248
-
249
- if ( this . mode === 'page' ) {
250
- if ( ! shouldAutoScroll ) return ;
251
-
252
- const scrollContainer = getScrollContainer ( this . widget . rootComponent ) ;
253
- const result = autoScroll ( scrollContainer , point . y ) ;
254
- if ( ! result ) {
255
- this . clearRaf ( ) ;
256
- return ;
257
- }
258
- this . rafID = requestAnimationFrame ( ( ) =>
259
- this . _updateDropIndicator (
260
- point ,
261
- dragPayload ,
262
- dropPayload ,
263
- dropBlock ,
264
- true
265
- )
266
- ) ;
267
- } else {
268
- this . clearRaf ( ) ;
269
- }
270
242
} ;
271
243
272
- clearRaf ( ) {
273
- if ( this . rafID ) {
274
- cancelAnimationFrame ( this . rafID ) ;
275
- this . rafID = 0 ;
276
- }
277
- }
278
-
279
244
private readonly _resetDropResult = ( ) => {
280
245
if ( this . dropIndicator ) this . dropIndicator . rect = null ;
281
246
} ;
@@ -670,6 +635,7 @@ export class DragEventWatcher {
670
635
const widget = this . widget ;
671
636
const std = this . std ;
672
637
const disposables = widget . disposables ;
638
+ const scrollable = getScrollContainer ( this . host ) ;
673
639
674
640
disposables . add (
675
641
std . dnd . draggable < DragBlockEntity > ( {
@@ -718,6 +684,17 @@ export class DragEventWatcher {
718
684
} )
719
685
) ;
720
686
687
+ if ( scrollable ) {
688
+ disposables . add (
689
+ std . dnd . autoScroll < DragBlockEntity > ( {
690
+ element : scrollable ,
691
+ canScroll : ( { source } ) => {
692
+ return source . data . draggable ?. entity ?. type === 'blocks' ;
693
+ } ,
694
+ } )
695
+ ) ;
696
+ }
697
+
721
698
// used to handle drag move and drop
722
699
disposables . add (
723
700
std . dnd . monitor < DragBlockEntity > ( {
0 commit comments