1
1
import { Bookmark , BookmarkFolderID , Position } from './model'
2
2
3
+ type DragState = 'enter' | 'leave'
4
+
3
5
export class Drag {
4
6
readonly bookmark : Bookmark
5
7
readonly from : Position
6
8
readonly to : Position
7
- readonly hover : boolean
9
+ readonly state : DragState
8
10
9
- private constructor ( bookmark : Bookmark , from : Position , to : Position , hover : boolean ) {
11
+ private constructor ( bookmark : Bookmark , from : Position , to : Position , state : DragState ) {
10
12
this . bookmark = bookmark
11
13
this . from = from
12
14
this . to = to
13
- this . hover = hover
15
+ this . state = state
14
16
}
15
17
16
18
static start ( bookmark : Bookmark , from : Position ) {
17
- return new Drag ( bookmark , from , from , true )
19
+ return new Drag ( bookmark , from , from , 'enter' )
18
20
}
19
21
20
22
enterTo ( to : Position ) {
21
- return new Drag ( this . bookmark , this . from , to , true )
23
+ return new Drag ( this . bookmark , this . from , to , 'enter' )
22
24
}
23
25
24
26
leave ( ) {
25
- return new Drag ( this . bookmark , this . from , this . to , false )
27
+ return new Drag ( this . bookmark , this . from , this . to , 'leave' )
26
28
}
27
29
28
30
calculateDestination ( ) : Position {
@@ -37,7 +39,7 @@ export class Drag {
37
39
export type BookmarkWithDragProps = Bookmark & {
38
40
readonly dragFrom ?: true
39
41
readonly dragTo ?: true
40
- readonly hover ?: true
42
+ readonly state ?: DragState
41
43
}
42
44
43
45
export const reorderBookmarks = (
@@ -49,25 +51,25 @@ export const reorderBookmarks = (
49
51
return bookmarks
50
52
}
51
53
54
+ // move the bookmark in the folder
52
55
if ( folderID === drag . from . folderID && drag . from . folderID === drag . to . folderID ) {
53
- // move the bookmark in the folder
54
56
const r : BookmarkWithDragProps [ ] = [ ...bookmarks ]
55
57
r . splice ( drag . from . index , 1 )
56
- r . splice ( drag . to . index , 0 , { ...drag . bookmark , dragFrom : true , dragTo : true , hover : drag . hover || undefined } )
58
+ r . splice ( drag . to . index , 0 , { ...drag . bookmark , dragFrom : true , dragTo : true , state : drag . state } )
57
59
return r
58
60
}
59
61
60
- // when move across the folder, keep the element to receive the dragEnd event
62
+ // move the bookmark across the folders
61
63
if ( folderID === drag . from . folderID ) {
62
64
const r : BookmarkWithDragProps [ ] = [ ...bookmarks ]
65
+ // keep the element to receive the dragEnd event
63
66
r . splice ( drag . from . index , 1 )
64
- r . push ( { ...drag . bookmark , dragFrom : true } )
67
+ r . push ( { ...drag . bookmark , dragFrom : true , state : drag . state } )
65
68
return r
66
69
}
67
-
68
70
if ( folderID === drag . to . folderID ) {
69
71
const r : BookmarkWithDragProps [ ] = [ ...bookmarks ]
70
- r . splice ( drag . to . index , 0 , { ...drag . bookmark , dragTo : true , hover : drag . hover || undefined } )
72
+ r . splice ( drag . to . index , 0 , { ...drag . bookmark , dragTo : true , state : drag . state } )
71
73
return r
72
74
}
73
75
0 commit comments