1
1
import PropTypes from 'prop-types'
2
2
import React from 'react'
3
3
import * as dates from '../../utils/dates'
4
- import { findDOMNode } from 'react-dom'
5
4
import { DnDContext } from './DnDContext'
6
5
7
6
import Selection , {
8
7
getBoundsForNode ,
9
8
getEventNodeFromPoint ,
10
9
} from '../../Selection'
11
10
import TimeGridEvent from '../../TimeGridEvent'
12
- import { dragAccessors } from './common'
11
+ import { dragAccessors , eventTimes , pointInColumn } from './common'
13
12
import NoopWrapper from '../../NoopWrapper'
14
13
15
- const pointInColumn = ( bounds , { x, y } ) => {
16
- const { left, right, top } = bounds
17
- return x < right + 10 && x > left && y > top
18
- }
19
- const propTypes = { }
20
-
21
14
class EventContainerWrapper extends React . Component {
22
15
static propTypes = {
23
16
accessors : PropTypes . object . isRequired ,
@@ -33,6 +26,7 @@ class EventContainerWrapper extends React.Component {
33
26
constructor ( ...args ) {
34
27
super ( ...args )
35
28
this . state = { }
29
+ this . ref = React . createRef ( )
36
30
}
37
31
38
32
componentDidMount ( ) {
@@ -65,43 +59,31 @@ class EventContainerWrapper extends React.Component {
65
59
} )
66
60
}
67
61
68
- handleMove = ( point , boundaryBox ) => {
62
+ handleMove = ( point , bounds ) => {
63
+ if ( ! pointInColumn ( bounds , point ) ) return this . reset ( )
69
64
const { event } = this . context . draggable . dragAndDropAction
70
65
const { accessors, slotMetrics } = this . props
71
66
72
- if ( ! pointInColumn ( boundaryBox , point ) ) {
73
- this . reset ( )
74
- return
75
- }
76
-
77
- let currentSlot = slotMetrics . closestSlotFromPoint (
67
+ const newSlot = slotMetrics . closestSlotFromPoint (
78
68
{ y : point . y - this . eventOffsetTop , x : point . x } ,
79
- boundaryBox
69
+ bounds
80
70
)
81
71
82
- let eventStart = accessors . start ( event )
83
- let eventEnd = accessors . end ( event )
84
- let end = dates . add (
85
- currentSlot ,
86
- dates . diff ( eventStart , eventEnd , 'minutes' ) ,
87
- 'minutes'
88
- )
89
-
90
- this . update ( event , slotMetrics . getRange ( currentSlot , end , false , true ) )
72
+ const { duration } = eventTimes ( event , accessors )
73
+ let newEnd = dates . add ( newSlot , duration , 'milliseconds' )
74
+ this . update ( event , slotMetrics . getRange ( newSlot , newEnd , false , true ) )
91
75
}
92
76
93
- handleResize ( point , boundaryBox ) {
94
- let start , end
77
+ handleResize ( point , bounds ) {
95
78
const { accessors, slotMetrics } = this . props
96
79
const { event, direction } = this . context . draggable . dragAndDropAction
80
+ const newTime = slotMetrics . closestSlotFromPoint ( point , bounds )
97
81
98
- let currentSlot = slotMetrics . closestSlotFromPoint ( point , boundaryBox )
82
+ let { start , end } = eventTimes ( event , accessors )
99
83
if ( direction === 'UP' ) {
100
- end = accessors . end ( event )
101
- start = dates . min ( currentSlot , slotMetrics . closestSlotFromDate ( end , - 1 ) )
84
+ start = dates . min ( newTime , slotMetrics . closestSlotFromDate ( end , - 1 ) )
102
85
} else if ( direction === 'DOWN' ) {
103
- start = accessors . start ( event )
104
- end = dates . max ( currentSlot , slotMetrics . closestSlotFromDate ( start ) )
86
+ end = dates . max ( newTime , slotMetrics . closestSlotFromDate ( start ) )
105
87
}
106
88
107
89
this . update ( event , slotMetrics . getRange ( start , end ) )
@@ -124,10 +106,11 @@ class EventContainerWrapper extends React.Component {
124
106
}
125
107
126
108
_selectable = ( ) => {
127
- let node = findDOMNode ( this )
109
+ let wrapper = this . ref . current
110
+ let node = wrapper . children [ 0 ]
128
111
let isBeingDragged = false
129
112
let selector = ( this . _selector = new Selection ( ( ) =>
130
- node . closest ( '.rbc-time-view' )
113
+ wrapper . closest ( '.rbc-time-view' )
131
114
) )
132
115
133
116
selector . on ( 'beforeSelect' , point => {
@@ -141,6 +124,12 @@ class EventContainerWrapper extends React.Component {
141
124
const eventNode = getEventNodeFromPoint ( node , point )
142
125
if ( ! eventNode ) return false
143
126
127
+ // eventOffsetTop is distance from the top of the event to the initial
128
+ // mouseDown position. We need this later to compute the new top of the
129
+ // event during move operations, since the final location is really a
130
+ // delta from this point. note: if we want to DRY this with WeekWrapper,
131
+ // probably better just to capture the mouseDown point here and do the
132
+ // placement computation in handleMove()...
144
133
this . eventOffsetTop = point . y - getBoundsForNode ( eventNode ) . top
145
134
} )
146
135
@@ -154,19 +143,14 @@ class EventContainerWrapper extends React.Component {
154
143
155
144
selector . on ( 'dropFromOutside' , point => {
156
145
if ( ! this . context . draggable . onDropFromOutside ) return
157
-
158
146
const bounds = getBoundsForNode ( node )
159
-
160
147
if ( ! pointInColumn ( bounds , point ) ) return
161
-
162
148
this . handleDropFromOutside ( point , bounds )
163
149
} )
164
150
165
151
selector . on ( 'dragOver' , point => {
166
152
if ( ! this . context . draggable . dragFromOutsideItem ) return
167
-
168
153
const bounds = getBoundsForNode ( node )
169
-
170
154
this . handleDropFromOutside ( point , bounds )
171
155
} )
172
156
@@ -212,7 +196,7 @@ class EventContainerWrapper extends React.Component {
212
196
this . _selector = null
213
197
}
214
198
215
- render ( ) {
199
+ renderContent ( ) {
216
200
const {
217
201
children,
218
202
accessors,
@@ -223,7 +207,6 @@ class EventContainerWrapper extends React.Component {
223
207
} = this . props
224
208
225
209
let { event, top, height } = this . state
226
-
227
210
if ( ! event ) return children
228
211
229
212
const events = children . props . children
@@ -263,8 +246,10 @@ class EventContainerWrapper extends React.Component {
263
246
) ,
264
247
} )
265
248
}
266
- }
267
249
268
- EventContainerWrapper . propTypes = propTypes
250
+ render ( ) {
251
+ return < div ref = { this . ref } > { this . renderContent ( ) } </ div >
252
+ }
253
+ }
269
254
270
255
export default EventContainerWrapper
0 commit comments