arg. otherwise, will default to any???\nvar RenderHook = /** @class */ (function (_super) {\n __extends(RenderHook, _super);\n function RenderHook() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.rootElRef = createRef();\n _this.handleRootEl = function (el) {\n setRef(_this.rootElRef, el);\n if (_this.props.elRef) {\n setRef(_this.props.elRef, el);\n }\n };\n return _this;\n }\n RenderHook.prototype.render = function () {\n var _this = this;\n var props = this.props;\n var hookProps = props.hookProps;\n return (createElement(MountHook, { hookProps: hookProps, didMount: props.didMount, willUnmount: props.willUnmount, elRef: this.handleRootEl }, function (rootElRef) { return (createElement(ContentHook, { hookProps: hookProps, content: props.content, defaultContent: props.defaultContent, backupElRef: _this.rootElRef }, function (innerElRef, innerContent) { return props.children(rootElRef, normalizeClassNames(props.classNames, hookProps), innerElRef, innerContent); })); }));\n };\n return RenderHook;\n}(BaseComponent));\n// TODO: rename to be about function, not default. use in above type\n// for forcing rerender of components that use the ContentHook\nvar CustomContentRenderContext = createContext(0);\nfunction ContentHook(props) {\n return (createElement(CustomContentRenderContext.Consumer, null, function (renderId) { return (createElement(ContentHookInner, __assign({ renderId: renderId }, props))); }));\n}\nvar ContentHookInner = /** @class */ (function (_super) {\n __extends(ContentHookInner, _super);\n function ContentHookInner() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.innerElRef = createRef();\n return _this;\n }\n ContentHookInner.prototype.render = function () {\n return this.props.children(this.innerElRef, this.renderInnerContent());\n };\n ContentHookInner.prototype.componentDidMount = function () {\n this.updateCustomContent();\n };\n ContentHookInner.prototype.componentDidUpdate = function () {\n this.updateCustomContent();\n };\n ContentHookInner.prototype.componentWillUnmount = function () {\n if (this.customContentInfo && this.customContentInfo.destroy) {\n this.customContentInfo.destroy();\n }\n };\n ContentHookInner.prototype.renderInnerContent = function () {\n var contentTypeHandlers = this.context.pluginHooks.contentTypeHandlers;\n var _a = this, props = _a.props, customContentInfo = _a.customContentInfo;\n var rawVal = props.content;\n var innerContent = normalizeContent(rawVal, props.hookProps);\n var innerContentVDom = null;\n if (innerContent === undefined) { // use the default\n innerContent = normalizeContent(props.defaultContent, props.hookProps);\n }\n if (innerContent !== undefined) { // we allow custom content handlers to return nothing\n if (customContentInfo) {\n customContentInfo.contentVal = innerContent[customContentInfo.contentKey];\n }\n else if (typeof innerContent === 'object') {\n // look for a prop that would indicate a custom content handler is needed\n for (var contentKey in contentTypeHandlers) {\n if (innerContent[contentKey] !== undefined) {\n var stuff = contentTypeHandlers[contentKey]();\n customContentInfo = this.customContentInfo = __assign({ contentKey: contentKey, contentVal: innerContent[contentKey] }, stuff);\n break;\n }\n }\n }\n if (customContentInfo) {\n innerContentVDom = []; // signal that something was specified\n }\n else {\n innerContentVDom = innerContent; // assume a [p]react vdom node. use it\n }\n }\n return innerContentVDom;\n };\n ContentHookInner.prototype.updateCustomContent = function () {\n if (this.customContentInfo) {\n this.customContentInfo.render(this.innerElRef.current || this.props.backupElRef.current, // the element to render into\n this.customContentInfo.contentVal);\n }\n };\n return ContentHookInner;\n}(BaseComponent));\nvar MountHook = /** @class */ (function (_super) {\n __extends(MountHook, _super);\n function MountHook() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.handleRootEl = function (rootEl) {\n _this.rootEl = rootEl;\n if (_this.props.elRef) {\n setRef(_this.props.elRef, rootEl);\n }\n };\n return _this;\n }\n MountHook.prototype.render = function () {\n return this.props.children(this.handleRootEl);\n };\n MountHook.prototype.componentDidMount = function () {\n var callback = this.props.didMount;\n if (callback) {\n callback(__assign(__assign({}, this.props.hookProps), { el: this.rootEl }));\n }\n };\n MountHook.prototype.componentWillUnmount = function () {\n var callback = this.props.willUnmount;\n if (callback) {\n callback(__assign(__assign({}, this.props.hookProps), { el: this.rootEl }));\n }\n };\n return MountHook;\n}(BaseComponent));\nfunction buildClassNameNormalizer() {\n var currentGenerator;\n var currentHookProps;\n var currentClassNames = [];\n return function (generator, hookProps) {\n if (!currentHookProps || !isPropsEqual(currentHookProps, hookProps) || generator !== currentGenerator) {\n currentGenerator = generator;\n currentHookProps = hookProps;\n currentClassNames = normalizeClassNames(generator, hookProps);\n }\n return currentClassNames;\n };\n}\nfunction normalizeClassNames(classNames, hookProps) {\n if (typeof classNames === 'function') {\n classNames = classNames(hookProps);\n }\n return parseClassNames(classNames);\n}\nfunction normalizeContent(input, hookProps) {\n if (typeof input === 'function') {\n return input(hookProps, createElement); // give the function the vdom-creation func\n }\n return input;\n}\n\nvar ViewRoot = /** @class */ (function (_super) {\n __extends(ViewRoot, _super);\n function ViewRoot() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.normalizeClassNames = buildClassNameNormalizer();\n return _this;\n }\n ViewRoot.prototype.render = function () {\n var _a = this, props = _a.props, context = _a.context;\n var options = context.options;\n var hookProps = { view: context.viewApi };\n var customClassNames = this.normalizeClassNames(options.viewClassNames, hookProps);\n return (createElement(MountHook, { hookProps: hookProps, didMount: options.viewDidMount, willUnmount: options.viewWillUnmount, elRef: props.elRef }, function (rootElRef) { return props.children(rootElRef, [\"fc-\" + props.viewSpec.type + \"-view\", 'fc-view'].concat(customClassNames)); }));\n };\n return ViewRoot;\n}(BaseComponent));\n\nfunction parseViewConfigs(inputs) {\n return mapHash(inputs, parseViewConfig);\n}\nfunction parseViewConfig(input) {\n var rawOptions = typeof input === 'function' ?\n { component: input } :\n input;\n var component = rawOptions.component;\n if (rawOptions.content) {\n component = createViewHookComponent(rawOptions);\n // TODO: remove content/classNames/didMount/etc from options?\n }\n return {\n superType: rawOptions.type,\n component: component,\n rawOptions: rawOptions,\n };\n}\nfunction createViewHookComponent(options) {\n return function (viewProps) { return (createElement(ViewContextType.Consumer, null, function (context) { return (createElement(ViewRoot, { viewSpec: context.viewSpec }, function (viewElRef, viewClassNames) {\n var hookProps = __assign(__assign({}, viewProps), { nextDayThreshold: context.options.nextDayThreshold });\n return (createElement(RenderHook, { hookProps: hookProps, classNames: options.classNames, content: options.content, didMount: options.didMount, willUnmount: options.willUnmount, elRef: viewElRef }, function (rootElRef, customClassNames, innerElRef, innerContent) { return (createElement(\"div\", { className: viewClassNames.concat(customClassNames).join(' '), ref: rootElRef }, innerContent)); }));\n })); })); };\n}\n\nfunction buildViewSpecs(defaultInputs, optionOverrides, dynamicOptionOverrides, localeDefaults) {\n var defaultConfigs = parseViewConfigs(defaultInputs);\n var overrideConfigs = parseViewConfigs(optionOverrides.views);\n var viewDefs = compileViewDefs(defaultConfigs, overrideConfigs);\n return mapHash(viewDefs, function (viewDef) { return buildViewSpec(viewDef, overrideConfigs, optionOverrides, dynamicOptionOverrides, localeDefaults); });\n}\nfunction buildViewSpec(viewDef, overrideConfigs, optionOverrides, dynamicOptionOverrides, localeDefaults) {\n var durationInput = viewDef.overrides.duration ||\n viewDef.defaults.duration ||\n dynamicOptionOverrides.duration ||\n optionOverrides.duration;\n var duration = null;\n var durationUnit = '';\n var singleUnit = '';\n var singleUnitOverrides = {};\n if (durationInput) {\n duration = createDurationCached(durationInput);\n if (duration) { // valid?\n var denom = greatestDurationDenominator(duration);\n durationUnit = denom.unit;\n if (denom.value === 1) {\n singleUnit = durationUnit;\n singleUnitOverrides = overrideConfigs[durationUnit] ? overrideConfigs[durationUnit].rawOptions : {};\n }\n }\n }\n var queryButtonText = function (optionsSubset) {\n var buttonTextMap = optionsSubset.buttonText || {};\n var buttonTextKey = viewDef.defaults.buttonTextKey;\n if (buttonTextKey != null && buttonTextMap[buttonTextKey] != null) {\n return buttonTextMap[buttonTextKey];\n }\n if (buttonTextMap[viewDef.type] != null) {\n return buttonTextMap[viewDef.type];\n }\n if (buttonTextMap[singleUnit] != null) {\n return buttonTextMap[singleUnit];\n }\n return null;\n };\n return {\n type: viewDef.type,\n component: viewDef.component,\n duration: duration,\n durationUnit: durationUnit,\n singleUnit: singleUnit,\n optionDefaults: viewDef.defaults,\n optionOverrides: __assign(__assign({}, singleUnitOverrides), viewDef.overrides),\n buttonTextOverride: queryButtonText(dynamicOptionOverrides) ||\n queryButtonText(optionOverrides) || // constructor-specified buttonText lookup hash takes precedence\n viewDef.overrides.buttonText,\n buttonTextDefault: queryButtonText(localeDefaults) ||\n viewDef.defaults.buttonText ||\n queryButtonText(BASE_OPTION_DEFAULTS) ||\n viewDef.type, // fall back to given view name\n };\n}\n// hack to get memoization working\nvar durationInputMap = {};\nfunction createDurationCached(durationInput) {\n var json = JSON.stringify(durationInput);\n var res = durationInputMap[json];\n if (res === undefined) {\n res = createDuration(durationInput);\n durationInputMap[json] = res;\n }\n return res;\n}\n\nvar DateProfileGenerator = /** @class */ (function () {\n function DateProfileGenerator(props) {\n this.props = props;\n this.nowDate = getNow(props.nowInput, props.dateEnv);\n this.initHiddenDays();\n }\n /* Date Range Computation\n ------------------------------------------------------------------------------------------------------------------*/\n // Builds a structure with info about what the dates/ranges will be for the \"prev\" view.\n DateProfileGenerator.prototype.buildPrev = function (currentDateProfile, currentDate, forceToValid) {\n var dateEnv = this.props.dateEnv;\n var prevDate = dateEnv.subtract(dateEnv.startOf(currentDate, currentDateProfile.currentRangeUnit), // important for start-of-month\n currentDateProfile.dateIncrement);\n return this.build(prevDate, -1, forceToValid);\n };\n // Builds a structure with info about what the dates/ranges will be for the \"next\" view.\n DateProfileGenerator.prototype.buildNext = function (currentDateProfile, currentDate, forceToValid) {\n var dateEnv = this.props.dateEnv;\n var nextDate = dateEnv.add(dateEnv.startOf(currentDate, currentDateProfile.currentRangeUnit), // important for start-of-month\n currentDateProfile.dateIncrement);\n return this.build(nextDate, 1, forceToValid);\n };\n // Builds a structure holding dates/ranges for rendering around the given date.\n // Optional direction param indicates whether the date is being incremented/decremented\n // from its previous value. decremented = -1, incremented = 1 (default).\n DateProfileGenerator.prototype.build = function (currentDate, direction, forceToValid) {\n if (forceToValid === void 0) { forceToValid = true; }\n var props = this.props;\n var validRange;\n var currentInfo;\n var isRangeAllDay;\n var renderRange;\n var activeRange;\n var isValid;\n validRange = this.buildValidRange();\n validRange = this.trimHiddenDays(validRange);\n if (forceToValid) {\n currentDate = constrainMarkerToRange(currentDate, validRange);\n }\n currentInfo = this.buildCurrentRangeInfo(currentDate, direction);\n isRangeAllDay = /^(year|month|week|day)$/.test(currentInfo.unit);\n renderRange = this.buildRenderRange(this.trimHiddenDays(currentInfo.range), currentInfo.unit, isRangeAllDay);\n renderRange = this.trimHiddenDays(renderRange);\n activeRange = renderRange;\n if (!props.showNonCurrentDates) {\n activeRange = intersectRanges(activeRange, currentInfo.range);\n }\n activeRange = this.adjustActiveRange(activeRange);\n activeRange = intersectRanges(activeRange, validRange); // might return null\n // it's invalid if the originally requested date is not contained,\n // or if the range is completely outside of the valid range.\n isValid = rangesIntersect(currentInfo.range, validRange);\n return {\n // constraint for where prev/next operations can go and where events can be dragged/resized to.\n // an object with optional start and end properties.\n validRange: validRange,\n // range the view is formally responsible for.\n // for example, a month view might have 1st-31st, excluding padded dates\n currentRange: currentInfo.range,\n // name of largest unit being displayed, like \"month\" or \"week\"\n currentRangeUnit: currentInfo.unit,\n isRangeAllDay: isRangeAllDay,\n // dates that display events and accept drag-n-drop\n // will be `null` if no dates accept events\n activeRange: activeRange,\n // date range with a rendered skeleton\n // includes not-active days that need some sort of DOM\n renderRange: renderRange,\n // Duration object that denotes the first visible time of any given day\n slotMinTime: props.slotMinTime,\n // Duration object that denotes the exclusive visible end time of any given day\n slotMaxTime: props.slotMaxTime,\n isValid: isValid,\n // how far the current date will move for a prev/next operation\n dateIncrement: this.buildDateIncrement(currentInfo.duration),\n // pass a fallback (might be null) ^\n };\n };\n // Builds an object with optional start/end properties.\n // Indicates the minimum/maximum dates to display.\n // not responsible for trimming hidden days.\n DateProfileGenerator.prototype.buildValidRange = function () {\n var input = this.props.validRangeInput;\n var simpleInput = typeof input === 'function'\n ? input.call(this.props.calendarApi, this.nowDate)\n : input;\n return this.refineRange(simpleInput) ||\n { start: null, end: null }; // completely open-ended\n };\n // Builds a structure with info about the \"current\" range, the range that is\n // highlighted as being the current month for example.\n // See build() for a description of `direction`.\n // Guaranteed to have `range` and `unit` properties. `duration` is optional.\n DateProfileGenerator.prototype.buildCurrentRangeInfo = function (date, direction) {\n var props = this.props;\n var duration = null;\n var unit = null;\n var range = null;\n var dayCount;\n if (props.duration) {\n duration = props.duration;\n unit = props.durationUnit;\n range = this.buildRangeFromDuration(date, direction, duration, unit);\n }\n else if ((dayCount = this.props.dayCount)) {\n unit = 'day';\n range = this.buildRangeFromDayCount(date, direction, dayCount);\n }\n else if ((range = this.buildCustomVisibleRange(date))) {\n unit = props.dateEnv.greatestWholeUnit(range.start, range.end).unit;\n }\n else {\n duration = this.getFallbackDuration();\n unit = greatestDurationDenominator(duration).unit;\n range = this.buildRangeFromDuration(date, direction, duration, unit);\n }\n return { duration: duration, unit: unit, range: range };\n };\n DateProfileGenerator.prototype.getFallbackDuration = function () {\n return createDuration({ day: 1 });\n };\n // Returns a new activeRange to have time values (un-ambiguate)\n // slotMinTime or slotMaxTime causes the range to expand.\n DateProfileGenerator.prototype.adjustActiveRange = function (range) {\n var _a = this.props, dateEnv = _a.dateEnv, usesMinMaxTime = _a.usesMinMaxTime, slotMinTime = _a.slotMinTime, slotMaxTime = _a.slotMaxTime;\n var start = range.start, end = range.end;\n if (usesMinMaxTime) {\n // expand active range if slotMinTime is negative (why not when positive?)\n if (asRoughDays(slotMinTime) < 0) {\n start = startOfDay(start); // necessary?\n start = dateEnv.add(start, slotMinTime);\n }\n // expand active range if slotMaxTime is beyond one day (why not when negative?)\n if (asRoughDays(slotMaxTime) > 1) {\n end = startOfDay(end); // necessary?\n end = addDays(end, -1);\n end = dateEnv.add(end, slotMaxTime);\n }\n }\n return { start: start, end: end };\n };\n // Builds the \"current\" range when it is specified as an explicit duration.\n // `unit` is the already-computed greatestDurationDenominator unit of duration.\n DateProfileGenerator.prototype.buildRangeFromDuration = function (date, direction, duration, unit) {\n var _a = this.props, dateEnv = _a.dateEnv, dateAlignment = _a.dateAlignment;\n var start;\n var end;\n var res;\n // compute what the alignment should be\n if (!dateAlignment) {\n var dateIncrement = this.props.dateIncrement;\n if (dateIncrement) {\n // use the smaller of the two units\n if (asRoughMs(dateIncrement) < asRoughMs(duration)) {\n dateAlignment = greatestDurationDenominator(dateIncrement).unit;\n }\n else {\n dateAlignment = unit;\n }\n }\n else {\n dateAlignment = unit;\n }\n }\n // if the view displays a single day or smaller\n if (asRoughDays(duration) <= 1) {\n if (this.isHiddenDay(start)) {\n start = this.skipHiddenDays(start, direction);\n start = startOfDay(start);\n }\n }\n function computeRes() {\n start = dateEnv.startOf(date, dateAlignment);\n end = dateEnv.add(start, duration);\n res = { start: start, end: end };\n }\n computeRes();\n // if range is completely enveloped by hidden days, go past the hidden days\n if (!this.trimHiddenDays(res)) {\n date = this.skipHiddenDays(date, direction);\n computeRes();\n }\n return res;\n };\n // Builds the \"current\" range when a dayCount is specified.\n DateProfileGenerator.prototype.buildRangeFromDayCount = function (date, direction, dayCount) {\n var _a = this.props, dateEnv = _a.dateEnv, dateAlignment = _a.dateAlignment;\n var runningCount = 0;\n var start = date;\n var end;\n if (dateAlignment) {\n start = dateEnv.startOf(start, dateAlignment);\n }\n start = startOfDay(start);\n start = this.skipHiddenDays(start, direction);\n end = start;\n do {\n end = addDays(end, 1);\n if (!this.isHiddenDay(end)) {\n runningCount += 1;\n }\n } while (runningCount < dayCount);\n return { start: start, end: end };\n };\n // Builds a normalized range object for the \"visible\" range,\n // which is a way to define the currentRange and activeRange at the same time.\n DateProfileGenerator.prototype.buildCustomVisibleRange = function (date) {\n var props = this.props;\n var input = props.visibleRangeInput;\n var simpleInput = typeof input === 'function'\n ? input.call(props.calendarApi, props.dateEnv.toDate(date))\n : input;\n var range = this.refineRange(simpleInput);\n if (range && (range.start == null || range.end == null)) {\n return null;\n }\n return range;\n };\n // Computes the range that will represent the element/cells for *rendering*,\n // but which may have voided days/times.\n // not responsible for trimming hidden days.\n DateProfileGenerator.prototype.buildRenderRange = function (currentRange, currentRangeUnit, isRangeAllDay) {\n return currentRange;\n };\n // Compute the duration value that should be added/substracted to the current date\n // when a prev/next operation happens.\n DateProfileGenerator.prototype.buildDateIncrement = function (fallback) {\n var dateIncrement = this.props.dateIncrement;\n var customAlignment;\n if (dateIncrement) {\n return dateIncrement;\n }\n if ((customAlignment = this.props.dateAlignment)) {\n return createDuration(1, customAlignment);\n }\n if (fallback) {\n return fallback;\n }\n return createDuration({ days: 1 });\n };\n DateProfileGenerator.prototype.refineRange = function (rangeInput) {\n if (rangeInput) {\n var range = parseRange(rangeInput, this.props.dateEnv);\n if (range) {\n range = computeVisibleDayRange(range);\n }\n return range;\n }\n return null;\n };\n /* Hidden Days\n ------------------------------------------------------------------------------------------------------------------*/\n // Initializes internal variables related to calculating hidden days-of-week\n DateProfileGenerator.prototype.initHiddenDays = function () {\n var hiddenDays = this.props.hiddenDays || []; // array of day-of-week indices that are hidden\n var isHiddenDayHash = []; // is the day-of-week hidden? (hash with day-of-week-index -> bool)\n var dayCnt = 0;\n var i;\n if (this.props.weekends === false) {\n hiddenDays.push(0, 6); // 0=sunday, 6=saturday\n }\n for (i = 0; i < 7; i += 1) {\n if (!(isHiddenDayHash[i] = hiddenDays.indexOf(i) !== -1)) {\n dayCnt += 1;\n }\n }\n if (!dayCnt) {\n throw new Error('invalid hiddenDays'); // all days were hidden? bad.\n }\n this.isHiddenDayHash = isHiddenDayHash;\n };\n // Remove days from the beginning and end of the range that are computed as hidden.\n // If the whole range is trimmed off, returns null\n DateProfileGenerator.prototype.trimHiddenDays = function (range) {\n var start = range.start, end = range.end;\n if (start) {\n start = this.skipHiddenDays(start);\n }\n if (end) {\n end = this.skipHiddenDays(end, -1, true);\n }\n if (start == null || end == null || start < end) {\n return { start: start, end: end };\n }\n return null;\n };\n // Is the current day hidden?\n // `day` is a day-of-week index (0-6), or a Date (used for UTC)\n DateProfileGenerator.prototype.isHiddenDay = function (day) {\n if (day instanceof Date) {\n day = day.getUTCDay();\n }\n return this.isHiddenDayHash[day];\n };\n // Incrementing the current day until it is no longer a hidden day, returning a copy.\n // DOES NOT CONSIDER validRange!\n // If the initial value of `date` is not a hidden day, don't do anything.\n // Pass `isExclusive` as `true` if you are dealing with an end date.\n // `inc` defaults to `1` (increment one day forward each time)\n DateProfileGenerator.prototype.skipHiddenDays = function (date, inc, isExclusive) {\n if (inc === void 0) { inc = 1; }\n if (isExclusive === void 0) { isExclusive = false; }\n while (this.isHiddenDayHash[(date.getUTCDay() + (isExclusive ? inc : 0) + 7) % 7]) {\n date = addDays(date, inc);\n }\n return date;\n };\n return DateProfileGenerator;\n}());\n\nfunction reduceViewType(viewType, action) {\n switch (action.type) {\n case 'CHANGE_VIEW_TYPE':\n viewType = action.viewType;\n }\n return viewType;\n}\n\nfunction reduceDynamicOptionOverrides(dynamicOptionOverrides, action) {\n var _a;\n switch (action.type) {\n case 'SET_OPTION':\n return __assign(__assign({}, dynamicOptionOverrides), (_a = {}, _a[action.optionName] = action.rawOptionValue, _a));\n default:\n return dynamicOptionOverrides;\n }\n}\n\nfunction reduceDateProfile(currentDateProfile, action, currentDate, dateProfileGenerator) {\n var dp;\n switch (action.type) {\n case 'CHANGE_VIEW_TYPE':\n return dateProfileGenerator.build(action.dateMarker || currentDate);\n case 'CHANGE_DATE':\n return dateProfileGenerator.build(action.dateMarker);\n case 'PREV':\n dp = dateProfileGenerator.buildPrev(currentDateProfile, currentDate);\n if (dp.isValid) {\n return dp;\n }\n break;\n case 'NEXT':\n dp = dateProfileGenerator.buildNext(currentDateProfile, currentDate);\n if (dp.isValid) {\n return dp;\n }\n break;\n }\n return currentDateProfile;\n}\n\nfunction initEventSources(calendarOptions, dateProfile, context) {\n var activeRange = dateProfile ? dateProfile.activeRange : null;\n return addSources({}, parseInitialSources(calendarOptions, context), activeRange, context);\n}\nfunction reduceEventSources(eventSources, action, dateProfile, context) {\n var activeRange = dateProfile ? dateProfile.activeRange : null; // need this check?\n switch (action.type) {\n case 'ADD_EVENT_SOURCES': // already parsed\n return addSources(eventSources, action.sources, activeRange, context);\n case 'REMOVE_EVENT_SOURCE':\n return removeSource(eventSources, action.sourceId);\n case 'PREV': // TODO: how do we track all actions that affect dateProfile :(\n case 'NEXT':\n case 'CHANGE_DATE':\n case 'CHANGE_VIEW_TYPE':\n if (dateProfile) {\n return fetchDirtySources(eventSources, activeRange, context);\n }\n return eventSources;\n case 'FETCH_EVENT_SOURCES':\n return fetchSourcesByIds(eventSources, action.sourceIds ? // why no type?\n arrayToHash(action.sourceIds) :\n excludeStaticSources(eventSources, context), activeRange, action.isRefetch || false, context);\n case 'RECEIVE_EVENTS':\n case 'RECEIVE_EVENT_ERROR':\n return receiveResponse(eventSources, action.sourceId, action.fetchId, action.fetchRange);\n case 'REMOVE_ALL_EVENT_SOURCES':\n return {};\n default:\n return eventSources;\n }\n}\nfunction reduceEventSourcesNewTimeZone(eventSources, dateProfile, context) {\n var activeRange = dateProfile ? dateProfile.activeRange : null; // need this check?\n return fetchSourcesByIds(eventSources, excludeStaticSources(eventSources, context), activeRange, true, context);\n}\nfunction computeEventSourcesLoading(eventSources) {\n for (var sourceId in eventSources) {\n if (eventSources[sourceId].isFetching) {\n return true;\n }\n }\n return false;\n}\nfunction addSources(eventSourceHash, sources, fetchRange, context) {\n var hash = {};\n for (var _i = 0, sources_1 = sources; _i < sources_1.length; _i++) {\n var source = sources_1[_i];\n hash[source.sourceId] = source;\n }\n if (fetchRange) {\n hash = fetchDirtySources(hash, fetchRange, context);\n }\n return __assign(__assign({}, eventSourceHash), hash);\n}\nfunction removeSource(eventSourceHash, sourceId) {\n return filterHash(eventSourceHash, function (eventSource) { return eventSource.sourceId !== sourceId; });\n}\nfunction fetchDirtySources(sourceHash, fetchRange, context) {\n return fetchSourcesByIds(sourceHash, filterHash(sourceHash, function (eventSource) { return isSourceDirty(eventSource, fetchRange, context); }), fetchRange, false, context);\n}\nfunction isSourceDirty(eventSource, fetchRange, context) {\n if (!doesSourceNeedRange(eventSource, context)) {\n return !eventSource.latestFetchId;\n }\n return !context.options.lazyFetching ||\n !eventSource.fetchRange ||\n eventSource.isFetching || // always cancel outdated in-progress fetches\n fetchRange.start < eventSource.fetchRange.start ||\n fetchRange.end > eventSource.fetchRange.end;\n}\nfunction fetchSourcesByIds(prevSources, sourceIdHash, fetchRange, isRefetch, context) {\n var nextSources = {};\n for (var sourceId in prevSources) {\n var source = prevSources[sourceId];\n if (sourceIdHash[sourceId]) {\n nextSources[sourceId] = fetchSource(source, fetchRange, isRefetch, context);\n }\n else {\n nextSources[sourceId] = source;\n }\n }\n return nextSources;\n}\nfunction fetchSource(eventSource, fetchRange, isRefetch, context) {\n var options = context.options, calendarApi = context.calendarApi;\n var sourceDef = context.pluginHooks.eventSourceDefs[eventSource.sourceDefId];\n var fetchId = guid();\n sourceDef.fetch({\n eventSource: eventSource,\n range: fetchRange,\n isRefetch: isRefetch,\n context: context,\n }, function (res) {\n var rawEvents = res.rawEvents;\n if (options.eventSourceSuccess) {\n rawEvents = options.eventSourceSuccess.call(calendarApi, rawEvents, res.xhr) || rawEvents;\n }\n if (eventSource.success) {\n rawEvents = eventSource.success.call(calendarApi, rawEvents, res.xhr) || rawEvents;\n }\n context.dispatch({\n type: 'RECEIVE_EVENTS',\n sourceId: eventSource.sourceId,\n fetchId: fetchId,\n fetchRange: fetchRange,\n rawEvents: rawEvents,\n });\n }, function (error) {\n console.warn(error.message, error);\n if (options.eventSourceFailure) {\n options.eventSourceFailure.call(calendarApi, error);\n }\n if (eventSource.failure) {\n eventSource.failure(error);\n }\n context.dispatch({\n type: 'RECEIVE_EVENT_ERROR',\n sourceId: eventSource.sourceId,\n fetchId: fetchId,\n fetchRange: fetchRange,\n error: error,\n });\n });\n return __assign(__assign({}, eventSource), { isFetching: true, latestFetchId: fetchId });\n}\nfunction receiveResponse(sourceHash, sourceId, fetchId, fetchRange) {\n var _a;\n var eventSource = sourceHash[sourceId];\n if (eventSource && // not already removed\n fetchId === eventSource.latestFetchId) {\n return __assign(__assign({}, sourceHash), (_a = {}, _a[sourceId] = __assign(__assign({}, eventSource), { isFetching: false, fetchRange: fetchRange }), _a));\n }\n return sourceHash;\n}\nfunction excludeStaticSources(eventSources, context) {\n return filterHash(eventSources, function (eventSource) { return doesSourceNeedRange(eventSource, context); });\n}\nfunction parseInitialSources(rawOptions, context) {\n var refiners = buildEventSourceRefiners(context);\n var rawSources = [].concat(rawOptions.eventSources || []);\n var sources = []; // parsed\n if (rawOptions.initialEvents) {\n rawSources.unshift(rawOptions.initialEvents);\n }\n if (rawOptions.events) {\n rawSources.unshift(rawOptions.events);\n }\n for (var _i = 0, rawSources_1 = rawSources; _i < rawSources_1.length; _i++) {\n var rawSource = rawSources_1[_i];\n var source = parseEventSource(rawSource, context, refiners);\n if (source) {\n sources.push(source);\n }\n }\n return sources;\n}\nfunction doesSourceNeedRange(eventSource, context) {\n var defs = context.pluginHooks.eventSourceDefs;\n return !defs[eventSource.sourceDefId].ignoreRange;\n}\n\nfunction reduceEventStore(eventStore, action, eventSources, dateProfile, context) {\n switch (action.type) {\n case 'RECEIVE_EVENTS': // raw\n return receiveRawEvents(eventStore, eventSources[action.sourceId], action.fetchId, action.fetchRange, action.rawEvents, context);\n case 'ADD_EVENTS': // already parsed, but not expanded\n return addEvent(eventStore, action.eventStore, // new ones\n dateProfile ? dateProfile.activeRange : null, context);\n case 'RESET_EVENTS':\n return action.eventStore;\n case 'MERGE_EVENTS': // already parsed and expanded\n return mergeEventStores(eventStore, action.eventStore);\n case 'PREV': // TODO: how do we track all actions that affect dateProfile :(\n case 'NEXT':\n case 'CHANGE_DATE':\n case 'CHANGE_VIEW_TYPE':\n if (dateProfile) {\n return expandRecurring(eventStore, dateProfile.activeRange, context);\n }\n return eventStore;\n case 'REMOVE_EVENTS':\n return excludeSubEventStore(eventStore, action.eventStore);\n case 'REMOVE_EVENT_SOURCE':\n return excludeEventsBySourceId(eventStore, action.sourceId);\n case 'REMOVE_ALL_EVENT_SOURCES':\n return filterEventStoreDefs(eventStore, function (eventDef) { return (!eventDef.sourceId // only keep events with no source id\n ); });\n case 'REMOVE_ALL_EVENTS':\n return createEmptyEventStore();\n default:\n return eventStore;\n }\n}\nfunction receiveRawEvents(eventStore, eventSource, fetchId, fetchRange, rawEvents, context) {\n if (eventSource && // not already removed\n fetchId === eventSource.latestFetchId // TODO: wish this logic was always in event-sources\n ) {\n var subset = parseEvents(transformRawEvents(rawEvents, eventSource, context), eventSource, context);\n if (fetchRange) {\n subset = expandRecurring(subset, fetchRange, context);\n }\n return mergeEventStores(excludeEventsBySourceId(eventStore, eventSource.sourceId), subset);\n }\n return eventStore;\n}\nfunction transformRawEvents(rawEvents, eventSource, context) {\n var calEachTransform = context.options.eventDataTransform;\n var sourceEachTransform = eventSource ? eventSource.eventDataTransform : null;\n if (sourceEachTransform) {\n rawEvents = transformEachRawEvent(rawEvents, sourceEachTransform);\n }\n if (calEachTransform) {\n rawEvents = transformEachRawEvent(rawEvents, calEachTransform);\n }\n return rawEvents;\n}\nfunction transformEachRawEvent(rawEvents, func) {\n var refinedEvents;\n if (!func) {\n refinedEvents = rawEvents;\n }\n else {\n refinedEvents = [];\n for (var _i = 0, rawEvents_1 = rawEvents; _i < rawEvents_1.length; _i++) {\n var rawEvent = rawEvents_1[_i];\n var refinedEvent = func(rawEvent);\n if (refinedEvent) {\n refinedEvents.push(refinedEvent);\n }\n else if (refinedEvent == null) {\n refinedEvents.push(rawEvent);\n } // if a different falsy value, do nothing\n }\n }\n return refinedEvents;\n}\nfunction addEvent(eventStore, subset, expandRange, context) {\n if (expandRange) {\n subset = expandRecurring(subset, expandRange, context);\n }\n return mergeEventStores(eventStore, subset);\n}\nfunction rezoneEventStoreDates(eventStore, oldDateEnv, newDateEnv) {\n var defs = eventStore.defs;\n var instances = mapHash(eventStore.instances, function (instance) {\n var def = defs[instance.defId];\n if (def.allDay || def.recurringDef) {\n return instance; // isn't dependent on timezone\n }\n return __assign(__assign({}, instance), { range: {\n start: newDateEnv.createMarker(oldDateEnv.toDate(instance.range.start, instance.forcedStartTzo)),\n end: newDateEnv.createMarker(oldDateEnv.toDate(instance.range.end, instance.forcedEndTzo)),\n }, forcedStartTzo: newDateEnv.canComputeOffset ? null : instance.forcedStartTzo, forcedEndTzo: newDateEnv.canComputeOffset ? null : instance.forcedEndTzo });\n });\n return { defs: defs, instances: instances };\n}\nfunction excludeEventsBySourceId(eventStore, sourceId) {\n return filterEventStoreDefs(eventStore, function (eventDef) { return eventDef.sourceId !== sourceId; });\n}\n// QUESTION: why not just return instances? do a general object-property-exclusion util\nfunction excludeInstances(eventStore, removals) {\n return {\n defs: eventStore.defs,\n instances: filterHash(eventStore.instances, function (instance) { return !removals[instance.instanceId]; }),\n };\n}\n\nfunction reduceDateSelection(currentSelection, action) {\n switch (action.type) {\n case 'UNSELECT_DATES':\n return null;\n case 'SELECT_DATES':\n return action.selection;\n default:\n return currentSelection;\n }\n}\n\nfunction reduceSelectedEvent(currentInstanceId, action) {\n switch (action.type) {\n case 'UNSELECT_EVENT':\n return '';\n case 'SELECT_EVENT':\n return action.eventInstanceId;\n default:\n return currentInstanceId;\n }\n}\n\nfunction reduceEventDrag(currentDrag, action) {\n var newDrag;\n switch (action.type) {\n case 'UNSET_EVENT_DRAG':\n return null;\n case 'SET_EVENT_DRAG':\n newDrag = action.state;\n return {\n affectedEvents: newDrag.affectedEvents,\n mutatedEvents: newDrag.mutatedEvents,\n isEvent: newDrag.isEvent,\n };\n default:\n return currentDrag;\n }\n}\n\nfunction reduceEventResize(currentResize, action) {\n var newResize;\n switch (action.type) {\n case 'UNSET_EVENT_RESIZE':\n return null;\n case 'SET_EVENT_RESIZE':\n newResize = action.state;\n return {\n affectedEvents: newResize.affectedEvents,\n mutatedEvents: newResize.mutatedEvents,\n isEvent: newResize.isEvent,\n };\n default:\n return currentResize;\n }\n}\n\nfunction parseToolbars(calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi) {\n var viewsWithButtons = [];\n var headerToolbar = calendarOptions.headerToolbar ? parseToolbar(calendarOptions.headerToolbar, calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi, viewsWithButtons) : null;\n var footerToolbar = calendarOptions.footerToolbar ? parseToolbar(calendarOptions.footerToolbar, calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi, viewsWithButtons) : null;\n return { headerToolbar: headerToolbar, footerToolbar: footerToolbar, viewsWithButtons: viewsWithButtons };\n}\nfunction parseToolbar(sectionStrHash, calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi, viewsWithButtons) {\n return mapHash(sectionStrHash, function (sectionStr) { return parseSection(sectionStr, calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi, viewsWithButtons); });\n}\n/*\nBAD: querying icons and text here. should be done at render time\n*/\nfunction parseSection(sectionStr, calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi, viewsWithButtons) {\n var isRtl = calendarOptions.direction === 'rtl';\n var calendarCustomButtons = calendarOptions.customButtons || {};\n var calendarButtonTextOverrides = calendarOptionOverrides.buttonText || {};\n var calendarButtonText = calendarOptions.buttonText || {};\n var sectionSubstrs = sectionStr ? sectionStr.split(' ') : [];\n return sectionSubstrs.map(function (buttonGroupStr) { return (buttonGroupStr.split(',').map(function (buttonName) {\n if (buttonName === 'title') {\n return { buttonName: buttonName };\n }\n var customButtonProps;\n var viewSpec;\n var buttonClick;\n var buttonIcon; // only one of these will be set\n var buttonText; // \"\n if ((customButtonProps = calendarCustomButtons[buttonName])) {\n buttonClick = function (ev) {\n if (customButtonProps.click) {\n customButtonProps.click.call(ev.target, ev, ev.target); // TODO: use Calendar this context?\n }\n };\n (buttonIcon = theme.getCustomButtonIconClass(customButtonProps)) ||\n (buttonIcon = theme.getIconClass(buttonName, isRtl)) ||\n (buttonText = customButtonProps.text);\n }\n else if ((viewSpec = viewSpecs[buttonName])) {\n viewsWithButtons.push(buttonName);\n buttonClick = function () {\n calendarApi.changeView(buttonName);\n };\n (buttonText = viewSpec.buttonTextOverride) ||\n (buttonIcon = theme.getIconClass(buttonName, isRtl)) ||\n (buttonText = viewSpec.buttonTextDefault);\n }\n else if (calendarApi[buttonName]) { // a calendarApi method\n buttonClick = function () {\n calendarApi[buttonName]();\n };\n (buttonText = calendarButtonTextOverrides[buttonName]) ||\n (buttonIcon = theme.getIconClass(buttonName, isRtl)) ||\n (buttonText = calendarButtonText[buttonName]);\n // ^ everything else is considered default\n }\n return { buttonName: buttonName, buttonClick: buttonClick, buttonIcon: buttonIcon, buttonText: buttonText };\n })); });\n}\n\nvar eventSourceDef$2 = {\n ignoreRange: true,\n parseMeta: function (refined) {\n if (Array.isArray(refined.events)) {\n return refined.events;\n }\n return null;\n },\n fetch: function (arg, success) {\n success({\n rawEvents: arg.eventSource.meta,\n });\n },\n};\nvar arrayEventSourcePlugin = createPlugin({\n eventSourceDefs: [eventSourceDef$2],\n});\n\nvar eventSourceDef$1 = {\n parseMeta: function (refined) {\n if (typeof refined.events === 'function') {\n return refined.events;\n }\n return null;\n },\n fetch: function (arg, success, failure) {\n var dateEnv = arg.context.dateEnv;\n var func = arg.eventSource.meta;\n unpromisify(func.bind(null, buildRangeApiWithTimeZone(arg.range, dateEnv)), function (rawEvents) {\n success({ rawEvents: rawEvents }); // needs an object response\n }, failure);\n },\n};\nvar funcEventSourcePlugin = createPlugin({\n eventSourceDefs: [eventSourceDef$1],\n});\n\nfunction requestJson(method, url, params, successCallback, failureCallback) {\n method = method.toUpperCase();\n var body = null;\n if (method === 'GET') {\n url = injectQueryStringParams(url, params);\n }\n else {\n body = encodeParams(params);\n }\n var xhr = new XMLHttpRequest();\n xhr.open(method, url, true);\n if (method !== 'GET') {\n xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');\n }\n xhr.onload = function () {\n if (xhr.status >= 200 && xhr.status < 400) {\n var parsed = false;\n var res = void 0;\n try {\n res = JSON.parse(xhr.responseText);\n parsed = true;\n }\n catch (err) {\n // will handle parsed=false\n }\n if (parsed) {\n successCallback(res, xhr);\n }\n else {\n failureCallback('Failure parsing JSON', xhr);\n }\n }\n else {\n failureCallback('Request failed', xhr);\n }\n };\n xhr.onerror = function () {\n failureCallback('Request failed', xhr);\n };\n xhr.send(body);\n}\nfunction injectQueryStringParams(url, params) {\n return url +\n (url.indexOf('?') === -1 ? '?' : '&') +\n encodeParams(params);\n}\nfunction encodeParams(params) {\n var parts = [];\n for (var key in params) {\n parts.push(encodeURIComponent(key) + \"=\" + encodeURIComponent(params[key]));\n }\n return parts.join('&');\n}\n\nvar JSON_FEED_EVENT_SOURCE_REFINERS = {\n method: String,\n extraParams: identity,\n startParam: String,\n endParam: String,\n timeZoneParam: String,\n};\n\nvar eventSourceDef = {\n parseMeta: function (refined) {\n if (refined.url && (refined.format === 'json' || !refined.format)) {\n return {\n url: refined.url,\n format: 'json',\n method: (refined.method || 'GET').toUpperCase(),\n extraParams: refined.extraParams,\n startParam: refined.startParam,\n endParam: refined.endParam,\n timeZoneParam: refined.timeZoneParam,\n };\n }\n return null;\n },\n fetch: function (arg, success, failure) {\n var meta = arg.eventSource.meta;\n var requestParams = buildRequestParams(meta, arg.range, arg.context);\n requestJson(meta.method, meta.url, requestParams, function (rawEvents, xhr) {\n success({ rawEvents: rawEvents, xhr: xhr });\n }, function (errorMessage, xhr) {\n failure({ message: errorMessage, xhr: xhr });\n });\n },\n};\nvar jsonFeedEventSourcePlugin = createPlugin({\n eventSourceRefiners: JSON_FEED_EVENT_SOURCE_REFINERS,\n eventSourceDefs: [eventSourceDef],\n});\nfunction buildRequestParams(meta, range, context) {\n var dateEnv = context.dateEnv, options = context.options;\n var startParam;\n var endParam;\n var timeZoneParam;\n var customRequestParams;\n var params = {};\n startParam = meta.startParam;\n if (startParam == null) {\n startParam = options.startParam;\n }\n endParam = meta.endParam;\n if (endParam == null) {\n endParam = options.endParam;\n }\n timeZoneParam = meta.timeZoneParam;\n if (timeZoneParam == null) {\n timeZoneParam = options.timeZoneParam;\n }\n // retrieve any outbound GET/POST data from the options\n if (typeof meta.extraParams === 'function') {\n // supplied as a function that returns a key/value object\n customRequestParams = meta.extraParams();\n }\n else {\n // probably supplied as a straight key/value object\n customRequestParams = meta.extraParams || {};\n }\n __assign(params, customRequestParams);\n params[startParam] = dateEnv.formatIso(range.start);\n params[endParam] = dateEnv.formatIso(range.end);\n if (dateEnv.timeZone !== 'local') {\n params[timeZoneParam] = dateEnv.timeZone;\n }\n return params;\n}\n\nvar SIMPLE_RECURRING_REFINERS = {\n daysOfWeek: identity,\n startTime: createDuration,\n endTime: createDuration,\n duration: createDuration,\n startRecur: identity,\n endRecur: identity,\n};\n\nvar recurring = {\n parse: function (refined, dateEnv) {\n if (refined.daysOfWeek || refined.startTime || refined.endTime || refined.startRecur || refined.endRecur) {\n var recurringData = {\n daysOfWeek: refined.daysOfWeek || null,\n startTime: refined.startTime || null,\n endTime: refined.endTime || null,\n startRecur: refined.startRecur ? dateEnv.createMarker(refined.startRecur) : null,\n endRecur: refined.endRecur ? dateEnv.createMarker(refined.endRecur) : null,\n };\n var duration = void 0;\n if (refined.duration) {\n duration = refined.duration;\n }\n if (!duration && refined.startTime && refined.endTime) {\n duration = subtractDurations(refined.endTime, refined.startTime);\n }\n return {\n allDayGuess: Boolean(!refined.startTime && !refined.endTime),\n duration: duration,\n typeData: recurringData, // doesn't need endTime anymore but oh well\n };\n }\n return null;\n },\n expand: function (typeData, framingRange, dateEnv) {\n var clippedFramingRange = intersectRanges(framingRange, { start: typeData.startRecur, end: typeData.endRecur });\n if (clippedFramingRange) {\n return expandRanges(typeData.daysOfWeek, typeData.startTime, clippedFramingRange, dateEnv);\n }\n return [];\n },\n};\nvar simpleRecurringEventsPlugin = createPlugin({\n recurringTypes: [recurring],\n eventRefiners: SIMPLE_RECURRING_REFINERS,\n});\nfunction expandRanges(daysOfWeek, startTime, framingRange, dateEnv) {\n var dowHash = daysOfWeek ? arrayToHash(daysOfWeek) : null;\n var dayMarker = startOfDay(framingRange.start);\n var endMarker = framingRange.end;\n var instanceStarts = [];\n while (dayMarker < endMarker) {\n var instanceStart \n // if everyday, or this particular day-of-week\n = void 0;\n // if everyday, or this particular day-of-week\n if (!dowHash || dowHash[dayMarker.getUTCDay()]) {\n if (startTime) {\n instanceStart = dateEnv.add(dayMarker, startTime);\n }\n else {\n instanceStart = dayMarker;\n }\n instanceStarts.push(instanceStart);\n }\n dayMarker = addDays(dayMarker, 1);\n }\n return instanceStarts;\n}\n\nvar changeHandlerPlugin = createPlugin({\n optionChangeHandlers: {\n events: function (events, context) {\n handleEventSources([events], context);\n },\n eventSources: handleEventSources,\n },\n});\n/*\nBUG: if `event` was supplied, all previously-given `eventSources` will be wiped out\n*/\nfunction handleEventSources(inputs, context) {\n var unfoundSources = hashValuesToArray(context.getCurrentData().eventSources);\n var newInputs = [];\n for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) {\n var input = inputs_1[_i];\n var inputFound = false;\n for (var i = 0; i < unfoundSources.length; i += 1) {\n if (unfoundSources[i]._raw === input) {\n unfoundSources.splice(i, 1); // delete\n inputFound = true;\n break;\n }\n }\n if (!inputFound) {\n newInputs.push(input);\n }\n }\n for (var _a = 0, unfoundSources_1 = unfoundSources; _a < unfoundSources_1.length; _a++) {\n var unfoundSource = unfoundSources_1[_a];\n context.dispatch({\n type: 'REMOVE_EVENT_SOURCE',\n sourceId: unfoundSource.sourceId,\n });\n }\n for (var _b = 0, newInputs_1 = newInputs; _b < newInputs_1.length; _b++) {\n var newInput = newInputs_1[_b];\n context.calendarApi.addEventSource(newInput);\n }\n}\n\nfunction handleDateProfile(dateProfile, context) {\n context.emitter.trigger('datesSet', __assign(__assign({}, buildRangeApiWithTimeZone(dateProfile.activeRange, context.dateEnv)), { view: context.viewApi }));\n}\n\nfunction handleEventStore(eventStore, context) {\n var emitter = context.emitter;\n if (emitter.hasHandlers('eventsSet')) {\n emitter.trigger('eventsSet', buildEventApis(eventStore, context));\n }\n}\n\n/*\nthis array is exposed on the root namespace so that UMD plugins can add to it.\nsee the rollup-bundles script.\n*/\nvar globalPlugins = [\n arrayEventSourcePlugin,\n funcEventSourcePlugin,\n jsonFeedEventSourcePlugin,\n simpleRecurringEventsPlugin,\n changeHandlerPlugin,\n createPlugin({\n isLoadingFuncs: [\n function (state) { return computeEventSourcesLoading(state.eventSources); },\n ],\n contentTypeHandlers: {\n html: function () { return ({ render: injectHtml }); },\n domNodes: function () { return ({ render: injectDomNodes }); },\n },\n propSetHandlers: {\n dateProfile: handleDateProfile,\n eventStore: handleEventStore,\n },\n }),\n];\nfunction injectHtml(el, html) {\n el.innerHTML = html;\n}\nfunction injectDomNodes(el, domNodes) {\n var oldNodes = Array.prototype.slice.call(el.childNodes); // TODO: use array util\n var newNodes = Array.prototype.slice.call(domNodes); // TODO: use array util\n if (!isArraysEqual(oldNodes, newNodes)) {\n for (var _i = 0, newNodes_1 = newNodes; _i < newNodes_1.length; _i++) {\n var newNode = newNodes_1[_i];\n el.appendChild(newNode);\n }\n oldNodes.forEach(removeElement);\n }\n}\n\nvar DelayedRunner = /** @class */ (function () {\n function DelayedRunner(drainedOption) {\n this.drainedOption = drainedOption;\n this.isRunning = false;\n this.isDirty = false;\n this.pauseDepths = {};\n this.timeoutId = 0;\n }\n DelayedRunner.prototype.request = function (delay) {\n this.isDirty = true;\n if (!this.isPaused()) {\n this.clearTimeout();\n if (delay == null) {\n this.tryDrain();\n }\n else {\n this.timeoutId = setTimeout(// NOT OPTIMAL! TODO: look at debounce\n this.tryDrain.bind(this), delay);\n }\n }\n };\n DelayedRunner.prototype.pause = function (scope) {\n if (scope === void 0) { scope = ''; }\n var pauseDepths = this.pauseDepths;\n pauseDepths[scope] = (pauseDepths[scope] || 0) + 1;\n this.clearTimeout();\n };\n DelayedRunner.prototype.resume = function (scope, force) {\n if (scope === void 0) { scope = ''; }\n var pauseDepths = this.pauseDepths;\n if (scope in pauseDepths) {\n if (force) {\n delete pauseDepths[scope];\n }\n else {\n pauseDepths[scope] -= 1;\n var depth = pauseDepths[scope];\n if (depth <= 0) {\n delete pauseDepths[scope];\n }\n }\n this.tryDrain();\n }\n };\n DelayedRunner.prototype.isPaused = function () {\n return Object.keys(this.pauseDepths).length;\n };\n DelayedRunner.prototype.tryDrain = function () {\n if (!this.isRunning && !this.isPaused()) {\n this.isRunning = true;\n while (this.isDirty) {\n this.isDirty = false;\n this.drained(); // might set isDirty to true again\n }\n this.isRunning = false;\n }\n };\n DelayedRunner.prototype.clear = function () {\n this.clearTimeout();\n this.isDirty = false;\n this.pauseDepths = {};\n };\n DelayedRunner.prototype.clearTimeout = function () {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n this.timeoutId = 0;\n }\n };\n DelayedRunner.prototype.drained = function () {\n if (this.drainedOption) {\n this.drainedOption();\n }\n };\n return DelayedRunner;\n}());\n\nvar TaskRunner = /** @class */ (function () {\n function TaskRunner(runTaskOption, drainedOption) {\n this.runTaskOption = runTaskOption;\n this.drainedOption = drainedOption;\n this.queue = [];\n this.delayedRunner = new DelayedRunner(this.drain.bind(this));\n }\n TaskRunner.prototype.request = function (task, delay) {\n this.queue.push(task);\n this.delayedRunner.request(delay);\n };\n TaskRunner.prototype.pause = function (scope) {\n this.delayedRunner.pause(scope);\n };\n TaskRunner.prototype.resume = function (scope, force) {\n this.delayedRunner.resume(scope, force);\n };\n TaskRunner.prototype.drain = function () {\n var queue = this.queue;\n while (queue.length) {\n var completedTasks = [];\n var task = void 0;\n while ((task = queue.shift())) {\n this.runTask(task);\n completedTasks.push(task);\n }\n this.drained(completedTasks);\n } // keep going, in case new tasks were added in the drained handler\n };\n TaskRunner.prototype.runTask = function (task) {\n if (this.runTaskOption) {\n this.runTaskOption(task);\n }\n };\n TaskRunner.prototype.drained = function (completedTasks) {\n if (this.drainedOption) {\n this.drainedOption(completedTasks);\n }\n };\n return TaskRunner;\n}());\n\n// Computes what the title at the top of the calendarApi should be for this view\nfunction buildTitle(dateProfile, viewOptions, dateEnv) {\n var range;\n // for views that span a large unit of time, show the proper interval, ignoring stray days before and after\n if (/^(year|month)$/.test(dateProfile.currentRangeUnit)) {\n range = dateProfile.currentRange;\n }\n else { // for day units or smaller, use the actual day range\n range = dateProfile.activeRange;\n }\n return dateEnv.formatRange(range.start, range.end, createFormatter(viewOptions.titleFormat || buildTitleFormat(dateProfile)), {\n isEndExclusive: dateProfile.isRangeAllDay,\n defaultSeparator: viewOptions.titleRangeSeparator,\n });\n}\n// Generates the format string that should be used to generate the title for the current date range.\n// Attempts to compute the most appropriate format if not explicitly specified with `titleFormat`.\nfunction buildTitleFormat(dateProfile) {\n var currentRangeUnit = dateProfile.currentRangeUnit;\n if (currentRangeUnit === 'year') {\n return { year: 'numeric' };\n }\n if (currentRangeUnit === 'month') {\n return { year: 'numeric', month: 'long' }; // like \"September 2014\"\n }\n var days = diffWholeDays(dateProfile.currentRange.start, dateProfile.currentRange.end);\n if (days !== null && days > 1) {\n // multi-day range. shorter, like \"Sep 9 - 10 2014\"\n return { year: 'numeric', month: 'short', day: 'numeric' };\n }\n // one day. longer, like \"September 9 2014\"\n return { year: 'numeric', month: 'long', day: 'numeric' };\n}\n\n// in future refactor, do the redux-style function(state=initial) for initial-state\n// also, whatever is happening in constructor, have it happen in action queue too\nvar CalendarDataManager = /** @class */ (function () {\n function CalendarDataManager(props) {\n var _this = this;\n this.computeOptionsData = memoize(this._computeOptionsData);\n this.computeCurrentViewData = memoize(this._computeCurrentViewData);\n this.organizeRawLocales = memoize(organizeRawLocales);\n this.buildLocale = memoize(buildLocale);\n this.buildPluginHooks = buildBuildPluginHooks();\n this.buildDateEnv = memoize(buildDateEnv);\n this.buildTheme = memoize(buildTheme);\n this.parseToolbars = memoize(parseToolbars);\n this.buildViewSpecs = memoize(buildViewSpecs);\n this.buildDateProfileGenerator = memoizeObjArg(buildDateProfileGenerator);\n this.buildViewApi = memoize(buildViewApi);\n this.buildViewUiProps = memoizeObjArg(buildViewUiProps);\n this.buildEventUiBySource = memoize(buildEventUiBySource, isPropsEqual);\n this.buildEventUiBases = memoize(buildEventUiBases);\n this.parseContextBusinessHours = memoizeObjArg(parseContextBusinessHours);\n this.buildTitle = memoize(buildTitle);\n this.emitter = new Emitter();\n this.actionRunner = new TaskRunner(this._handleAction.bind(this), this.updateData.bind(this));\n this.currentCalendarOptionsInput = {};\n this.currentCalendarOptionsRefined = {};\n this.currentViewOptionsInput = {};\n this.currentViewOptionsRefined = {};\n this.currentCalendarOptionsRefiners = {};\n this.getCurrentData = function () { return _this.data; };\n this.dispatch = function (action) {\n _this.actionRunner.request(action); // protects against recursive calls to _handleAction\n };\n this.props = props;\n this.actionRunner.pause();\n var dynamicOptionOverrides = {};\n var optionsData = this.computeOptionsData(props.optionOverrides, dynamicOptionOverrides, props.calendarApi);\n var currentViewType = optionsData.calendarOptions.initialView || optionsData.pluginHooks.initialView;\n var currentViewData = this.computeCurrentViewData(currentViewType, optionsData, props.optionOverrides, dynamicOptionOverrides);\n // wire things up\n // TODO: not DRY\n props.calendarApi.currentDataManager = this;\n this.emitter.setThisContext(props.calendarApi);\n this.emitter.setOptions(currentViewData.options);\n var currentDate = getInitialDate(optionsData.calendarOptions, optionsData.dateEnv);\n var dateProfile = currentViewData.dateProfileGenerator.build(currentDate);\n if (!rangeContainsMarker(dateProfile.activeRange, currentDate)) {\n currentDate = dateProfile.currentRange.start;\n }\n var calendarContext = {\n dateEnv: optionsData.dateEnv,\n options: optionsData.calendarOptions,\n pluginHooks: optionsData.pluginHooks,\n calendarApi: props.calendarApi,\n dispatch: this.dispatch,\n emitter: this.emitter,\n getCurrentData: this.getCurrentData,\n };\n // needs to be after setThisContext\n for (var _i = 0, _a = optionsData.pluginHooks.contextInit; _i < _a.length; _i++) {\n var callback = _a[_i];\n callback(calendarContext);\n }\n // NOT DRY\n var eventSources = initEventSources(optionsData.calendarOptions, dateProfile, calendarContext);\n var initialState = {\n dynamicOptionOverrides: dynamicOptionOverrides,\n currentViewType: currentViewType,\n currentDate: currentDate,\n dateProfile: dateProfile,\n businessHours: this.parseContextBusinessHours(calendarContext),\n eventSources: eventSources,\n eventUiBases: {},\n eventStore: createEmptyEventStore(),\n renderableEventStore: createEmptyEventStore(),\n dateSelection: null,\n eventSelection: '',\n eventDrag: null,\n eventResize: null,\n selectionConfig: this.buildViewUiProps(calendarContext).selectionConfig,\n };\n var contextAndState = __assign(__assign({}, calendarContext), initialState);\n for (var _b = 0, _c = optionsData.pluginHooks.reducers; _b < _c.length; _b++) {\n var reducer = _c[_b];\n __assign(initialState, reducer(null, null, contextAndState));\n }\n if (computeIsLoading(initialState, calendarContext)) {\n this.emitter.trigger('loading', true); // NOT DRY\n }\n this.state = initialState;\n this.updateData();\n this.actionRunner.resume();\n }\n CalendarDataManager.prototype.resetOptions = function (optionOverrides, append) {\n var props = this.props;\n props.optionOverrides = append\n ? __assign(__assign({}, props.optionOverrides), optionOverrides) : optionOverrides;\n this.actionRunner.request({\n type: 'NOTHING',\n });\n };\n CalendarDataManager.prototype._handleAction = function (action) {\n var _a = this, props = _a.props, state = _a.state, emitter = _a.emitter;\n var dynamicOptionOverrides = reduceDynamicOptionOverrides(state.dynamicOptionOverrides, action);\n var optionsData = this.computeOptionsData(props.optionOverrides, dynamicOptionOverrides, props.calendarApi);\n var currentViewType = reduceViewType(state.currentViewType, action);\n var currentViewData = this.computeCurrentViewData(currentViewType, optionsData, props.optionOverrides, dynamicOptionOverrides);\n // wire things up\n // TODO: not DRY\n props.calendarApi.currentDataManager = this;\n emitter.setThisContext(props.calendarApi);\n emitter.setOptions(currentViewData.options);\n var calendarContext = {\n dateEnv: optionsData.dateEnv,\n options: optionsData.calendarOptions,\n pluginHooks: optionsData.pluginHooks,\n calendarApi: props.calendarApi,\n dispatch: this.dispatch,\n emitter: emitter,\n getCurrentData: this.getCurrentData,\n };\n var currentDate = state.currentDate, dateProfile = state.dateProfile;\n if (this.data && this.data.dateProfileGenerator !== currentViewData.dateProfileGenerator) { // hack\n dateProfile = currentViewData.dateProfileGenerator.build(currentDate);\n }\n currentDate = reduceCurrentDate(currentDate, action);\n dateProfile = reduceDateProfile(dateProfile, action, currentDate, currentViewData.dateProfileGenerator);\n if (action.type === 'PREV' || // TODO: move this logic into DateProfileGenerator\n action.type === 'NEXT' || // \"\n !rangeContainsMarker(dateProfile.currentRange, currentDate)) {\n currentDate = dateProfile.currentRange.start;\n }\n var eventSources = reduceEventSources(state.eventSources, action, dateProfile, calendarContext);\n var eventStore = reduceEventStore(state.eventStore, action, eventSources, dateProfile, calendarContext);\n var isEventsLoading = computeEventSourcesLoading(eventSources); // BAD. also called in this func in computeIsLoading\n var renderableEventStore = (isEventsLoading && !currentViewData.options.progressiveEventRendering) ?\n (state.renderableEventStore || eventStore) : // try from previous state\n eventStore;\n var _b = this.buildViewUiProps(calendarContext), eventUiSingleBase = _b.eventUiSingleBase, selectionConfig = _b.selectionConfig; // will memoize obj\n var eventUiBySource = this.buildEventUiBySource(eventSources);\n var eventUiBases = this.buildEventUiBases(renderableEventStore.defs, eventUiSingleBase, eventUiBySource);\n var newState = {\n dynamicOptionOverrides: dynamicOptionOverrides,\n currentViewType: currentViewType,\n currentDate: currentDate,\n dateProfile: dateProfile,\n eventSources: eventSources,\n eventStore: eventStore,\n renderableEventStore: renderableEventStore,\n selectionConfig: selectionConfig,\n eventUiBases: eventUiBases,\n businessHours: this.parseContextBusinessHours(calendarContext),\n dateSelection: reduceDateSelection(state.dateSelection, action),\n eventSelection: reduceSelectedEvent(state.eventSelection, action),\n eventDrag: reduceEventDrag(state.eventDrag, action),\n eventResize: reduceEventResize(state.eventResize, action),\n };\n var contextAndState = __assign(__assign({}, calendarContext), newState);\n for (var _i = 0, _c = optionsData.pluginHooks.reducers; _i < _c.length; _i++) {\n var reducer = _c[_i];\n __assign(newState, reducer(state, action, contextAndState)); // give the OLD state, for old value\n }\n var wasLoading = computeIsLoading(state, calendarContext);\n var isLoading = computeIsLoading(newState, calendarContext);\n // TODO: use propSetHandlers in plugin system\n if (!wasLoading && isLoading) {\n emitter.trigger('loading', true);\n }\n else if (wasLoading && !isLoading) {\n emitter.trigger('loading', false);\n }\n this.state = newState;\n if (props.onAction) {\n props.onAction(action);\n }\n };\n CalendarDataManager.prototype.updateData = function () {\n var _a = this, props = _a.props, state = _a.state;\n var oldData = this.data;\n var optionsData = this.computeOptionsData(props.optionOverrides, state.dynamicOptionOverrides, props.calendarApi);\n var currentViewData = this.computeCurrentViewData(state.currentViewType, optionsData, props.optionOverrides, state.dynamicOptionOverrides);\n var data = this.data = __assign(__assign(__assign({ viewTitle: this.buildTitle(state.dateProfile, currentViewData.options, optionsData.dateEnv), calendarApi: props.calendarApi, dispatch: this.dispatch, emitter: this.emitter, getCurrentData: this.getCurrentData }, optionsData), currentViewData), state);\n var changeHandlers = optionsData.pluginHooks.optionChangeHandlers;\n var oldCalendarOptions = oldData && oldData.calendarOptions;\n var newCalendarOptions = optionsData.calendarOptions;\n if (oldCalendarOptions && oldCalendarOptions !== newCalendarOptions) {\n if (oldCalendarOptions.timeZone !== newCalendarOptions.timeZone) {\n // hack\n state.eventSources = data.eventSources = reduceEventSourcesNewTimeZone(data.eventSources, state.dateProfile, data);\n state.eventStore = data.eventStore = rezoneEventStoreDates(data.eventStore, oldData.dateEnv, data.dateEnv);\n }\n for (var optionName in changeHandlers) {\n if (oldCalendarOptions[optionName] !== newCalendarOptions[optionName]) {\n changeHandlers[optionName](newCalendarOptions[optionName], data);\n }\n }\n }\n if (props.onData) {\n props.onData(data);\n }\n };\n CalendarDataManager.prototype._computeOptionsData = function (optionOverrides, dynamicOptionOverrides, calendarApi) {\n // TODO: blacklist options that are handled by optionChangeHandlers\n var _a = this.processRawCalendarOptions(optionOverrides, dynamicOptionOverrides), refinedOptions = _a.refinedOptions, pluginHooks = _a.pluginHooks, localeDefaults = _a.localeDefaults, availableLocaleData = _a.availableLocaleData, extra = _a.extra;\n warnUnknownOptions(extra);\n var dateEnv = this.buildDateEnv(refinedOptions.timeZone, refinedOptions.locale, refinedOptions.weekNumberCalculation, refinedOptions.firstDay, refinedOptions.weekText, pluginHooks, availableLocaleData, refinedOptions.defaultRangeSeparator);\n var viewSpecs = this.buildViewSpecs(pluginHooks.views, optionOverrides, dynamicOptionOverrides, localeDefaults);\n var theme = this.buildTheme(refinedOptions, pluginHooks);\n var toolbarConfig = this.parseToolbars(refinedOptions, optionOverrides, theme, viewSpecs, calendarApi);\n return {\n calendarOptions: refinedOptions,\n pluginHooks: pluginHooks,\n dateEnv: dateEnv,\n viewSpecs: viewSpecs,\n theme: theme,\n toolbarConfig: toolbarConfig,\n localeDefaults: localeDefaults,\n availableRawLocales: availableLocaleData.map,\n };\n };\n // always called from behind a memoizer\n CalendarDataManager.prototype.processRawCalendarOptions = function (optionOverrides, dynamicOptionOverrides) {\n var _a = mergeRawOptions([\n BASE_OPTION_DEFAULTS,\n optionOverrides,\n dynamicOptionOverrides,\n ]), locales = _a.locales, locale = _a.locale;\n var availableLocaleData = this.organizeRawLocales(locales);\n var availableRawLocales = availableLocaleData.map;\n var localeDefaults = this.buildLocale(locale || availableLocaleData.defaultCode, availableRawLocales).options;\n var pluginHooks = this.buildPluginHooks(optionOverrides.plugins || [], globalPlugins);\n var refiners = this.currentCalendarOptionsRefiners = __assign(__assign(__assign(__assign(__assign({}, BASE_OPTION_REFINERS), CALENDAR_LISTENER_REFINERS), CALENDAR_OPTION_REFINERS), pluginHooks.listenerRefiners), pluginHooks.optionRefiners);\n var extra = {};\n var raw = mergeRawOptions([\n BASE_OPTION_DEFAULTS,\n localeDefaults,\n optionOverrides,\n dynamicOptionOverrides,\n ]);\n var refined = {};\n var currentRaw = this.currentCalendarOptionsInput;\n var currentRefined = this.currentCalendarOptionsRefined;\n var anyChanges = false;\n for (var optionName in raw) {\n if (optionName !== 'plugins') { // because plugins is special-cased\n if (raw[optionName] === currentRaw[optionName] ||\n (COMPLEX_OPTION_COMPARATORS[optionName] &&\n (optionName in currentRaw) &&\n COMPLEX_OPTION_COMPARATORS[optionName](currentRaw[optionName], raw[optionName]))) {\n refined[optionName] = currentRefined[optionName];\n }\n else if (refiners[optionName]) {\n refined[optionName] = refiners[optionName](raw[optionName]);\n anyChanges = true;\n }\n else {\n extra[optionName] = currentRaw[optionName];\n }\n }\n }\n if (anyChanges) {\n this.currentCalendarOptionsInput = raw;\n this.currentCalendarOptionsRefined = refined;\n }\n return {\n rawOptions: this.currentCalendarOptionsInput,\n refinedOptions: this.currentCalendarOptionsRefined,\n pluginHooks: pluginHooks,\n availableLocaleData: availableLocaleData,\n localeDefaults: localeDefaults,\n extra: extra,\n };\n };\n CalendarDataManager.prototype._computeCurrentViewData = function (viewType, optionsData, optionOverrides, dynamicOptionOverrides) {\n var viewSpec = optionsData.viewSpecs[viewType];\n if (!viewSpec) {\n throw new Error(\"viewType \\\"\" + viewType + \"\\\" is not available. Please make sure you've loaded all neccessary plugins\");\n }\n var _a = this.processRawViewOptions(viewSpec, optionsData.pluginHooks, optionsData.localeDefaults, optionOverrides, dynamicOptionOverrides), refinedOptions = _a.refinedOptions, extra = _a.extra;\n warnUnknownOptions(extra);\n var dateProfileGenerator = this.buildDateProfileGenerator({\n dateProfileGeneratorClass: viewSpec.optionDefaults.dateProfileGeneratorClass,\n duration: viewSpec.duration,\n durationUnit: viewSpec.durationUnit,\n usesMinMaxTime: viewSpec.optionDefaults.usesMinMaxTime,\n dateEnv: optionsData.dateEnv,\n calendarApi: this.props.calendarApi,\n slotMinTime: refinedOptions.slotMinTime,\n slotMaxTime: refinedOptions.slotMaxTime,\n showNonCurrentDates: refinedOptions.showNonCurrentDates,\n dayCount: refinedOptions.dayCount,\n dateAlignment: refinedOptions.dateAlignment,\n dateIncrement: refinedOptions.dateIncrement,\n hiddenDays: refinedOptions.hiddenDays,\n weekends: refinedOptions.weekends,\n nowInput: refinedOptions.now,\n validRangeInput: refinedOptions.validRange,\n visibleRangeInput: refinedOptions.visibleRange,\n monthMode: refinedOptions.monthMode,\n fixedWeekCount: refinedOptions.fixedWeekCount,\n });\n var viewApi = this.buildViewApi(viewType, this.getCurrentData, optionsData.dateEnv);\n return { viewSpec: viewSpec, options: refinedOptions, dateProfileGenerator: dateProfileGenerator, viewApi: viewApi };\n };\n CalendarDataManager.prototype.processRawViewOptions = function (viewSpec, pluginHooks, localeDefaults, optionOverrides, dynamicOptionOverrides) {\n var raw = mergeRawOptions([\n BASE_OPTION_DEFAULTS,\n viewSpec.optionDefaults,\n localeDefaults,\n optionOverrides,\n viewSpec.optionOverrides,\n dynamicOptionOverrides,\n ]);\n var refiners = __assign(__assign(__assign(__assign(__assign(__assign({}, BASE_OPTION_REFINERS), CALENDAR_LISTENER_REFINERS), CALENDAR_OPTION_REFINERS), VIEW_OPTION_REFINERS), pluginHooks.listenerRefiners), pluginHooks.optionRefiners);\n var refined = {};\n var currentRaw = this.currentViewOptionsInput;\n var currentRefined = this.currentViewOptionsRefined;\n var anyChanges = false;\n var extra = {};\n for (var optionName in raw) {\n if (raw[optionName] === currentRaw[optionName]) {\n refined[optionName] = currentRefined[optionName];\n }\n else {\n if (raw[optionName] === this.currentCalendarOptionsInput[optionName]) {\n if (optionName in this.currentCalendarOptionsRefined) { // might be an \"extra\" prop\n refined[optionName] = this.currentCalendarOptionsRefined[optionName];\n }\n }\n else if (refiners[optionName]) {\n refined[optionName] = refiners[optionName](raw[optionName]);\n }\n else {\n extra[optionName] = raw[optionName];\n }\n anyChanges = true;\n }\n }\n if (anyChanges) {\n this.currentViewOptionsInput = raw;\n this.currentViewOptionsRefined = refined;\n }\n return {\n rawOptions: this.currentViewOptionsInput,\n refinedOptions: this.currentViewOptionsRefined,\n extra: extra,\n };\n };\n return CalendarDataManager;\n}());\nfunction buildDateEnv(timeZone, explicitLocale, weekNumberCalculation, firstDay, weekText, pluginHooks, availableLocaleData, defaultSeparator) {\n var locale = buildLocale(explicitLocale || availableLocaleData.defaultCode, availableLocaleData.map);\n return new DateEnv({\n calendarSystem: 'gregory',\n timeZone: timeZone,\n namedTimeZoneImpl: pluginHooks.namedTimeZonedImpl,\n locale: locale,\n weekNumberCalculation: weekNumberCalculation,\n firstDay: firstDay,\n weekText: weekText,\n cmdFormatter: pluginHooks.cmdFormatter,\n defaultSeparator: defaultSeparator,\n });\n}\nfunction buildTheme(options, pluginHooks) {\n var ThemeClass = pluginHooks.themeClasses[options.themeSystem] || StandardTheme;\n return new ThemeClass(options);\n}\nfunction buildDateProfileGenerator(props) {\n var DateProfileGeneratorClass = props.dateProfileGeneratorClass || DateProfileGenerator;\n return new DateProfileGeneratorClass(props);\n}\nfunction buildViewApi(type, getCurrentData, dateEnv) {\n return new ViewApi(type, getCurrentData, dateEnv);\n}\nfunction buildEventUiBySource(eventSources) {\n return mapHash(eventSources, function (eventSource) { return eventSource.ui; });\n}\nfunction buildEventUiBases(eventDefs, eventUiSingleBase, eventUiBySource) {\n var eventUiBases = { '': eventUiSingleBase };\n for (var defId in eventDefs) {\n var def = eventDefs[defId];\n if (def.sourceId && eventUiBySource[def.sourceId]) {\n eventUiBases[defId] = eventUiBySource[def.sourceId];\n }\n }\n return eventUiBases;\n}\nfunction buildViewUiProps(calendarContext) {\n var options = calendarContext.options;\n return {\n eventUiSingleBase: createEventUi({\n display: options.eventDisplay,\n editable: options.editable,\n startEditable: options.eventStartEditable,\n durationEditable: options.eventDurationEditable,\n constraint: options.eventConstraint,\n overlap: typeof options.eventOverlap === 'boolean' ? options.eventOverlap : undefined,\n allow: options.eventAllow,\n backgroundColor: options.eventBackgroundColor,\n borderColor: options.eventBorderColor,\n textColor: options.eventTextColor,\n color: options.eventColor,\n // classNames: options.eventClassNames // render hook will handle this\n }, calendarContext),\n selectionConfig: createEventUi({\n constraint: options.selectConstraint,\n overlap: typeof options.selectOverlap === 'boolean' ? options.selectOverlap : undefined,\n allow: options.selectAllow,\n }, calendarContext),\n };\n}\nfunction computeIsLoading(state, context) {\n for (var _i = 0, _a = context.pluginHooks.isLoadingFuncs; _i < _a.length; _i++) {\n var isLoadingFunc = _a[_i];\n if (isLoadingFunc(state)) {\n return true;\n }\n }\n return false;\n}\nfunction parseContextBusinessHours(calendarContext) {\n return parseBusinessHours(calendarContext.options.businessHours, calendarContext);\n}\nfunction warnUnknownOptions(options, viewName) {\n for (var optionName in options) {\n console.warn(\"Unknown option '\" + optionName + \"'\" +\n (viewName ? \" for view '\" + viewName + \"'\" : ''));\n }\n}\n\n// TODO: move this to react plugin?\nvar CalendarDataProvider = /** @class */ (function (_super) {\n __extends(CalendarDataProvider, _super);\n function CalendarDataProvider(props) {\n var _this = _super.call(this, props) || this;\n _this.handleData = function (data) {\n if (!_this.dataManager) { // still within initial run, before assignment in constructor\n // eslint-disable-next-line react/no-direct-mutation-state\n _this.state = data; // can't use setState yet\n }\n else {\n _this.setState(data);\n }\n };\n _this.dataManager = new CalendarDataManager({\n optionOverrides: props.optionOverrides,\n calendarApi: props.calendarApi,\n onData: _this.handleData,\n });\n return _this;\n }\n CalendarDataProvider.prototype.render = function () {\n return this.props.children(this.state);\n };\n CalendarDataProvider.prototype.componentDidUpdate = function (prevProps) {\n var newOptionOverrides = this.props.optionOverrides;\n if (newOptionOverrides !== prevProps.optionOverrides) { // prevent recursive handleData\n this.dataManager.resetOptions(newOptionOverrides);\n }\n };\n return CalendarDataProvider;\n}(Component));\n\n// HELPERS\n/*\nif nextDayThreshold is specified, slicing is done in an all-day fashion.\nyou can get nextDayThreshold from context.nextDayThreshold\n*/\nfunction sliceEvents(props, allDay) {\n return sliceEventStore(props.eventStore, props.eventUiBases, props.dateProfile.activeRange, allDay ? props.nextDayThreshold : null).fg;\n}\n\nvar NamedTimeZoneImpl = /** @class */ (function () {\n function NamedTimeZoneImpl(timeZoneName) {\n this.timeZoneName = timeZoneName;\n }\n return NamedTimeZoneImpl;\n}());\n\nvar SegHierarchy = /** @class */ (function () {\n function SegHierarchy() {\n // settings\n this.strictOrder = false;\n this.allowReslicing = false;\n this.maxCoord = -1; // -1 means no max\n this.maxStackCnt = -1; // -1 means no max\n this.levelCoords = []; // ordered\n this.entriesByLevel = []; // parallel with levelCoords\n this.stackCnts = {}; // TODO: use better technique!?\n }\n SegHierarchy.prototype.addSegs = function (inputs) {\n var hiddenEntries = [];\n for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) {\n var input = inputs_1[_i];\n this.insertEntry(input, hiddenEntries);\n }\n return hiddenEntries;\n };\n SegHierarchy.prototype.insertEntry = function (entry, hiddenEntries) {\n var insertion = this.findInsertion(entry);\n if (this.isInsertionValid(insertion, entry)) {\n this.insertEntryAt(entry, insertion);\n return 1;\n }\n return this.handleInvalidInsertion(insertion, entry, hiddenEntries);\n };\n SegHierarchy.prototype.isInsertionValid = function (insertion, entry) {\n return (this.maxCoord === -1 || insertion.levelCoord + entry.thickness <= this.maxCoord) &&\n (this.maxStackCnt === -1 || insertion.stackCnt < this.maxStackCnt);\n };\n // returns number of new entries inserted\n SegHierarchy.prototype.handleInvalidInsertion = function (insertion, entry, hiddenEntries) {\n if (this.allowReslicing && insertion.touchingEntry) {\n return this.splitEntry(entry, insertion.touchingEntry, hiddenEntries);\n }\n hiddenEntries.push(entry);\n return 0;\n };\n SegHierarchy.prototype.splitEntry = function (entry, barrier, hiddenEntries) {\n var partCnt = 0;\n var splitHiddenEntries = [];\n var entrySpan = entry.span;\n var barrierSpan = barrier.span;\n if (entrySpan.start < barrierSpan.start) {\n partCnt += this.insertEntry({\n index: entry.index,\n thickness: entry.thickness,\n span: { start: entrySpan.start, end: barrierSpan.start },\n }, splitHiddenEntries);\n }\n if (entrySpan.end > barrierSpan.end) {\n partCnt += this.insertEntry({\n index: entry.index,\n thickness: entry.thickness,\n span: { start: barrierSpan.end, end: entrySpan.end },\n }, splitHiddenEntries);\n }\n if (partCnt) {\n hiddenEntries.push.apply(hiddenEntries, __spreadArray([{\n index: entry.index,\n thickness: entry.thickness,\n span: intersectSpans(barrierSpan, entrySpan), // guaranteed to intersect\n }], splitHiddenEntries));\n return partCnt;\n }\n hiddenEntries.push(entry);\n return 0;\n };\n SegHierarchy.prototype.insertEntryAt = function (entry, insertion) {\n var _a = this, entriesByLevel = _a.entriesByLevel, levelCoords = _a.levelCoords;\n var destLevel = insertion.level;\n if (destLevel >= levelCoords.length || // level doesn't exist yet\n levelCoords[destLevel] > insertion.levelCoord // destLevel needs to be pushed forward to make way\n ) {\n // create a new level\n insertAt(levelCoords, destLevel, insertion.levelCoord);\n insertAt(entriesByLevel, destLevel, [entry]);\n }\n else {\n // insert into existing level\n insertAt(entriesByLevel[destLevel], insertion.lateralEnd, entry);\n }\n this.stackCnts[buildEntryKey(entry)] = insertion.stackCnt;\n };\n SegHierarchy.prototype.findInsertion = function (newEntry) {\n var _a = this, levelCoords = _a.levelCoords, entriesByLevel = _a.entriesByLevel, stackCnts = _a.stackCnts, strictOrder = _a.strictOrder;\n var levelCnt = levelCoords.length;\n var resLevelCoord = 0;\n var resLevel = 0;\n var lateralStart = 0;\n var lateralEnd = 0;\n var touchingLevel = -1;\n var touchingEntry = null; // last touch entry\n for (var level = 0; level < levelCnt; level += 1) {\n var levelCoord = levelCoords[level];\n // if the current level is past the placed entry, we have found a good empty space and can stop.\n // if strictOrder, keep finding more lateral intersections.\n if (!strictOrder && levelCoord >= resLevelCoord + newEntry.thickness) {\n break;\n }\n var entries = entriesByLevel[level];\n var entry = void 0;\n var searchRes = binarySearch(entries, newEntry.span.start, getEntrySpanEnd);\n lateralStart = searchRes[0] + searchRes[1]; // if exact match (which doesn't collide), go to next one\n lateralEnd = lateralStart; // also functions as a moving index\n while ( // loop through entries that horizontally intersect\n (entry = entries[lateralEnd]) && // but not past the whole entry list\n entry.span.start < newEntry.span.end // and not entirely past newEntry\n ) {\n if (strictOrder || // strict-mode doesn't care about vert intersection. record touch and keep pushing down\n ( // vertically intersects?\n resLevelCoord < levelCoord + entry.thickness &&\n resLevelCoord + newEntry.thickness > levelCoord)) {\n // push down the potential destination\n resLevelCoord = levelCoord + entry.thickness; // move to bottom of colliding entry\n touchingLevel = level;\n touchingEntry = entry;\n }\n lateralEnd += 1;\n }\n // regardless of whether there were collisions in the current level,\n // keep updating the final-destination level until it goes past the final-destination coord.\n if (levelCoord < resLevelCoord) {\n resLevel = level + 1;\n }\n }\n return {\n level: resLevel,\n levelCoord: resLevelCoord,\n lateralStart: lateralStart,\n lateralEnd: lateralEnd,\n touchingLevel: touchingLevel,\n touchingEntry: touchingEntry,\n stackCnt: touchingEntry ? stackCnts[buildEntryKey(touchingEntry)] + 1 : 0,\n };\n };\n // sorted by levelCoord (lowest to highest)\n SegHierarchy.prototype.toRects = function () {\n var _a = this, entriesByLevel = _a.entriesByLevel, levelCoords = _a.levelCoords;\n var levelCnt = entriesByLevel.length;\n var rects = [];\n for (var level = 0; level < levelCnt; level += 1) {\n var entries = entriesByLevel[level];\n var levelCoord = levelCoords[level];\n for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {\n var entry = entries_1[_i];\n rects.push(__assign(__assign({}, entry), { levelCoord: levelCoord }));\n }\n }\n return rects;\n };\n return SegHierarchy;\n}());\nfunction getEntrySpanEnd(entry) {\n return entry.span.end;\n}\nfunction buildEntryKey(entry) {\n return entry.index + ':' + entry.span.start;\n}\n// returns groups with entries sorted by input order\nfunction groupIntersectingEntries(entries) {\n var merges = [];\n for (var _i = 0, entries_2 = entries; _i < entries_2.length; _i++) {\n var entry = entries_2[_i];\n var filteredMerges = [];\n var hungryMerge = {\n span: entry.span,\n entries: [entry],\n };\n for (var _a = 0, merges_1 = merges; _a < merges_1.length; _a++) {\n var merge = merges_1[_a];\n if (intersectSpans(merge.span, hungryMerge.span)) {\n hungryMerge = {\n entries: merge.entries.concat(hungryMerge.entries),\n span: joinSpans(merge.span, hungryMerge.span),\n };\n }\n else {\n filteredMerges.push(merge);\n }\n }\n filteredMerges.push(hungryMerge);\n merges = filteredMerges;\n }\n return merges;\n}\nfunction joinSpans(span0, span1) {\n return {\n start: Math.min(span0.start, span1.start),\n end: Math.max(span0.end, span1.end),\n };\n}\nfunction intersectSpans(span0, span1) {\n var start = Math.max(span0.start, span1.start);\n var end = Math.min(span0.end, span1.end);\n if (start < end) {\n return { start: start, end: end };\n }\n return null;\n}\n// general util\n// ---------------------------------------------------------------------------------------------------------------------\nfunction insertAt(arr, index, item) {\n arr.splice(index, 0, item);\n}\nfunction binarySearch(a, searchVal, getItemVal) {\n var startIndex = 0;\n var endIndex = a.length; // exclusive\n if (!endIndex || searchVal < getItemVal(a[startIndex])) { // no items OR before first item\n return [0, 0];\n }\n if (searchVal > getItemVal(a[endIndex - 1])) { // after last item\n return [endIndex, 0];\n }\n while (startIndex < endIndex) {\n var middleIndex = Math.floor(startIndex + (endIndex - startIndex) / 2);\n var middleVal = getItemVal(a[middleIndex]);\n if (searchVal < middleVal) {\n endIndex = middleIndex;\n }\n else if (searchVal > middleVal) {\n startIndex = middleIndex + 1;\n }\n else { // equal!\n return [middleIndex, 1];\n }\n }\n return [startIndex, 0];\n}\n\nvar Interaction = /** @class */ (function () {\n function Interaction(settings) {\n this.component = settings.component;\n this.isHitComboAllowed = settings.isHitComboAllowed || null;\n }\n Interaction.prototype.destroy = function () {\n };\n return Interaction;\n}());\nfunction parseInteractionSettings(component, input) {\n return {\n component: component,\n el: input.el,\n useEventCenter: input.useEventCenter != null ? input.useEventCenter : true,\n isHitComboAllowed: input.isHitComboAllowed || null,\n };\n}\nfunction interactionSettingsToStore(settings) {\n var _a;\n return _a = {},\n _a[settings.component.uid] = settings,\n _a;\n}\n// global state\nvar interactionSettingsStore = {};\n\n/*\nAn abstraction for a dragging interaction originating on an event.\nDoes higher-level things than PointerDragger, such as possibly:\n- a \"mirror\" that moves with the pointer\n- a minimum number of pixels or other criteria for a true drag to begin\n\nsubclasses must emit:\n- pointerdown\n- dragstart\n- dragmove\n- pointerup\n- dragend\n*/\nvar ElementDragging = /** @class */ (function () {\n function ElementDragging(el, selector) {\n this.emitter = new Emitter();\n }\n ElementDragging.prototype.destroy = function () {\n };\n ElementDragging.prototype.setMirrorIsVisible = function (bool) {\n // optional if subclass doesn't want to support a mirror\n };\n ElementDragging.prototype.setMirrorNeedsRevert = function (bool) {\n // optional if subclass doesn't want to support a mirror\n };\n ElementDragging.prototype.setAutoScrollEnabled = function (bool) {\n // optional\n };\n return ElementDragging;\n}());\n\n// TODO: get rid of this in favor of options system,\n// tho it's really easy to access this globally rather than pass thru options.\nvar config = {};\n\n/*\nInformation about what will happen when an external element is dragged-and-dropped\nonto a calendar. Contains information for creating an event.\n*/\nvar DRAG_META_REFINERS = {\n startTime: createDuration,\n duration: createDuration,\n create: Boolean,\n sourceId: String,\n};\nfunction parseDragMeta(raw) {\n var _a = refineProps(raw, DRAG_META_REFINERS), refined = _a.refined, extra = _a.extra;\n return {\n startTime: refined.startTime || null,\n duration: refined.duration || null,\n create: refined.create != null ? refined.create : true,\n sourceId: refined.sourceId,\n leftoverProps: extra,\n };\n}\n\nvar ToolbarSection = /** @class */ (function (_super) {\n __extends(ToolbarSection, _super);\n function ToolbarSection() {\n return _super !== null && _super.apply(this, arguments) || this;\n }\n ToolbarSection.prototype.render = function () {\n var _this = this;\n var children = this.props.widgetGroups.map(function (widgetGroup) { return _this.renderWidgetGroup(widgetGroup); });\n return createElement.apply(void 0, __spreadArray(['div', { className: 'fc-toolbar-chunk' }], children));\n };\n ToolbarSection.prototype.renderWidgetGroup = function (widgetGroup) {\n var props = this.props;\n var theme = this.context.theme;\n var children = [];\n var isOnlyButtons = true;\n for (var _i = 0, widgetGroup_1 = widgetGroup; _i < widgetGroup_1.length; _i++) {\n var widget = widgetGroup_1[_i];\n var buttonName = widget.buttonName, buttonClick = widget.buttonClick, buttonText = widget.buttonText, buttonIcon = widget.buttonIcon;\n if (buttonName === 'title') {\n isOnlyButtons = false;\n children.push(createElement(\"h2\", { className: \"fc-toolbar-title\" }, props.title));\n }\n else {\n var ariaAttrs = buttonIcon ? { 'aria-label': buttonName } : {};\n var buttonClasses = [\"fc-\" + buttonName + \"-button\", theme.getClass('button')];\n if (buttonName === props.activeButton) {\n buttonClasses.push(theme.getClass('buttonActive'));\n }\n var isDisabled = (!props.isTodayEnabled && buttonName === 'today') ||\n (!props.isPrevEnabled && buttonName === 'prev') ||\n (!props.isNextEnabled && buttonName === 'next');\n children.push(createElement(\"button\", __assign({ disabled: isDisabled, className: buttonClasses.join(' '), onClick: buttonClick, type: \"button\" }, ariaAttrs), buttonText || (buttonIcon ? createElement(\"span\", { className: buttonIcon }) : '')));\n }\n }\n if (children.length > 1) {\n var groupClassName = (isOnlyButtons && theme.getClass('buttonGroup')) || '';\n return createElement.apply(void 0, __spreadArray(['div', { className: groupClassName }], children));\n }\n return children[0];\n };\n return ToolbarSection;\n}(BaseComponent));\n\nvar Toolbar = /** @class */ (function (_super) {\n __extends(Toolbar, _super);\n function Toolbar() {\n return _super !== null && _super.apply(this, arguments) || this;\n }\n Toolbar.prototype.render = function () {\n var _a = this.props, model = _a.model, extraClassName = _a.extraClassName;\n var forceLtr = false;\n var startContent;\n var endContent;\n var centerContent = model.center;\n if (model.left) {\n forceLtr = true;\n startContent = model.left;\n }\n else {\n startContent = model.start;\n }\n if (model.right) {\n forceLtr = true;\n endContent = model.right;\n }\n else {\n endContent = model.end;\n }\n var classNames = [\n extraClassName || '',\n 'fc-toolbar',\n forceLtr ? 'fc-toolbar-ltr' : '',\n ];\n return (createElement(\"div\", { className: classNames.join(' ') },\n this.renderSection('start', startContent || []),\n this.renderSection('center', centerContent || []),\n this.renderSection('end', endContent || [])));\n };\n Toolbar.prototype.renderSection = function (key, widgetGroups) {\n var props = this.props;\n return (createElement(ToolbarSection, { key: key, widgetGroups: widgetGroups, title: props.title, activeButton: props.activeButton, isTodayEnabled: props.isTodayEnabled, isPrevEnabled: props.isPrevEnabled, isNextEnabled: props.isNextEnabled }));\n };\n return Toolbar;\n}(BaseComponent));\n\n// TODO: do function component?\nvar ViewContainer = /** @class */ (function (_super) {\n __extends(ViewContainer, _super);\n function ViewContainer() {\n var _this = _super !== null && _super.apply(this, arguments) || this;\n _this.state = {\n availableWidth: null,\n };\n _this.handleEl = function (el) {\n _this.el = el;\n setRef(_this.props.elRef, el);\n _this.updateAvailableWidth();\n };\n _this.handleResize = function () {\n _this.updateAvailableWidth();\n };\n return _this;\n }\n ViewContainer.prototype.render = function () {\n var _a = this, props = _a.props, state = _a.state;\n var aspectRatio = props.aspectRatio;\n var classNames = [\n 'fc-view-harness',\n (aspectRatio || props.liquid || props.height)\n ? 'fc-view-harness-active' // harness controls the height\n : 'fc-view-harness-passive', // let the view do the height\n ];\n var height = '';\n var paddingBottom = '';\n if (aspectRatio) {\n if (state.availableWidth !== null) {\n height = state.availableWidth / aspectRatio;\n }\n else {\n // while waiting to know availableWidth, we can't set height to *zero*\n // because will cause lots of unnecessary scrollbars within scrollgrid.\n // BETTER: don't start rendering ANYTHING yet until we know container width\n // NOTE: why not always use paddingBottom? Causes height oscillation (issue 5606)\n paddingBottom = (1 / aspectRatio) * 100 + \"%\";\n }\n }\n else {\n height = props.height || '';\n }\n return (createElement(\"div\", { ref: this.handleEl, onClick: props.onClick, className: classNames.join(' '), style: { height: height, paddingBottom: paddingBottom } }, props.children));\n };\n ViewContainer.prototype.componentDidMount = function () {\n this.context.addResizeHandler(this.handleResize);\n };\n ViewContainer.prototype.componentWillUnmount = function () {\n this.context.removeResizeHandler(this.handleResize);\n };\n ViewContainer.prototype.updateAvailableWidth = function () {\n if (this.el && // needed. but why?\n this.props.aspectRatio // aspectRatio is the only height setting that needs availableWidth\n ) {\n this.setState({ availableWidth: this.el.offsetWidth });\n }\n };\n return ViewContainer;\n}(BaseComponent));\n\n/*\nDetects when the user clicks on an event within a DateComponent\n*/\nvar EventClicking = /** @class */ (function (_super) {\n __extends(EventClicking, _super);\n function EventClicking(settings) {\n var _this = _super.call(this, settings) || this;\n _this.handleSegClick = function (ev, segEl) {\n var component = _this.component;\n var context = component.context;\n var seg = getElSeg(segEl);\n if (seg && // might be the