Newer
Older
else {
duration = this.getFallbackDuration();
unit = greatestDurationDenominator(duration).unit;
range = this.buildRangeFromDuration(date, direction, duration, unit);
}
return { duration: duration, unit: unit, range: range };
};
DateProfileGenerator.prototype.getFallbackDuration = function () {
return createDuration({ day: 1 });
};
// Returns a new activeRange to have time values (un-ambiguate)
// slotMinTime or slotMaxTime causes the range to expand.
DateProfileGenerator.prototype.adjustActiveRange = function (range) {
var _a = this.props, dateEnv = _a.dateEnv, usesMinMaxTime = _a.usesMinMaxTime, slotMinTime = _a.slotMinTime, slotMaxTime = _a.slotMaxTime;
var start = range.start, end = range.end;
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
if (usesMinMaxTime) {
// expand active range if slotMinTime is negative (why not when positive?)
if (asRoughDays(slotMinTime) < 0) {
start = startOfDay(start); // necessary?
start = dateEnv.add(start, slotMinTime);
}
// expand active range if slotMaxTime is beyond one day (why not when negative?)
if (asRoughDays(slotMaxTime) > 1) {
end = startOfDay(end); // necessary?
end = addDays(end, -1);
end = dateEnv.add(end, slotMaxTime);
}
}
return { start: start, end: end };
};
// Builds the "current" range when it is specified as an explicit duration.
// `unit` is the already-computed greatestDurationDenominator unit of duration.
DateProfileGenerator.prototype.buildRangeFromDuration = function (date, direction, duration, unit) {
var _a = this.props, dateEnv = _a.dateEnv, dateAlignment = _a.dateAlignment;
var start;
var end;
var res;
// compute what the alignment should be
if (!dateAlignment) {
var dateIncrement = this.props.dateIncrement;
if (dateIncrement) {
// use the smaller of the two units
if (asRoughMs(dateIncrement) < asRoughMs(duration)) {
dateAlignment = greatestDurationDenominator(dateIncrement).unit;
}
else {
dateAlignment = unit;
}
}
else {
dateAlignment = unit;
}
}
// if the view displays a single day or smaller
if (asRoughDays(duration) <= 1) {
if (this.isHiddenDay(start)) {
start = this.skipHiddenDays(start, direction);
start = startOfDay(start);
}
}
function computeRes() {
start = dateEnv.startOf(date, dateAlignment);
end = dateEnv.add(start, duration);
res = { start: start, end: end };
}
computeRes();
// if range is completely enveloped by hidden days, go past the hidden days
if (!this.trimHiddenDays(res)) {
date = this.skipHiddenDays(date, direction);
computeRes();
}
return res;
};
// Builds the "current" range when a dayCount is specified.
DateProfileGenerator.prototype.buildRangeFromDayCount = function (date, direction, dayCount) {
var _a = this.props, dateEnv = _a.dateEnv, dateAlignment = _a.dateAlignment;
var runningCount = 0;
var start = date;
var end;
if (dateAlignment) {
start = dateEnv.startOf(start, dateAlignment);
}
start = startOfDay(start);
start = this.skipHiddenDays(start, direction);
end = start;
do {
end = addDays(end, 1);
if (!this.isHiddenDay(end)) {
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
}
} while (runningCount < dayCount);
return { start: start, end: end };
};
// Builds a normalized range object for the "visible" range,
// which is a way to define the currentRange and activeRange at the same time.
DateProfileGenerator.prototype.buildCustomVisibleRange = function (date) {
var props = this.props;
var input = props.visibleRangeInput;
var simpleInput = typeof input === 'function'
? input.call(props.calendarApi, props.dateEnv.toDate(date))
: input;
var range = this.refineRange(simpleInput);
if (range && (range.start == null || range.end == null)) {
return null;
}
return range;
};
// Computes the range that will represent the element/cells for *rendering*,
// but which may have voided days/times.
// not responsible for trimming hidden days.
DateProfileGenerator.prototype.buildRenderRange = function (currentRange, currentRangeUnit, isRangeAllDay) {
return currentRange;
};
// Compute the duration value that should be added/substracted to the current date
// when a prev/next operation happens.
DateProfileGenerator.prototype.buildDateIncrement = function (fallback) {
var dateIncrement = this.props.dateIncrement;
var customAlignment;
if (dateIncrement) {
return dateIncrement;
}
if ((customAlignment = this.props.dateAlignment)) {
return createDuration(1, customAlignment);
}
return fallback;
}
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
};
DateProfileGenerator.prototype.refineRange = function (rangeInput) {
if (rangeInput) {
var range = parseRange(rangeInput, this.props.dateEnv);
if (range) {
range = computeVisibleDayRange(range);
}
return range;
}
return null;
};
/* Hidden Days
------------------------------------------------------------------------------------------------------------------*/
// Initializes internal variables related to calculating hidden days-of-week
DateProfileGenerator.prototype.initHiddenDays = function () {
var hiddenDays = this.props.hiddenDays || []; // array of day-of-week indices that are hidden
var isHiddenDayHash = []; // is the day-of-week hidden? (hash with day-of-week-index -> bool)
var dayCnt = 0;
var i;
if (this.props.weekends === false) {
hiddenDays.push(0, 6); // 0=sunday, 6=saturday
}
if (!(isHiddenDayHash[i] = hiddenDays.indexOf(i) !== -1)) {
}
}
if (!dayCnt) {
throw new Error('invalid hiddenDays'); // all days were hidden? bad.
}
this.isHiddenDayHash = isHiddenDayHash;
};
// Remove days from the beginning and end of the range that are computed as hidden.
// If the whole range is trimmed off, returns null
DateProfileGenerator.prototype.trimHiddenDays = function (range) {
var start = range.start, end = range.end;
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
if (start) {
start = this.skipHiddenDays(start);
}
if (end) {
end = this.skipHiddenDays(end, -1, true);
}
if (start == null || end == null || start < end) {
return { start: start, end: end };
}
return null;
};
// Is the current day hidden?
// `day` is a day-of-week index (0-6), or a Date (used for UTC)
DateProfileGenerator.prototype.isHiddenDay = function (day) {
if (day instanceof Date) {
day = day.getUTCDay();
}
return this.isHiddenDayHash[day];
};
// Incrementing the current day until it is no longer a hidden day, returning a copy.
// DOES NOT CONSIDER validRange!
// If the initial value of `date` is not a hidden day, don't do anything.
// Pass `isExclusive` as `true` if you are dealing with an end date.
// `inc` defaults to `1` (increment one day forward each time)
DateProfileGenerator.prototype.skipHiddenDays = function (date, inc, isExclusive) {
if (inc === void 0) { inc = 1; }
if (isExclusive === void 0) { isExclusive = false; }
while (this.isHiddenDayHash[(date.getUTCDay() + (isExclusive ? inc : 0) + 7) % 7]) {
date = addDays(date, inc);
}
return date;
};
return DateProfileGenerator;
}());
function reduceViewType(viewType, action) {
switch (action.type) {
case 'CHANGE_VIEW_TYPE':
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
}
return viewType;
}
function reduceDynamicOptionOverrides(dynamicOptionOverrides, action) {
var _a;
switch (action.type) {
case 'SET_OPTION':
return __assign(__assign({}, dynamicOptionOverrides), (_a = {}, _a[action.optionName] = action.rawOptionValue, _a));
default:
return dynamicOptionOverrides;
}
}
function reduceDateProfile(currentDateProfile, action, currentDate, dateProfileGenerator) {
var dp;
switch (action.type) {
case 'CHANGE_VIEW_TYPE':
return dateProfileGenerator.build(action.dateMarker || currentDate);
case 'CHANGE_DATE':
if (!currentDateProfile.activeRange ||
!rangeContainsMarker(currentDateProfile.currentRange, action.dateMarker) // don't move if date already in view
) {
return dateProfileGenerator.build(action.dateMarker);
}
break;
case 'PREV':
dp = dateProfileGenerator.buildPrev(currentDateProfile, currentDate);
if (dp.isValid) {
return dp;
}
break;
case 'NEXT':
dp = dateProfileGenerator.buildNext(currentDateProfile, currentDate);
if (dp.isValid) {
return dp;
}
break;
}
return currentDateProfile;
}
function initEventSources(calendarOptions, dateProfile, context) {
var activeRange = dateProfile ? dateProfile.activeRange : null;
return addSources({}, parseInitialSources(calendarOptions, context), activeRange, context);
}
function reduceEventSources(eventSources, action, dateProfile, context) {
var activeRange = dateProfile ? dateProfile.activeRange : null; // need this check?
switch (action.type) {
case 'ADD_EVENT_SOURCES': // already parsed
return addSources(eventSources, action.sources, activeRange, context);
case 'REMOVE_EVENT_SOURCE':
return removeSource(eventSources, action.sourceId);
case 'PREV': // TODO: how do we track all actions that affect dateProfile :(
case 'NEXT':
case 'CHANGE_DATE':
case 'CHANGE_VIEW_TYPE':
if (dateProfile) {
return fetchDirtySources(eventSources, activeRange, context);
}
case 'FETCH_EVENT_SOURCES':
return fetchSourcesByIds(eventSources, action.sourceIds ? // why no type?
arrayToHash(action.sourceIds) :
excludeStaticSources(eventSources, context), activeRange, context);
case 'RECEIVE_EVENTS':
case 'RECEIVE_EVENT_ERROR':
return receiveResponse(eventSources, action.sourceId, action.fetchId, action.fetchRange);
case 'REMOVE_ALL_EVENT_SOURCES':
return {};
default:
return eventSources;
}
}
function reduceEventSourcesNewTimeZone(eventSources, dateProfile, context) {
var activeRange = dateProfile ? dateProfile.activeRange : null; // need this check?
return fetchSourcesByIds(eventSources, excludeStaticSources(eventSources, context), activeRange, context);
}
function computeEventSourcesLoading(eventSources) {
for (var sourceId in eventSources) {
if (eventSources[sourceId].isFetching) {
}
function addSources(eventSourceHash, sources, fetchRange, context) {
var hash = {};
for (var _i = 0, sources_1 = sources; _i < sources_1.length; _i++) {
var source = sources_1[_i];
hash[source.sourceId] = source;
}
if (fetchRange) {
hash = fetchDirtySources(hash, fetchRange, context);
}
return __assign(__assign({}, eventSourceHash), hash);
}
function removeSource(eventSourceHash, sourceId) {
return filterHash(eventSourceHash, function (eventSource) { return eventSource.sourceId !== sourceId; });
}
function fetchDirtySources(sourceHash, fetchRange, context) {
return fetchSourcesByIds(sourceHash, filterHash(sourceHash, function (eventSource) { return isSourceDirty(eventSource, fetchRange, context); }), fetchRange, context);
}
function isSourceDirty(eventSource, fetchRange, context) {
if (!doesSourceNeedRange(eventSource, context)) {
return !eventSource.latestFetchId;
}
return !context.options.lazyFetching ||
!eventSource.fetchRange ||
eventSource.isFetching || // always cancel outdated in-progress fetches
fetchRange.start < eventSource.fetchRange.start ||
fetchRange.end > eventSource.fetchRange.end;
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
}
function fetchSourcesByIds(prevSources, sourceIdHash, fetchRange, context) {
var nextSources = {};
for (var sourceId in prevSources) {
var source = prevSources[sourceId];
if (sourceIdHash[sourceId]) {
nextSources[sourceId] = fetchSource(source, fetchRange, context);
}
else {
nextSources[sourceId] = source;
}
}
return nextSources;
}
function fetchSource(eventSource, fetchRange, context) {
var options = context.options, calendarApi = context.calendarApi;
var sourceDef = context.pluginHooks.eventSourceDefs[eventSource.sourceDefId];
var fetchId = guid();
sourceDef.fetch({
eventSource: eventSource,
range: fetchRange,
}, function (res) {
var rawEvents = res.rawEvents;
if (options.eventSourceSuccess) {
rawEvents = options.eventSourceSuccess.call(calendarApi, rawEvents, res.xhr) || rawEvents;
}
if (eventSource.success) {
rawEvents = eventSource.success.call(calendarApi, rawEvents, res.xhr) || rawEvents;
}
context.dispatch({
type: 'RECEIVE_EVENTS',
sourceId: eventSource.sourceId,
fetchId: fetchId,
fetchRange: fetchRange,
});
}, function (error) {
console.warn(error.message, error);
if (options.eventSourceFailure) {
options.eventSourceFailure.call(calendarApi, error);
}
if (eventSource.failure) {
eventSource.failure(error);
}
context.dispatch({
type: 'RECEIVE_EVENT_ERROR',
sourceId: eventSource.sourceId,
fetchId: fetchId,
fetchRange: fetchRange,
});
});
return __assign(__assign({}, eventSource), { isFetching: true, latestFetchId: fetchId });
}
function receiveResponse(sourceHash, sourceId, fetchId, fetchRange) {
var _a;
var eventSource = sourceHash[sourceId];
if (eventSource && // not already removed
fetchId === eventSource.latestFetchId) {
return __assign(__assign({}, sourceHash), (_a = {}, _a[sourceId] = __assign(__assign({}, eventSource), { isFetching: false, fetchRange: fetchRange }), _a));
}
return sourceHash;
}
function excludeStaticSources(eventSources, context) {
return filterHash(eventSources, function (eventSource) { return doesSourceNeedRange(eventSource, context); });
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
}
function parseInitialSources(rawOptions, context) {
var refiners = buildEventSourceRefiners(context);
var rawSources = [].concat(rawOptions.eventSources || []);
var sources = []; // parsed
if (rawOptions.initialEvents) {
rawSources.unshift(rawOptions.initialEvents);
}
if (rawOptions.events) {
rawSources.unshift(rawOptions.events);
}
for (var _i = 0, rawSources_1 = rawSources; _i < rawSources_1.length; _i++) {
var rawSource = rawSources_1[_i];
var source = parseEventSource(rawSource, context, refiners);
if (source) {
sources.push(source);
}
}
return sources;
}
function doesSourceNeedRange(eventSource, context) {
var defs = context.pluginHooks.eventSourceDefs;
return !defs[eventSource.sourceDefId].ignoreRange;
}
function reduceDateSelection(currentSelection, action) {
switch (action.type) {
case 'UNSELECT_DATES':
return null;
case 'SELECT_DATES':
return action.selection;
default:
return currentSelection;
}
}
function reduceSelectedEvent(currentInstanceId, action) {
switch (action.type) {
case 'UNSELECT_EVENT':
return '';
case 'SELECT_EVENT':
return action.eventInstanceId;
default:
return currentInstanceId;
}
}
function reduceEventDrag(currentDrag, action) {
var newDrag;
switch (action.type) {
case 'UNSET_EVENT_DRAG':
return null;
case 'SET_EVENT_DRAG':
newDrag = action.state;
return {
affectedEvents: newDrag.affectedEvents,
mutatedEvents: newDrag.mutatedEvents,
};
default:
return currentDrag;
}
}
function reduceEventResize(currentResize, action) {
var newResize;
switch (action.type) {
case 'UNSET_EVENT_RESIZE':
return null;
case 'SET_EVENT_RESIZE':
newResize = action.state;
return {
affectedEvents: newResize.affectedEvents,
mutatedEvents: newResize.mutatedEvents,
};
default:
return currentResize;
}
}
function parseToolbars(calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi) {
var viewsWithButtons = [];
var headerToolbar = calendarOptions.headerToolbar ? parseToolbar(calendarOptions.headerToolbar, calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi, viewsWithButtons) : null;
var footerToolbar = calendarOptions.footerToolbar ? parseToolbar(calendarOptions.footerToolbar, calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi, viewsWithButtons) : null;
return { headerToolbar: headerToolbar, footerToolbar: footerToolbar, viewsWithButtons: viewsWithButtons };
}
function parseToolbar(sectionStrHash, calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi, viewsWithButtons) {
return mapHash(sectionStrHash, function (sectionStr) { return parseSection(sectionStr, calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi, viewsWithButtons); });
}
/*
BAD: querying icons and text here. should be done at render time
*/
function parseSection(sectionStr, calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi, viewsWithButtons) {
var isRtl = calendarOptions.direction === 'rtl';
var calendarCustomButtons = calendarOptions.customButtons || {};
var calendarButtonTextOverrides = calendarOptionOverrides.buttonText || {};
var calendarButtonText = calendarOptions.buttonText || {};
var sectionSubstrs = sectionStr ? sectionStr.split(' ') : [];
return sectionSubstrs.map(function (buttonGroupStr) { return (buttonGroupStr.split(',').map(function (buttonName) {
if (buttonName === 'title') {
return { buttonName: buttonName };
}
var customButtonProps;
var viewSpec;
var buttonClick;
var buttonIcon; // only one of these will be set
var buttonText; // "
if ((customButtonProps = calendarCustomButtons[buttonName])) {
buttonClick = function (ev) {
if (customButtonProps.click) {
customButtonProps.click.call(ev.target, ev, ev.target);
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
};
(buttonIcon = theme.getCustomButtonIconClass(customButtonProps)) ||
(buttonIcon = theme.getIconClass(buttonName, isRtl)) ||
(buttonText = customButtonProps.text);
}
else if ((viewSpec = viewSpecs[buttonName])) {
viewsWithButtons.push(buttonName);
buttonClick = function () {
calendarApi.changeView(buttonName);
};
(buttonText = viewSpec.buttonTextOverride) ||
(buttonIcon = theme.getIconClass(buttonName, isRtl)) ||
(buttonText = viewSpec.buttonTextDefault);
}
else if (calendarApi[buttonName]) { // a calendarApi method
buttonClick = function () {
calendarApi[buttonName]();
};
(buttonText = calendarButtonTextOverrides[buttonName]) ||
(buttonIcon = theme.getIconClass(buttonName, isRtl)) ||
(buttonText = calendarButtonText[buttonName]);
// ^ everything else is considered default
}
return { buttonName: buttonName, buttonClick: buttonClick, buttonIcon: buttonIcon, buttonText: buttonText };
})); });
}
var eventSourceDef = {
ignoreRange: true,
parseMeta: function (refined) {
if (Array.isArray(refined.events)) {
return refined.events;
}
return null;
},
fetch: function (arg, success) {
success({
};
var arrayEventSourcePlugin = createPlugin({
});
var eventSourceDef$1 = {
parseMeta: function (refined) {
if (typeof refined.events === 'function') {
return refined.events;
}
return null;
},
fetch: function (arg, success, failure) {
var dateEnv = arg.context.dateEnv;
var func = arg.eventSource.meta;
unpromisify(func.bind(null, buildRangeApiWithTimeZone(arg.range, dateEnv)), function (rawEvents) {
success({ rawEvents: rawEvents }); // needs an object response
};
var funcEventSourcePlugin = createPlugin({
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
});
function requestJson(method, url, params, successCallback, failureCallback) {
method = method.toUpperCase();
var body = null;
if (method === 'GET') {
url = injectQueryStringParams(url, params);
}
else {
body = encodeParams(params);
}
var xhr = new XMLHttpRequest();
xhr.open(method, url, true);
if (method !== 'GET') {
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
xhr.onload = function () {
if (xhr.status >= 200 && xhr.status < 400) {
var parsed = false;
var res = void 0;
try {
res = JSON.parse(xhr.responseText);
parsed = true;
}
catch (err) {
// will handle parsed=false
}
if (parsed) {
successCallback(res, xhr);
}
else {
failureCallback('Failure parsing JSON', xhr);
}
}
else {
failureCallback('Request failed', xhr);
}
};
xhr.onerror = function () {
failureCallback('Request failed', xhr);
};
xhr.send(body);
}
function injectQueryStringParams(url, params) {
return url +
(url.indexOf('?') === -1 ? '?' : '&') +
encodeParams(params);
}
function encodeParams(params) {
var parts = [];
for (var key in params) {
parts.push(encodeURIComponent(key) + "=" + encodeURIComponent(params[key]));
}
return parts.join('&');
}
var JSON_FEED_EVENT_SOURCE_REFINERS = {
method: String,
extraParams: identity,
startParam: String,
endParam: String,
};
var eventSourceDef$2 = {
parseMeta: function (refined) {
if (refined.url && (refined.format === 'json' || !refined.format)) {
return {
url: refined.url,
method: (refined.method || 'GET').toUpperCase(),
extraParams: refined.extraParams,
startParam: refined.startParam,
endParam: refined.endParam,
};
}
return null;
},
fetch: function (arg, success, failure) {
var meta = arg.eventSource.meta;
var requestParams = buildRequestParams(meta, arg.range, arg.context);
requestJson(meta.method, meta.url, requestParams, function (rawEvents, xhr) {
success({ rawEvents: rawEvents, xhr: xhr });
}, function (errorMessage, xhr) {
failure({ message: errorMessage, xhr: xhr });
});
};
var jsonFeedEventSourcePlugin = createPlugin({
eventSourceRefiners: JSON_FEED_EVENT_SOURCE_REFINERS,
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
});
function buildRequestParams(meta, range, context) {
var dateEnv = context.dateEnv, options = context.options;
var startParam;
var endParam;
var timeZoneParam;
var customRequestParams;
var params = {};
startParam = meta.startParam;
if (startParam == null) {
startParam = options.startParam;
}
endParam = meta.endParam;
if (endParam == null) {
endParam = options.endParam;
}
timeZoneParam = meta.timeZoneParam;
if (timeZoneParam == null) {
timeZoneParam = options.timeZoneParam;
}
// retrieve any outbound GET/POST data from the options
if (typeof meta.extraParams === 'function') {
// supplied as a function that returns a key/value object
customRequestParams = meta.extraParams();
}
else {
// probably supplied as a straight key/value object
customRequestParams = meta.extraParams || {};
}
__assign(params, customRequestParams);
params[startParam] = dateEnv.formatIso(range.start);
params[endParam] = dateEnv.formatIso(range.end);
if (dateEnv.timeZone !== 'local') {
params[timeZoneParam] = dateEnv.timeZone;
}
return params;
}
var SIMPLE_RECURRING_REFINERS = {
daysOfWeek: identity,
startTime: createDuration,
endTime: createDuration,
duration: createDuration,
startRecur: identity,
};
var recurring = {
parse: function (refined, dateEnv) {
if (refined.daysOfWeek || refined.startTime || refined.endTime || refined.startRecur || refined.endRecur) {
var recurringData = {
daysOfWeek: refined.daysOfWeek || null,
startTime: refined.startTime || null,
endTime: refined.endTime || null,
startRecur: refined.startRecur ? dateEnv.createMarker(refined.startRecur) : null,
endRecur: refined.endRecur ? dateEnv.createMarker(refined.endRecur) : null,
};
var duration = void 0;
if (refined.duration) {
duration = refined.duration;
}
if (!duration && refined.startTime && refined.endTime) {
duration = subtractDurations(refined.endTime, refined.startTime);
}
return {
allDayGuess: Boolean(!refined.startTime && !refined.endTime),
duration: duration,
};
}
return null;
},
expand: function (typeData, framingRange, dateEnv) {
var clippedFramingRange = intersectRanges(framingRange, { start: typeData.startRecur, end: typeData.endRecur });
if (clippedFramingRange) {
return expandRanges(typeData.daysOfWeek, typeData.startTime, clippedFramingRange, dateEnv);
}
};
var simpleRecurringEventsPlugin = createPlugin({
recurringTypes: [recurring],
eventRefiners: SIMPLE_RECURRING_REFINERS,
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
});
function expandRanges(daysOfWeek, startTime, framingRange, dateEnv) {
var dowHash = daysOfWeek ? arrayToHash(daysOfWeek) : null;
var dayMarker = startOfDay(framingRange.start);
var endMarker = framingRange.end;
var instanceStarts = [];
while (dayMarker < endMarker) {
var instanceStart
// if everyday, or this particular day-of-week
= void 0;
// if everyday, or this particular day-of-week
if (!dowHash || dowHash[dayMarker.getUTCDay()]) {
if (startTime) {
instanceStart = dateEnv.add(dayMarker, startTime);
}
else {
instanceStart = dayMarker;
}
instanceStarts.push(instanceStart);
}
dayMarker = addDays(dayMarker, 1);
}
return instanceStarts;
}
var changeHandlerPlugin = createPlugin({
optionChangeHandlers: {
events: function (events, context) {
handleEventSources([events], context);
},
eventSources: handleEventSources,
},
});
/*
BUG: if `event` was supplied, all previously-given `eventSources` will be wiped out
*/
function handleEventSources(inputs, context) {
var unfoundSources = hashValuesToArray(context.getCurrentData().eventSources);
var newInputs = [];
for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) {
var input = inputs_1[_i];
var inputFound = false;
for (var i = 0; i < unfoundSources.length; i += 1) {
if (unfoundSources[i]._raw === input) {
unfoundSources.splice(i, 1); // delete
inputFound = true;
break;
}
}
if (!inputFound) {
newInputs.push(input);
}
}
for (var _a = 0, unfoundSources_1 = unfoundSources; _a < unfoundSources_1.length; _a++) {
var unfoundSource = unfoundSources_1[_a];
context.dispatch({
type: 'REMOVE_EVENT_SOURCE',
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
});
}
for (var _b = 0, newInputs_1 = newInputs; _b < newInputs_1.length; _b++) {
var newInput = newInputs_1[_b];
context.calendarApi.addEventSource(newInput);
}
}
function handleDateProfile(dateProfile, context) {
context.emitter.trigger('datesSet', __assign(__assign({}, buildRangeApiWithTimeZone(dateProfile.activeRange, context.dateEnv)), { view: context.viewApi }));
}
function handleEventStore(eventStore, context) {
var emitter = context.emitter;
if (emitter.hasHandlers('eventsSet')) {
emitter.trigger('eventsSet', buildEventApis(eventStore, context));
}
}
/*
this array is exposed on the root namespace so that UMD plugins can add to it.
see the rollup-bundles script.
*/
var globalPlugins = [
arrayEventSourcePlugin,
funcEventSourcePlugin,
jsonFeedEventSourcePlugin,
simpleRecurringEventsPlugin,
changeHandlerPlugin,
createPlugin({
isLoadingFuncs: [
function (state) { return computeEventSourcesLoading(state.eventSources); },
],
contentTypeHandlers: {
html: function () { return ({ render: injectHtml }); },
domNodes: function () { return ({ render: injectDomNodes }); },
},
propSetHandlers: {
dateProfile: handleDateProfile,
eventStore: handleEventStore,
},
}),
function injectHtml(el, html) {
el.innerHTML = html;
}
function injectDomNodes(el, domNodes) {
var oldNodes = Array.prototype.slice.call(el.childNodes); // TODO: use array util
var newNodes = Array.prototype.slice.call(domNodes); // TODO: use array util
if (!isArraysEqual(oldNodes, newNodes)) {
for (var _i = 0, newNodes_1 = newNodes; _i < newNodes_1.length; _i++) {
var newNode = newNodes_1[_i];
el.appendChild(newNode);
}
oldNodes.forEach(removeElement);
}
}
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
var DelayedRunner = /** @class */ (function () {
function DelayedRunner(drainedOption) {
this.drainedOption = drainedOption;
this.isRunning = false;
this.isDirty = false;
this.pauseDepths = {};
this.timeoutId = 0;
}
DelayedRunner.prototype.request = function (delay) {
this.isDirty = true;
if (!this.isPaused()) {
this.clearTimeout();
if (delay == null) {
this.tryDrain();
}
else {
this.timeoutId = setTimeout(// NOT OPTIMAL! TODO: look at debounce
this.tryDrain.bind(this), delay);
}
}
};
DelayedRunner.prototype.pause = function (scope) {
if (scope === void 0) { scope = ''; }
var pauseDepths = this.pauseDepths;
pauseDepths[scope] = (pauseDepths[scope] || 0) + 1;
this.clearTimeout();
};
DelayedRunner.prototype.resume = function (scope, force) {
if (scope === void 0) { scope = ''; }
var pauseDepths = this.pauseDepths;
if (scope in pauseDepths) {
if (force) {
delete pauseDepths[scope];
}
else {
pauseDepths[scope] -= 1;
var depth = pauseDepths[scope];
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
if (depth <= 0) {
delete pauseDepths[scope];
}
}
this.tryDrain();
}
};
DelayedRunner.prototype.isPaused = function () {
return Object.keys(this.pauseDepths).length;
};
DelayedRunner.prototype.tryDrain = function () {
if (!this.isRunning && !this.isPaused()) {
this.isRunning = true;
while (this.isDirty) {
this.isDirty = false;
this.drained(); // might set isDirty to true again
}
this.isRunning = false;
}
};
DelayedRunner.prototype.clear = function () {
this.clearTimeout();
this.isDirty = false;
this.pauseDepths = {};
};
DelayedRunner.prototype.clearTimeout = function () {
if (this.timeoutId) {
clearTimeout(this.timeoutId);
this.timeoutId = 0;
}
};
DelayedRunner.prototype.drained = function () {
if (this.drainedOption) {
this.drainedOption();
}
};
return DelayedRunner;
}());
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
var TaskRunner = /** @class */ (function () {
function TaskRunner(runTaskOption, drainedOption) {
this.runTaskOption = runTaskOption;
this.drainedOption = drainedOption;
this.queue = [];
this.delayedRunner = new DelayedRunner(this.drain.bind(this));
}
TaskRunner.prototype.request = function (task, delay) {
this.queue.push(task);
this.delayedRunner.request(delay);
};
TaskRunner.prototype.pause = function (scope) {
this.delayedRunner.pause(scope);
};
TaskRunner.prototype.resume = function (scope, force) {
this.delayedRunner.resume(scope, force);
};
TaskRunner.prototype.drain = function () {
var queue = this.queue;
while (queue.length) {
var completedTasks = [];
var task = void 0;
while ((task = queue.shift())) {
this.runTask(task);
completedTasks.push(task);
}
this.drained(completedTasks);
} // keep going, in case new tasks were added in the drained handler
};
TaskRunner.prototype.runTask = function (task) {
if (this.runTaskOption) {
this.runTaskOption(task);
}
};
TaskRunner.prototype.drained = function (completedTasks) {
if (this.drainedOption) {
this.drainedOption(completedTasks);
}
};
return TaskRunner;
}());
// Computes what the title at the top of the calendarApi should be for this view
function buildTitle(dateProfile, viewOptions, dateEnv) {
var range;
// for views that span a large unit of time, show the proper interval, ignoring stray days before and after
if (/^(year|month)$/.test(dateProfile.currentRangeUnit)) {
range = dateProfile.currentRange;
}
else { // for day units or smaller, use the actual day range
range = dateProfile.activeRange;
}
return dateEnv.formatRange(range.start, range.end, createFormatter(viewOptions.titleFormat || buildTitleFormat(dateProfile)), {
isEndExclusive: dateProfile.isRangeAllDay,
defaultSeparator: viewOptions.titleRangeSeparator,
});
}
// Generates the format string that should be used to generate the title for the current date range.
// Attempts to compute the most appropriate format if not explicitly specified with `titleFormat`.
function buildTitleFormat(dateProfile) {
var currentRangeUnit = dateProfile.currentRangeUnit;
if (currentRangeUnit === 'year') {
return { year: 'numeric' };
}
return { year: 'numeric', month: 'long' }; // like "September 2014"
}
var days = diffWholeDays(dateProfile.currentRange.start, dateProfile.currentRange.end);
if (days !== null && days > 1) {
// multi-day range. shorter, like "Sep 9 - 10 2014"
return { year: 'numeric', month: 'short', day: 'numeric' };
// one day. longer, like "September 9 2014"
return { year: 'numeric', month: 'long', day: 'numeric' };
}
// in future refactor, do the redux-style function(state=initial) for initial-state