Skip to content

Commit

Permalink
eventOverlap is the only things that accepts a function
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Dec 13, 2018
1 parent ac701a3 commit 7660be4
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 100 deletions.
23 changes: 18 additions & 5 deletions src/Calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { CalendarState, Action } from './reducers/types'
import EventSourceApi from './api/EventSourceApi'
import EventApi from './api/EventApi'
import { createEmptyEventStore, EventStore, eventTupleToStore } from './structs/event-store'
import { processScopedUiProps, EventUiHash, EventUi, processUnscopedUiProps } from './component/event-ui'
import { processScopedUiProps, EventUiHash, EventUi } from './component/event-ui'
import PointerDragging, { PointerDragEvent } from './dnd/PointerDragging'
import EventDragging from './interactions/EventDragging'
import { buildViewSpecs, ViewSpecHash, ViewSpec } from './structs/view-spec'
Expand Down Expand Up @@ -64,8 +64,8 @@ export default class Calendar {

private buildDateEnv = memoize(buildDateEnv)
private buildTheme = memoize(buildTheme)
private buildEventUiSingleBase = memoize(processScopedUiProps.bind(null, 'event') as typeof processUnscopedUiProps) // hack for ts
private buildSelectionConfig = memoize(processScopedUiProps.bind(null, 'select') as typeof processUnscopedUiProps) // hack for ts
private buildEventUiSingleBase = memoize(this._buildSelectionConfig)
private buildSelectionConfig = memoize(this._buildEventUiSingleBase)
private buildEventUiBySource = memoizeOutput(buildEventUiBySource, isPropsEqual)
private buildEventUiBases = memoize(buildEventUiBases)

Expand Down Expand Up @@ -406,7 +406,7 @@ export default class Calendar {
this.renderableEventStore :
state.eventStore

let eventUiSingleBase = this.buildEventUiSingleBase(viewSpec.options, this)
let eventUiSingleBase = this.buildEventUiSingleBase(viewSpec.options)
let eventUiBySource = this.buildEventUiBySource(state.eventSources)
let eventUiBases = this.eventUiBases = this.buildEventUiBases(renderableEventStore.defs, eventUiSingleBase, eventUiBySource)

Expand Down Expand Up @@ -545,7 +545,7 @@ export default class Calendar {
options.cmdFormatter
)

this.selectionConfig = this.buildSelectionConfig(options, this) // needs dateEnv. do after :(
this.selectionConfig = this.buildSelectionConfig(options) // needs dateEnv. do after :(

// ineffecient to do every time?
this.viewSpecs = buildViewSpecs(
Expand All @@ -561,6 +561,19 @@ export default class Calendar {
}


_buildSelectionConfig(rawOpts) {
return processScopedUiProps('select', rawOpts, this)
}


_buildEventUiSingleBase(rawOpts) {
if (rawOpts.editable) { // so 'editable' affected events
rawOpts = Object.assign({}, rawOpts, { eventEditable: true })
}
return processScopedUiProps('event', rawOpts, this)
}


// Trigger
// -----------------------------------------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion src/api/EventApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export default class EventApi implements EventTuple {
get startEditable(): boolean { return this.def.ui.startEditable }
get durationEditable(): boolean { return this.def.ui.durationEditable }
get constraint(): any { return this.def.ui.constraints[0] || null }
get overlap(): any { return this.def.ui.overlaps[0] || null }
get overlap(): any { return this.def.ui.overlap }
get allow(): any { return this.def.ui.allows[0] || null }
get backgroundColor(): string { return this.def.ui.backgroundColor }
get borderColor(): string { return this.def.ui.borderColor }
Expand Down
31 changes: 8 additions & 23 deletions src/component/event-ui.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Constraint, Allow, normalizeConstraint, ConstraintInput, Overlap } from '../validation'
import { Constraint, AllowFunc, normalizeConstraint, ConstraintInput } from '../validation'
import { parseClassName } from '../util/html'
import { refineProps, capitaliseFirstLetter } from '../util/misc'
import Calendar from '../Calendar'
Expand All @@ -12,8 +12,8 @@ export interface UnscopedEventUiInput {
startEditable?: boolean
durationEditable?: boolean
constraint?: ConstraintInput
overlap?: Overlap
allow?: Allow
overlap?: boolean
allow?: AllowFunc
className?: string[] | string
classNames?: string[] | string
backgroundColor?: string
Expand All @@ -22,27 +22,12 @@ export interface UnscopedEventUiInput {
color?: string
}

export interface EventScopedEventUiInput { // has the word "event" in all the props
editable?: boolean // only one not scoped
eventStartEditable?: boolean
eventDurationEditable?: boolean
eventConstraint?: ConstraintInput
eventOverlap?: Overlap
eventAllow?: Allow
eventClassName?: string[] | string
eventClassNames?: string[] | string
eventBackgroundColor?: string
eventBorderColor?: string
eventTextColor?: string
eventColor?: string
}

export interface EventUi {
startEditable: boolean | null
durationEditable: boolean | null
constraints: Constraint[]
overlaps: Overlap[]
allows: Allow[]
overlap: boolean | null
allows: AllowFunc[]
backgroundColor: string
borderColor: string
textColor: string,
Expand Down Expand Up @@ -74,7 +59,7 @@ export function processUnscopedUiProps(rawProps: UnscopedEventUiInput, calendar:
startEditable: props.startEditable != null ? props.startEditable : props.editable,
durationEditable: props.durationEditable != null ? props.durationEditable : props.editable,
constraints: constraint != null ? [ constraint ] : [],
overlaps: props.overlap != null ? [ props.overlap ] : [],
overlap: props.overlap,
allows: props.allow != null ? [ props.allow ] : [],
backgroundColor: props.backgroundColor || props.color,
borderColor: props.borderColor || props.color,
Expand All @@ -101,7 +86,7 @@ const EMPTY_EVENT_UI: EventUi = {
startEditable: null,
durationEditable: null,
constraints: [],
overlaps: [],
overlap: null,
allows: [],
backgroundColor: '',
borderColor: '',
Expand All @@ -119,7 +104,7 @@ function combineTwoEventUis(item0: EventUi, item1: EventUi): EventUi { // hash1
startEditable: item1.startEditable != null ? item1.startEditable : item0.startEditable,
durationEditable: item1.durationEditable != null ? item1.durationEditable : item0.durationEditable,
constraints: item0.constraints.concat(item1.constraints),
overlaps: item0.overlaps.concat(item1.overlaps),
overlap: typeof item1.overlap === 'boolean' ? item1.overlap : item0.overlap,
allows: item0.allows.concat(item1.allows),
backgroundColor: item1.backgroundColor || item0.backgroundColor,
borderColor: item1.borderColor || item0.borderColor,
Expand Down
3 changes: 2 additions & 1 deletion src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export {
} from './util/dom-manip'

export { EventStore, filterEventStoreDefs, createEmptyEventStore } from './structs/event-store'
export { EventUiHash, EventUi, processScopedUiProps, EventScopedEventUiInput, combineEventUis } from './component/event-ui'
export { EventUiHash, EventUi, processScopedUiProps, combineEventUis } from './component/event-ui'
export { default as Splitter, SplittableProps } from './component/event-splitting'
export { buildGotoAnchorHtml, getAllDayHtml, getDayClasses } from './component/date-rendering'

Expand Down Expand Up @@ -161,3 +161,4 @@ export { default as DayTable, DayTableSeg, DayTableCell } from './common/DayTabl
export { default as Slicer, SlicedProps } from './common/slicing-utils'

export { EventMutation } from './structs/event-mutation'
export { ConstraintInput, AllowFunc } from './validation'
18 changes: 16 additions & 2 deletions src/structs/event-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { EventInput } from './event'
import Calendar from '../Calendar'
import { DateRange } from '../datelib/date-range'
import { EventSourceFunc } from '../event-sources/func-event-source'
import { EventScopedEventUiInput, processUnscopedUiProps } from '../component/event-ui'
import { processUnscopedUiProps } from '../component/event-ui'
import { EventUi } from '../component/event-ui'
import { ConstraintInput, AllowFunc } from '../validation'

/*
Parsing and normalization of the EventSource data type, which defines how event data is fetched.
Expand All @@ -23,7 +24,7 @@ export type EventInputTransformer = (eventInput: EventInput) => EventInput | nul
export type EventSourceSuccessResponseHandler = (rawData: any, response: any) => EventInput[] | void
export type EventSourceErrorResponseHandler = (error: EventSourceError) => void

export interface ExtendedEventSourceInput extends EventScopedEventUiInput {
export interface ExtendedEventSourceInput {
id?: string | number // only accept number?
allDayDefault?: boolean
eventDataTransform?: EventInputTransformer
Expand All @@ -43,6 +44,19 @@ export interface ExtendedEventSourceInput extends EventScopedEventUiInput {
success?: EventSourceSuccessResponseHandler
failure?: EventSourceErrorResponseHandler

editable?: boolean
startEditable?: boolean
durationEditable?: boolean
constraint?: ConstraintInput
overlap?: boolean
allow?: AllowFunc
className?: string[] | string
classNames?: string[] | string
backgroundColor?: string
borderColor?: string
textColor?: string
color?: string

[otherProp: string]: any // in case plugins want more props
}

Expand Down
24 changes: 19 additions & 5 deletions src/types/input-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import { FormatterInput } from '../datelib/formatting'
import { DateRangeInput } from '../datelib/date-range'
import { BusinessHoursInput } from '../structs/business-hours'
import EventApi from '../api/EventApi'
import { Allow, ConstraintInput, Overlap } from '../validation'
import { AllowFunc, ConstraintInput, OverlapFunc } from '../validation'
import { PluginDef } from '../plugin-system'
import { UnscopedEventUiInput } from '../component/event-ui'


export interface ToolbarInput {
Expand Down Expand Up @@ -71,7 +70,7 @@ export interface DropInfo {
end: Date
}

export interface OptionsInputBase extends UnscopedEventUiInput {
export interface OptionsInputBase {
header?: boolean | ToolbarInput
footer?: boolean | ToolbarInput
customButtons?: { [name: string]: CustomButtonInput }
Expand Down Expand Up @@ -140,9 +139,24 @@ export interface OptionsInputBase extends UnscopedEventUiInput {
selectMirror?: boolean
unselectAuto?: boolean
unselectCancel?: string

selectConstraint?: ConstraintInput
selectOverlap?: Overlap
selectAllow?: Allow
selectOverlap?: boolean | OverlapFunc
selectAllow?: AllowFunc

editable?: boolean
eventStartEditable?: boolean
eventDurationEditable?: boolean
eventConstraint?: ConstraintInput
eventOverlap?: boolean | OverlapFunc // allows a function, unlike EventUi
eventAllow?: AllowFunc
eventClassName?: string[] | string
eventClassNames?: string[] | string
eventBackgroundColor?: string
eventBorderColor?: string
eventTextColor?: string
eventColor?: string

events?: EventSourceInput
eventSources?: EventSourceInput[]
allDayDefault?: boolean
Expand Down

0 comments on commit 7660be4

Please sign in to comment.