import { __assign } from 'tslib' ; import { guid } from '../util/misc' ; import { DateInput } from '../datelib/env' ; import { startOfDay } from '../datelib/marker' ; import { parseRecurring } from './recurring-event' ; import { CalendarContext } from '../CalendarContext' ; import { EventDef } from './event-def' ; import { createEventInstance , EventInstance } from './event-instance' ; import { EventSource } from './event-source' ; import { RefinedOptionsFromRefiners , RawOptionsFromRefiners , identity , Identity , Dictionary , refineProps } from '../options' ; import { EVENT_UI_REFINERS , createEventUi , EventUiInput , EventUiRefined } from '../component/event-ui' ; export const EVENT_NON_DATE_REFINERS = { id : String , groupId : String , title : String , url : String , interactive : Boolean , } ; export const EVENT_DATE_REFINERS = { start : identity as Identity < DateInput > , end : identity as Identity < DateInput > , date : identity as Identity < DateInput > , allDay : Boolean , } ; const EVENT_REFINERS = { ... EVENT_NON_DATE_REFINERS , ... EVENT_DATE_REFINERS , extendedProps : identity as Identity < Dictionary > , } ; type BuiltInEventRefiners = typeof EVENT_REFINERS ; export interface EventRefiners extends BuiltInEventRefiners { } export type EventInput = EventUiInput & RawOptionsFromRefiners < Required < EventRefiners > > & { [ extendedProp ] : any ; } ; export type EventRefined = EventUiRefined & RefinedOptionsFromRefiners < Required < EventRefiners > > ; export interface EventTuple { def : EventDef ; instance : EventInstance | null ; } export type EventInputTransformer = ( input : EventInput ) => EventInput ; export type EventDefMemberAdder = ( refined : EventRefined ) => Partial < EventDef > ; export function parseEvent ( raw , eventSource , context , allowOpenRange , refiners = buildEventRefiners ( context ) ) { let { refined , extra } = refineEventDef ( raw , context , refiners ) ; let defaultAllDay = computeIsDefaultAllDay ( eventSource , context ) ; let recurringRes = parseRecurring ( refined , defaultAllDay , context . dateEnv , context . pluginHooks . recurringTypes ) ; if ( recurringRes ) { let def = parseEventDef ( refined , extra , eventSource ? eventSource . sourceId : '' , recurringRes . allDay , Boolean ( recurringRes . duration ) , context ) ; def . recurringDef = { typeId : recurringRes . typeId , typeData : recurringRes . typeData , duration : recurringRes . duration , } ; return { def , instance : null } ; } let singleRes = parseSingle ( refined , defaultAllDay , context , allowOpenRange ) ; if ( singleRes ) { let def = parseEventDef ( refined , extra , eventSource ? eventSource . sourceId : '' , singleRes . allDay , singleRes . hasEnd , context ) ; let instance = createEventInstance ( def . defId , singleRes . range , singleRes . forcedStartTzo , singleRes . forcedEndTzo ) ; return { def , instance } ; } return null ; } export function refineEventDef ( raw , context , refiners = buildEventRefiners ( context ) ) { return refineProps ( raw , refiners ) ; } export function buildEventRefiners ( context ) { return { ... EVENT_UI_REFINERS , ... EVENT_REFINERS , ... context . pluginHooks . eventRefiners } ; } export function parseEventDef ( refined , extra , sourceId , allDay , hasEnd , context ) { let def = { title : refined . title || '' , groupId : refined . groupId || '' , publicId : refined . id || '' , url : refined . url || '' , recurringDef : null , defId : guid ( ) , sourceId , allDay , hasEnd , interactive : refined . interactive , ui : createEventUi ( refined , context ) , extendedProps : { ... ( refined . extendedProps || { } ) , ... extra , } , } ; for ( let memberAdder of context . pluginHooks . eventDefMemberAdders ) { __assign ( def , memberAdder ( refined ) ) ; } Object . freeze ( def . ui . classNames ) ; Object . freeze ( def . extendedProps ) ; return def ; } function parseSingle ( refined , defaultAllDay , context , allowOpenRange ? ) { let { allDay } = refined ; let startMeta ; let startMarker = null ; let hasEnd = false ; let endMeta ; let endMarker = null ; let startInput = refined . start != null ? refined . start : refined . date ; startMeta = context . dateEnv . createMarkerMeta ( startInput ) ; if ( startMeta ) { startMarker = startMeta . marker ; } else if ( ! allowOpenRange ) { return null ; } if ( refined . end != null ) { endMeta = context . dateEnv . createMarkerMeta ( refined . end ) ; } if ( allDay == null ) { if ( defaultAllDay != null ) { allDay = defaultAllDay ; } else { allDay = ( ! startMeta || startMeta . isTimeUnspecified ) && ( ! endMeta || endMeta . isTimeUnspecified ) ; } } if ( allDay && startMarker ) { startMarker = startOfDay ( startMarker ) ; } if ( endMeta ) { endMarker = endMeta . marker ; if ( allDay ) { endMarker = startOfDay ( endMarker ) ; } if ( startMarker && endMarker <= startMarker ) { endMarker = null ; } } if ( endMarker ) { hasEnd = true ; } else if ( ! allowOpenRange ) { hasEnd = context . options . forceEventDuration || false ; endMarker = context . dateEnv . add ( startMarker , allDay ? context . options . defaultAllDayEventDuration : context . options . defaultTimedEventDuration ) ; } return { allDay , hasEnd , range : { start : startMarker , end : endMarker } , forcedStartTzo : startMeta ? startMeta . forcedTzo : null , forcedEndTzo : endMeta ? endMeta . forcedTzo : null , } ; } function computeIsDefaultAllDay ( eventSource , context ) { let res = null ; if ( eventSource ) { res = eventSource . defaultAllDay ; } if ( res == null ) { res = context . options . defaultAllDay ; } return res ; }