Newer
Older
};
return { def: def, instance: null };
}
var singleRes = parseSingle(refined, defaultAllDay, context, allowOpenRange);
if (singleRes) {
var def = parseEventDef(refined, extra, eventSource ? eventSource.sourceId : '', singleRes.allDay, singleRes.hasEnd, context);
var instance = createEventInstance(def.defId, singleRes.range, singleRes.forcedStartTzo, singleRes.forcedEndTzo);
return { def: def, instance: instance };
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
}
return null;
}
function refineEventDef(raw, context, refiners) {
if (refiners === void 0) { refiners = buildEventRefiners(context); }
return refineProps(raw, refiners);
}
function buildEventRefiners(context) {
return __assign(__assign(__assign({}, EVENT_UI_REFINERS), EVENT_REFINERS), context.pluginHooks.eventRefiners);
}
/*
Will NOT populate extendedProps with the leftover properties.
Will NOT populate date-related props.
*/
function parseEventDef(refined, extra, sourceId, allDay, hasEnd, context) {
var def = {
title: refined.title || '',
groupId: refined.groupId || '',
publicId: refined.id || '',
url: refined.url || '',
recurringDef: null,
defId: guid(),
sourceId: sourceId,
allDay: allDay,
hasEnd: hasEnd,
ui: createEventUi(refined, context),
extendedProps: __assign(__assign({}, (refined.extendedProps || {})), extra),
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
};
for (var _i = 0, _a = context.pluginHooks.eventDefMemberAdders; _i < _a.length; _i++) {
var memberAdder = _a[_i];
__assign(def, memberAdder(refined));
}
// help out EventApi from having user modify props
Object.freeze(def.ui.classNames);
Object.freeze(def.extendedProps);
return def;
}
function parseSingle(refined, defaultAllDay, context, allowOpenRange) {
var allDay = refined.allDay;
var startMeta;
var startMarker = null;
var hasEnd = false;
var endMeta;
var endMarker = null;
var 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 {
// fall back to the date props LAST
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: allDay,
hasEnd: hasEnd,
range: { start: startMarker, end: endMarker },
forcedStartTzo: startMeta ? startMeta.forcedTzo : null,
forcedEndTzo: endMeta ? endMeta.forcedTzo : null,
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
};
}
function computeIsDefaultAllDay(eventSource, context) {
var res = null;
if (eventSource) {
res = eventSource.defaultAllDay;
}
if (res == null) {
res = context.options.defaultAllDay;
}
return res;
}
/* Date stuff that doesn't belong in datelib core
----------------------------------------------------------------------------------------------------------------------*/
// given a timed range, computes an all-day range that has the same exact duration,
// but whose start time is aligned with the start of the day.
function computeAlignedDayRange(timedRange) {
var dayCnt = Math.floor(diffDays(timedRange.start, timedRange.end)) || 1;
var start = startOfDay(timedRange.start);
var end = addDays(start, dayCnt);
return { start: start, end: end };
}
// given a timed range, computes an all-day range based on how for the end date bleeds into the next day
// TODO: give nextDayThreshold a default arg
function computeVisibleDayRange(timedRange, nextDayThreshold) {
if (nextDayThreshold === void 0) { nextDayThreshold = createDuration(0); }
var startDay = null;
var endDay = null;
if (timedRange.end) {
endDay = startOfDay(timedRange.end);
var endTimeMS = timedRange.end.valueOf() - endDay.valueOf(); // # of milliseconds into `endDay`
// If the end time is actually inclusively part of the next day and is equal to or
// beyond the next day threshold, adjust the end to be the exclusive end of `endDay`.
// Otherwise, leaving it as inclusive will cause it to exclude `endDay`.
if (endTimeMS && endTimeMS >= asRoughMs(nextDayThreshold)) {
endDay = addDays(endDay, 1);
}
}
if (timedRange.start) {
startDay = startOfDay(timedRange.start); // the beginning of the day the range starts
// If end is within `startDay` but not past nextDayThreshold, assign the default duration of one day.
if (endDay && endDay <= startDay) {
endDay = addDays(startDay, 1);
}
}
return { start: startDay, end: endDay };
}
// spans from one day into another?
function isMultiDayRange(range) {
var visibleRange = computeVisibleDayRange(range);
return diffDays(visibleRange.start, visibleRange.end) > 1;
}
function diffDates(date0, date1, dateEnv, largeUnit) {
if (largeUnit === 'year') {
return createDuration(dateEnv.diffWholeYears(date0, date1), 'year');
}
return createDuration(dateEnv.diffWholeMonths(date0, date1), 'month');
}
return diffDayAndTime(date0, date1); // returns a duration
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
}
function parseRange(input, dateEnv) {
var start = null;
var end = null;
if (input.start) {
start = dateEnv.createMarker(input.start);
}
if (input.end) {
end = dateEnv.createMarker(input.end);
}
if (!start && !end) {
return null;
}
if (start && end && end < start) {
return null;
}
return { start: start, end: end };
}
// SIDE-EFFECT: will mutate ranges.
// Will return a new array result.
function invertRanges(ranges, constraintRange) {
var invertedRanges = [];
var start = constraintRange.start; // the end of the previous range. the start of the new range
var i;
var dateRange;
// ranges need to be in order. required for our date-walking algorithm
ranges.sort(compareRanges);
for (i = 0; i < ranges.length; i += 1) {
dateRange = ranges[i];
// add the span of time before the event (if there is any)
if (dateRange.start > start) { // compare millisecond time (skip any ambig logic)
invertedRanges.push({ start: start, end: dateRange.start });
}
if (dateRange.end > start) {
start = dateRange.end;
}
}
// add the span of time after the last event (if there is any)
if (start < constraintRange.end) { // compare millisecond time (skip any ambig logic)
invertedRanges.push({ start: start, end: constraintRange.end });
}
return invertedRanges;
}
function compareRanges(range0, range1) {
return range0.start.valueOf() - range1.start.valueOf(); // earlier ranges go first
}
function intersectRanges(range0, range1) {
var start = range0.start, end = range0.end;
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
var newRange = null;
if (range1.start !== null) {
if (start === null) {
start = range1.start;
}
else {
start = new Date(Math.max(start.valueOf(), range1.start.valueOf()));
}
}
if (range1.end != null) {
if (end === null) {
end = range1.end;
}
else {
end = new Date(Math.min(end.valueOf(), range1.end.valueOf()));
}
}
if (start === null || end === null || start < end) {
newRange = { start: start, end: end };
}
return newRange;
}
function rangesEqual(range0, range1) {
return (range0.start === null ? null : range0.start.valueOf()) === (range1.start === null ? null : range1.start.valueOf()) &&
(range0.end === null ? null : range0.end.valueOf()) === (range1.end === null ? null : range1.end.valueOf());
}
function rangesIntersect(range0, range1) {
return (range0.end === null || range1.start === null || range0.end > range1.start) &&
(range0.start === null || range1.end === null || range0.start < range1.end);
}
function rangeContainsRange(outerRange, innerRange) {
return (outerRange.start === null || (innerRange.start !== null && innerRange.start >= outerRange.start)) &&
(outerRange.end === null || (innerRange.end !== null && innerRange.end <= outerRange.end));
}
function rangeContainsMarker(range, date) {
return (range.start === null || date >= range.start) &&
(range.end === null || date < range.end);
}
// If the given date is not within the given range, move it inside.
// (If it's past the end, make it one millisecond before the end).
function constrainMarkerToRange(date, range) {
if (range.start != null && date < range.start) {
return range.start;
}
if (range.end != null && date >= range.end) {
return new Date(range.end.valueOf() - 1);
}
return date;
}
/*
Specifying nextDayThreshold signals that all-day ranges should be sliced.
*/
function sliceEventStore(eventStore, eventUiBases, framingRange, nextDayThreshold) {
var inverseBgByGroupId = {};
var inverseBgByDefId = {};
var defByGroupId = {};
var bgRanges = [];
var fgRanges = [];
var eventUis = compileEventUis(eventStore.defs, eventUiBases);
for (var defId in eventStore.defs) {
var def = eventStore.defs[defId];
var ui = eventUis[def.defId];
if (ui.display === 'inverse-background') {
if (def.groupId) {
inverseBgByGroupId[def.groupId] = [];
if (!defByGroupId[def.groupId]) {
defByGroupId[def.groupId] = def;
}
}
else {
inverseBgByDefId[defId] = [];
}
}
}
for (var instanceId in eventStore.instances) {
var instance = eventStore.instances[instanceId];
var def = eventStore.defs[instance.defId];
var ui = eventUis[def.defId];
var origRange = instance.range;
var normalRange = (!def.allDay && nextDayThreshold) ?
computeVisibleDayRange(origRange, nextDayThreshold) :
origRange;
var slicedRange = intersectRanges(normalRange, framingRange);
if (slicedRange) {
if (ui.display === 'inverse-background') {
if (def.groupId) {
inverseBgByGroupId[def.groupId].push(slicedRange);
}
else {
inverseBgByDefId[instance.defId].push(slicedRange);
}
}
else if (ui.display !== 'none') {
(ui.display === 'background' ? bgRanges : fgRanges).push({
def: def,
ui: ui,
instance: instance,
range: slicedRange,
isStart: normalRange.start && normalRange.start.valueOf() === slicedRange.start.valueOf(),
isEnd: normalRange.end && normalRange.end.valueOf() === slicedRange.end.valueOf(),
});
}
}
}
for (var groupId in inverseBgByGroupId) { // BY GROUP
var ranges = inverseBgByGroupId[groupId];
var invertedRanges = invertRanges(ranges, framingRange);
for (var _i = 0, invertedRanges_1 = invertedRanges; _i < invertedRanges_1.length; _i++) {
var invertedRange = invertedRanges_1[_i];
var def = defByGroupId[groupId];
var ui = eventUis[def.defId];
bgRanges.push({
def: def,
ui: ui,
instance: null,
range: invertedRange,
isStart: false,
});
}
}
for (var defId in inverseBgByDefId) {
var ranges = inverseBgByDefId[defId];
var invertedRanges = invertRanges(ranges, framingRange);
for (var _a = 0, invertedRanges_2 = invertedRanges; _a < invertedRanges_2.length; _a++) {
var invertedRange = invertedRanges_2[_a];
bgRanges.push({
def: eventStore.defs[defId],
ui: eventUis[defId],
instance: null,
range: invertedRange,
isStart: false,
});
}
}
return { bg: bgRanges, fg: fgRanges };
}
function hasBgRendering(def) {
return def.ui.display === 'background' || def.ui.display === 'inverse-background';
}
function setElSeg(el, seg) {
el.fcSeg = seg;
}
function getElSeg(el) {
return el.fcSeg ||
el.parentNode.fcSeg || // for the harness
null;
}
// event ui computation
function compileEventUis(eventDefs, eventUiBases) {
return mapHash(eventDefs, function (eventDef) { return compileEventUi(eventDef, eventUiBases); });
}
function compileEventUi(eventDef, eventUiBases) {
var uis = [];
if (eventUiBases['']) {
uis.push(eventUiBases['']);
}
if (eventUiBases[eventDef.defId]) {
uis.push(eventUiBases[eventDef.defId]);
}
uis.push(eventDef.ui);
return combineEventUis(uis);
}
function sortEventSegs(segs, eventOrderSpecs) {
var objs = segs.map(buildSegCompareObj);
objs.sort(function (obj0, obj1) { return compareByFieldSpecs(obj0, obj1, eventOrderSpecs); });
return objs.map(function (c) { return c._seg; });
}
// returns a object with all primitive props that can be compared
function buildSegCompareObj(seg) {
var eventRange = seg.eventRange;
var eventDef = eventRange.def;
var range = eventRange.instance ? eventRange.instance.range : eventRange.range;
var start = range.start ? range.start.valueOf() : 0; // TODO: better support for open-range events
var end = range.end ? range.end.valueOf() : 0; // "
return __assign(__assign(__assign({}, eventDef.extendedProps), eventDef), { id: eventDef.publicId, start: start,
end: end, duration: end - start, allDay: Number(eventDef.allDay), _seg: seg });
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
}
function computeSegDraggable(seg, context) {
var pluginHooks = context.pluginHooks;
var transformers = pluginHooks.isDraggableTransformers;
var _a = seg.eventRange, def = _a.def, ui = _a.ui;
var val = ui.startEditable;
for (var _i = 0, transformers_1 = transformers; _i < transformers_1.length; _i++) {
var transformer = transformers_1[_i];
val = transformer(val, def, ui, context);
}
return val;
}
function computeSegStartResizable(seg, context) {
return seg.isStart && seg.eventRange.ui.durationEditable && context.options.eventResizableFromStart;
}
function computeSegEndResizable(seg, context) {
return seg.isEnd && seg.eventRange.ui.durationEditable;
}
function buildSegTimeText(seg, timeFormat, context, defaultDisplayEventTime, // defaults to true
defaultDisplayEventEnd, // defaults to true
startOverride, endOverride) {
var dateEnv = context.dateEnv, options = context.options;
var displayEventTime = options.displayEventTime, displayEventEnd = options.displayEventEnd;
var eventDef = seg.eventRange.def;
var eventInstance = seg.eventRange.instance;
if (displayEventTime == null) {
displayEventTime = defaultDisplayEventTime !== false;
}
if (displayEventEnd == null) {
displayEventEnd = defaultDisplayEventEnd !== false;
}
if (displayEventTime && !eventDef.allDay && (seg.isStart || seg.isEnd)) {
var segStart = startOverride || (seg.isStart ? eventInstance.range.start : (seg.start || seg.eventRange.range.start));
var segEnd = endOverride || (seg.isEnd ? eventInstance.range.end : (seg.end || seg.eventRange.range.end));
if (displayEventEnd && eventDef.hasEnd) {
return dateEnv.formatRange(segStart, segEnd, timeFormat, {
forcedStartTzo: startOverride ? null : eventInstance.forcedStartTzo,
forcedEndTzo: endOverride ? null : eventInstance.forcedEndTzo,
return dateEnv.format(segStart, timeFormat, {
forcedTzo: startOverride ? null : eventInstance.forcedStartTzo,
});
}
return '';
}
function getSegMeta(seg, todayRange, nowDate) {
var segRange = seg.eventRange.range;
return {
isPast: segRange.end < (nowDate || todayRange.start),
isFuture: segRange.start >= (nowDate || todayRange.end),
isToday: todayRange && rangeContainsMarker(todayRange, segRange.start),
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
};
}
function getEventClassNames(props) {
var classNames = ['fc-event'];
if (props.isMirror) {
classNames.push('fc-event-mirror');
}
if (props.isDraggable) {
classNames.push('fc-event-draggable');
}
if (props.isStartResizable || props.isEndResizable) {
classNames.push('fc-event-resizable');
}
if (props.isDragging) {
classNames.push('fc-event-dragging');
}
if (props.isResizing) {
classNames.push('fc-event-resizing');
}
if (props.isSelected) {
classNames.push('fc-event-selected');
}
if (props.isStart) {
classNames.push('fc-event-start');
}
if (props.isEnd) {
classNames.push('fc-event-end');
}
if (props.isPast) {
classNames.push('fc-event-past');
}
if (props.isToday) {
classNames.push('fc-event-today');
}
if (props.isFuture) {
classNames.push('fc-event-future');
}
return classNames;
}
function buildEventRangeKey(eventRange) {
return eventRange.instance
? eventRange.instance.instanceId
: eventRange.def.defId + ":" + eventRange.range.start.toISOString();
// inverse-background events don't have specific instances. TODO: better solution
}
var STANDARD_PROPS = {
start: identity,
end: identity,
};
function parseDateSpan(raw, dateEnv, defaultDuration) {
var span = parseOpenDateSpan(raw, dateEnv);
var range = span.range;
if (!range.start) {
return null;
}
if (!range.end) {
if (defaultDuration == null) {
return null;
}
range.end = dateEnv.add(range.start, defaultDuration);
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
}
return span;
}
/*
TODO: somehow combine with parseRange?
Will return null if the start/end props were present but parsed invalidly.
*/
function parseOpenDateSpan(raw, dateEnv) {
var _a = refineProps(raw, STANDARD_PROPS), standardProps = _a.refined, extra = _a.extra;
var startMeta = standardProps.start ? dateEnv.createMarkerMeta(standardProps.start) : null;
var endMeta = standardProps.end ? dateEnv.createMarkerMeta(standardProps.end) : null;
var allDay = standardProps.allDay;
if (allDay == null) {
allDay = (startMeta && startMeta.isTimeUnspecified) &&
(!endMeta || endMeta.isTimeUnspecified);
}
return __assign({ range: {
start: startMeta ? startMeta.marker : null,
end: endMeta ? endMeta.marker : null,
}, allDay: allDay }, extra);
}
function isDateSpansEqual(span0, span1) {
return rangesEqual(span0.range, span1.range) &&
span0.allDay === span1.allDay &&
isSpanPropsEqual(span0, span1);
}
// the NON-DATE-RELATED props
function isSpanPropsEqual(span0, span1) {
for (var propName in span1) {
if (propName !== 'range' && propName !== 'allDay') {
if (span0[propName] !== span1[propName]) {
return false;
}
}
}
// are there any props that span0 has that span1 DOESN'T have?
// both have range/allDay, so no need to special-case.
for (var propName in span0) {
if (!(propName in span1)) {
return false;
}
}
return true;
}
function buildDateSpanApi(span, dateEnv) {
return __assign(__assign({}, buildRangeApi(span.range, dateEnv, span.allDay)), { allDay: span.allDay });
}
function buildRangeApiWithTimeZone(range, dateEnv, omitTime) {
return __assign(__assign({}, buildRangeApi(range, dateEnv, omitTime)), { timeZone: dateEnv.timeZone });
}
function buildRangeApi(range, dateEnv, omitTime) {
return {
start: dateEnv.toDate(range.start),
end: dateEnv.toDate(range.end),
startStr: dateEnv.formatIso(range.start, { omitTime: omitTime }),
endStr: dateEnv.formatIso(range.end, { omitTime: omitTime }),
};
}
function fabricateEventRange(dateSpan, eventUiBases, context) {
var res = refineEventDef({ editable: false }, context);
var def = parseEventDef(res.refined, res.extra, '', // sourceId
dateSpan.allDay, true, // hasEnd
context);
return {
def: def,
ui: compileEventUi(def, eventUiBases),
instance: createEventInstance(def.defId, dateSpan.range),
range: dateSpan.range,
isStart: true,
};
}
function triggerDateSelect(selection, pev, context) {
context.emitter.trigger('select', __assign(__assign({}, buildDateSpanApiWithContext(selection, context)), { jsEvent: pev ? pev.origEvent : null, view: context.viewApi || context.calendarApi.view }));
}
function triggerDateUnselect(pev, context) {
context.emitter.trigger('unselect', {
jsEvent: pev ? pev.origEvent : null,
view: context.viewApi || context.calendarApi.view,
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
});
}
function buildDateSpanApiWithContext(dateSpan, context) {
var props = {};
for (var _i = 0, _a = context.pluginHooks.dateSpanTransforms; _i < _a.length; _i++) {
var transform = _a[_i];
__assign(props, transform(dateSpan, context));
}
__assign(props, buildDateSpanApi(dateSpan, context.dateEnv));
return props;
}
// Given an event's allDay status and start date, return what its fallback end date should be.
// TODO: rename to computeDefaultEventEnd
function getDefaultEventEnd(allDay, marker, context) {
var dateEnv = context.dateEnv, options = context.options;
var end = marker;
if (allDay) {
end = startOfDay(end);
end = dateEnv.add(end, options.defaultAllDayEventDuration);
}
else {
end = dateEnv.add(end, options.defaultTimedEventDuration);
}
return end;
}
// applies the mutation to ALL defs/instances within the event store
function applyMutationToEventStore(eventStore, eventConfigBase, mutation, context) {
var eventConfigs = compileEventUis(eventStore.defs, eventConfigBase);
var dest = createEmptyEventStore();
for (var defId in eventStore.defs) {
var def = eventStore.defs[defId];
dest.defs[defId] = applyMutationToEventDef(def, eventConfigs[defId], mutation, context);
}
for (var instanceId in eventStore.instances) {
var instance = eventStore.instances[instanceId];
var def = dest.defs[instance.defId]; // important to grab the newly modified def
dest.instances[instanceId] = applyMutationToEventInstance(instance, def, eventConfigs[instance.defId], mutation, context);
}
return dest;
}
function applyMutationToEventDef(eventDef, eventConfig, mutation, context) {
var standardProps = mutation.standardProps || {};
// if hasEnd has not been specified, guess a good value based on deltas.
// if duration will change, there's no way the default duration will persist,
// and thus, we need to mark the event as having a real end
if (standardProps.hasEnd == null &&
eventConfig.durationEditable &&
(mutation.startDelta || mutation.endDelta)) {
standardProps.hasEnd = true; // TODO: is this mutation okay?
}
var copy = __assign(__assign(__assign({}, eventDef), standardProps), { ui: __assign(__assign({}, eventDef.ui), standardProps.ui) });
if (mutation.extendedProps) {
copy.extendedProps = __assign(__assign({}, copy.extendedProps), mutation.extendedProps);
}
for (var _i = 0, _a = context.pluginHooks.eventDefMutationAppliers; _i < _a.length; _i++) {
var applier = _a[_i];
applier(copy, mutation, context);
}
if (!copy.hasEnd && context.options.forceEventDuration) {
copy.hasEnd = true;
}
return copy;
}
function applyMutationToEventInstance(eventInstance, eventDef, // must first be modified by applyMutationToEventDef
eventConfig, mutation, context) {
var dateEnv = context.dateEnv;
var forceAllDay = mutation.standardProps && mutation.standardProps.allDay === true;
var clearEnd = mutation.standardProps && mutation.standardProps.hasEnd === false;
var copy = __assign({}, eventInstance);
if (forceAllDay) {
copy.range = computeAlignedDayRange(copy.range);
}
if (mutation.datesDelta && eventConfig.startEditable) {
copy.range = {
start: dateEnv.add(copy.range.start, mutation.datesDelta),
end: dateEnv.add(copy.range.end, mutation.datesDelta),
};
}
if (mutation.startDelta && eventConfig.durationEditable) {
copy.range = {
start: dateEnv.add(copy.range.start, mutation.startDelta),
};
}
if (mutation.endDelta && eventConfig.durationEditable) {
copy.range = {
start: copy.range.start,
end: dateEnv.add(copy.range.end, mutation.endDelta),
};
}
if (clearEnd) {
copy.range = {
start: copy.range.start,
end: getDefaultEventEnd(eventDef.allDay, copy.range.start, context),
};
}
// in case event was all-day but the supplied deltas were not
// better util for this?
if (eventDef.allDay) {
copy.range = {
start: startOfDay(copy.range.start),
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
};
}
// handle invalid durations
if (copy.range.end < copy.range.start) {
copy.range.end = getDefaultEventEnd(eventDef.allDay, copy.range.start, context);
}
return copy;
}
// no public types yet. when there are, export from:
// import {} from './api-type-deps'
var ViewApi = /** @class */ (function () {
function ViewApi(type, getCurrentData, dateEnv) {
this.type = type;
this.getCurrentData = getCurrentData;
this.dateEnv = dateEnv;
}
Object.defineProperty(ViewApi.prototype, "calendar", {
get: function () {
return this.getCurrentData().calendarApi;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ViewApi.prototype, "title", {
get: function () {
return this.getCurrentData().viewTitle;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ViewApi.prototype, "activeStart", {
get: function () {
return this.dateEnv.toDate(this.getCurrentData().dateProfile.activeRange.start);
},
enumerable: false,
configurable: true
});
Object.defineProperty(ViewApi.prototype, "activeEnd", {
get: function () {
return this.dateEnv.toDate(this.getCurrentData().dateProfile.activeRange.end);
},
enumerable: false,
configurable: true
});
Object.defineProperty(ViewApi.prototype, "currentStart", {
get: function () {
return this.dateEnv.toDate(this.getCurrentData().dateProfile.currentRange.start);
},
enumerable: false,
configurable: true
});
Object.defineProperty(ViewApi.prototype, "currentEnd", {
get: function () {
return this.dateEnv.toDate(this.getCurrentData().dateProfile.currentRange.end);
},
enumerable: false,
configurable: true
});
ViewApi.prototype.getOption = function (name) {
return this.getCurrentData().options[name]; // are the view-specific options
};
return ViewApi;
}());
var EVENT_SOURCE_REFINERS = {
id: String,
defaultAllDay: Boolean,
url: String,
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
events: identity,
eventDataTransform: identity,
// for any network-related sources
success: identity,
failure: identity,
};
function parseEventSource(raw, context, refiners) {
if (refiners === void 0) { refiners = buildEventSourceRefiners(context); }
var rawObj;
if (typeof raw === 'string') {
rawObj = { url: raw };
}
else if (typeof raw === 'function' || Array.isArray(raw)) {
rawObj = { events: raw };
}
else if (typeof raw === 'object' && raw) { // not null
rawObj = raw;
}
if (rawObj) {
var _a = refineProps(rawObj, refiners), refined = _a.refined, extra = _a.extra;
var metaRes = buildEventSourceMeta(refined, context);
if (metaRes) {
return {
_raw: raw,
isFetching: false,
latestFetchId: '',
fetchRange: null,
defaultAllDay: refined.defaultAllDay,
eventDataTransform: refined.eventDataTransform,
success: refined.success,
failure: refined.failure,
publicId: refined.id || '',
sourceId: guid(),
sourceDefId: metaRes.sourceDefId,
meta: metaRes.meta,
ui: createEventUi(refined, context),
};
}
}
return null;
}
function buildEventSourceRefiners(context) {
return __assign(__assign(__assign({}, EVENT_UI_REFINERS), EVENT_SOURCE_REFINERS), context.pluginHooks.eventSourceRefiners);
}
function buildEventSourceMeta(raw, context) {
var defs = context.pluginHooks.eventSourceDefs;
for (var i = defs.length - 1; i >= 0; i -= 1) { // later-added plugins take precedence
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
var def = defs[i];
var meta = def.parseMeta(raw);
if (meta) {
return { sourceDefId: i, meta: meta };
}
}
return null;
}
function reduceCurrentDate(currentDate, action) {
switch (action.type) {
case 'CHANGE_DATE':
return action.dateMarker;
default:
return currentDate;
}
}
function getInitialDate(options, dateEnv) {
var initialDateInput = options.initialDate;
// compute the initial ambig-timezone date
if (initialDateInput != null) {
return dateEnv.createMarker(initialDateInput);
}
return getNow(options.now, dateEnv); // getNow already returns unzoned
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
}
function getNow(nowInput, dateEnv) {
if (typeof nowInput === 'function') {
nowInput = nowInput();
}
if (nowInput == null) {
return dateEnv.createNowMarker();
}
return dateEnv.createMarker(nowInput);
}
var CalendarApi = /** @class */ (function () {
function CalendarApi() {
}
CalendarApi.prototype.getCurrentData = function () {
return this.currentDataManager.getCurrentData();
};
CalendarApi.prototype.dispatch = function (action) {
return this.currentDataManager.dispatch(action);
};
Object.defineProperty(CalendarApi.prototype, "view", {
get: function () { return this.getCurrentData().viewApi; } // for public API
,
enumerable: false,
configurable: true
});
CalendarApi.prototype.batchRendering = function (callback) {
callback();
};
CalendarApi.prototype.updateSize = function () {
this.trigger('_resize', true);
};
// Options
// -----------------------------------------------------------------------------------------------------------------
CalendarApi.prototype.setOption = function (name, val) {
this.dispatch({
type: 'SET_OPTION',
optionName: name,
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
});
};
CalendarApi.prototype.getOption = function (name) {
return this.currentDataManager.currentCalendarOptionsInput[name];
};
CalendarApi.prototype.getAvailableLocaleCodes = function () {
return Object.keys(this.getCurrentData().availableRawLocales);
};
// Trigger
// -----------------------------------------------------------------------------------------------------------------
CalendarApi.prototype.on = function (handlerName, handler) {
var currentDataManager = this.currentDataManager;
if (currentDataManager.currentCalendarOptionsRefiners[handlerName]) {
currentDataManager.emitter.on(handlerName, handler);
}
else {
console.warn("Unknown listener name '" + handlerName + "'");
}
};
CalendarApi.prototype.off = function (handlerName, handler) {
this.currentDataManager.emitter.off(handlerName, handler);
};
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
CalendarApi.prototype.trigger = function (handlerName) {
var _a;
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
(_a = this.currentDataManager.emitter).trigger.apply(_a, __spreadArrays([handlerName], args));
};
// View
// -----------------------------------------------------------------------------------------------------------------
CalendarApi.prototype.changeView = function (viewType, dateOrRange) {
var _this = this;
this.batchRendering(function () {
_this.unselect();
if (dateOrRange) {
if (dateOrRange.start && dateOrRange.end) { // a range
_this.dispatch({
type: 'CHANGE_VIEW_TYPE',
viewType: viewType,
});
_this.dispatch({
type: 'SET_OPTION',
optionName: 'visibleRange',
});
}
else {
var dateEnv = _this.getCurrentData().dateEnv;
_this.dispatch({
type: 'CHANGE_VIEW_TYPE',
viewType: viewType,
dateMarker: dateEnv.createMarker(dateOrRange),
});
}
}
else {
_this.dispatch({
type: 'CHANGE_VIEW_TYPE',
});
}
});
};
// Forces navigation to a view for the given date.
// `viewType` can be a specific view name or a generic one like "week" or "day".
// needs to change
CalendarApi.prototype.zoomTo = function (dateMarker, viewType) {
var state = this.getCurrentData();
var spec;
viewType = viewType || 'day'; // day is default zoom
spec = state.viewSpecs[viewType] || this.getUnitViewSpec(viewType);
this.unselect();
if (spec) {
this.dispatch({
type: 'CHANGE_VIEW_TYPE',
viewType: spec.type,
});
}
else {
this.dispatch({
type: 'CHANGE_DATE',
});
}
};
// Given a duration singular unit, like "week" or "day", finds a matching view spec.
// Preference is given to views that have corresponding buttons.
CalendarApi.prototype.getUnitViewSpec = function (unit) {
var _a = this.getCurrentData(), viewSpecs = _a.viewSpecs, toolbarConfig = _a.toolbarConfig;
var viewTypes = [].concat(toolbarConfig.viewsWithButtons);
var i;
var spec;
for (var viewType in viewSpecs) {
viewTypes.push(viewType);
}
for (i = 0; i < viewTypes.length; i += 1) {
spec = viewSpecs[viewTypes[i]];
if (spec) {
if (spec.singleUnit === unit) {
return spec;
}
}
}
};
// Current Date
// -----------------------------------------------------------------------------------------------------------------
CalendarApi.prototype.prev = function () {
this.unselect();
this.dispatch({ type: 'PREV' });
};
CalendarApi.prototype.next = function () {
this.unselect();
this.dispatch({ type: 'NEXT' });
};
CalendarApi.prototype.prevYear = function () {
var state = this.getCurrentData();
this.unselect();
this.dispatch({
type: 'CHANGE_DATE',
dateMarker: state.dateEnv.addYears(state.currentDate, -1),
});
};
CalendarApi.prototype.nextYear = function () {
var state = this.getCurrentData();
this.unselect();
this.dispatch({
type: 'CHANGE_DATE',
dateMarker: state.dateEnv.addYears(state.currentDate, 1),