-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathcommon.js
46 lines (38 loc) · 1.3 KB
/
common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { wrapAccessor } from '../../utils/accessors'
import { createFactory } from 'react'
export const dragAccessors = {
start: wrapAccessor(e => e.start),
end: wrapAccessor(e => e.end),
}
function nest(...Components) {
const factories = Components.filter(Boolean).map(createFactory)
const Nest = ({ children, ...props }) =>
factories.reduceRight((child, factory) => factory(props, child), children)
return Nest
}
export function mergeComponents(components = {}, addons) {
const keys = Object.keys(addons)
const result = { ...components }
keys.forEach(key => {
result[key] = components[key]
? nest(components[key], addons[key])
: addons[key]
})
return result
}
export function pointInColumn(bounds, point) {
const { left, right, top } = bounds
const { x, y } = point
return x < right + 10 && x > left && y > top
}
export function eventTimes(event, accessors, localizer) {
let start = accessors.start(event)
let end = accessors.end(event)
const isZeroDuration =
localizer.eq(start, end, 'minutes') &&
localizer.diff(start, end, 'minutes') === 0
// make zero duration midnight events at least one day long
if (isZeroDuration) end = localizer.add(end, 1, 'day')
const duration = localizer.diff(end, start, 'milliseconds')
return { start, end, duration }
}