better-staridc-MNBT
1/*!
2FullCalendar Core Package v4.3.1
3Docs & License: https://fullcalendar.io/
4(c) 2019 Adam Shaw
5*/
6
7(function (global, factory) {
8 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
9 typeof define === 'function' && define.amd ? define(['exports'], factory) :
10 (global = global || self, factory(global.FullCalendar = {}));
11}(this, function (exports) { 'use strict';
12
13 // Creating
14 // ----------------------------------------------------------------------------------------------------------------
15 var elementPropHash = {
16 className: true,
17 colSpan: true,
18 rowSpan: true
19 };
20 var containerTagHash = {
21 '<tr': 'tbody',
22 '<td': 'tr'
23 };
24 function createElement(tagName, attrs, content) {
25 var el = document.createElement(tagName);
26 if (attrs) {
27 for (var attrName in attrs) {
28 if (attrName === 'style') {
29 applyStyle(el, attrs[attrName]);
30 }
31 else if (elementPropHash[attrName]) {
32 el[attrName] = attrs[attrName];
33 }
34 else {
35 el.setAttribute(attrName, attrs[attrName]);
36 }
37 }
38 }
39 if (typeof content === 'string') {
40 el.innerHTML = content; // shortcut. no need to process HTML in any way
41 }
42 else if (content != null) {
43 appendToElement(el, content);
44 }
45 return el;
46 }
47 function htmlToElement(html) {
48 html = html.trim();
49 var container = document.createElement(computeContainerTag(html));
50 container.innerHTML = html;
51 return container.firstChild;
52 }
53 function htmlToElements(html) {
54 return Array.prototype.slice.call(htmlToNodeList(html));
55 }
56 function htmlToNodeList(html) {
57 html = html.trim();
58 var container = document.createElement(computeContainerTag(html));
59 container.innerHTML = html;
60 return container.childNodes;
61 }
62 // assumes html already trimmed and tag names are lowercase
63 function computeContainerTag(html) {
64 return containerTagHash[html.substr(0, 3) // faster than using regex
65 ] || 'div';
66 }
67 function appendToElement(el, content) {
68 var childNodes = normalizeContent(content);
69 for (var i = 0; i < childNodes.length; i++) {
70 el.appendChild(childNodes[i]);
71 }
72 }
73 function prependToElement(parent, content) {
74 var newEls = normalizeContent(content);
75 var afterEl = parent.firstChild || null; // if no firstChild, will append to end, but that's okay, b/c there were no children
76 for (var i = 0; i < newEls.length; i++) {
77 parent.insertBefore(newEls[i], afterEl);
78 }
79 }
80 function insertAfterElement(refEl, content) {
81 var newEls = normalizeContent(content);
82 var afterEl = refEl.nextSibling || null;
83 for (var i = 0; i < newEls.length; i++) {
84 refEl.parentNode.insertBefore(newEls[i], afterEl);
85 }
86 }
87 function normalizeContent(content) {
88 var els;
89 if (typeof content === 'string') {
90 els = htmlToElements(content);
91 }
92 else if (content instanceof Node) {
93 els = [content];
94 }
95 else { // Node[] or NodeList
96 els = Array.prototype.slice.call(content);
97 }
98 return els;
99 }
100 function removeElement(el) {
101 if (el.parentNode) {
102 el.parentNode.removeChild(el);
103 }
104 }
105 // Querying
106 // ----------------------------------------------------------------------------------------------------------------
107 // from https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
108 var matchesMethod = Element.prototype.matches ||
109 Element.prototype.matchesSelector ||
110 Element.prototype.msMatchesSelector;
111 var closestMethod = Element.prototype.closest || function (selector) {
112 // polyfill
113 var el = this;
114 if (!document.documentElement.contains(el)) {
115 return null;
116 }
117 do {
118 if (elementMatches(el, selector)) {
119 return el;
120 }
121 el = el.parentElement || el.parentNode;
122 } while (el !== null && el.nodeType === 1);
123 return null;
124 };
125 function elementClosest(el, selector) {
126 return closestMethod.call(el, selector);
127 }
128 function elementMatches(el, selector) {
129 return matchesMethod.call(el, selector);
130 }
131 // accepts multiple subject els
132 // returns a real array. good for methods like forEach
133 function findElements(container, selector) {
134 var containers = container instanceof HTMLElement ? [container] : container;
135 var allMatches = [];
136 for (var i = 0; i < containers.length; i++) {
137 var matches = containers[i].querySelectorAll(selector);
138 for (var j = 0; j < matches.length; j++) {
139 allMatches.push(matches[j]);
140 }
141 }
142 return allMatches;
143 }
144 // accepts multiple subject els
145 // only queries direct child elements
146 function findChildren(parent, selector) {
147 var parents = parent instanceof HTMLElement ? [parent] : parent;
148 var allMatches = [];
149 for (var i = 0; i < parents.length; i++) {
150 var childNodes = parents[i].children; // only ever elements
151 for (var j = 0; j < childNodes.length; j++) {
152 var childNode = childNodes[j];
153 if (!selector || elementMatches(childNode, selector)) {
154 allMatches.push(childNode);
155 }
156 }
157 }
158 return allMatches;
159 }
160 // Attributes
161 // ----------------------------------------------------------------------------------------------------------------
162 function forceClassName(el, className, bool) {
163 if (bool) {
164 el.classList.add(className);
165 }
166 else {
167 el.classList.remove(className);
168 }
169 }
170 // Style
171 // ----------------------------------------------------------------------------------------------------------------
172 var PIXEL_PROP_RE = /(top|left|right|bottom|width|height)$/i;
173 function applyStyle(el, props) {
174 for (var propName in props) {
175 applyStyleProp(el, propName, props[propName]);
176 }
177 }
178 function applyStyleProp(el, name, val) {
179 if (val == null) {
180 el.style[name] = '';
181 }
182 else if (typeof val === 'number' && PIXEL_PROP_RE.test(name)) {
183 el.style[name] = val + 'px';
184 }
185 else {
186 el.style[name] = val;
187 }
188 }
189
190 function pointInsideRect(point, rect) {
191 return point.left >= rect.left &&
192 point.left < rect.right &&
193 point.top >= rect.top &&
194 point.top < rect.bottom;
195 }
196 // Returns a new rectangle that is the intersection of the two rectangles. If they don't intersect, returns false
197 function intersectRects(rect1, rect2) {
198 var res = {
199 left: Math.max(rect1.left, rect2.left),
200 right: Math.min(rect1.right, rect2.right),
201 top: Math.max(rect1.top, rect2.top),
202 bottom: Math.min(rect1.bottom, rect2.bottom)
203 };
204 if (res.left < res.right && res.top < res.bottom) {
205 return res;
206 }
207 return false;
208 }
209 function translateRect(rect, deltaX, deltaY) {
210 return {
211 left: rect.left + deltaX,
212 right: rect.right + deltaX,
213 top: rect.top + deltaY,
214 bottom: rect.bottom + deltaY
215 };
216 }
217 // Returns a new point that will have been moved to reside within the given rectangle
218 function constrainPoint(point, rect) {
219 return {
220 left: Math.min(Math.max(point.left, rect.left), rect.right),
221 top: Math.min(Math.max(point.top, rect.top), rect.bottom)
222 };
223 }
224 // Returns a point that is the center of the given rectangle
225 function getRectCenter(rect) {
226 return {
227 left: (rect.left + rect.right) / 2,
228 top: (rect.top + rect.bottom) / 2
229 };
230 }
231 // Subtracts point2's coordinates from point1's coordinates, returning a delta
232 function diffPoints(point1, point2) {
233 return {
234 left: point1.left - point2.left,
235 top: point1.top - point2.top
236 };
237 }
238
239 // Logic for determining if, when the element is right-to-left, the scrollbar appears on the left side
240 var isRtlScrollbarOnLeft = null;
241 function getIsRtlScrollbarOnLeft() {
242 if (isRtlScrollbarOnLeft === null) {
243 isRtlScrollbarOnLeft = computeIsRtlScrollbarOnLeft();
244 }
245 return isRtlScrollbarOnLeft;
246 }
247 function computeIsRtlScrollbarOnLeft() {
248 var outerEl = createElement('div', {
249 style: {
250 position: 'absolute',
251 top: -1000,
252 left: 0,
253 border: 0,
254 padding: 0,
255 overflow: 'scroll',
256 direction: 'rtl'
257 }
258 }, '<div></div>');
259 document.body.appendChild(outerEl);
260 var innerEl = outerEl.firstChild;
261 var res = innerEl.getBoundingClientRect().left > outerEl.getBoundingClientRect().left;
262 removeElement(outerEl);
263 return res;
264 }
265 // The scrollbar width computations in computeEdges are sometimes flawed when it comes to
266 // retina displays, rounding, and IE11. Massage them into a usable value.
267 function sanitizeScrollbarWidth(width) {
268 width = Math.max(0, width); // no negatives
269 width = Math.round(width);
270 return width;
271 }
272
273 function computeEdges(el, getPadding) {
274 if (getPadding === void 0) { getPadding = false; }
275 var computedStyle = window.getComputedStyle(el);
276 var borderLeft = parseInt(computedStyle.borderLeftWidth, 10) || 0;
277 var borderRight = parseInt(computedStyle.borderRightWidth, 10) || 0;
278 var borderTop = parseInt(computedStyle.borderTopWidth, 10) || 0;
279 var borderBottom = parseInt(computedStyle.borderBottomWidth, 10) || 0;
280 // must use offset(Width|Height) because compatible with client(Width|Height)
281 var scrollbarLeftRight = sanitizeScrollbarWidth(el.offsetWidth - el.clientWidth - borderLeft - borderRight);
282 var scrollbarBottom = sanitizeScrollbarWidth(el.offsetHeight - el.clientHeight - borderTop - borderBottom);
283 var res = {
284 borderLeft: borderLeft,
285 borderRight: borderRight,
286 borderTop: borderTop,
287 borderBottom: borderBottom,
288 scrollbarBottom: scrollbarBottom,
289 scrollbarLeft: 0,
290 scrollbarRight: 0
291 };
292 if (getIsRtlScrollbarOnLeft() && computedStyle.direction === 'rtl') { // is the scrollbar on the left side?
293 res.scrollbarLeft = scrollbarLeftRight;
294 }
295 else {
296 res.scrollbarRight = scrollbarLeftRight;
297 }
298 if (getPadding) {
299 res.paddingLeft = parseInt(computedStyle.paddingLeft, 10) || 0;
300 res.paddingRight = parseInt(computedStyle.paddingRight, 10) || 0;
301 res.paddingTop = parseInt(computedStyle.paddingTop, 10) || 0;
302 res.paddingBottom = parseInt(computedStyle.paddingBottom, 10) || 0;
303 }
304 return res;
305 }
306 function computeInnerRect(el, goWithinPadding) {
307 if (goWithinPadding === void 0) { goWithinPadding = false; }
308 var outerRect = computeRect(el);
309 var edges = computeEdges(el, goWithinPadding);
310 var res = {
311 left: outerRect.left + edges.borderLeft + edges.scrollbarLeft,
312 right: outerRect.right - edges.borderRight - edges.scrollbarRight,
313 top: outerRect.top + edges.borderTop,
314 bottom: outerRect.bottom - edges.borderBottom - edges.scrollbarBottom
315 };
316 if (goWithinPadding) {
317 res.left += edges.paddingLeft;
318 res.right -= edges.paddingRight;
319 res.top += edges.paddingTop;
320 res.bottom -= edges.paddingBottom;
321 }
322 return res;
323 }
324 function computeRect(el) {
325 var rect = el.getBoundingClientRect();
326 return {
327 left: rect.left + window.pageXOffset,
328 top: rect.top + window.pageYOffset,
329 right: rect.right + window.pageXOffset,
330 bottom: rect.bottom + window.pageYOffset
331 };
332 }
333 function computeViewportRect() {
334 return {
335 left: window.pageXOffset,
336 right: window.pageXOffset + document.documentElement.clientWidth,
337 top: window.pageYOffset,
338 bottom: window.pageYOffset + document.documentElement.clientHeight
339 };
340 }
341 function computeHeightAndMargins(el) {
342 return el.getBoundingClientRect().height + computeVMargins(el);
343 }
344 function computeVMargins(el) {
345 var computed = window.getComputedStyle(el);
346 return parseInt(computed.marginTop, 10) +
347 parseInt(computed.marginBottom, 10);
348 }
349 // does not return window
350 function getClippingParents(el) {
351 var parents = [];
352 while (el instanceof HTMLElement) { // will stop when gets to document or null
353 var computedStyle = window.getComputedStyle(el);
354 if (computedStyle.position === 'fixed') {
355 break;
356 }
357 if ((/(auto|scroll)/).test(computedStyle.overflow + computedStyle.overflowY + computedStyle.overflowX)) {
358 parents.push(el);
359 }
360 el = el.parentNode;
361 }
362 return parents;
363 }
364 function computeClippingRect(el) {
365 return getClippingParents(el)
366 .map(function (el) {
367 return computeInnerRect(el);
368 })
369 .concat(computeViewportRect())
370 .reduce(function (rect0, rect1) {
371 return intersectRects(rect0, rect1) || rect1; // should always intersect
372 });
373 }
374
375 // Stops a mouse/touch event from doing it's native browser action
376 function preventDefault(ev) {
377 ev.preventDefault();
378 }
379 // Event Delegation
380 // ----------------------------------------------------------------------------------------------------------------
381 function listenBySelector(container, eventType, selector, handler) {
382 function realHandler(ev) {
383 var matchedChild = elementClosest(ev.target, selector);
384 if (matchedChild) {
385 handler.call(matchedChild, ev, matchedChild);
386 }
387 }
388 container.addEventListener(eventType, realHandler);
389 return function () {
390 container.removeEventListener(eventType, realHandler);
391 };
392 }
393 function listenToHoverBySelector(container, selector, onMouseEnter, onMouseLeave) {
394 var currentMatchedChild;
395 return listenBySelector(container, 'mouseover', selector, function (ev, matchedChild) {
396 if (matchedChild !== currentMatchedChild) {
397 currentMatchedChild = matchedChild;
398 onMouseEnter(ev, matchedChild);
399 var realOnMouseLeave_1 = function (ev) {
400 currentMatchedChild = null;
401 onMouseLeave(ev, matchedChild);
402 matchedChild.removeEventListener('mouseleave', realOnMouseLeave_1);
403 };
404 // listen to the next mouseleave, and then unattach
405 matchedChild.addEventListener('mouseleave', realOnMouseLeave_1);
406 }
407 });
408 }
409 // Animation
410 // ----------------------------------------------------------------------------------------------------------------
411 var transitionEventNames = [
412 'webkitTransitionEnd',
413 'otransitionend',
414 'oTransitionEnd',
415 'msTransitionEnd',
416 'transitionend'
417 ];
418 // triggered only when the next single subsequent transition finishes
419 function whenTransitionDone(el, callback) {
420 var realCallback = function (ev) {
421 callback(ev);
422 transitionEventNames.forEach(function (eventName) {
423 el.removeEventListener(eventName, realCallback);
424 });
425 };
426 transitionEventNames.forEach(function (eventName) {
427 el.addEventListener(eventName, realCallback); // cross-browser way to determine when the transition finishes
428 });
429 }
430
431 var DAY_IDS = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
432 // Adding
433 function addWeeks(m, n) {
434 var a = dateToUtcArray(m);
435 a[2] += n * 7;
436 return arrayToUtcDate(a);
437 }
438 function addDays(m, n) {
439 var a = dateToUtcArray(m);
440 a[2] += n;
441 return arrayToUtcDate(a);
442 }
443 function addMs(m, n) {
444 var a = dateToUtcArray(m);
445 a[6] += n;
446 return arrayToUtcDate(a);
447 }
448 // Diffing (all return floats)
449 function diffWeeks(m0, m1) {
450 return diffDays(m0, m1) / 7;
451 }
452 function diffDays(m0, m1) {
453 return (m1.valueOf() - m0.valueOf()) / (1000 * 60 * 60 * 24);
454 }
455 function diffHours(m0, m1) {
456 return (m1.valueOf() - m0.valueOf()) / (1000 * 60 * 60);
457 }
458 function diffMinutes(m0, m1) {
459 return (m1.valueOf() - m0.valueOf()) / (1000 * 60);
460 }
461 function diffSeconds(m0, m1) {
462 return (m1.valueOf() - m0.valueOf()) / 1000;
463 }
464 function diffDayAndTime(m0, m1) {
465 var m0day = startOfDay(m0);
466 var m1day = startOfDay(m1);
467 return {
468 years: 0,
469 months: 0,
470 days: Math.round(diffDays(m0day, m1day)),
471 milliseconds: (m1.valueOf() - m1day.valueOf()) - (m0.valueOf() - m0day.valueOf())
472 };
473 }
474 // Diffing Whole Units
475 function diffWholeWeeks(m0, m1) {
476 var d = diffWholeDays(m0, m1);
477 if (d !== null && d % 7 === 0) {
478 return d / 7;
479 }
480 return null;
481 }
482 function diffWholeDays(m0, m1) {
483 if (timeAsMs(m0) === timeAsMs(m1)) {
484 return Math.round(diffDays(m0, m1));
485 }
486 return null;
487 }
488 // Start-Of
489 function startOfDay(m) {
490 return arrayToUtcDate([
491 m.getUTCFullYear(),
492 m.getUTCMonth(),
493 m.getUTCDate()
494 ]);
495 }
496 function startOfHour(m) {
497 return arrayToUtcDate([
498 m.getUTCFullYear(),
499 m.getUTCMonth(),
500 m.getUTCDate(),
501 m.getUTCHours()
502 ]);
503 }
504 function startOfMinute(m) {
505 return arrayToUtcDate([
506 m.getUTCFullYear(),
507 m.getUTCMonth(),
508 m.getUTCDate(),
509 m.getUTCHours(),
510 m.getUTCMinutes()
511 ]);
512 }
513 function startOfSecond(m) {
514 return arrayToUtcDate([
515 m.getUTCFullYear(),
516 m.getUTCMonth(),
517 m.getUTCDate(),
518 m.getUTCHours(),
519 m.getUTCMinutes(),
520 m.getUTCSeconds()
521 ]);
522 }
523 // Week Computation
524 function weekOfYear(marker, dow, doy) {
525 var y = marker.getUTCFullYear();
526 var w = weekOfGivenYear(marker, y, dow, doy);
527 if (w < 1) {
528 return weekOfGivenYear(marker, y - 1, dow, doy);
529 }
530 var nextW = weekOfGivenYear(marker, y + 1, dow, doy);
531 if (nextW >= 1) {
532 return Math.min(w, nextW);
533 }
534 return w;
535 }
536 function weekOfGivenYear(marker, year, dow, doy) {
537 var firstWeekStart = arrayToUtcDate([year, 0, 1 + firstWeekOffset(year, dow, doy)]);
538 var dayStart = startOfDay(marker);
539 var days = Math.round(diffDays(firstWeekStart, dayStart));
540 return Math.floor(days / 7) + 1; // zero-indexed
541 }
542 // start-of-first-week - start-of-year
543 function firstWeekOffset(year, dow, doy) {
544 // first-week day -- which january is always in the first week (4 for iso, 1 for other)
545 var fwd = 7 + dow - doy;
546 // first-week day local weekday -- which local weekday is fwd
547 var fwdlw = (7 + arrayToUtcDate([year, 0, fwd]).getUTCDay() - dow) % 7;
548 return -fwdlw + fwd - 1;
549 }
550 // Array Conversion
551 function dateToLocalArray(date) {
552 return [
553 date.getFullYear(),
554 date.getMonth(),
555 date.getDate(),
556 date.getHours(),
557 date.getMinutes(),
558 date.getSeconds(),
559 date.getMilliseconds()
560 ];
561 }
562 function arrayToLocalDate(a) {
563 return new Date(a[0], a[1] || 0, a[2] == null ? 1 : a[2], // day of month
564 a[3] || 0, a[4] || 0, a[5] || 0);
565 }
566 function dateToUtcArray(date) {
567 return [
568 date.getUTCFullYear(),
569 date.getUTCMonth(),
570 date.getUTCDate(),
571 date.getUTCHours(),
572 date.getUTCMinutes(),
573 date.getUTCSeconds(),
574 date.getUTCMilliseconds()
575 ];
576 }
577 function arrayToUtcDate(a) {
578 // according to web standards (and Safari), a month index is required.
579 // massage if only given a year.
580 if (a.length === 1) {
581 a = a.concat([0]);
582 }
583 return new Date(Date.UTC.apply(Date, a));
584 }
585 // Other Utils
586 function isValidDate(m) {
587 return !isNaN(m.valueOf());
588 }
589 function timeAsMs(m) {
590 return m.getUTCHours() * 1000 * 60 * 60 +
591 m.getUTCMinutes() * 1000 * 60 +
592 m.getUTCSeconds() * 1000 +
593 m.getUTCMilliseconds();
594 }
595
596 var INTERNAL_UNITS = ['years', 'months', 'days', 'milliseconds'];
597 var PARSE_RE = /^(-?)(?:(\d+)\.)?(\d+):(\d\d)(?::(\d\d)(?:\.(\d\d\d))?)?/;
598 // Parsing and Creation
599 function createDuration(input, unit) {
600 var _a;
601 if (typeof input === 'string') {
602 return parseString(input);
603 }
604 else if (typeof input === 'object' && input) { // non-null object
605 return normalizeObject(input);
606 }
607 else if (typeof input === 'number') {
608 return normalizeObject((_a = {}, _a[unit || 'milliseconds'] = input, _a));
609 }
610 else {
611 return null;
612 }
613 }
614 function parseString(s) {
615 var m = PARSE_RE.exec(s);
616 if (m) {
617 var sign = m[1] ? -1 : 1;
618 return {
619 years: 0,
620 months: 0,
621 days: sign * (m[2] ? parseInt(m[2], 10) : 0),
622 milliseconds: sign * ((m[3] ? parseInt(m[3], 10) : 0) * 60 * 60 * 1000 + // hours
623 (m[4] ? parseInt(m[4], 10) : 0) * 60 * 1000 + // minutes
624 (m[5] ? parseInt(m[5], 10) : 0) * 1000 + // seconds
625 (m[6] ? parseInt(m[6], 10) : 0) // ms
626 )
627 };
628 }
629 return null;
630 }
631 function normalizeObject(obj) {
632 return {
633 years: obj.years || obj.year || 0,
634 months: obj.months || obj.month || 0,
635 days: (obj.days || obj.day || 0) +
636 getWeeksFromInput(obj) * 7,
637 milliseconds: (obj.hours || obj.hour || 0) * 60 * 60 * 1000 + // hours
638 (obj.minutes || obj.minute || 0) * 60 * 1000 + // minutes
639 (obj.seconds || obj.second || 0) * 1000 + // seconds
640 (obj.milliseconds || obj.millisecond || obj.ms || 0) // ms
641 };
642 }
643 function getWeeksFromInput(obj) {
644 return obj.weeks || obj.week || 0;
645 }
646 // Equality
647 function durationsEqual(d0, d1) {
648 return d0.years === d1.years &&
649 d0.months === d1.months &&
650 d0.days === d1.days &&
651 d0.milliseconds === d1.milliseconds;
652 }
653 function isSingleDay(dur) {
654 return dur.years === 0 && dur.months === 0 && dur.days === 1 && dur.milliseconds === 0;
655 }
656 // Simple Math
657 function addDurations(d0, d1) {
658 return {
659 years: d0.years + d1.years,
660 months: d0.months + d1.months,
661 days: d0.days + d1.days,
662 milliseconds: d0.milliseconds + d1.milliseconds
663 };
664 }
665 function subtractDurations(d1, d0) {
666 return {
667 years: d1.years - d0.years,
668 months: d1.months - d0.months,
669 days: d1.days - d0.days,
670 milliseconds: d1.milliseconds - d0.milliseconds
671 };
672 }
673 function multiplyDuration(d, n) {
674 return {
675 years: d.years * n,
676 months: d.months * n,
677 days: d.days * n,
678 milliseconds: d.milliseconds * n
679 };
680 }
681 // Conversions
682 // "Rough" because they are based on average-case Gregorian months/years
683 function asRoughYears(dur) {
684 return asRoughDays(dur) / 365;
685 }
686 function asRoughMonths(dur) {
687 return asRoughDays(dur) / 30;
688 }
689 function asRoughDays(dur) {
690 return asRoughMs(dur) / 864e5;
691 }
692 function asRoughMinutes(dur) {
693 return asRoughMs(dur) / (1000 * 60);
694 }
695 function asRoughSeconds(dur) {
696 return asRoughMs(dur) / 1000;
697 }
698 function asRoughMs(dur) {
699 return dur.years * (365 * 864e5) +
700 dur.months * (30 * 864e5) +
701 dur.days * 864e5 +
702 dur.milliseconds;
703 }
704 // Advanced Math
705 function wholeDivideDurations(numerator, denominator) {
706 var res = null;
707 for (var i = 0; i < INTERNAL_UNITS.length; i++) {
708 var unit = INTERNAL_UNITS[i];
709 if (denominator[unit]) {
710 var localRes = numerator[unit] / denominator[unit];
711 if (!isInt(localRes) || (res !== null && res !== localRes)) {
712 return null;
713 }
714 res = localRes;
715 }
716 else if (numerator[unit]) {
717 // needs to divide by something but can't!
718 return null;
719 }
720 }
721 return res;
722 }
723 function greatestDurationDenominator(dur, dontReturnWeeks) {
724 var ms = dur.milliseconds;
725 if (ms) {
726 if (ms % 1000 !== 0) {
727 return { unit: 'millisecond', value: ms };
728 }
729 if (ms % (1000 * 60) !== 0) {
730 return { unit: 'second', value: ms / 1000 };
731 }
732 if (ms % (1000 * 60 * 60) !== 0) {
733 return { unit: 'minute', value: ms / (1000 * 60) };
734 }
735 if (ms) {
736 return { unit: 'hour', value: ms / (1000 * 60 * 60) };
737 }
738 }
739 if (dur.days) {
740 if (!dontReturnWeeks && dur.days % 7 === 0) {
741 return { unit: 'week', value: dur.days / 7 };
742 }
743 return { unit: 'day', value: dur.days };
744 }
745 if (dur.months) {
746 return { unit: 'month', value: dur.months };
747 }
748 if (dur.years) {
749 return { unit: 'year', value: dur.years };
750 }
751 return { unit: 'millisecond', value: 0 };
752 }
753
754 /* FullCalendar-specific DOM Utilities
755 ----------------------------------------------------------------------------------------------------------------------*/
756 // Given the scrollbar widths of some other container, create borders/margins on rowEls in order to match the left
757 // and right space that was offset by the scrollbars. A 1-pixel border first, then margin beyond that.
758 function compensateScroll(rowEl, scrollbarWidths) {
759 if (scrollbarWidths.left) {
760 applyStyle(rowEl, {
761 borderLeftWidth: 1,
762 marginLeft: scrollbarWidths.left - 1
763 });
764 }
765 if (scrollbarWidths.right) {
766 applyStyle(rowEl, {
767 borderRightWidth: 1,
768 marginRight: scrollbarWidths.right - 1
769 });
770 }
771 }
772 // Undoes compensateScroll and restores all borders/margins
773 function uncompensateScroll(rowEl) {
774 applyStyle(rowEl, {
775 marginLeft: '',
776 marginRight: '',
777 borderLeftWidth: '',
778 borderRightWidth: ''
779 });
780 }
781 // Make the mouse cursor express that an event is not allowed in the current area
782 function disableCursor() {
783 document.body.classList.add('fc-not-allowed');
784 }
785 // Returns the mouse cursor to its original look
786 function enableCursor() {
787 document.body.classList.remove('fc-not-allowed');
788 }
789 // Given a total available height to fill, have `els` (essentially child rows) expand to accomodate.
790 // By default, all elements that are shorter than the recommended height are expanded uniformly, not considering
791 // any other els that are already too tall. if `shouldRedistribute` is on, it considers these tall rows and
792 // reduces the available height.
793 function distributeHeight(els, availableHeight, shouldRedistribute) {
794 // *FLOORING NOTE*: we floor in certain places because zoom can give inaccurate floating-point dimensions,
795 // and it is better to be shorter than taller, to avoid creating unnecessary scrollbars.
796 var minOffset1 = Math.floor(availableHeight / els.length); // for non-last element
797 var minOffset2 = Math.floor(availableHeight - minOffset1 * (els.length - 1)); // for last element *FLOORING NOTE*
798 var flexEls = []; // elements that are allowed to expand. array of DOM nodes
799 var flexOffsets = []; // amount of vertical space it takes up
800 var flexHeights = []; // actual css height
801 var usedHeight = 0;
802 undistributeHeight(els); // give all elements their natural height
803 // find elements that are below the recommended height (expandable).
804 // important to query for heights in a single first pass (to avoid reflow oscillation).
805 els.forEach(function (el, i) {
806 var minOffset = i === els.length - 1 ? minOffset2 : minOffset1;
807 var naturalHeight = el.getBoundingClientRect().height;
808 var naturalOffset = naturalHeight + computeVMargins(el);
809 if (naturalOffset < minOffset) {
810 flexEls.push(el);
811 flexOffsets.push(naturalOffset);
812 flexHeights.push(naturalHeight);
813 }
814 else {
815 // this element stretches past recommended height (non-expandable). mark the space as occupied.
816 usedHeight += naturalOffset;
817 }
818 });
819 // readjust the recommended height to only consider the height available to non-maxed-out rows.
820 if (shouldRedistribute) {
821 availableHeight -= usedHeight;
822 minOffset1 = Math.floor(availableHeight / flexEls.length);
823 minOffset2 = Math.floor(availableHeight - minOffset1 * (flexEls.length - 1)); // *FLOORING NOTE*
824 }
825 // assign heights to all expandable elements
826 flexEls.forEach(function (el, i) {
827 var minOffset = i === flexEls.length - 1 ? minOffset2 : minOffset1;
828 var naturalOffset = flexOffsets[i];
829 var naturalHeight = flexHeights[i];
830 var newHeight = minOffset - (naturalOffset - naturalHeight); // subtract the margin/padding
831 if (naturalOffset < minOffset) { // we check this again because redistribution might have changed things
832 el.style.height = newHeight + 'px';
833 }
834 });
835 }
836 // Undoes distrubuteHeight, restoring all els to their natural height
837 function undistributeHeight(els) {
838 els.forEach(function (el) {
839 el.style.height = '';
840 });
841 }
842 // Given `els`, a set of <td> cells, find the cell with the largest natural width and set the widths of all the
843 // cells to be that width.
844 // PREREQUISITE: if you want a cell to take up width, it needs to have a single inner element w/ display:inline
845 function matchCellWidths(els) {
846 var maxInnerWidth = 0;
847 els.forEach(function (el) {
848 var innerEl = el.firstChild; // hopefully an element
849 if (innerEl instanceof HTMLElement) {
850 var innerWidth_1 = innerEl.getBoundingClientRect().width;
851 if (innerWidth_1 > maxInnerWidth) {
852 maxInnerWidth = innerWidth_1;
853 }
854 }
855 });
856 maxInnerWidth++; // sometimes not accurate of width the text needs to stay on one line. insurance
857 els.forEach(function (el) {
858 el.style.width = maxInnerWidth + 'px';
859 });
860 return maxInnerWidth;
861 }
862 // Given one element that resides inside another,
863 // Subtracts the height of the inner element from the outer element.
864 function subtractInnerElHeight(outerEl, innerEl) {
865 // effin' IE8/9/10/11 sometimes returns 0 for dimensions. this weird hack was the only thing that worked
866 var reflowStyleProps = {
867 position: 'relative',
868 left: -1 // ensure reflow in case the el was already relative. negative is less likely to cause new scroll
869 };
870 applyStyle(outerEl, reflowStyleProps);
871 applyStyle(innerEl, reflowStyleProps);
872 var diff = // grab the dimensions
873 outerEl.getBoundingClientRect().height -
874 innerEl.getBoundingClientRect().height;
875 // undo hack
876 var resetStyleProps = { position: '', left: '' };
877 applyStyle(outerEl, resetStyleProps);
878 applyStyle(innerEl, resetStyleProps);
879 return diff;
880 }
881 /* Selection
882 ----------------------------------------------------------------------------------------------------------------------*/
883 function preventSelection(el) {
884 el.classList.add('fc-unselectable');
885 el.addEventListener('selectstart', preventDefault);
886 }
887 function allowSelection(el) {
888 el.classList.remove('fc-unselectable');
889 el.removeEventListener('selectstart', preventDefault);
890 }
891 /* Context Menu
892 ----------------------------------------------------------------------------------------------------------------------*/
893 function preventContextMenu(el) {
894 el.addEventListener('contextmenu', preventDefault);
895 }
896 function allowContextMenu(el) {
897 el.removeEventListener('contextmenu', preventDefault);
898 }
899 /* Object Ordering by Field
900 ----------------------------------------------------------------------------------------------------------------------*/
901 function parseFieldSpecs(input) {
902 var specs = [];
903 var tokens = [];
904 var i;
905 var token;
906 if (typeof input === 'string') {
907 tokens = input.split(/\s*,\s*/);
908 }
909 else if (typeof input === 'function') {
910 tokens = [input];
911 }
912 else if (Array.isArray(input)) {
913 tokens = input;
914 }
915 for (i = 0; i < tokens.length; i++) {
916 token = tokens[i];
917 if (typeof token === 'string') {
918 specs.push(token.charAt(0) === '-' ?
919 { field: token.substring(1), order: -1 } :
920 { field: token, order: 1 });
921 }
922 else if (typeof token === 'function') {
923 specs.push({ func: token });
924 }
925 }
926 return specs;
927 }
928 function compareByFieldSpecs(obj0, obj1, fieldSpecs) {
929 var i;
930 var cmp;
931 for (i = 0; i < fieldSpecs.length; i++) {
932 cmp = compareByFieldSpec(obj0, obj1, fieldSpecs[i]);
933 if (cmp) {
934 return cmp;
935 }
936 }
937 return 0;
938 }
939 function compareByFieldSpec(obj0, obj1, fieldSpec) {
940 if (fieldSpec.func) {
941 return fieldSpec.func(obj0, obj1);
942 }
943 return flexibleCompare(obj0[fieldSpec.field], obj1[fieldSpec.field])
944 * (fieldSpec.order || 1);
945 }
946 function flexibleCompare(a, b) {
947 if (!a && !b) {
948 return 0;
949 }
950 if (b == null) {
951 return -1;
952 }
953 if (a == null) {
954 return 1;
955 }
956 if (typeof a === 'string' || typeof b === 'string') {
957 return String(a).localeCompare(String(b));
958 }
959 return a - b;
960 }
961 /* String Utilities
962 ----------------------------------------------------------------------------------------------------------------------*/
963 function capitaliseFirstLetter(str) {
964 return str.charAt(0).toUpperCase() + str.slice(1);
965 }
966 function padStart(val, len) {
967 var s = String(val);
968 return '000'.substr(0, len - s.length) + s;
969 }
970 /* Number Utilities
971 ----------------------------------------------------------------------------------------------------------------------*/
972 function compareNumbers(a, b) {
973 return a - b;
974 }
975 function isInt(n) {
976 return n % 1 === 0;
977 }
978 /* Weird Utilities
979 ----------------------------------------------------------------------------------------------------------------------*/
980 function applyAll(functions, thisObj, args) {
981 if (typeof functions === 'function') { // supplied a single function
982 functions = [functions];
983 }
984 if (functions) {
985 var i = void 0;
986 var ret = void 0;
987 for (i = 0; i < functions.length; i++) {
988 ret = functions[i].apply(thisObj, args) || ret;
989 }
990 return ret;
991 }
992 }
993 function firstDefined() {
994 var args = [];
995 for (var _i = 0; _i < arguments.length; _i++) {
996 args[_i] = arguments[_i];
997 }
998 for (var i = 0; i < args.length; i++) {
999 if (args[i] !== undefined) {
1000 return args[i];
1001 }
1002 }
1003 }
1004 // Returns a function, that, as long as it continues to be invoked, will not
1005 // be triggered. The function will be called after it stops being called for
1006 // N milliseconds. If `immediate` is passed, trigger the function on the
1007 // leading edge, instead of the trailing.
1008 // https://github.com/jashkenas/underscore/blob/1.6.0/underscore.js#L714
1009 function debounce(func, wait) {
1010 var timeout;
1011 var args;
1012 var context;
1013 var timestamp;
1014 var result;
1015 var later = function () {
1016 var last = new Date().valueOf() - timestamp;
1017 if (last < wait) {
1018 timeout = setTimeout(later, wait - last);
1019 }
1020 else {
1021 timeout = null;
1022 result = func.apply(context, args);
1023 context = args = null;
1024 }
1025 };
1026 return function () {
1027 context = this;
1028 args = arguments;
1029 timestamp = new Date().valueOf();
1030 if (!timeout) {
1031 timeout = setTimeout(later, wait);
1032 }
1033 return result;
1034 };
1035 }
1036 // Number and Boolean are only types that defaults or not computed for
1037 // TODO: write more comments
1038 function refineProps(rawProps, processors, defaults, leftoverProps) {
1039 if (defaults === void 0) { defaults = {}; }
1040 var refined = {};
1041 for (var key in processors) {
1042 var processor = processors[key];
1043 if (rawProps[key] !== undefined) {
1044 // found
1045 if (processor === Function) {
1046 refined[key] = typeof rawProps[key] === 'function' ? rawProps[key] : null;
1047 }
1048 else if (processor) { // a refining function?
1049 refined[key] = processor(rawProps[key]);
1050 }
1051 else {
1052 refined[key] = rawProps[key];
1053 }
1054 }
1055 else if (defaults[key] !== undefined) {
1056 // there's an explicit default
1057 refined[key] = defaults[key];
1058 }
1059 else {
1060 // must compute a default
1061 if (processor === String) {
1062 refined[key] = ''; // empty string is default for String
1063 }
1064 else if (!processor || processor === Number || processor === Boolean || processor === Function) {
1065 refined[key] = null; // assign null for other non-custom processor funcs
1066 }
1067 else {
1068 refined[key] = processor(null); // run the custom processor func
1069 }
1070 }
1071 }
1072 if (leftoverProps) {
1073 for (var key in rawProps) {
1074 if (processors[key] === undefined) {
1075 leftoverProps[key] = rawProps[key];
1076 }
1077 }
1078 }
1079 return refined;
1080 }
1081 /* Date stuff that doesn't belong in datelib core
1082 ----------------------------------------------------------------------------------------------------------------------*/
1083 // given a timed range, computes an all-day range that has the same exact duration,
1084 // but whose start time is aligned with the start of the day.
1085 function computeAlignedDayRange(timedRange) {
1086 var dayCnt = Math.floor(diffDays(timedRange.start, timedRange.end)) || 1;
1087 var start = startOfDay(timedRange.start);
1088 var end = addDays(start, dayCnt);
1089 return { start: start, end: end };
1090 }
1091 // given a timed range, computes an all-day range based on how for the end date bleeds into the next day
1092 // TODO: give nextDayThreshold a default arg
1093 function computeVisibleDayRange(timedRange, nextDayThreshold) {
1094 if (nextDayThreshold === void 0) { nextDayThreshold = createDuration(0); }
1095 var startDay = null;
1096 var endDay = null;
1097 if (timedRange.end) {
1098 endDay = startOfDay(timedRange.end);
1099 var endTimeMS = timedRange.end.valueOf() - endDay.valueOf(); // # of milliseconds into `endDay`
1100 // If the end time is actually inclusively part of the next day and is equal to or
1101 // beyond the next day threshold, adjust the end to be the exclusive end of `endDay`.
1102 // Otherwise, leaving it as inclusive will cause it to exclude `endDay`.
1103 if (endTimeMS && endTimeMS >= asRoughMs(nextDayThreshold)) {
1104 endDay = addDays(endDay, 1);
1105 }
1106 }
1107 if (timedRange.start) {
1108 startDay = startOfDay(timedRange.start); // the beginning of the day the range starts
1109 // If end is within `startDay` but not past nextDayThreshold, assign the default duration of one day.
1110 if (endDay && endDay <= startDay) {
1111 endDay = addDays(startDay, 1);
1112 }
1113 }
1114 return { start: startDay, end: endDay };
1115 }
1116 // spans from one day into another?
1117 function isMultiDayRange(range) {
1118 var visibleRange = computeVisibleDayRange(range);
1119 return diffDays(visibleRange.start, visibleRange.end) > 1;
1120 }
1121 function diffDates(date0, date1, dateEnv, largeUnit) {
1122 if (largeUnit === 'year') {
1123 return createDuration(dateEnv.diffWholeYears(date0, date1), 'year');
1124 }
1125 else if (largeUnit === 'month') {
1126 return createDuration(dateEnv.diffWholeMonths(date0, date1), 'month');
1127 }
1128 else {
1129 return diffDayAndTime(date0, date1); // returns a duration
1130 }
1131 }
1132
1133 /*! *****************************************************************************
1134 Copyright (c) Microsoft Corporation. All rights reserved.
1135 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
1136 this file except in compliance with the License. You may obtain a copy of the
1137 License at http://www.apache.org/licenses/LICENSE-2.0
1138
1139 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1140 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
1141 WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
1142 MERCHANTABLITY OR NON-INFRINGEMENT.
1143
1144 See the Apache Version 2.0 License for specific language governing permissions
1145 and limitations under the License.
1146 ***************************************************************************** */
1147 /* global Reflect, Promise */
1148
1149 var extendStatics = function(d, b) {
1150 extendStatics = Object.setPrototypeOf ||
1151 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
1152 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
1153 return extendStatics(d, b);
1154 };
1155
1156 function __extends(d, b) {
1157 extendStatics(d, b);
1158 function __() { this.constructor = d; }
1159 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1160 }
1161
1162 var __assign = function() {
1163 __assign = Object.assign || function __assign(t) {
1164 for (var s, i = 1, n = arguments.length; i < n; i++) {
1165 s = arguments[i];
1166 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
1167 }
1168 return t;
1169 };
1170 return __assign.apply(this, arguments);
1171 };
1172
1173 function parseRecurring(eventInput, allDayDefault, dateEnv, recurringTypes, leftovers) {
1174 for (var i = 0; i < recurringTypes.length; i++) {
1175 var localLeftovers = {};
1176 var parsed = recurringTypes[i].parse(eventInput, localLeftovers, dateEnv);
1177 if (parsed) {
1178 var allDay = localLeftovers.allDay;
1179 delete localLeftovers.allDay; // remove from leftovers
1180 if (allDay == null) {
1181 allDay = allDayDefault;
1182 if (allDay == null) {
1183 allDay = parsed.allDayGuess;
1184 if (allDay == null) {
1185 allDay = false;
1186 }
1187 }
1188 }
1189 __assign(leftovers, localLeftovers);
1190 return {
1191 allDay: allDay,
1192 duration: parsed.duration,
1193 typeData: parsed.typeData,
1194 typeId: i
1195 };
1196 }
1197 }
1198 return null;
1199 }
1200 /*
1201 Event MUST have a recurringDef
1202 */
1203 function expandRecurringRanges(eventDef, duration, framingRange, dateEnv, recurringTypes) {
1204 var typeDef = recurringTypes[eventDef.recurringDef.typeId];
1205 var markers = typeDef.expand(eventDef.recurringDef.typeData, {
1206 start: dateEnv.subtract(framingRange.start, duration),
1207 end: framingRange.end
1208 }, dateEnv);
1209 // the recurrence plugins don't guarantee that all-day events are start-of-day, so we have to
1210 if (eventDef.allDay) {
1211 markers = markers.map(startOfDay);
1212 }
1213 return markers;
1214 }
1215
1216 var hasOwnProperty = Object.prototype.hasOwnProperty;
1217 // Merges an array of objects into a single object.
1218 // The second argument allows for an array of property names who's object values will be merged together.
1219 function mergeProps(propObjs, complexProps) {
1220 var dest = {};
1221 var i;
1222 var name;
1223 var complexObjs;
1224 var j;
1225 var val;
1226 var props;
1227 if (complexProps) {
1228 for (i = 0; i < complexProps.length; i++) {
1229 name = complexProps[i];
1230 complexObjs = [];
1231 // collect the trailing object values, stopping when a non-object is discovered
1232 for (j = propObjs.length - 1; j >= 0; j--) {
1233 val = propObjs[j][name];
1234 if (typeof val === 'object' && val) { // non-null object
1235 complexObjs.unshift(val);
1236 }
1237 else if (val !== undefined) {
1238 dest[name] = val; // if there were no objects, this value will be used
1239 break;
1240 }
1241 }
1242 // if the trailing values were objects, use the merged value
1243 if (complexObjs.length) {
1244 dest[name] = mergeProps(complexObjs);
1245 }
1246 }
1247 }
1248 // copy values into the destination, going from last to first
1249 for (i = propObjs.length - 1; i >= 0; i--) {
1250 props = propObjs[i];
1251 for (name in props) {
1252 if (!(name in dest)) { // if already assigned by previous props or complex props, don't reassign
1253 dest[name] = props[name];
1254 }
1255 }
1256 }
1257 return dest;
1258 }
1259 function filterHash(hash, func) {
1260 var filtered = {};
1261 for (var key in hash) {
1262 if (func(hash[key], key)) {
1263 filtered[key] = hash[key];
1264 }
1265 }
1266 return filtered;
1267 }
1268 function mapHash(hash, func) {
1269 var newHash = {};
1270 for (var key in hash) {
1271 newHash[key] = func(hash[key], key);
1272 }
1273 return newHash;
1274 }
1275 function arrayToHash(a) {
1276 var hash = {};
1277 for (var _i = 0, a_1 = a; _i < a_1.length; _i++) {
1278 var item = a_1[_i];
1279 hash[item] = true;
1280 }
1281 return hash;
1282 }
1283 function hashValuesToArray(obj) {
1284 var a = [];
1285 for (var key in obj) {
1286 a.push(obj[key]);
1287 }
1288 return a;
1289 }
1290 function isPropsEqual(obj0, obj1) {
1291 for (var key in obj0) {
1292 if (hasOwnProperty.call(obj0, key)) {
1293 if (!(key in obj1)) {
1294 return false;
1295 }
1296 }
1297 }
1298 for (var key in obj1) {
1299 if (hasOwnProperty.call(obj1, key)) {
1300 if (obj0[key] !== obj1[key]) {
1301 return false;
1302 }
1303 }
1304 }
1305 return true;
1306 }
1307
1308 function parseEvents(rawEvents, sourceId, calendar, allowOpenRange) {
1309 var eventStore = createEmptyEventStore();
1310 for (var _i = 0, rawEvents_1 = rawEvents; _i < rawEvents_1.length; _i++) {
1311 var rawEvent = rawEvents_1[_i];
1312 var tuple = parseEvent(rawEvent, sourceId, calendar, allowOpenRange);
1313 if (tuple) {
1314 eventTupleToStore(tuple, eventStore);
1315 }
1316 }
1317 return eventStore;
1318 }
1319 function eventTupleToStore(tuple, eventStore) {
1320 if (eventStore === void 0) { eventStore = createEmptyEventStore(); }
1321 eventStore.defs[tuple.def.defId] = tuple.def;
1322 if (tuple.instance) {
1323 eventStore.instances[tuple.instance.instanceId] = tuple.instance;
1324 }
1325 return eventStore;
1326 }
1327 function expandRecurring(eventStore, framingRange, calendar) {
1328 var dateEnv = calendar.dateEnv;
1329 var defs = eventStore.defs, instances = eventStore.instances;
1330 // remove existing recurring instances
1331 instances = filterHash(instances, function (instance) {
1332 return !defs[instance.defId].recurringDef;
1333 });
1334 for (var defId in defs) {
1335 var def = defs[defId];
1336 if (def.recurringDef) {
1337 var duration = def.recurringDef.duration;
1338 if (!duration) {
1339 duration = def.allDay ?
1340 calendar.defaultAllDayEventDuration :
1341 calendar.defaultTimedEventDuration;
1342 }
1343 var starts = expandRecurringRanges(def, duration, framingRange, calendar.dateEnv, calendar.pluginSystem.hooks.recurringTypes);
1344 for (var _i = 0, starts_1 = starts; _i < starts_1.length; _i++) {
1345 var start = starts_1[_i];
1346 var instance = createEventInstance(defId, {
1347 start: start,
1348 end: dateEnv.add(start, duration)
1349 });
1350 instances[instance.instanceId] = instance;
1351 }
1352 }
1353 }
1354 return { defs: defs, instances: instances };
1355 }
1356 // retrieves events that have the same groupId as the instance specified by `instanceId`
1357 // or they are the same as the instance.
1358 // why might instanceId not be in the store? an event from another calendar?
1359 function getRelevantEvents(eventStore, instanceId) {
1360 var instance = eventStore.instances[instanceId];
1361 if (instance) {
1362 var def_1 = eventStore.defs[instance.defId];
1363 // get events/instances with same group
1364 var newStore = filterEventStoreDefs(eventStore, function (lookDef) {
1365 return isEventDefsGrouped(def_1, lookDef);
1366 });
1367 // add the original
1368 // TODO: wish we could use eventTupleToStore or something like it
1369 newStore.defs[def_1.defId] = def_1;
1370 newStore.instances[instance.instanceId] = instance;
1371 return newStore;
1372 }
1373 return createEmptyEventStore();
1374 }
1375 function isEventDefsGrouped(def0, def1) {
1376 return Boolean(def0.groupId && def0.groupId === def1.groupId);
1377 }
1378 function transformRawEvents(rawEvents, eventSource, calendar) {
1379 var calEachTransform = calendar.opt('eventDataTransform');
1380 var sourceEachTransform = eventSource ? eventSource.eventDataTransform : null;
1381 if (sourceEachTransform) {
1382 rawEvents = transformEachRawEvent(rawEvents, sourceEachTransform);
1383 }
1384 if (calEachTransform) {
1385 rawEvents = transformEachRawEvent(rawEvents, calEachTransform);
1386 }
1387 return rawEvents;
1388 }
1389 function transformEachRawEvent(rawEvents, func) {
1390 var refinedEvents;
1391 if (!func) {
1392 refinedEvents = rawEvents;
1393 }
1394 else {
1395 refinedEvents = [];
1396 for (var _i = 0, rawEvents_2 = rawEvents; _i < rawEvents_2.length; _i++) {
1397 var rawEvent = rawEvents_2[_i];
1398 var refinedEvent = func(rawEvent);
1399 if (refinedEvent) {
1400 refinedEvents.push(refinedEvent);
1401 }
1402 else if (refinedEvent == null) {
1403 refinedEvents.push(rawEvent);
1404 } // if a different falsy value, do nothing
1405 }
1406 }
1407 return refinedEvents;
1408 }
1409 function createEmptyEventStore() {
1410 return { defs: {}, instances: {} };
1411 }
1412 function mergeEventStores(store0, store1) {
1413 return {
1414 defs: __assign({}, store0.defs, store1.defs),
1415 instances: __assign({}, store0.instances, store1.instances)
1416 };
1417 }
1418 function filterEventStoreDefs(eventStore, filterFunc) {
1419 var defs = filterHash(eventStore.defs, filterFunc);
1420 var instances = filterHash(eventStore.instances, function (instance) {
1421 return defs[instance.defId]; // still exists?
1422 });
1423 return { defs: defs, instances: instances };
1424 }
1425
1426 function parseRange(input, dateEnv) {
1427 var start = null;
1428 var end = null;
1429 if (input.start) {
1430 start = dateEnv.createMarker(input.start);
1431 }
1432 if (input.end) {
1433 end = dateEnv.createMarker(input.end);
1434 }
1435 if (!start && !end) {
1436 return null;
1437 }
1438 if (start && end && end < start) {
1439 return null;
1440 }
1441 return { start: start, end: end };
1442 }
1443 // SIDE-EFFECT: will mutate ranges.
1444 // Will return a new array result.
1445 function invertRanges(ranges, constraintRange) {
1446 var invertedRanges = [];
1447 var start = constraintRange.start; // the end of the previous range. the start of the new range
1448 var i;
1449 var dateRange;
1450 // ranges need to be in order. required for our date-walking algorithm
1451 ranges.sort(compareRanges);
1452 for (i = 0; i < ranges.length; i++) {
1453 dateRange = ranges[i];
1454 // add the span of time before the event (if there is any)
1455 if (dateRange.start > start) { // compare millisecond time (skip any ambig logic)
1456 invertedRanges.push({ start: start, end: dateRange.start });
1457 }
1458 if (dateRange.end > start) {
1459 start = dateRange.end;
1460 }
1461 }
1462 // add the span of time after the last event (if there is any)
1463 if (start < constraintRange.end) { // compare millisecond time (skip any ambig logic)
1464 invertedRanges.push({ start: start, end: constraintRange.end });
1465 }
1466 return invertedRanges;
1467 }
1468 function compareRanges(range0, range1) {
1469 return range0.start.valueOf() - range1.start.valueOf(); // earlier ranges go first
1470 }
1471 function intersectRanges(range0, range1) {
1472 var start = range0.start;
1473 var end = range0.end;
1474 var newRange = null;
1475 if (range1.start !== null) {
1476 if (start === null) {
1477 start = range1.start;
1478 }
1479 else {
1480 start = new Date(Math.max(start.valueOf(), range1.start.valueOf()));
1481 }
1482 }
1483 if (range1.end != null) {
1484 if (end === null) {
1485 end = range1.end;
1486 }
1487 else {
1488 end = new Date(Math.min(end.valueOf(), range1.end.valueOf()));
1489 }
1490 }
1491 if (start === null || end === null || start < end) {
1492 newRange = { start: start, end: end };
1493 }
1494 return newRange;
1495 }
1496 function rangesEqual(range0, range1) {
1497 return (range0.start === null ? null : range0.start.valueOf()) === (range1.start === null ? null : range1.start.valueOf()) &&
1498 (range0.end === null ? null : range0.end.valueOf()) === (range1.end === null ? null : range1.end.valueOf());
1499 }
1500 function rangesIntersect(range0, range1) {
1501 return (range0.end === null || range1.start === null || range0.end > range1.start) &&
1502 (range0.start === null || range1.end === null || range0.start < range1.end);
1503 }
1504 function rangeContainsRange(outerRange, innerRange) {
1505 return (outerRange.start === null || (innerRange.start !== null && innerRange.start >= outerRange.start)) &&
1506 (outerRange.end === null || (innerRange.end !== null && innerRange.end <= outerRange.end));
1507 }
1508 function rangeContainsMarker(range, date) {
1509 return (range.start === null || date >= range.start) &&
1510 (range.end === null || date < range.end);
1511 }
1512 // If the given date is not within the given range, move it inside.
1513 // (If it's past the end, make it one millisecond before the end).
1514 function constrainMarkerToRange(date, range) {
1515 if (range.start != null && date < range.start) {
1516 return range.start;
1517 }
1518 if (range.end != null && date >= range.end) {
1519 return new Date(range.end.valueOf() - 1);
1520 }
1521 return date;
1522 }
1523
1524 function removeExact(array, exactVal) {
1525 var removeCnt = 0;
1526 var i = 0;
1527 while (i < array.length) {
1528 if (array[i] === exactVal) {
1529 array.splice(i, 1);
1530 removeCnt++;
1531 }
1532 else {
1533 i++;
1534 }
1535 }
1536 return removeCnt;
1537 }
1538 function isArraysEqual(a0, a1) {
1539 var len = a0.length;
1540 var i;
1541 if (len !== a1.length) { // not array? or not same length?
1542 return false;
1543 }
1544 for (i = 0; i < len; i++) {
1545 if (a0[i] !== a1[i]) {
1546 return false;
1547 }
1548 }
1549 return true;
1550 }
1551
1552 function memoize(workerFunc) {
1553 var args;
1554 var res;
1555 return function () {
1556 if (!args || !isArraysEqual(args, arguments)) {
1557 args = arguments;
1558 res = workerFunc.apply(this, arguments);
1559 }
1560 return res;
1561 };
1562 }
1563 /*
1564 always executes the workerFunc, but if the result is equal to the previous result,
1565 return the previous result instead.
1566 */
1567 function memoizeOutput(workerFunc, equalityFunc) {
1568 var cachedRes = null;
1569 return function () {
1570 var newRes = workerFunc.apply(this, arguments);
1571 if (cachedRes === null || !(cachedRes === newRes || equalityFunc(cachedRes, newRes))) {
1572 cachedRes = newRes;
1573 }
1574 return cachedRes;
1575 };
1576 }
1577
1578 var EXTENDED_SETTINGS_AND_SEVERITIES = {
1579 week: 3,
1580 separator: 0,
1581 omitZeroMinute: 0,
1582 meridiem: 0,
1583 omitCommas: 0
1584 };
1585 var STANDARD_DATE_PROP_SEVERITIES = {
1586 timeZoneName: 7,
1587 era: 6,
1588 year: 5,
1589 month: 4,
1590 day: 2,
1591 weekday: 2,
1592 hour: 1,
1593 minute: 1,
1594 second: 1
1595 };
1596 var MERIDIEM_RE = /\s*([ap])\.?m\.?/i; // eats up leading spaces too
1597 var COMMA_RE = /,/g; // we need re for globalness
1598 var MULTI_SPACE_RE = /\s+/g;
1599 var LTR_RE = /\u200e/g; // control character
1600 var UTC_RE = /UTC|GMT/;
1601 var NativeFormatter = /** @class */ (function () {
1602 function NativeFormatter(formatSettings) {
1603 var standardDateProps = {};
1604 var extendedSettings = {};
1605 var severity = 0;
1606 for (var name_1 in formatSettings) {
1607 if (name_1 in EXTENDED_SETTINGS_AND_SEVERITIES) {
1608 extendedSettings[name_1] = formatSettings[name_1];
1609 severity = Math.max(EXTENDED_SETTINGS_AND_SEVERITIES[name_1], severity);
1610 }
1611 else {
1612 standardDateProps[name_1] = formatSettings[name_1];
1613 if (name_1 in STANDARD_DATE_PROP_SEVERITIES) {
1614 severity = Math.max(STANDARD_DATE_PROP_SEVERITIES[name_1], severity);
1615 }
1616 }
1617 }
1618 this.standardDateProps = standardDateProps;
1619 this.extendedSettings = extendedSettings;
1620 this.severity = severity;
1621 this.buildFormattingFunc = memoize(buildFormattingFunc);
1622 }
1623 NativeFormatter.prototype.format = function (date, context) {
1624 return this.buildFormattingFunc(this.standardDateProps, this.extendedSettings, context)(date);
1625 };
1626 NativeFormatter.prototype.formatRange = function (start, end, context) {
1627 var _a = this, standardDateProps = _a.standardDateProps, extendedSettings = _a.extendedSettings;
1628 var diffSeverity = computeMarkerDiffSeverity(start.marker, end.marker, context.calendarSystem);
1629 if (!diffSeverity) {
1630 return this.format(start, context);
1631 }
1632 var biggestUnitForPartial = diffSeverity;
1633 if (biggestUnitForPartial > 1 && // the two dates are different in a way that's larger scale than time
1634 (standardDateProps.year === 'numeric' || standardDateProps.year === '2-digit') &&
1635 (standardDateProps.month === 'numeric' || standardDateProps.month === '2-digit') &&
1636 (standardDateProps.day === 'numeric' || standardDateProps.day === '2-digit')) {
1637 biggestUnitForPartial = 1; // make it look like the dates are only different in terms of time
1638 }
1639 var full0 = this.format(start, context);
1640 var full1 = this.format(end, context);
1641 if (full0 === full1) {
1642 return full0;
1643 }
1644 var partialDateProps = computePartialFormattingOptions(standardDateProps, biggestUnitForPartial);
1645 var partialFormattingFunc = buildFormattingFunc(partialDateProps, extendedSettings, context);
1646 var partial0 = partialFormattingFunc(start);
1647 var partial1 = partialFormattingFunc(end);
1648 var insertion = findCommonInsertion(full0, partial0, full1, partial1);
1649 var separator = extendedSettings.separator || '';
1650 if (insertion) {
1651 return insertion.before + partial0 + separator + partial1 + insertion.after;
1652 }
1653 return full0 + separator + full1;
1654 };
1655 NativeFormatter.prototype.getLargestUnit = function () {
1656 switch (this.severity) {
1657 case 7:
1658 case 6:
1659 case 5:
1660 return 'year';
1661 case 4:
1662 return 'month';
1663 case 3:
1664 return 'week';
1665 default:
1666 return 'day';
1667 }
1668 };
1669 return NativeFormatter;
1670 }());
1671 function buildFormattingFunc(standardDateProps, extendedSettings, context) {
1672 var standardDatePropCnt = Object.keys(standardDateProps).length;
1673 if (standardDatePropCnt === 1 && standardDateProps.timeZoneName === 'short') {
1674 return function (date) {
1675 return formatTimeZoneOffset(date.timeZoneOffset);
1676 };
1677 }
1678 if (standardDatePropCnt === 0 && extendedSettings.week) {
1679 return function (date) {
1680 return formatWeekNumber(context.computeWeekNumber(date.marker), context.weekLabel, context.locale, extendedSettings.week);
1681 };
1682 }
1683 return buildNativeFormattingFunc(standardDateProps, extendedSettings, context);
1684 }
1685 function buildNativeFormattingFunc(standardDateProps, extendedSettings, context) {
1686 standardDateProps = __assign({}, standardDateProps); // copy
1687 extendedSettings = __assign({}, extendedSettings); // copy
1688 sanitizeSettings(standardDateProps, extendedSettings);
1689 standardDateProps.timeZone = 'UTC'; // we leverage the only guaranteed timeZone for our UTC markers
1690 var normalFormat = new Intl.DateTimeFormat(context.locale.codes, standardDateProps);
1691 var zeroFormat; // needed?
1692 if (extendedSettings.omitZeroMinute) {
1693 var zeroProps = __assign({}, standardDateProps);
1694 delete zeroProps.minute; // seconds and ms were already considered in sanitizeSettings
1695 zeroFormat = new Intl.DateTimeFormat(context.locale.codes, zeroProps);
1696 }
1697 return function (date) {
1698 var marker = date.marker;
1699 var format;
1700 if (zeroFormat && !marker.getUTCMinutes()) {
1701 format = zeroFormat;
1702 }
1703 else {
1704 format = normalFormat;
1705 }
1706 var s = format.format(marker);
1707 return postProcess(s, date, standardDateProps, extendedSettings, context);
1708 };
1709 }
1710 function sanitizeSettings(standardDateProps, extendedSettings) {
1711 // deal with a browser inconsistency where formatting the timezone
1712 // requires that the hour/minute be present.
1713 if (standardDateProps.timeZoneName) {
1714 if (!standardDateProps.hour) {
1715 standardDateProps.hour = '2-digit';
1716 }
1717 if (!standardDateProps.minute) {
1718 standardDateProps.minute = '2-digit';
1719 }
1720 }
1721 // only support short timezone names
1722 if (standardDateProps.timeZoneName === 'long') {
1723 standardDateProps.timeZoneName = 'short';
1724 }
1725 // if requesting to display seconds, MUST display minutes
1726 if (extendedSettings.omitZeroMinute && (standardDateProps.second || standardDateProps.millisecond)) {
1727 delete extendedSettings.omitZeroMinute;
1728 }
1729 }
1730 function postProcess(s, date, standardDateProps, extendedSettings, context) {
1731 s = s.replace(LTR_RE, ''); // remove left-to-right control chars. do first. good for other regexes
1732 if (standardDateProps.timeZoneName === 'short') {
1733 s = injectTzoStr(s, (context.timeZone === 'UTC' || date.timeZoneOffset == null) ?
1734 'UTC' : // important to normalize for IE, which does "GMT"
1735 formatTimeZoneOffset(date.timeZoneOffset));
1736 }
1737 if (extendedSettings.omitCommas) {
1738 s = s.replace(COMMA_RE, '').trim();
1739 }
1740 if (extendedSettings.omitZeroMinute) {
1741 s = s.replace(':00', ''); // zeroFormat doesn't always achieve this
1742 }
1743 // ^ do anything that might create adjacent spaces before this point,
1744 // because MERIDIEM_RE likes to eat up loading spaces
1745 if (extendedSettings.meridiem === false) {
1746 s = s.replace(MERIDIEM_RE, '').trim();
1747 }
1748 else if (extendedSettings.meridiem === 'narrow') { // a/p
1749 s = s.replace(MERIDIEM_RE, function (m0, m1) {
1750 return m1.toLocaleLowerCase();
1751 });
1752 }
1753 else if (extendedSettings.meridiem === 'short') { // am/pm
1754 s = s.replace(MERIDIEM_RE, function (m0, m1) {
1755 return m1.toLocaleLowerCase() + 'm';
1756 });
1757 }
1758 else if (extendedSettings.meridiem === 'lowercase') { // other meridiem transformers already converted to lowercase
1759 s = s.replace(MERIDIEM_RE, function (m0) {
1760 return m0.toLocaleLowerCase();
1761 });
1762 }
1763 s = s.replace(MULTI_SPACE_RE, ' ');
1764 s = s.trim();
1765 return s;
1766 }
1767 function injectTzoStr(s, tzoStr) {
1768 var replaced = false;
1769 s = s.replace(UTC_RE, function () {
1770 replaced = true;
1771 return tzoStr;
1772 });
1773 // IE11 doesn't include UTC/GMT in the original string, so append to end
1774 if (!replaced) {
1775 s += ' ' + tzoStr;
1776 }
1777 return s;
1778 }
1779 function formatWeekNumber(num, weekLabel, locale, display) {
1780 var parts = [];
1781 if (display === 'narrow') {
1782 parts.push(weekLabel);
1783 }
1784 else if (display === 'short') {
1785 parts.push(weekLabel, ' ');
1786 }
1787 // otherwise, considered 'numeric'
1788 parts.push(locale.simpleNumberFormat.format(num));
1789 if (locale.options.isRtl) { // TODO: use control characters instead?
1790 parts.reverse();
1791 }
1792 return parts.join('');
1793 }
1794 // Range Formatting Utils
1795 // 0 = exactly the same
1796 // 1 = different by time
1797 // and bigger
1798 function computeMarkerDiffSeverity(d0, d1, ca) {
1799 if (ca.getMarkerYear(d0) !== ca.getMarkerYear(d1)) {
1800 return 5;
1801 }
1802 if (ca.getMarkerMonth(d0) !== ca.getMarkerMonth(d1)) {
1803 return 4;
1804 }
1805 if (ca.getMarkerDay(d0) !== ca.getMarkerDay(d1)) {
1806 return 2;
1807 }
1808 if (timeAsMs(d0) !== timeAsMs(d1)) {
1809 return 1;
1810 }
1811 return 0;
1812 }
1813 function computePartialFormattingOptions(options, biggestUnit) {
1814 var partialOptions = {};
1815 for (var name_2 in options) {
1816 if (!(name_2 in STANDARD_DATE_PROP_SEVERITIES) || // not a date part prop (like timeZone)
1817 STANDARD_DATE_PROP_SEVERITIES[name_2] <= biggestUnit) {
1818 partialOptions[name_2] = options[name_2];
1819 }
1820 }
1821 return partialOptions;
1822 }
1823 function findCommonInsertion(full0, partial0, full1, partial1) {
1824 var i0 = 0;
1825 while (i0 < full0.length) {
1826 var found0 = full0.indexOf(partial0, i0);
1827 if (found0 === -1) {
1828 break;
1829 }
1830 var before0 = full0.substr(0, found0);
1831 i0 = found0 + partial0.length;
1832 var after0 = full0.substr(i0);
1833 var i1 = 0;
1834 while (i1 < full1.length) {
1835 var found1 = full1.indexOf(partial1, i1);
1836 if (found1 === -1) {
1837 break;
1838 }
1839 var before1 = full1.substr(0, found1);
1840 i1 = found1 + partial1.length;
1841 var after1 = full1.substr(i1);
1842 if (before0 === before1 && after0 === after1) {
1843 return {
1844 before: before0,
1845 after: after0
1846 };
1847 }
1848 }
1849 }
1850 return null;
1851 }
1852
1853 /*
1854 TODO: fix the terminology of "formatter" vs "formatting func"
1855 */
1856 /*
1857 At the time of instantiation, this object does not know which cmd-formatting system it will use.
1858 It receives this at the time of formatting, as a setting.
1859 */
1860 var CmdFormatter = /** @class */ (function () {
1861 function CmdFormatter(cmdStr, separator) {
1862 this.cmdStr = cmdStr;
1863 this.separator = separator;
1864 }
1865 CmdFormatter.prototype.format = function (date, context) {
1866 return context.cmdFormatter(this.cmdStr, createVerboseFormattingArg(date, null, context, this.separator));
1867 };
1868 CmdFormatter.prototype.formatRange = function (start, end, context) {
1869 return context.cmdFormatter(this.cmdStr, createVerboseFormattingArg(start, end, context, this.separator));
1870 };
1871 return CmdFormatter;
1872 }());
1873
1874 var FuncFormatter = /** @class */ (function () {
1875 function FuncFormatter(func) {
1876 this.func = func;
1877 }
1878 FuncFormatter.prototype.format = function (date, context) {
1879 return this.func(createVerboseFormattingArg(date, null, context));
1880 };
1881 FuncFormatter.prototype.formatRange = function (start, end, context) {
1882 return this.func(createVerboseFormattingArg(start, end, context));
1883 };
1884 return FuncFormatter;
1885 }());
1886
1887 // Formatter Object Creation
1888 function createFormatter(input, defaultSeparator) {
1889 if (typeof input === 'object' && input) { // non-null object
1890 if (typeof defaultSeparator === 'string') {
1891 input = __assign({ separator: defaultSeparator }, input);
1892 }
1893 return new NativeFormatter(input);
1894 }
1895 else if (typeof input === 'string') {
1896 return new CmdFormatter(input, defaultSeparator);
1897 }
1898 else if (typeof input === 'function') {
1899 return new FuncFormatter(input);
1900 }
1901 }
1902 // String Utils
1903 // timeZoneOffset is in minutes
1904 function buildIsoString(marker, timeZoneOffset, stripZeroTime) {
1905 if (stripZeroTime === void 0) { stripZeroTime = false; }
1906 var s = marker.toISOString();
1907 s = s.replace('.000', '');
1908 if (stripZeroTime) {
1909 s = s.replace('T00:00:00Z', '');
1910 }
1911 if (s.length > 10) { // time part wasn't stripped, can add timezone info
1912 if (timeZoneOffset == null) {
1913 s = s.replace('Z', '');
1914 }
1915 else if (timeZoneOffset !== 0) {
1916 s = s.replace('Z', formatTimeZoneOffset(timeZoneOffset, true));
1917 }
1918 // otherwise, its UTC-0 and we want to keep the Z
1919 }
1920 return s;
1921 }
1922 function formatIsoTimeString(marker) {
1923 return padStart(marker.getUTCHours(), 2) + ':' +
1924 padStart(marker.getUTCMinutes(), 2) + ':' +
1925 padStart(marker.getUTCSeconds(), 2);
1926 }
1927 function formatTimeZoneOffset(minutes, doIso) {
1928 if (doIso === void 0) { doIso = false; }
1929 var sign = minutes < 0 ? '-' : '+';
1930 var abs = Math.abs(minutes);
1931 var hours = Math.floor(abs / 60);
1932 var mins = Math.round(abs % 60);
1933 if (doIso) {
1934 return sign + padStart(hours, 2) + ':' + padStart(mins, 2);
1935 }
1936 else {
1937 return 'GMT' + sign + hours + (mins ? ':' + padStart(mins, 2) : '');
1938 }
1939 }
1940 // Arg Utils
1941 function createVerboseFormattingArg(start, end, context, separator) {
1942 var startInfo = expandZonedMarker(start, context.calendarSystem);
1943 var endInfo = end ? expandZonedMarker(end, context.calendarSystem) : null;
1944 return {
1945 date: startInfo,
1946 start: startInfo,
1947 end: endInfo,
1948 timeZone: context.timeZone,
1949 localeCodes: context.locale.codes,
1950 separator: separator
1951 };
1952 }
1953 function expandZonedMarker(dateInfo, calendarSystem) {
1954 var a = calendarSystem.markerToArray(dateInfo.marker);
1955 return {
1956 marker: dateInfo.marker,
1957 timeZoneOffset: dateInfo.timeZoneOffset,
1958 array: a,
1959 year: a[0],
1960 month: a[1],
1961 day: a[2],
1962 hour: a[3],
1963 minute: a[4],
1964 second: a[5],
1965 millisecond: a[6]
1966 };
1967 }
1968
1969 var EventSourceApi = /** @class */ (function () {
1970 function EventSourceApi(calendar, internalEventSource) {
1971 this.calendar = calendar;
1972 this.internalEventSource = internalEventSource;
1973 }
1974 EventSourceApi.prototype.remove = function () {
1975 this.calendar.dispatch({
1976 type: 'REMOVE_EVENT_SOURCE',
1977 sourceId: this.internalEventSource.sourceId
1978 });
1979 };
1980 EventSourceApi.prototype.refetch = function () {
1981 this.calendar.dispatch({
1982 type: 'FETCH_EVENT_SOURCES',
1983 sourceIds: [this.internalEventSource.sourceId]
1984 });
1985 };
1986 Object.defineProperty(EventSourceApi.prototype, "id", {
1987 get: function () {
1988 return this.internalEventSource.publicId;
1989 },
1990 enumerable: true,
1991 configurable: true
1992 });
1993 Object.defineProperty(EventSourceApi.prototype, "url", {
1994 // only relevant to json-feed event sources
1995 get: function () {
1996 return this.internalEventSource.meta.url;
1997 },
1998 enumerable: true,
1999 configurable: true
2000 });
2001 return EventSourceApi;
2002 }());
2003
2004 var EventApi = /** @class */ (function () {
2005 function EventApi(calendar, def, instance) {
2006 this._calendar = calendar;
2007 this._def = def;
2008 this._instance = instance || null;
2009 }
2010 /*
2011 TODO: make event struct more responsible for this
2012 */
2013 EventApi.prototype.setProp = function (name, val) {
2014 var _a, _b;
2015 if (name in DATE_PROPS) ;
2016 else if (name in NON_DATE_PROPS) {
2017 if (typeof NON_DATE_PROPS[name] === 'function') {
2018 val = NON_DATE_PROPS[name](val);
2019 }
2020 this.mutate({
2021 standardProps: (_a = {}, _a[name] = val, _a)
2022 });
2023 }
2024 else if (name in UNSCOPED_EVENT_UI_PROPS) {
2025 var ui = void 0;
2026 if (typeof UNSCOPED_EVENT_UI_PROPS[name] === 'function') {
2027 val = UNSCOPED_EVENT_UI_PROPS[name](val);
2028 }
2029 if (name === 'color') {
2030 ui = { backgroundColor: val, borderColor: val };
2031 }
2032 else if (name === 'editable') {
2033 ui = { startEditable: val, durationEditable: val };
2034 }
2035 else {
2036 ui = (_b = {}, _b[name] = val, _b);
2037 }
2038 this.mutate({
2039 standardProps: { ui: ui }
2040 });
2041 }
2042 };
2043 EventApi.prototype.setExtendedProp = function (name, val) {
2044 var _a;
2045 this.mutate({
2046 extendedProps: (_a = {}, _a[name] = val, _a)
2047 });
2048 };
2049 EventApi.prototype.setStart = function (startInput, options) {
2050 if (options === void 0) { options = {}; }
2051 var dateEnv = this._calendar.dateEnv;
2052 var start = dateEnv.createMarker(startInput);
2053 if (start && this._instance) { // TODO: warning if parsed bad
2054 var instanceRange = this._instance.range;
2055 var startDelta = diffDates(instanceRange.start, start, dateEnv, options.granularity); // what if parsed bad!?
2056 if (options.maintainDuration) {
2057 this.mutate({ datesDelta: startDelta });
2058 }
2059 else {
2060 this.mutate({ startDelta: startDelta });
2061 }
2062 }
2063 };
2064 EventApi.prototype.setEnd = function (endInput, options) {
2065 if (options === void 0) { options = {}; }
2066 var dateEnv = this._calendar.dateEnv;
2067 var end;
2068 if (endInput != null) {
2069 end = dateEnv.createMarker(endInput);
2070 if (!end) {
2071 return; // TODO: warning if parsed bad
2072 }
2073 }
2074 if (this._instance) {
2075 if (end) {
2076 var endDelta = diffDates(this._instance.range.end, end, dateEnv, options.granularity);
2077 this.mutate({ endDelta: endDelta });
2078 }
2079 else {
2080 this.mutate({ standardProps: { hasEnd: false } });
2081 }
2082 }
2083 };
2084 EventApi.prototype.setDates = function (startInput, endInput, options) {
2085 if (options === void 0) { options = {}; }
2086 var dateEnv = this._calendar.dateEnv;
2087 var standardProps = { allDay: options.allDay };
2088 var start = dateEnv.createMarker(startInput);
2089 var end;
2090 if (!start) {
2091 return; // TODO: warning if parsed bad
2092 }
2093 if (endInput != null) {
2094 end = dateEnv.createMarker(endInput);
2095 if (!end) { // TODO: warning if parsed bad
2096 return;
2097 }
2098 }
2099 if (this._instance) {
2100 var instanceRange = this._instance.range;
2101 // when computing the diff for an event being converted to all-day,
2102 // compute diff off of the all-day values the way event-mutation does.
2103 if (options.allDay === true) {
2104 instanceRange = computeAlignedDayRange(instanceRange);
2105 }
2106 var startDelta = diffDates(instanceRange.start, start, dateEnv, options.granularity);
2107 if (end) {
2108 var endDelta = diffDates(instanceRange.end, end, dateEnv, options.granularity);
2109 if (durationsEqual(startDelta, endDelta)) {
2110 this.mutate({ datesDelta: startDelta, standardProps: standardProps });
2111 }
2112 else {
2113 this.mutate({ startDelta: startDelta, endDelta: endDelta, standardProps: standardProps });
2114 }
2115 }
2116 else { // means "clear the end"
2117 standardProps.hasEnd = false;
2118 this.mutate({ datesDelta: startDelta, standardProps: standardProps });
2119 }
2120 }
2121 };
2122 EventApi.prototype.moveStart = function (deltaInput) {
2123 var delta = createDuration(deltaInput);
2124 if (delta) { // TODO: warning if parsed bad
2125 this.mutate({ startDelta: delta });
2126 }
2127 };
2128 EventApi.prototype.moveEnd = function (deltaInput) {
2129 var delta = createDuration(deltaInput);
2130 if (delta) { // TODO: warning if parsed bad
2131 this.mutate({ endDelta: delta });
2132 }
2133 };
2134 EventApi.prototype.moveDates = function (deltaInput) {
2135 var delta = createDuration(deltaInput);
2136 if (delta) { // TODO: warning if parsed bad
2137 this.mutate({ datesDelta: delta });
2138 }
2139 };
2140 EventApi.prototype.setAllDay = function (allDay, options) {
2141 if (options === void 0) { options = {}; }
2142 var standardProps = { allDay: allDay };
2143 var maintainDuration = options.maintainDuration;
2144 if (maintainDuration == null) {
2145 maintainDuration = this._calendar.opt('allDayMaintainDuration');
2146 }
2147 if (this._def.allDay !== allDay) {
2148 standardProps.hasEnd = maintainDuration;
2149 }
2150 this.mutate({ standardProps: standardProps });
2151 };
2152 EventApi.prototype.formatRange = function (formatInput) {
2153 var dateEnv = this._calendar.dateEnv;
2154 var instance = this._instance;
2155 var formatter = createFormatter(formatInput, this._calendar.opt('defaultRangeSeparator'));
2156 if (this._def.hasEnd) {
2157 return dateEnv.formatRange(instance.range.start, instance.range.end, formatter, {
2158 forcedStartTzo: instance.forcedStartTzo,
2159 forcedEndTzo: instance.forcedEndTzo
2160 });
2161 }
2162 else {
2163 return dateEnv.format(instance.range.start, formatter, {
2164 forcedTzo: instance.forcedStartTzo
2165 });
2166 }
2167 };
2168 EventApi.prototype.mutate = function (mutation) {
2169 var def = this._def;
2170 var instance = this._instance;
2171 if (instance) {
2172 this._calendar.dispatch({
2173 type: 'MUTATE_EVENTS',
2174 instanceId: instance.instanceId,
2175 mutation: mutation,
2176 fromApi: true
2177 });
2178 var eventStore = this._calendar.state.eventStore;
2179 this._def = eventStore.defs[def.defId];
2180 this._instance = eventStore.instances[instance.instanceId];
2181 }
2182 };
2183 EventApi.prototype.remove = function () {
2184 this._calendar.dispatch({
2185 type: 'REMOVE_EVENT_DEF',
2186 defId: this._def.defId
2187 });
2188 };
2189 Object.defineProperty(EventApi.prototype, "source", {
2190 get: function () {
2191 var sourceId = this._def.sourceId;
2192 if (sourceId) {
2193 return new EventSourceApi(this._calendar, this._calendar.state.eventSources[sourceId]);
2194 }
2195 return null;
2196 },
2197 enumerable: true,
2198 configurable: true
2199 });
2200 Object.defineProperty(EventApi.prototype, "start", {
2201 get: function () {
2202 return this._instance ?
2203 this._calendar.dateEnv.toDate(this._instance.range.start) :
2204 null;
2205 },
2206 enumerable: true,
2207 configurable: true
2208 });
2209 Object.defineProperty(EventApi.prototype, "end", {
2210 get: function () {
2211 return (this._instance && this._def.hasEnd) ?
2212 this._calendar.dateEnv.toDate(this._instance.range.end) :
2213 null;
2214 },
2215 enumerable: true,
2216 configurable: true
2217 });
2218 Object.defineProperty(EventApi.prototype, "id", {
2219 // computable props that all access the def
2220 // TODO: find a TypeScript-compatible way to do this at scale
2221 get: function () { return this._def.publicId; },
2222 enumerable: true,
2223 configurable: true
2224 });
2225 Object.defineProperty(EventApi.prototype, "groupId", {
2226 get: function () { return this._def.groupId; },
2227 enumerable: true,
2228 configurable: true
2229 });
2230 Object.defineProperty(EventApi.prototype, "allDay", {
2231 get: function () { return this._def.allDay; },
2232 enumerable: true,
2233 configurable: true
2234 });
2235 Object.defineProperty(EventApi.prototype, "title", {
2236 get: function () { return this._def.title; },
2237 enumerable: true,
2238 configurable: true
2239 });
2240 Object.defineProperty(EventApi.prototype, "url", {
2241 get: function () { return this._def.url; },
2242 enumerable: true,
2243 configurable: true
2244 });
2245 Object.defineProperty(EventApi.prototype, "rendering", {
2246 get: function () { return this._def.rendering; },
2247 enumerable: true,
2248 configurable: true
2249 });
2250 Object.defineProperty(EventApi.prototype, "startEditable", {
2251 get: function () { return this._def.ui.startEditable; },
2252 enumerable: true,
2253 configurable: true
2254 });
2255 Object.defineProperty(EventApi.prototype, "durationEditable", {
2256 get: function () { return this._def.ui.durationEditable; },
2257 enumerable: true,
2258 configurable: true
2259 });
2260 Object.defineProperty(EventApi.prototype, "constraint", {
2261 get: function () { return this._def.ui.constraints[0] || null; },
2262 enumerable: true,
2263 configurable: true
2264 });
2265 Object.defineProperty(EventApi.prototype, "overlap", {
2266 get: function () { return this._def.ui.overlap; },
2267 enumerable: true,
2268 configurable: true
2269 });
2270 Object.defineProperty(EventApi.prototype, "allow", {
2271 get: function () { return this._def.ui.allows[0] || null; },
2272 enumerable: true,
2273 configurable: true
2274 });
2275 Object.defineProperty(EventApi.prototype, "backgroundColor", {
2276 get: function () { return this._def.ui.backgroundColor; },
2277 enumerable: true,
2278 configurable: true
2279 });
2280 Object.defineProperty(EventApi.prototype, "borderColor", {
2281 get: function () { return this._def.ui.borderColor; },
2282 enumerable: true,
2283 configurable: true
2284 });
2285 Object.defineProperty(EventApi.prototype, "textColor", {
2286 get: function () { return this._def.ui.textColor; },
2287 enumerable: true,
2288 configurable: true
2289 });
2290 Object.defineProperty(EventApi.prototype, "classNames", {
2291 // NOTE: user can't modify these because Object.freeze was called in event-def parsing
2292 get: function () { return this._def.ui.classNames; },
2293 enumerable: true,
2294 configurable: true
2295 });
2296 Object.defineProperty(EventApi.prototype, "extendedProps", {
2297 get: function () { return this._def.extendedProps; },
2298 enumerable: true,
2299 configurable: true
2300 });
2301 return EventApi;
2302 }());
2303
2304 /*
2305 Specifying nextDayThreshold signals that all-day ranges should be sliced.
2306 */
2307 function sliceEventStore(eventStore, eventUiBases, framingRange, nextDayThreshold) {
2308 var inverseBgByGroupId = {};
2309 var inverseBgByDefId = {};
2310 var defByGroupId = {};
2311 var bgRanges = [];
2312 var fgRanges = [];
2313 var eventUis = compileEventUis(eventStore.defs, eventUiBases);
2314 for (var defId in eventStore.defs) {
2315 var def = eventStore.defs[defId];
2316 if (def.rendering === 'inverse-background') {
2317 if (def.groupId) {
2318 inverseBgByGroupId[def.groupId] = [];
2319 if (!defByGroupId[def.groupId]) {
2320 defByGroupId[def.groupId] = def;
2321 }
2322 }
2323 else {
2324 inverseBgByDefId[defId] = [];
2325 }
2326 }
2327 }
2328 for (var instanceId in eventStore.instances) {
2329 var instance = eventStore.instances[instanceId];
2330 var def = eventStore.defs[instance.defId];
2331 var ui = eventUis[def.defId];
2332 var origRange = instance.range;
2333 var normalRange = (!def.allDay && nextDayThreshold) ?
2334 computeVisibleDayRange(origRange, nextDayThreshold) :
2335 origRange;
2336 var slicedRange = intersectRanges(normalRange, framingRange);
2337 if (slicedRange) {
2338 if (def.rendering === 'inverse-background') {
2339 if (def.groupId) {
2340 inverseBgByGroupId[def.groupId].push(slicedRange);
2341 }
2342 else {
2343 inverseBgByDefId[instance.defId].push(slicedRange);
2344 }
2345 }
2346 else {
2347 (def.rendering === 'background' ? bgRanges : fgRanges).push({
2348 def: def,
2349 ui: ui,
2350 instance: instance,
2351 range: slicedRange,
2352 isStart: normalRange.start && normalRange.start.valueOf() === slicedRange.start.valueOf(),
2353 isEnd: normalRange.end && normalRange.end.valueOf() === slicedRange.end.valueOf()
2354 });
2355 }
2356 }
2357 }
2358 for (var groupId in inverseBgByGroupId) { // BY GROUP
2359 var ranges = inverseBgByGroupId[groupId];
2360 var invertedRanges = invertRanges(ranges, framingRange);
2361 for (var _i = 0, invertedRanges_1 = invertedRanges; _i < invertedRanges_1.length; _i++) {
2362 var invertedRange = invertedRanges_1[_i];
2363 var def = defByGroupId[groupId];
2364 var ui = eventUis[def.defId];
2365 bgRanges.push({
2366 def: def,
2367 ui: ui,
2368 instance: null,
2369 range: invertedRange,
2370 isStart: false,
2371 isEnd: false
2372 });
2373 }
2374 }
2375 for (var defId in inverseBgByDefId) {
2376 var ranges = inverseBgByDefId[defId];
2377 var invertedRanges = invertRanges(ranges, framingRange);
2378 for (var _a = 0, invertedRanges_2 = invertedRanges; _a < invertedRanges_2.length; _a++) {
2379 var invertedRange = invertedRanges_2[_a];
2380 bgRanges.push({
2381 def: eventStore.defs[defId],
2382 ui: eventUis[defId],
2383 instance: null,
2384 range: invertedRange,
2385 isStart: false,
2386 isEnd: false
2387 });
2388 }
2389 }
2390 return { bg: bgRanges, fg: fgRanges };
2391 }
2392 function hasBgRendering(def) {
2393 return def.rendering === 'background' || def.rendering === 'inverse-background';
2394 }
2395 function filterSegsViaEls(view, segs, isMirror) {
2396 if (view.hasPublicHandlers('eventRender')) {
2397 segs = segs.filter(function (seg) {
2398 var custom = view.publiclyTrigger('eventRender', [
2399 {
2400 event: new EventApi(view.calendar, seg.eventRange.def, seg.eventRange.instance),
2401 isMirror: isMirror,
2402 isStart: seg.isStart,
2403 isEnd: seg.isEnd,
2404 // TODO: include seg.range once all components consistently generate it
2405 el: seg.el,
2406 view: view
2407 }
2408 ]);
2409 if (custom === false) { // means don't render at all
2410 return false;
2411 }
2412 else if (custom && custom !== true) {
2413 seg.el = custom;
2414 }
2415 return true;
2416 });
2417 }
2418 for (var _i = 0, segs_1 = segs; _i < segs_1.length; _i++) {
2419 var seg = segs_1[_i];
2420 setElSeg(seg.el, seg);
2421 }
2422 return segs;
2423 }
2424 function setElSeg(el, seg) {
2425 el.fcSeg = seg;
2426 }
2427 function getElSeg(el) {
2428 return el.fcSeg || null;
2429 }
2430 // event ui computation
2431 function compileEventUis(eventDefs, eventUiBases) {
2432 return mapHash(eventDefs, function (eventDef) {
2433 return compileEventUi(eventDef, eventUiBases);
2434 });
2435 }
2436 function compileEventUi(eventDef, eventUiBases) {
2437 var uis = [];
2438 if (eventUiBases['']) {
2439 uis.push(eventUiBases['']);
2440 }
2441 if (eventUiBases[eventDef.defId]) {
2442 uis.push(eventUiBases[eventDef.defId]);
2443 }
2444 uis.push(eventDef.ui);
2445 return combineEventUis(uis);
2446 }
2447
2448 // applies the mutation to ALL defs/instances within the event store
2449 function applyMutationToEventStore(eventStore, eventConfigBase, mutation, calendar) {
2450 var eventConfigs = compileEventUis(eventStore.defs, eventConfigBase);
2451 var dest = createEmptyEventStore();
2452 for (var defId in eventStore.defs) {
2453 var def = eventStore.defs[defId];
2454 dest.defs[defId] = applyMutationToEventDef(def, eventConfigs[defId], mutation, calendar.pluginSystem.hooks.eventDefMutationAppliers, calendar);
2455 }
2456 for (var instanceId in eventStore.instances) {
2457 var instance = eventStore.instances[instanceId];
2458 var def = dest.defs[instance.defId]; // important to grab the newly modified def
2459 dest.instances[instanceId] = applyMutationToEventInstance(instance, def, eventConfigs[instance.defId], mutation, calendar);
2460 }
2461 return dest;
2462 }
2463 function applyMutationToEventDef(eventDef, eventConfig, mutation, appliers, calendar) {
2464 var standardProps = mutation.standardProps || {};
2465 // if hasEnd has not been specified, guess a good value based on deltas.
2466 // if duration will change, there's no way the default duration will persist,
2467 // and thus, we need to mark the event as having a real end
2468 if (standardProps.hasEnd == null &&
2469 eventConfig.durationEditable &&
2470 (mutation.startDelta || mutation.endDelta)) {
2471 standardProps.hasEnd = true; // TODO: is this mutation okay?
2472 }
2473 var copy = __assign({}, eventDef, standardProps, { ui: __assign({}, eventDef.ui, standardProps.ui) });
2474 if (mutation.extendedProps) {
2475 copy.extendedProps = __assign({}, copy.extendedProps, mutation.extendedProps);
2476 }
2477 for (var _i = 0, appliers_1 = appliers; _i < appliers_1.length; _i++) {
2478 var applier = appliers_1[_i];
2479 applier(copy, mutation, calendar);
2480 }
2481 if (!copy.hasEnd && calendar.opt('forceEventDuration')) {
2482 copy.hasEnd = true;
2483 }
2484 return copy;
2485 }
2486 function applyMutationToEventInstance(eventInstance, eventDef, // must first be modified by applyMutationToEventDef
2487 eventConfig, mutation, calendar) {
2488 var dateEnv = calendar.dateEnv;
2489 var forceAllDay = mutation.standardProps && mutation.standardProps.allDay === true;
2490 var clearEnd = mutation.standardProps && mutation.standardProps.hasEnd === false;
2491 var copy = __assign({}, eventInstance);
2492 if (forceAllDay) {
2493 copy.range = computeAlignedDayRange(copy.range);
2494 }
2495 if (mutation.datesDelta && eventConfig.startEditable) {
2496 copy.range = {
2497 start: dateEnv.add(copy.range.start, mutation.datesDelta),
2498 end: dateEnv.add(copy.range.end, mutation.datesDelta)
2499 };
2500 }
2501 if (mutation.startDelta && eventConfig.durationEditable) {
2502 copy.range = {
2503 start: dateEnv.add(copy.range.start, mutation.startDelta),
2504 end: copy.range.end
2505 };
2506 }
2507 if (mutation.endDelta && eventConfig.durationEditable) {
2508 copy.range = {
2509 start: copy.range.start,
2510 end: dateEnv.add(copy.range.end, mutation.endDelta)
2511 };
2512 }
2513 if (clearEnd) {
2514 copy.range = {
2515 start: copy.range.start,
2516 end: calendar.getDefaultEventEnd(eventDef.allDay, copy.range.start)
2517 };
2518 }
2519 // in case event was all-day but the supplied deltas were not
2520 // better util for this?
2521 if (eventDef.allDay) {
2522 copy.range = {
2523 start: startOfDay(copy.range.start),
2524 end: startOfDay(copy.range.end)
2525 };
2526 }
2527 // handle invalid durations
2528 if (copy.range.end < copy.range.start) {
2529 copy.range.end = calendar.getDefaultEventEnd(eventDef.allDay, copy.range.start);
2530 }
2531 return copy;
2532 }
2533
2534 function reduceEventStore (eventStore, action, eventSources, dateProfile, calendar) {
2535 switch (action.type) {
2536 case 'RECEIVE_EVENTS': // raw
2537 return receiveRawEvents(eventStore, eventSources[action.sourceId], action.fetchId, action.fetchRange, action.rawEvents, calendar);
2538 case 'ADD_EVENTS': // already parsed, but not expanded
2539 return addEvent(eventStore, action.eventStore, // new ones
2540 dateProfile ? dateProfile.activeRange : null, calendar);
2541 case 'MERGE_EVENTS': // already parsed and expanded
2542 return mergeEventStores(eventStore, action.eventStore);
2543 case 'PREV': // TODO: how do we track all actions that affect dateProfile :(
2544 case 'NEXT':
2545 case 'SET_DATE':
2546 case 'SET_VIEW_TYPE':
2547 if (dateProfile) {
2548 return expandRecurring(eventStore, dateProfile.activeRange, calendar);
2549 }
2550 else {
2551 return eventStore;
2552 }
2553 case 'CHANGE_TIMEZONE':
2554 return rezoneDates(eventStore, action.oldDateEnv, calendar.dateEnv);
2555 case 'MUTATE_EVENTS':
2556 return applyMutationToRelated(eventStore, action.instanceId, action.mutation, action.fromApi, calendar);
2557 case 'REMOVE_EVENT_INSTANCES':
2558 return excludeInstances(eventStore, action.instances);
2559 case 'REMOVE_EVENT_DEF':
2560 return filterEventStoreDefs(eventStore, function (eventDef) {
2561 return eventDef.defId !== action.defId;
2562 });
2563 case 'REMOVE_EVENT_SOURCE':
2564 return excludeEventsBySourceId(eventStore, action.sourceId);
2565 case 'REMOVE_ALL_EVENT_SOURCES':
2566 return filterEventStoreDefs(eventStore, function (eventDef) {
2567 return !eventDef.sourceId; // only keep events with no source id
2568 });
2569 case 'REMOVE_ALL_EVENTS':
2570 return createEmptyEventStore();
2571 case 'RESET_EVENTS':
2572 return {
2573 defs: eventStore.defs,
2574 instances: eventStore.instances
2575 };
2576 default:
2577 return eventStore;
2578 }
2579 }
2580 function receiveRawEvents(eventStore, eventSource, fetchId, fetchRange, rawEvents, calendar) {
2581 if (eventSource && // not already removed
2582 fetchId === eventSource.latestFetchId // TODO: wish this logic was always in event-sources
2583 ) {
2584 var subset = parseEvents(transformRawEvents(rawEvents, eventSource, calendar), eventSource.sourceId, calendar);
2585 if (fetchRange) {
2586 subset = expandRecurring(subset, fetchRange, calendar);
2587 }
2588 return mergeEventStores(excludeEventsBySourceId(eventStore, eventSource.sourceId), subset);
2589 }
2590 return eventStore;
2591 }
2592 function addEvent(eventStore, subset, expandRange, calendar) {
2593 if (expandRange) {
2594 subset = expandRecurring(subset, expandRange, calendar);
2595 }
2596 return mergeEventStores(eventStore, subset);
2597 }
2598 function rezoneDates(eventStore, oldDateEnv, newDateEnv) {
2599 var defs = eventStore.defs;
2600 var instances = mapHash(eventStore.instances, function (instance) {
2601 var def = defs[instance.defId];
2602 if (def.allDay || def.recurringDef) {
2603 return instance; // isn't dependent on timezone
2604 }
2605 else {
2606 return __assign({}, instance, { range: {
2607 start: newDateEnv.createMarker(oldDateEnv.toDate(instance.range.start, instance.forcedStartTzo)),
2608 end: newDateEnv.createMarker(oldDateEnv.toDate(instance.range.end, instance.forcedEndTzo))
2609 }, forcedStartTzo: newDateEnv.canComputeOffset ? null : instance.forcedStartTzo, forcedEndTzo: newDateEnv.canComputeOffset ? null : instance.forcedEndTzo });
2610 }
2611 });
2612 return { defs: defs, instances: instances };
2613 }
2614 function applyMutationToRelated(eventStore, instanceId, mutation, fromApi, calendar) {
2615 var relevant = getRelevantEvents(eventStore, instanceId);
2616 var eventConfigBase = fromApi ?
2617 { '': {
2618 startEditable: true,
2619 durationEditable: true,
2620 constraints: [],
2621 overlap: null,
2622 allows: [],
2623 backgroundColor: '',
2624 borderColor: '',
2625 textColor: '',
2626 classNames: []
2627 } } :
2628 calendar.eventUiBases;
2629 relevant = applyMutationToEventStore(relevant, eventConfigBase, mutation, calendar);
2630 return mergeEventStores(eventStore, relevant);
2631 }
2632 function excludeEventsBySourceId(eventStore, sourceId) {
2633 return filterEventStoreDefs(eventStore, function (eventDef) {
2634 return eventDef.sourceId !== sourceId;
2635 });
2636 }
2637 // QUESTION: why not just return instances? do a general object-property-exclusion util
2638 function excludeInstances(eventStore, removals) {
2639 return {
2640 defs: eventStore.defs,
2641 instances: filterHash(eventStore.instances, function (instance) {
2642 return !removals[instance.instanceId];
2643 })
2644 };
2645 }
2646
2647 // high-level segmenting-aware tester functions
2648 // ------------------------------------------------------------------------------------------------------------------------
2649 function isInteractionValid(interaction, calendar) {
2650 return isNewPropsValid({ eventDrag: interaction }, calendar); // HACK: the eventDrag props is used for ALL interactions
2651 }
2652 function isDateSelectionValid(dateSelection, calendar) {
2653 return isNewPropsValid({ dateSelection: dateSelection }, calendar);
2654 }
2655 function isNewPropsValid(newProps, calendar) {
2656 var view = calendar.view;
2657 var props = __assign({ businessHours: view ? view.props.businessHours : createEmptyEventStore(), dateSelection: '', eventStore: calendar.state.eventStore, eventUiBases: calendar.eventUiBases, eventSelection: '', eventDrag: null, eventResize: null }, newProps);
2658 return (calendar.pluginSystem.hooks.isPropsValid || isPropsValid)(props, calendar);
2659 }
2660 function isPropsValid(state, calendar, dateSpanMeta, filterConfig) {
2661 if (dateSpanMeta === void 0) { dateSpanMeta = {}; }
2662 if (state.eventDrag && !isInteractionPropsValid(state, calendar, dateSpanMeta, filterConfig)) {
2663 return false;
2664 }
2665 if (state.dateSelection && !isDateSelectionPropsValid(state, calendar, dateSpanMeta, filterConfig)) {
2666 return false;
2667 }
2668 return true;
2669 }
2670 // Moving Event Validation
2671 // ------------------------------------------------------------------------------------------------------------------------
2672 function isInteractionPropsValid(state, calendar, dateSpanMeta, filterConfig) {
2673 var interaction = state.eventDrag; // HACK: the eventDrag props is used for ALL interactions
2674 var subjectEventStore = interaction.mutatedEvents;
2675 var subjectDefs = subjectEventStore.defs;
2676 var subjectInstances = subjectEventStore.instances;
2677 var subjectConfigs = compileEventUis(subjectDefs, interaction.isEvent ?
2678 state.eventUiBases :
2679 { '': calendar.selectionConfig } // if not a real event, validate as a selection
2680 );
2681 if (filterConfig) {
2682 subjectConfigs = mapHash(subjectConfigs, filterConfig);
2683 }
2684 var otherEventStore = excludeInstances(state.eventStore, interaction.affectedEvents.instances); // exclude the subject events. TODO: exclude defs too?
2685 var otherDefs = otherEventStore.defs;
2686 var otherInstances = otherEventStore.instances;
2687 var otherConfigs = compileEventUis(otherDefs, state.eventUiBases);
2688 for (var subjectInstanceId in subjectInstances) {
2689 var subjectInstance = subjectInstances[subjectInstanceId];
2690 var subjectRange = subjectInstance.range;
2691 var subjectConfig = subjectConfigs[subjectInstance.defId];
2692 var subjectDef = subjectDefs[subjectInstance.defId];
2693 // constraint
2694 if (!allConstraintsPass(subjectConfig.constraints, subjectRange, otherEventStore, state.businessHours, calendar)) {
2695 return false;
2696 }
2697 // overlap
2698 var overlapFunc = calendar.opt('eventOverlap');
2699 if (typeof overlapFunc !== 'function') {
2700 overlapFunc = null;
2701 }
2702 for (var otherInstanceId in otherInstances) {
2703 var otherInstance = otherInstances[otherInstanceId];
2704 // intersect! evaluate
2705 if (rangesIntersect(subjectRange, otherInstance.range)) {
2706 var otherOverlap = otherConfigs[otherInstance.defId].overlap;
2707 // consider the other event's overlap. only do this if the subject event is a "real" event
2708 if (otherOverlap === false && interaction.isEvent) {
2709 return false;
2710 }
2711 if (subjectConfig.overlap === false) {
2712 return false;
2713 }
2714 if (overlapFunc && !overlapFunc(new EventApi(calendar, otherDefs[otherInstance.defId], otherInstance), // still event
2715 new EventApi(calendar, subjectDef, subjectInstance) // moving event
2716 )) {
2717 return false;
2718 }
2719 }
2720 }
2721 // allow (a function)
2722 var calendarEventStore = calendar.state.eventStore; // need global-to-calendar, not local to component (splittable)state
2723 for (var _i = 0, _a = subjectConfig.allows; _i < _a.length; _i++) {
2724 var subjectAllow = _a[_i];
2725 var subjectDateSpan = __assign({}, dateSpanMeta, { range: subjectInstance.range, allDay: subjectDef.allDay });
2726 var origDef = calendarEventStore.defs[subjectDef.defId];
2727 var origInstance = calendarEventStore.instances[subjectInstanceId];
2728 var eventApi = void 0;
2729 if (origDef) { // was previously in the calendar
2730 eventApi = new EventApi(calendar, origDef, origInstance);
2731 }
2732 else { // was an external event
2733 eventApi = new EventApi(calendar, subjectDef); // no instance, because had no dates
2734 }
2735 if (!subjectAllow(calendar.buildDateSpanApi(subjectDateSpan), eventApi)) {
2736 return false;
2737 }
2738 }
2739 }
2740 return true;
2741 }
2742 // Date Selection Validation
2743 // ------------------------------------------------------------------------------------------------------------------------
2744 function isDateSelectionPropsValid(state, calendar, dateSpanMeta, filterConfig) {
2745 var relevantEventStore = state.eventStore;
2746 var relevantDefs = relevantEventStore.defs;
2747 var relevantInstances = relevantEventStore.instances;
2748 var selection = state.dateSelection;
2749 var selectionRange = selection.range;
2750 var selectionConfig = calendar.selectionConfig;
2751 if (filterConfig) {
2752 selectionConfig = filterConfig(selectionConfig);
2753 }
2754 // constraint
2755 if (!allConstraintsPass(selectionConfig.constraints, selectionRange, relevantEventStore, state.businessHours, calendar)) {
2756 return false;
2757 }
2758 // overlap
2759 var overlapFunc = calendar.opt('selectOverlap');
2760 if (typeof overlapFunc !== 'function') {
2761 overlapFunc = null;
2762 }
2763 for (var relevantInstanceId in relevantInstances) {
2764 var relevantInstance = relevantInstances[relevantInstanceId];
2765 // intersect! evaluate
2766 if (rangesIntersect(selectionRange, relevantInstance.range)) {
2767 if (selectionConfig.overlap === false) {
2768 return false;
2769 }
2770 if (overlapFunc && !overlapFunc(new EventApi(calendar, relevantDefs[relevantInstance.defId], relevantInstance))) {
2771 return false;
2772 }
2773 }
2774 }
2775 // allow (a function)
2776 for (var _i = 0, _a = selectionConfig.allows; _i < _a.length; _i++) {
2777 var selectionAllow = _a[_i];
2778 var fullDateSpan = __assign({}, dateSpanMeta, selection);
2779 if (!selectionAllow(calendar.buildDateSpanApi(fullDateSpan), null)) {
2780 return false;
2781 }
2782 }
2783 return true;
2784 }
2785 // Constraint Utils
2786 // ------------------------------------------------------------------------------------------------------------------------
2787 function allConstraintsPass(constraints, subjectRange, otherEventStore, businessHoursUnexpanded, calendar) {
2788 for (var _i = 0, constraints_1 = constraints; _i < constraints_1.length; _i++) {
2789 var constraint = constraints_1[_i];
2790 if (!anyRangesContainRange(constraintToRanges(constraint, subjectRange, otherEventStore, businessHoursUnexpanded, calendar), subjectRange)) {
2791 return false;
2792 }
2793 }
2794 return true;
2795 }
2796 function constraintToRanges(constraint, subjectRange, // for expanding a recurring constraint, or expanding business hours
2797 otherEventStore, // for if constraint is an even group ID
2798 businessHoursUnexpanded, // for if constraint is 'businessHours'
2799 calendar // for expanding businesshours
2800 ) {
2801 if (constraint === 'businessHours') {
2802 return eventStoreToRanges(expandRecurring(businessHoursUnexpanded, subjectRange, calendar));
2803 }
2804 else if (typeof constraint === 'string') { // an group ID
2805 return eventStoreToRanges(filterEventStoreDefs(otherEventStore, function (eventDef) {
2806 return eventDef.groupId === constraint;
2807 }));
2808 }
2809 else if (typeof constraint === 'object' && constraint) { // non-null object
2810 return eventStoreToRanges(expandRecurring(constraint, subjectRange, calendar));
2811 }
2812 return []; // if it's false
2813 }
2814 // TODO: move to event-store file?
2815 function eventStoreToRanges(eventStore) {
2816 var instances = eventStore.instances;
2817 var ranges = [];
2818 for (var instanceId in instances) {
2819 ranges.push(instances[instanceId].range);
2820 }
2821 return ranges;
2822 }
2823 // TODO: move to geom file?
2824 function anyRangesContainRange(outerRanges, innerRange) {
2825 for (var _i = 0, outerRanges_1 = outerRanges; _i < outerRanges_1.length; _i++) {
2826 var outerRange = outerRanges_1[_i];
2827 if (rangeContainsRange(outerRange, innerRange)) {
2828 return true;
2829 }
2830 }
2831 return false;
2832 }
2833 // Parsing
2834 // ------------------------------------------------------------------------------------------------------------------------
2835 function normalizeConstraint(input, calendar) {
2836 if (Array.isArray(input)) {
2837 return parseEvents(input, '', calendar, true); // allowOpenRange=true
2838 }
2839 else if (typeof input === 'object' && input) { // non-null object
2840 return parseEvents([input], '', calendar, true); // allowOpenRange=true
2841 }
2842 else if (input != null) {
2843 return String(input);
2844 }
2845 else {
2846 return null;
2847 }
2848 }
2849
2850 function htmlEscape(s) {
2851 return (s + '').replace(/&/g, '&')
2852 .replace(/</g, '<')
2853 .replace(/>/g, '>')
2854 .replace(/'/g, ''')
2855 .replace(/"/g, '"')
2856 .replace(/\n/g, '<br />');
2857 }
2858 // Given a hash of CSS properties, returns a string of CSS.
2859 // Uses property names as-is (no camel-case conversion). Will not make statements for null/undefined values.
2860 function cssToStr(cssProps) {
2861 var statements = [];
2862 for (var name_1 in cssProps) {
2863 var val = cssProps[name_1];
2864 if (val != null && val !== '') {
2865 statements.push(name_1 + ':' + val);
2866 }
2867 }
2868 return statements.join(';');
2869 }
2870 // Given an object hash of HTML attribute names to values,
2871 // generates a string that can be injected between < > in HTML
2872 function attrsToStr(attrs) {
2873 var parts = [];
2874 for (var name_2 in attrs) {
2875 var val = attrs[name_2];
2876 if (val != null) {
2877 parts.push(name_2 + '="' + htmlEscape(val) + '"');
2878 }
2879 }
2880 return parts.join(' ');
2881 }
2882 function parseClassName(raw) {
2883 if (Array.isArray(raw)) {
2884 return raw;
2885 }
2886 else if (typeof raw === 'string') {
2887 return raw.split(/\s+/);
2888 }
2889 else {
2890 return [];
2891 }
2892 }
2893
2894 var UNSCOPED_EVENT_UI_PROPS = {
2895 editable: Boolean,
2896 startEditable: Boolean,
2897 durationEditable: Boolean,
2898 constraint: null,
2899 overlap: null,
2900 allow: null,
2901 className: parseClassName,
2902 classNames: parseClassName,
2903 color: String,
2904 backgroundColor: String,
2905 borderColor: String,
2906 textColor: String
2907 };
2908 function processUnscopedUiProps(rawProps, calendar, leftovers) {
2909 var props = refineProps(rawProps, UNSCOPED_EVENT_UI_PROPS, {}, leftovers);
2910 var constraint = normalizeConstraint(props.constraint, calendar);
2911 return {
2912 startEditable: props.startEditable != null ? props.startEditable : props.editable,
2913 durationEditable: props.durationEditable != null ? props.durationEditable : props.editable,
2914 constraints: constraint != null ? [constraint] : [],
2915 overlap: props.overlap,
2916 allows: props.allow != null ? [props.allow] : [],
2917 backgroundColor: props.backgroundColor || props.color,
2918 borderColor: props.borderColor || props.color,
2919 textColor: props.textColor,
2920 classNames: props.classNames.concat(props.className)
2921 };
2922 }
2923 function processScopedUiProps(prefix, rawScoped, calendar, leftovers) {
2924 var rawUnscoped = {};
2925 var wasFound = {};
2926 for (var key in UNSCOPED_EVENT_UI_PROPS) {
2927 var scopedKey = prefix + capitaliseFirstLetter(key);
2928 rawUnscoped[key] = rawScoped[scopedKey];
2929 wasFound[scopedKey] = true;
2930 }
2931 if (prefix === 'event') {
2932 rawUnscoped.editable = rawScoped.editable; // special case. there is no 'eventEditable', just 'editable'
2933 }
2934 if (leftovers) {
2935 for (var key in rawScoped) {
2936 if (!wasFound[key]) {
2937 leftovers[key] = rawScoped[key];
2938 }
2939 }
2940 }
2941 return processUnscopedUiProps(rawUnscoped, calendar);
2942 }
2943 var EMPTY_EVENT_UI = {
2944 startEditable: null,
2945 durationEditable: null,
2946 constraints: [],
2947 overlap: null,
2948 allows: [],
2949 backgroundColor: '',
2950 borderColor: '',
2951 textColor: '',
2952 classNames: []
2953 };
2954 // prevent against problems with <2 args!
2955 function combineEventUis(uis) {
2956 return uis.reduce(combineTwoEventUis, EMPTY_EVENT_UI);
2957 }
2958 function combineTwoEventUis(item0, item1) {
2959 return {
2960 startEditable: item1.startEditable != null ? item1.startEditable : item0.startEditable,
2961 durationEditable: item1.durationEditable != null ? item1.durationEditable : item0.durationEditable,
2962 constraints: item0.constraints.concat(item1.constraints),
2963 overlap: typeof item1.overlap === 'boolean' ? item1.overlap : item0.overlap,
2964 allows: item0.allows.concat(item1.allows),
2965 backgroundColor: item1.backgroundColor || item0.backgroundColor,
2966 borderColor: item1.borderColor || item0.borderColor,
2967 textColor: item1.textColor || item0.textColor,
2968 classNames: item0.classNames.concat(item1.classNames)
2969 };
2970 }
2971
2972 var NON_DATE_PROPS = {
2973 id: String,
2974 groupId: String,
2975 title: String,
2976 url: String,
2977 rendering: String,
2978 extendedProps: null
2979 };
2980 var DATE_PROPS = {
2981 start: null,
2982 date: null,
2983 end: null,
2984 allDay: null
2985 };
2986 var uid = 0;
2987 function parseEvent(raw, sourceId, calendar, allowOpenRange) {
2988 var allDayDefault = computeIsAllDayDefault(sourceId, calendar);
2989 var leftovers0 = {};
2990 var recurringRes = parseRecurring(raw, // raw, but with single-event stuff stripped out
2991 allDayDefault, calendar.dateEnv, calendar.pluginSystem.hooks.recurringTypes, leftovers0 // will populate with non-recurring props
2992 );
2993 if (recurringRes) {
2994 var def = parseEventDef(leftovers0, sourceId, recurringRes.allDay, Boolean(recurringRes.duration), calendar);
2995 def.recurringDef = {
2996 typeId: recurringRes.typeId,
2997 typeData: recurringRes.typeData,
2998 duration: recurringRes.duration
2999 };
3000 return { def: def, instance: null };
3001 }
3002 else {
3003 var leftovers1 = {};
3004 var singleRes = parseSingle(raw, allDayDefault, calendar, leftovers1, allowOpenRange);
3005 if (singleRes) {
3006 var def = parseEventDef(leftovers1, sourceId, singleRes.allDay, singleRes.hasEnd, calendar);
3007 var instance = createEventInstance(def.defId, singleRes.range, singleRes.forcedStartTzo, singleRes.forcedEndTzo);
3008 return { def: def, instance: instance };
3009 }
3010 }
3011 return null;
3012 }
3013 /*
3014 Will NOT populate extendedProps with the leftover properties.
3015 Will NOT populate date-related props.
3016 The EventNonDateInput has been normalized (id => publicId, etc).
3017 */
3018 function parseEventDef(raw, sourceId, allDay, hasEnd, calendar) {
3019 var leftovers = {};
3020 var def = pluckNonDateProps(raw, calendar, leftovers);
3021 def.defId = String(uid++);
3022 def.sourceId = sourceId;
3023 def.allDay = allDay;
3024 def.hasEnd = hasEnd;
3025 for (var _i = 0, _a = calendar.pluginSystem.hooks.eventDefParsers; _i < _a.length; _i++) {
3026 var eventDefParser = _a[_i];
3027 var newLeftovers = {};
3028 eventDefParser(def, leftovers, newLeftovers);
3029 leftovers = newLeftovers;
3030 }
3031 def.extendedProps = __assign(leftovers, def.extendedProps || {});
3032 // help out EventApi from having user modify props
3033 Object.freeze(def.ui.classNames);
3034 Object.freeze(def.extendedProps);
3035 return def;
3036 }
3037 function createEventInstance(defId, range, forcedStartTzo, forcedEndTzo) {
3038 return {
3039 instanceId: String(uid++),
3040 defId: defId,
3041 range: range,
3042 forcedStartTzo: forcedStartTzo == null ? null : forcedStartTzo,
3043 forcedEndTzo: forcedEndTzo == null ? null : forcedEndTzo
3044 };
3045 }
3046 function parseSingle(raw, allDayDefault, calendar, leftovers, allowOpenRange) {
3047 var props = pluckDateProps(raw, leftovers);
3048 var allDay = props.allDay;
3049 var startMeta;
3050 var startMarker = null;
3051 var hasEnd = false;
3052 var endMeta;
3053 var endMarker = null;
3054 startMeta = calendar.dateEnv.createMarkerMeta(props.start);
3055 if (startMeta) {
3056 startMarker = startMeta.marker;
3057 }
3058 else if (!allowOpenRange) {
3059 return null;
3060 }
3061 if (props.end != null) {
3062 endMeta = calendar.dateEnv.createMarkerMeta(props.end);
3063 }
3064 if (allDay == null) {
3065 if (allDayDefault != null) {
3066 allDay = allDayDefault;
3067 }
3068 else {
3069 // fall back to the date props LAST
3070 allDay = (!startMeta || startMeta.isTimeUnspecified) &&
3071 (!endMeta || endMeta.isTimeUnspecified);
3072 }
3073 }
3074 if (allDay && startMarker) {
3075 startMarker = startOfDay(startMarker);
3076 }
3077 if (endMeta) {
3078 endMarker = endMeta.marker;
3079 if (allDay) {
3080 endMarker = startOfDay(endMarker);
3081 }
3082 if (startMarker && endMarker <= startMarker) {
3083 endMarker = null;
3084 }
3085 }
3086 if (endMarker) {
3087 hasEnd = true;
3088 }
3089 else if (!allowOpenRange) {
3090 hasEnd = calendar.opt('forceEventDuration') || false;
3091 endMarker = calendar.dateEnv.add(startMarker, allDay ?
3092 calendar.defaultAllDayEventDuration :
3093 calendar.defaultTimedEventDuration);
3094 }
3095 return {
3096 allDay: allDay,
3097 hasEnd: hasEnd,
3098 range: { start: startMarker, end: endMarker },
3099 forcedStartTzo: startMeta ? startMeta.forcedTzo : null,
3100 forcedEndTzo: endMeta ? endMeta.forcedTzo : null
3101 };
3102 }
3103 function pluckDateProps(raw, leftovers) {
3104 var props = refineProps(raw, DATE_PROPS, {}, leftovers);
3105 props.start = (props.start !== null) ? props.start : props.date;
3106 delete props.date;
3107 return props;
3108 }
3109 function pluckNonDateProps(raw, calendar, leftovers) {
3110 var preLeftovers = {};
3111 var props = refineProps(raw, NON_DATE_PROPS, {}, preLeftovers);
3112 var ui = processUnscopedUiProps(preLeftovers, calendar, leftovers);
3113 props.publicId = props.id;
3114 delete props.id;
3115 props.ui = ui;
3116 return props;
3117 }
3118 function computeIsAllDayDefault(sourceId, calendar) {
3119 var res = null;
3120 if (sourceId) {
3121 var source = calendar.state.eventSources[sourceId];
3122 res = source.allDayDefault;
3123 }
3124 if (res == null) {
3125 res = calendar.opt('allDayDefault');
3126 }
3127 return res;
3128 }
3129
3130 var DEF_DEFAULTS = {
3131 startTime: '09:00',
3132 endTime: '17:00',
3133 daysOfWeek: [1, 2, 3, 4, 5],
3134 rendering: 'inverse-background',
3135 classNames: 'fc-nonbusiness',
3136 groupId: '_businessHours' // so multiple defs get grouped
3137 };
3138 /*
3139 TODO: pass around as EventDefHash!!!
3140 */
3141 function parseBusinessHours(input, calendar) {
3142 return parseEvents(refineInputs(input), '', calendar);
3143 }
3144 function refineInputs(input) {
3145 var rawDefs;
3146 if (input === true) {
3147 rawDefs = [{}]; // will get DEF_DEFAULTS verbatim
3148 }
3149 else if (Array.isArray(input)) {
3150 // if specifying an array, every sub-definition NEEDS a day-of-week
3151 rawDefs = input.filter(function (rawDef) {
3152 return rawDef.daysOfWeek;
3153 });
3154 }
3155 else if (typeof input === 'object' && input) { // non-null object
3156 rawDefs = [input];
3157 }
3158 else { // is probably false
3159 rawDefs = [];
3160 }
3161 rawDefs = rawDefs.map(function (rawDef) {
3162 return __assign({}, DEF_DEFAULTS, rawDef);
3163 });
3164 return rawDefs;
3165 }
3166
3167 function memoizeRendering(renderFunc, unrenderFunc, dependencies) {
3168 if (dependencies === void 0) { dependencies = []; }
3169 var dependents = [];
3170 var thisContext;
3171 var prevArgs;
3172 function unrender() {
3173 if (prevArgs) {
3174 for (var _i = 0, dependents_1 = dependents; _i < dependents_1.length; _i++) {
3175 var dependent = dependents_1[_i];
3176 dependent.unrender();
3177 }
3178 if (unrenderFunc) {
3179 unrenderFunc.apply(thisContext, prevArgs);
3180 }
3181 prevArgs = null;
3182 }
3183 }
3184 function res() {
3185 if (!prevArgs || !isArraysEqual(prevArgs, arguments)) {
3186 unrender();
3187 thisContext = this;
3188 prevArgs = arguments;
3189 renderFunc.apply(this, arguments);
3190 }
3191 }
3192 res.dependents = dependents;
3193 res.unrender = unrender;
3194 for (var _i = 0, dependencies_1 = dependencies; _i < dependencies_1.length; _i++) {
3195 var dependency = dependencies_1[_i];
3196 dependency.dependents.push(res);
3197 }
3198 return res;
3199 }
3200
3201 var EMPTY_EVENT_STORE = createEmptyEventStore(); // for purecomponents. TODO: keep elsewhere
3202 var Splitter = /** @class */ (function () {
3203 function Splitter() {
3204 this.getKeysForEventDefs = memoize(this._getKeysForEventDefs);
3205 this.splitDateSelection = memoize(this._splitDateSpan);
3206 this.splitEventStore = memoize(this._splitEventStore);
3207 this.splitIndividualUi = memoize(this._splitIndividualUi);
3208 this.splitEventDrag = memoize(this._splitInteraction);
3209 this.splitEventResize = memoize(this._splitInteraction);
3210 this.eventUiBuilders = {}; // TODO: typescript protection
3211 }
3212 Splitter.prototype.splitProps = function (props) {
3213 var _this = this;
3214 var keyInfos = this.getKeyInfo(props);
3215 var defKeys = this.getKeysForEventDefs(props.eventStore);
3216 var dateSelections = this.splitDateSelection(props.dateSelection);
3217 var individualUi = this.splitIndividualUi(props.eventUiBases, defKeys); // the individual *bases*
3218 var eventStores = this.splitEventStore(props.eventStore, defKeys);
3219 var eventDrags = this.splitEventDrag(props.eventDrag);
3220 var eventResizes = this.splitEventResize(props.eventResize);
3221 var splitProps = {};
3222 this.eventUiBuilders = mapHash(keyInfos, function (info, key) {
3223 return _this.eventUiBuilders[key] || memoize(buildEventUiForKey);
3224 });
3225 for (var key in keyInfos) {
3226 var keyInfo = keyInfos[key];
3227 var eventStore = eventStores[key] || EMPTY_EVENT_STORE;
3228 var buildEventUi = this.eventUiBuilders[key];
3229 splitProps[key] = {
3230 businessHours: keyInfo.businessHours || props.businessHours,
3231 dateSelection: dateSelections[key] || null,
3232 eventStore: eventStore,
3233 eventUiBases: buildEventUi(props.eventUiBases[''], keyInfo.ui, individualUi[key]),
3234 eventSelection: eventStore.instances[props.eventSelection] ? props.eventSelection : '',
3235 eventDrag: eventDrags[key] || null,
3236 eventResize: eventResizes[key] || null
3237 };
3238 }
3239 return splitProps;
3240 };
3241 Splitter.prototype._splitDateSpan = function (dateSpan) {
3242 var dateSpans = {};
3243 if (dateSpan) {
3244 var keys = this.getKeysForDateSpan(dateSpan);
3245 for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
3246 var key = keys_1[_i];
3247 dateSpans[key] = dateSpan;
3248 }
3249 }
3250 return dateSpans;
3251 };
3252 Splitter.prototype._getKeysForEventDefs = function (eventStore) {
3253 var _this = this;
3254 return mapHash(eventStore.defs, function (eventDef) {
3255 return _this.getKeysForEventDef(eventDef);
3256 });
3257 };
3258 Splitter.prototype._splitEventStore = function (eventStore, defKeys) {
3259 var defs = eventStore.defs, instances = eventStore.instances;
3260 var splitStores = {};
3261 for (var defId in defs) {
3262 for (var _i = 0, _a = defKeys[defId]; _i < _a.length; _i++) {
3263 var key = _a[_i];
3264 if (!splitStores[key]) {
3265 splitStores[key] = createEmptyEventStore();
3266 }
3267 splitStores[key].defs[defId] = defs[defId];
3268 }
3269 }
3270 for (var instanceId in instances) {
3271 var instance = instances[instanceId];
3272 for (var _b = 0, _c = defKeys[instance.defId]; _b < _c.length; _b++) {
3273 var key = _c[_b];
3274 if (splitStores[key]) { // must have already been created
3275 splitStores[key].instances[instanceId] = instance;
3276 }
3277 }
3278 }
3279 return splitStores;
3280 };
3281 Splitter.prototype._splitIndividualUi = function (eventUiBases, defKeys) {
3282 var splitHashes = {};
3283 for (var defId in eventUiBases) {
3284 if (defId) { // not the '' key
3285 for (var _i = 0, _a = defKeys[defId]; _i < _a.length; _i++) {
3286 var key = _a[_i];
3287 if (!splitHashes[key]) {
3288 splitHashes[key] = {};
3289 }
3290 splitHashes[key][defId] = eventUiBases[defId];
3291 }
3292 }
3293 }
3294 return splitHashes;
3295 };
3296 Splitter.prototype._splitInteraction = function (interaction) {
3297 var splitStates = {};
3298 if (interaction) {
3299 var affectedStores_1 = this._splitEventStore(interaction.affectedEvents, this._getKeysForEventDefs(interaction.affectedEvents) // can't use cached. might be events from other calendar
3300 );
3301 // can't rely on defKeys because event data is mutated
3302 var mutatedKeysByDefId = this._getKeysForEventDefs(interaction.mutatedEvents);
3303 var mutatedStores_1 = this._splitEventStore(interaction.mutatedEvents, mutatedKeysByDefId);
3304 var populate = function (key) {
3305 if (!splitStates[key]) {
3306 splitStates[key] = {
3307 affectedEvents: affectedStores_1[key] || EMPTY_EVENT_STORE,
3308 mutatedEvents: mutatedStores_1[key] || EMPTY_EVENT_STORE,
3309 isEvent: interaction.isEvent,
3310 origSeg: interaction.origSeg
3311 };
3312 }
3313 };
3314 for (var key in affectedStores_1) {
3315 populate(key);
3316 }
3317 for (var key in mutatedStores_1) {
3318 populate(key);
3319 }
3320 }
3321 return splitStates;
3322 };
3323 return Splitter;
3324 }());
3325 function buildEventUiForKey(allUi, eventUiForKey, individualUi) {
3326 var baseParts = [];
3327 if (allUi) {
3328 baseParts.push(allUi);
3329 }
3330 if (eventUiForKey) {
3331 baseParts.push(eventUiForKey);
3332 }
3333 var stuff = {
3334 '': combineEventUis(baseParts)
3335 };
3336 if (individualUi) {
3337 __assign(stuff, individualUi);
3338 }
3339 return stuff;
3340 }
3341
3342 // Generates HTML for an anchor to another view into the calendar.
3343 // Will either generate an <a> tag or a non-clickable <span> tag, depending on enabled settings.
3344 // `gotoOptions` can either be a DateMarker, or an object with the form:
3345 // { date, type, forceOff }
3346 // `type` is a view-type like "day" or "week". default value is "day".
3347 // `attrs` and `innerHtml` are use to generate the rest of the HTML tag.
3348 function buildGotoAnchorHtml(component, gotoOptions, attrs, innerHtml) {
3349 var dateEnv = component.dateEnv;
3350 var date;
3351 var type;
3352 var forceOff;
3353 var finalOptions;
3354 if (gotoOptions instanceof Date) {
3355 date = gotoOptions; // a single date-like input
3356 }
3357 else {
3358 date = gotoOptions.date;
3359 type = gotoOptions.type;
3360 forceOff = gotoOptions.forceOff;
3361 }
3362 finalOptions = {
3363 date: dateEnv.formatIso(date, { omitTime: true }),
3364 type: type || 'day'
3365 };
3366 if (typeof attrs === 'string') {
3367 innerHtml = attrs;
3368 attrs = null;
3369 }
3370 attrs = attrs ? ' ' + attrsToStr(attrs) : ''; // will have a leading space
3371 innerHtml = innerHtml || '';
3372 if (!forceOff && component.opt('navLinks')) {
3373 return '<a' + attrs +
3374 ' data-goto="' + htmlEscape(JSON.stringify(finalOptions)) + '">' +
3375 innerHtml +
3376 '</a>';
3377 }
3378 else {
3379 return '<span' + attrs + '>' +
3380 innerHtml +
3381 '</span>';
3382 }
3383 }
3384 function getAllDayHtml(component) {
3385 return component.opt('allDayHtml') || htmlEscape(component.opt('allDayText'));
3386 }
3387 // Computes HTML classNames for a single-day element
3388 function getDayClasses(date, dateProfile, context, noThemeHighlight) {
3389 var calendar = context.calendar, view = context.view, theme = context.theme, dateEnv = context.dateEnv;
3390 var classes = [];
3391 var todayStart;
3392 var todayEnd;
3393 if (!rangeContainsMarker(dateProfile.activeRange, date)) {
3394 classes.push('fc-disabled-day');
3395 }
3396 else {
3397 classes.push('fc-' + DAY_IDS[date.getUTCDay()]);
3398 if (view.opt('monthMode') &&
3399 dateEnv.getMonth(date) !== dateEnv.getMonth(dateProfile.currentRange.start)) {
3400 classes.push('fc-other-month');
3401 }
3402 todayStart = startOfDay(calendar.getNow());
3403 todayEnd = addDays(todayStart, 1);
3404 if (date < todayStart) {
3405 classes.push('fc-past');
3406 }
3407 else if (date >= todayEnd) {
3408 classes.push('fc-future');
3409 }
3410 else {
3411 classes.push('fc-today');
3412 if (noThemeHighlight !== true) {
3413 classes.push(theme.getClass('today'));
3414 }
3415 }
3416 }
3417 return classes;
3418 }
3419
3420 // given a function that resolves a result asynchronously.
3421 // the function can either call passed-in success and failure callbacks,
3422 // or it can return a promise.
3423 // if you need to pass additional params to func, bind them first.
3424 function unpromisify(func, success, failure) {
3425 // guard against success/failure callbacks being called more than once
3426 // and guard against a promise AND callback being used together.
3427 var isResolved = false;
3428 var wrappedSuccess = function () {
3429 if (!isResolved) {
3430 isResolved = true;
3431 success.apply(this, arguments);
3432 }
3433 };
3434 var wrappedFailure = function () {
3435 if (!isResolved) {
3436 isResolved = true;
3437 if (failure) {
3438 failure.apply(this, arguments);
3439 }
3440 }
3441 };
3442 var res = func(wrappedSuccess, wrappedFailure);
3443 if (res && typeof res.then === 'function') {
3444 res.then(wrappedSuccess, wrappedFailure);
3445 }
3446 }
3447
3448 var Mixin = /** @class */ (function () {
3449 function Mixin() {
3450 }
3451 // mix into a CLASS
3452 Mixin.mixInto = function (destClass) {
3453 this.mixIntoObj(destClass.prototype);
3454 };
3455 // mix into ANY object
3456 Mixin.mixIntoObj = function (destObj) {
3457 var _this = this;
3458 Object.getOwnPropertyNames(this.prototype).forEach(function (name) {
3459 if (!destObj[name]) { // if destination doesn't already define it
3460 destObj[name] = _this.prototype[name];
3461 }
3462 });
3463 };
3464 /*
3465 will override existing methods
3466 TODO: remove! not used anymore
3467 */
3468 Mixin.mixOver = function (destClass) {
3469 var _this = this;
3470 Object.getOwnPropertyNames(this.prototype).forEach(function (name) {
3471 destClass.prototype[name] = _this.prototype[name];
3472 });
3473 };
3474 return Mixin;
3475 }());
3476
3477 /*
3478 USAGE:
3479 import { default as EmitterMixin, EmitterInterface } from './EmitterMixin'
3480 in class:
3481 on: EmitterInterface['on']
3482 one: EmitterInterface['one']
3483 off: EmitterInterface['off']
3484 trigger: EmitterInterface['trigger']
3485 triggerWith: EmitterInterface['triggerWith']
3486 hasHandlers: EmitterInterface['hasHandlers']
3487 after class:
3488 EmitterMixin.mixInto(TheClass)
3489 */
3490 var EmitterMixin = /** @class */ (function (_super) {
3491 __extends(EmitterMixin, _super);
3492 function EmitterMixin() {
3493 return _super !== null && _super.apply(this, arguments) || this;
3494 }
3495 EmitterMixin.prototype.on = function (type, handler) {
3496 addToHash(this._handlers || (this._handlers = {}), type, handler);
3497 return this; // for chaining
3498 };
3499 // todo: add comments
3500 EmitterMixin.prototype.one = function (type, handler) {
3501 addToHash(this._oneHandlers || (this._oneHandlers = {}), type, handler);
3502 return this; // for chaining
3503 };
3504 EmitterMixin.prototype.off = function (type, handler) {
3505 if (this._handlers) {
3506 removeFromHash(this._handlers, type, handler);
3507 }
3508 if (this._oneHandlers) {
3509 removeFromHash(this._oneHandlers, type, handler);
3510 }
3511 return this; // for chaining
3512 };
3513 EmitterMixin.prototype.trigger = function (type) {
3514 var args = [];
3515 for (var _i = 1; _i < arguments.length; _i++) {
3516 args[_i - 1] = arguments[_i];
3517 }
3518 this.triggerWith(type, this, args);
3519 return this; // for chaining
3520 };
3521 EmitterMixin.prototype.triggerWith = function (type, context, args) {
3522 if (this._handlers) {
3523 applyAll(this._handlers[type], context, args);
3524 }
3525 if (this._oneHandlers) {
3526 applyAll(this._oneHandlers[type], context, args);
3527 delete this._oneHandlers[type]; // will never fire again
3528 }
3529 return this; // for chaining
3530 };
3531 EmitterMixin.prototype.hasHandlers = function (type) {
3532 return (this._handlers && this._handlers[type] && this._handlers[type].length) ||
3533 (this._oneHandlers && this._oneHandlers[type] && this._oneHandlers[type].length);
3534 };
3535 return EmitterMixin;
3536 }(Mixin));
3537 function addToHash(hash, type, handler) {
3538 (hash[type] || (hash[type] = []))
3539 .push(handler);
3540 }
3541 function removeFromHash(hash, type, handler) {
3542 if (handler) {
3543 if (hash[type]) {
3544 hash[type] = hash[type].filter(function (func) {
3545 return func !== handler;
3546 });
3547 }
3548 }
3549 else {
3550 delete hash[type]; // remove all handler funcs for this type
3551 }
3552 }
3553
3554 /*
3555 Records offset information for a set of elements, relative to an origin element.
3556 Can record the left/right OR the top/bottom OR both.
3557 Provides methods for querying the cache by position.
3558 */
3559 var PositionCache = /** @class */ (function () {
3560 function PositionCache(originEl, els, isHorizontal, isVertical) {
3561 this.originEl = originEl;
3562 this.els = els;
3563 this.isHorizontal = isHorizontal;
3564 this.isVertical = isVertical;
3565 }
3566 // Queries the els for coordinates and stores them.
3567 // Call this method before using and of the get* methods below.
3568 PositionCache.prototype.build = function () {
3569 var originEl = this.originEl;
3570 var originClientRect = this.originClientRect =
3571 originEl.getBoundingClientRect(); // relative to viewport top-left
3572 if (this.isHorizontal) {
3573 this.buildElHorizontals(originClientRect.left);
3574 }
3575 if (this.isVertical) {
3576 this.buildElVerticals(originClientRect.top);
3577 }
3578 };
3579 // Populates the left/right internal coordinate arrays
3580 PositionCache.prototype.buildElHorizontals = function (originClientLeft) {
3581 var lefts = [];
3582 var rights = [];
3583 for (var _i = 0, _a = this.els; _i < _a.length; _i++) {
3584 var el = _a[_i];
3585 var rect = el.getBoundingClientRect();
3586 lefts.push(rect.left - originClientLeft);
3587 rights.push(rect.right - originClientLeft);
3588 }
3589 this.lefts = lefts;
3590 this.rights = rights;
3591 };
3592 // Populates the top/bottom internal coordinate arrays
3593 PositionCache.prototype.buildElVerticals = function (originClientTop) {
3594 var tops = [];
3595 var bottoms = [];
3596 for (var _i = 0, _a = this.els; _i < _a.length; _i++) {
3597 var el = _a[_i];
3598 var rect = el.getBoundingClientRect();
3599 tops.push(rect.top - originClientTop);
3600 bottoms.push(rect.bottom - originClientTop);
3601 }
3602 this.tops = tops;
3603 this.bottoms = bottoms;
3604 };
3605 // Given a left offset (from document left), returns the index of the el that it horizontally intersects.
3606 // If no intersection is made, returns undefined.
3607 PositionCache.prototype.leftToIndex = function (leftPosition) {
3608 var lefts = this.lefts;
3609 var rights = this.rights;
3610 var len = lefts.length;
3611 var i;
3612 for (i = 0; i < len; i++) {
3613 if (leftPosition >= lefts[i] && leftPosition < rights[i]) {
3614 return i;
3615 }
3616 }
3617 };
3618 // Given a top offset (from document top), returns the index of the el that it vertically intersects.
3619 // If no intersection is made, returns undefined.
3620 PositionCache.prototype.topToIndex = function (topPosition) {
3621 var tops = this.tops;
3622 var bottoms = this.bottoms;
3623 var len = tops.length;
3624 var i;
3625 for (i = 0; i < len; i++) {
3626 if (topPosition >= tops[i] && topPosition < bottoms[i]) {
3627 return i;
3628 }
3629 }
3630 };
3631 // Gets the width of the element at the given index
3632 PositionCache.prototype.getWidth = function (leftIndex) {
3633 return this.rights[leftIndex] - this.lefts[leftIndex];
3634 };
3635 // Gets the height of the element at the given index
3636 PositionCache.prototype.getHeight = function (topIndex) {
3637 return this.bottoms[topIndex] - this.tops[topIndex];
3638 };
3639 return PositionCache;
3640 }());
3641
3642 /*
3643 An object for getting/setting scroll-related information for an element.
3644 Internally, this is done very differently for window versus DOM element,
3645 so this object serves as a common interface.
3646 */
3647 var ScrollController = /** @class */ (function () {
3648 function ScrollController() {
3649 }
3650 ScrollController.prototype.getMaxScrollTop = function () {
3651 return this.getScrollHeight() - this.getClientHeight();
3652 };
3653 ScrollController.prototype.getMaxScrollLeft = function () {
3654 return this.getScrollWidth() - this.getClientWidth();
3655 };
3656 ScrollController.prototype.canScrollVertically = function () {
3657 return this.getMaxScrollTop() > 0;
3658 };
3659 ScrollController.prototype.canScrollHorizontally = function () {
3660 return this.getMaxScrollLeft() > 0;
3661 };
3662 ScrollController.prototype.canScrollUp = function () {
3663 return this.getScrollTop() > 0;
3664 };
3665 ScrollController.prototype.canScrollDown = function () {
3666 return this.getScrollTop() < this.getMaxScrollTop();
3667 };
3668 ScrollController.prototype.canScrollLeft = function () {
3669 return this.getScrollLeft() > 0;
3670 };
3671 ScrollController.prototype.canScrollRight = function () {
3672 return this.getScrollLeft() < this.getMaxScrollLeft();
3673 };
3674 return ScrollController;
3675 }());
3676 var ElementScrollController = /** @class */ (function (_super) {
3677 __extends(ElementScrollController, _super);
3678 function ElementScrollController(el) {
3679 var _this = _super.call(this) || this;
3680 _this.el = el;
3681 return _this;
3682 }
3683 ElementScrollController.prototype.getScrollTop = function () {
3684 return this.el.scrollTop;
3685 };
3686 ElementScrollController.prototype.getScrollLeft = function () {
3687 return this.el.scrollLeft;
3688 };
3689 ElementScrollController.prototype.setScrollTop = function (top) {
3690 this.el.scrollTop = top;
3691 };
3692 ElementScrollController.prototype.setScrollLeft = function (left) {
3693 this.el.scrollLeft = left;
3694 };
3695 ElementScrollController.prototype.getScrollWidth = function () {
3696 return this.el.scrollWidth;
3697 };
3698 ElementScrollController.prototype.getScrollHeight = function () {
3699 return this.el.scrollHeight;
3700 };
3701 ElementScrollController.prototype.getClientHeight = function () {
3702 return this.el.clientHeight;
3703 };
3704 ElementScrollController.prototype.getClientWidth = function () {
3705 return this.el.clientWidth;
3706 };
3707 return ElementScrollController;
3708 }(ScrollController));
3709 var WindowScrollController = /** @class */ (function (_super) {
3710 __extends(WindowScrollController, _super);
3711 function WindowScrollController() {
3712 return _super !== null && _super.apply(this, arguments) || this;
3713 }
3714 WindowScrollController.prototype.getScrollTop = function () {
3715 return window.pageYOffset;
3716 };
3717 WindowScrollController.prototype.getScrollLeft = function () {
3718 return window.pageXOffset;
3719 };
3720 WindowScrollController.prototype.setScrollTop = function (n) {
3721 window.scroll(window.pageXOffset, n);
3722 };
3723 WindowScrollController.prototype.setScrollLeft = function (n) {
3724 window.scroll(n, window.pageYOffset);
3725 };
3726 WindowScrollController.prototype.getScrollWidth = function () {
3727 return document.documentElement.scrollWidth;
3728 };
3729 WindowScrollController.prototype.getScrollHeight = function () {
3730 return document.documentElement.scrollHeight;
3731 };
3732 WindowScrollController.prototype.getClientHeight = function () {
3733 return document.documentElement.clientHeight;
3734 };
3735 WindowScrollController.prototype.getClientWidth = function () {
3736 return document.documentElement.clientWidth;
3737 };
3738 return WindowScrollController;
3739 }(ScrollController));
3740
3741 /*
3742 Embodies a div that has potential scrollbars
3743 */
3744 var ScrollComponent = /** @class */ (function (_super) {
3745 __extends(ScrollComponent, _super);
3746 function ScrollComponent(overflowX, overflowY) {
3747 var _this = _super.call(this, createElement('div', {
3748 className: 'fc-scroller'
3749 })) || this;
3750 _this.overflowX = overflowX;
3751 _this.overflowY = overflowY;
3752 _this.applyOverflow();
3753 return _this;
3754 }
3755 // sets to natural height, unlocks overflow
3756 ScrollComponent.prototype.clear = function () {
3757 this.setHeight('auto');
3758 this.applyOverflow();
3759 };
3760 ScrollComponent.prototype.destroy = function () {
3761 removeElement(this.el);
3762 };
3763 // Overflow
3764 // -----------------------------------------------------------------------------------------------------------------
3765 ScrollComponent.prototype.applyOverflow = function () {
3766 applyStyle(this.el, {
3767 overflowX: this.overflowX,
3768 overflowY: this.overflowY
3769 });
3770 };
3771 // Causes any 'auto' overflow values to resolves to 'scroll' or 'hidden'.
3772 // Useful for preserving scrollbar widths regardless of future resizes.
3773 // Can pass in scrollbarWidths for optimization.
3774 ScrollComponent.prototype.lockOverflow = function (scrollbarWidths) {
3775 var overflowX = this.overflowX;
3776 var overflowY = this.overflowY;
3777 scrollbarWidths = scrollbarWidths || this.getScrollbarWidths();
3778 if (overflowX === 'auto') {
3779 overflowX = (scrollbarWidths.bottom || // horizontal scrollbars?
3780 this.canScrollHorizontally() // OR scrolling pane with massless scrollbars?
3781 ) ? 'scroll' : 'hidden';
3782 }
3783 if (overflowY === 'auto') {
3784 overflowY = (scrollbarWidths.left || scrollbarWidths.right || // horizontal scrollbars?
3785 this.canScrollVertically() // OR scrolling pane with massless scrollbars?
3786 ) ? 'scroll' : 'hidden';
3787 }
3788 applyStyle(this.el, { overflowX: overflowX, overflowY: overflowY });
3789 };
3790 ScrollComponent.prototype.setHeight = function (height) {
3791 applyStyleProp(this.el, 'height', height);
3792 };
3793 ScrollComponent.prototype.getScrollbarWidths = function () {
3794 var edges = computeEdges(this.el);
3795 return {
3796 left: edges.scrollbarLeft,
3797 right: edges.scrollbarRight,
3798 bottom: edges.scrollbarBottom
3799 };
3800 };
3801 return ScrollComponent;
3802 }(ElementScrollController));
3803
3804 var Theme = /** @class */ (function () {
3805 function Theme(calendarOptions) {
3806 this.calendarOptions = calendarOptions;
3807 this.processIconOverride();
3808 }
3809 Theme.prototype.processIconOverride = function () {
3810 if (this.iconOverrideOption) {
3811 this.setIconOverride(this.calendarOptions[this.iconOverrideOption]);
3812 }
3813 };
3814 Theme.prototype.setIconOverride = function (iconOverrideHash) {
3815 var iconClassesCopy;
3816 var buttonName;
3817 if (typeof iconOverrideHash === 'object' && iconOverrideHash) { // non-null object
3818 iconClassesCopy = __assign({}, this.iconClasses);
3819 for (buttonName in iconOverrideHash) {
3820 iconClassesCopy[buttonName] = this.applyIconOverridePrefix(iconOverrideHash[buttonName]);
3821 }
3822 this.iconClasses = iconClassesCopy;
3823 }
3824 else if (iconOverrideHash === false) {
3825 this.iconClasses = {};
3826 }
3827 };
3828 Theme.prototype.applyIconOverridePrefix = function (className) {
3829 var prefix = this.iconOverridePrefix;
3830 if (prefix && className.indexOf(prefix) !== 0) { // if not already present
3831 className = prefix + className;
3832 }
3833 return className;
3834 };
3835 Theme.prototype.getClass = function (key) {
3836 return this.classes[key] || '';
3837 };
3838 Theme.prototype.getIconClass = function (buttonName) {
3839 var className = this.iconClasses[buttonName];
3840 if (className) {
3841 return this.baseIconClass + ' ' + className;
3842 }
3843 return '';
3844 };
3845 Theme.prototype.getCustomButtonIconClass = function (customButtonProps) {
3846 var className;
3847 if (this.iconOverrideCustomButtonOption) {
3848 className = customButtonProps[this.iconOverrideCustomButtonOption];
3849 if (className) {
3850 return this.baseIconClass + ' ' + this.applyIconOverridePrefix(className);
3851 }
3852 }
3853 return '';
3854 };
3855 return Theme;
3856 }());
3857 Theme.prototype.classes = {};
3858 Theme.prototype.iconClasses = {};
3859 Theme.prototype.baseIconClass = '';
3860 Theme.prototype.iconOverridePrefix = '';
3861
3862 var guid = 0;
3863 var Component = /** @class */ (function () {
3864 function Component(context, isView) {
3865 // HACK to populate view at top of component instantiation call chain
3866 if (isView) {
3867 context.view = this;
3868 }
3869 this.uid = String(guid++);
3870 this.context = context;
3871 this.dateEnv = context.dateEnv;
3872 this.theme = context.theme;
3873 this.view = context.view;
3874 this.calendar = context.calendar;
3875 this.isRtl = this.opt('dir') === 'rtl';
3876 }
3877 Component.addEqualityFuncs = function (newFuncs) {
3878 this.prototype.equalityFuncs = __assign({}, this.prototype.equalityFuncs, newFuncs);
3879 };
3880 Component.prototype.opt = function (name) {
3881 return this.context.options[name];
3882 };
3883 Component.prototype.receiveProps = function (props) {
3884 var _a = recycleProps(this.props || {}, props, this.equalityFuncs), anyChanges = _a.anyChanges, comboProps = _a.comboProps;
3885 this.props = comboProps;
3886 if (anyChanges) {
3887 this.render(comboProps);
3888 }
3889 };
3890 Component.prototype.render = function (props) {
3891 };
3892 // after destroy is called, this component won't ever be used again
3893 Component.prototype.destroy = function () {
3894 };
3895 return Component;
3896 }());
3897 Component.prototype.equalityFuncs = {};
3898 /*
3899 Reuses old values when equal. If anything is unequal, returns newProps as-is.
3900 Great for PureComponent, but won't be feasible with React, so just eliminate and use React's DOM diffing.
3901 */
3902 function recycleProps(oldProps, newProps, equalityFuncs) {
3903 var comboProps = {}; // some old, some new
3904 var anyChanges = false;
3905 for (var key in newProps) {
3906 if (key in oldProps && (oldProps[key] === newProps[key] ||
3907 (equalityFuncs[key] && equalityFuncs[key](oldProps[key], newProps[key])))) {
3908 // equal to old? use old prop
3909 comboProps[key] = oldProps[key];
3910 }
3911 else {
3912 comboProps[key] = newProps[key];
3913 anyChanges = true;
3914 }
3915 }
3916 for (var key in oldProps) {
3917 if (!(key in newProps)) {
3918 anyChanges = true;
3919 break;
3920 }
3921 }
3922 return { anyChanges: anyChanges, comboProps: comboProps };
3923 }
3924
3925 /*
3926 PURPOSES:
3927 - hook up to fg, fill, and mirror renderers
3928 - interface for dragging and hits
3929 */
3930 var DateComponent = /** @class */ (function (_super) {
3931 __extends(DateComponent, _super);
3932 function DateComponent(context, el, isView) {
3933 var _this = _super.call(this, context, isView) || this;
3934 _this.el = el;
3935 return _this;
3936 }
3937 DateComponent.prototype.destroy = function () {
3938 _super.prototype.destroy.call(this);
3939 removeElement(this.el);
3940 };
3941 // TODO: WHAT ABOUT (sourceSeg && sourceSeg.component.doesDragMirror)
3942 //
3943 // Event Drag-n-Drop Rendering (for both events and external elements)
3944 // ---------------------------------------------------------------------------------------------------------------
3945 /*
3946 renderEventDragSegs(state: EventSegUiInteractionState) {
3947 if (state) {
3948 let { isEvent, segs, sourceSeg } = state
3949
3950 if (this.eventRenderer) {
3951 this.eventRenderer.hideByHash(state.affectedInstances)
3952 }
3953
3954 // if the user is dragging something that is considered an event with real event data,
3955 // and this component likes to do drag mirrors OR the component where the seg came from
3956 // likes to do drag mirrors, then render a drag mirror.
3957 if (isEvent && (this.doesDragMirror || sourceSeg && sourceSeg.component.doesDragMirror)) {
3958 if (this.mirrorRenderer) {
3959 this.mirrorRenderer.renderSegs(segs, { isDragging: true, sourceSeg })
3960 }
3961 }
3962
3963 // if it would be impossible to render a drag mirror OR this component likes to render
3964 // highlights, then render a highlight.
3965 if (!isEvent || this.doesDragHighlight) {
3966 if (this.fillRenderer) {
3967 this.fillRenderer.renderSegs('highlight', segs)
3968 }
3969 }
3970 }
3971 }
3972 */
3973 // Hit System
3974 // -----------------------------------------------------------------------------------------------------------------
3975 DateComponent.prototype.buildPositionCaches = function () {
3976 };
3977 DateComponent.prototype.queryHit = function (positionLeft, positionTop, elWidth, elHeight) {
3978 return null; // this should be abstract
3979 };
3980 // Validation
3981 // -----------------------------------------------------------------------------------------------------------------
3982 DateComponent.prototype.isInteractionValid = function (interaction) {
3983 var calendar = this.calendar;
3984 var dateProfile = this.props.dateProfile; // HACK
3985 var instances = interaction.mutatedEvents.instances;
3986 if (dateProfile) { // HACK for DayTile
3987 for (var instanceId in instances) {
3988 if (!rangeContainsRange(dateProfile.validRange, instances[instanceId].range)) {
3989 return false;
3990 }
3991 }
3992 }
3993 return isInteractionValid(interaction, calendar);
3994 };
3995 DateComponent.prototype.isDateSelectionValid = function (selection) {
3996 var dateProfile = this.props.dateProfile; // HACK
3997 if (dateProfile && // HACK for DayTile
3998 !rangeContainsRange(dateProfile.validRange, selection.range)) {
3999 return false;
4000 }
4001 return isDateSelectionValid(selection, this.calendar);
4002 };
4003 // Triggering
4004 // -----------------------------------------------------------------------------------------------------------------
4005 // TODO: move to Calendar
4006 DateComponent.prototype.publiclyTrigger = function (name, args) {
4007 var calendar = this.calendar;
4008 return calendar.publiclyTrigger(name, args);
4009 };
4010 DateComponent.prototype.publiclyTriggerAfterSizing = function (name, args) {
4011 var calendar = this.calendar;
4012 return calendar.publiclyTriggerAfterSizing(name, args);
4013 };
4014 DateComponent.prototype.hasPublicHandlers = function (name) {
4015 var calendar = this.calendar;
4016 return calendar.hasPublicHandlers(name);
4017 };
4018 DateComponent.prototype.triggerRenderedSegs = function (segs, isMirrors) {
4019 var calendar = this.calendar;
4020 if (this.hasPublicHandlers('eventPositioned')) {
4021 for (var _i = 0, segs_1 = segs; _i < segs_1.length; _i++) {
4022 var seg = segs_1[_i];
4023 this.publiclyTriggerAfterSizing('eventPositioned', [
4024 {
4025 event: new EventApi(calendar, seg.eventRange.def, seg.eventRange.instance),
4026 isMirror: isMirrors,
4027 isStart: seg.isStart,
4028 isEnd: seg.isEnd,
4029 el: seg.el,
4030 view: this // safe to cast because this method is only called on context.view
4031 }
4032 ]);
4033 }
4034 }
4035 if (!calendar.state.loadingLevel) { // avoid initial empty state while pending
4036 calendar.afterSizingTriggers._eventsPositioned = [null]; // fire once
4037 }
4038 };
4039 DateComponent.prototype.triggerWillRemoveSegs = function (segs, isMirrors) {
4040 var calendar = this.calendar;
4041 for (var _i = 0, segs_2 = segs; _i < segs_2.length; _i++) {
4042 var seg = segs_2[_i];
4043 calendar.trigger('eventElRemove', seg.el);
4044 }
4045 if (this.hasPublicHandlers('eventDestroy')) {
4046 for (var _a = 0, segs_3 = segs; _a < segs_3.length; _a++) {
4047 var seg = segs_3[_a];
4048 this.publiclyTrigger('eventDestroy', [
4049 {
4050 event: new EventApi(calendar, seg.eventRange.def, seg.eventRange.instance),
4051 isMirror: isMirrors,
4052 el: seg.el,
4053 view: this // safe to cast because this method is only called on context.view
4054 }
4055 ]);
4056 }
4057 }
4058 };
4059 // Pointer Interaction Utils
4060 // -----------------------------------------------------------------------------------------------------------------
4061 DateComponent.prototype.isValidSegDownEl = function (el) {
4062 return !this.props.eventDrag && // HACK
4063 !this.props.eventResize && // HACK
4064 !elementClosest(el, '.fc-mirror') &&
4065 (this.isPopover() || !this.isInPopover(el));
4066 // ^above line ensures we don't detect a seg interaction within a nested component.
4067 // it's a HACK because it only supports a popover as the nested component.
4068 };
4069 DateComponent.prototype.isValidDateDownEl = function (el) {
4070 var segEl = elementClosest(el, this.fgSegSelector);
4071 return (!segEl || segEl.classList.contains('fc-mirror')) &&
4072 !elementClosest(el, '.fc-more') && // a "more.." link
4073 !elementClosest(el, 'a[data-goto]') && // a clickable nav link
4074 !this.isInPopover(el);
4075 };
4076 DateComponent.prototype.isPopover = function () {
4077 return this.el.classList.contains('fc-popover');
4078 };
4079 DateComponent.prototype.isInPopover = function (el) {
4080 return Boolean(elementClosest(el, '.fc-popover'));
4081 };
4082 return DateComponent;
4083 }(Component));
4084 DateComponent.prototype.fgSegSelector = '.fc-event-container > *';
4085 DateComponent.prototype.bgSegSelector = '.fc-bgevent:not(.fc-nonbusiness)';
4086
4087 var uid$1 = 0;
4088 function createPlugin(input) {
4089 return {
4090 id: String(uid$1++),
4091 deps: input.deps || [],
4092 reducers: input.reducers || [],
4093 eventDefParsers: input.eventDefParsers || [],
4094 isDraggableTransformers: input.isDraggableTransformers || [],
4095 eventDragMutationMassagers: input.eventDragMutationMassagers || [],
4096 eventDefMutationAppliers: input.eventDefMutationAppliers || [],
4097 dateSelectionTransformers: input.dateSelectionTransformers || [],
4098 datePointTransforms: input.datePointTransforms || [],
4099 dateSpanTransforms: input.dateSpanTransforms || [],
4100 views: input.views || {},
4101 viewPropsTransformers: input.viewPropsTransformers || [],
4102 isPropsValid: input.isPropsValid || null,
4103 externalDefTransforms: input.externalDefTransforms || [],
4104 eventResizeJoinTransforms: input.eventResizeJoinTransforms || [],
4105 viewContainerModifiers: input.viewContainerModifiers || [],
4106 eventDropTransformers: input.eventDropTransformers || [],
4107 componentInteractions: input.componentInteractions || [],
4108 calendarInteractions: input.calendarInteractions || [],
4109 themeClasses: input.themeClasses || {},
4110 eventSourceDefs: input.eventSourceDefs || [],
4111 cmdFormatter: input.cmdFormatter,
4112 recurringTypes: input.recurringTypes || [],
4113 namedTimeZonedImpl: input.namedTimeZonedImpl,
4114 defaultView: input.defaultView || '',
4115 elementDraggingImpl: input.elementDraggingImpl,
4116 optionChangeHandlers: input.optionChangeHandlers || {}
4117 };
4118 }
4119 var PluginSystem = /** @class */ (function () {
4120 function PluginSystem() {
4121 this.hooks = {
4122 reducers: [],
4123 eventDefParsers: [],
4124 isDraggableTransformers: [],
4125 eventDragMutationMassagers: [],
4126 eventDefMutationAppliers: [],
4127 dateSelectionTransformers: [],
4128 datePointTransforms: [],
4129 dateSpanTransforms: [],
4130 views: {},
4131 viewPropsTransformers: [],
4132 isPropsValid: null,
4133 externalDefTransforms: [],
4134 eventResizeJoinTransforms: [],
4135 viewContainerModifiers: [],
4136 eventDropTransformers: [],
4137 componentInteractions: [],
4138 calendarInteractions: [],
4139 themeClasses: {},
4140 eventSourceDefs: [],
4141 cmdFormatter: null,
4142 recurringTypes: [],
4143 namedTimeZonedImpl: null,
4144 defaultView: '',
4145 elementDraggingImpl: null,
4146 optionChangeHandlers: {}
4147 };
4148 this.addedHash = {};
4149 }
4150 PluginSystem.prototype.add = function (plugin) {
4151 if (!this.addedHash[plugin.id]) {
4152 this.addedHash[plugin.id] = true;
4153 for (var _i = 0, _a = plugin.deps; _i < _a.length; _i++) {
4154 var dep = _a[_i];
4155 this.add(dep);
4156 }
4157 this.hooks = combineHooks(this.hooks, plugin);
4158 }
4159 };
4160 return PluginSystem;
4161 }());
4162 function combineHooks(hooks0, hooks1) {
4163 return {
4164 reducers: hooks0.reducers.concat(hooks1.reducers),
4165 eventDefParsers: hooks0.eventDefParsers.concat(hooks1.eventDefParsers),
4166 isDraggableTransformers: hooks0.isDraggableTransformers.concat(hooks1.isDraggableTransformers),
4167 eventDragMutationMassagers: hooks0.eventDragMutationMassagers.concat(hooks1.eventDragMutationMassagers),
4168 eventDefMutationAppliers: hooks0.eventDefMutationAppliers.concat(hooks1.eventDefMutationAppliers),
4169 dateSelectionTransformers: hooks0.dateSelectionTransformers.concat(hooks1.dateSelectionTransformers),
4170 datePointTransforms: hooks0.datePointTransforms.concat(hooks1.datePointTransforms),
4171 dateSpanTransforms: hooks0.dateSpanTransforms.concat(hooks1.dateSpanTransforms),
4172 views: __assign({}, hooks0.views, hooks1.views),
4173 viewPropsTransformers: hooks0.viewPropsTransformers.concat(hooks1.viewPropsTransformers),
4174 isPropsValid: hooks1.isPropsValid || hooks0.isPropsValid,
4175 externalDefTransforms: hooks0.externalDefTransforms.concat(hooks1.externalDefTransforms),
4176 eventResizeJoinTransforms: hooks0.eventResizeJoinTransforms.concat(hooks1.eventResizeJoinTransforms),
4177 viewContainerModifiers: hooks0.viewContainerModifiers.concat(hooks1.viewContainerModifiers),
4178 eventDropTransformers: hooks0.eventDropTransformers.concat(hooks1.eventDropTransformers),
4179 calendarInteractions: hooks0.calendarInteractions.concat(hooks1.calendarInteractions),
4180 componentInteractions: hooks0.componentInteractions.concat(hooks1.componentInteractions),
4181 themeClasses: __assign({}, hooks0.themeClasses, hooks1.themeClasses),
4182 eventSourceDefs: hooks0.eventSourceDefs.concat(hooks1.eventSourceDefs),
4183 cmdFormatter: hooks1.cmdFormatter || hooks0.cmdFormatter,
4184 recurringTypes: hooks0.recurringTypes.concat(hooks1.recurringTypes),
4185 namedTimeZonedImpl: hooks1.namedTimeZonedImpl || hooks0.namedTimeZonedImpl,
4186 defaultView: hooks0.defaultView || hooks1.defaultView,
4187 elementDraggingImpl: hooks0.elementDraggingImpl || hooks1.elementDraggingImpl,
4188 optionChangeHandlers: __assign({}, hooks0.optionChangeHandlers, hooks1.optionChangeHandlers)
4189 };
4190 }
4191
4192 var eventSourceDef = {
4193 ignoreRange: true,
4194 parseMeta: function (raw) {
4195 if (Array.isArray(raw)) { // short form
4196 return raw;
4197 }
4198 else if (Array.isArray(raw.events)) {
4199 return raw.events;
4200 }
4201 return null;
4202 },
4203 fetch: function (arg, success) {
4204 success({
4205 rawEvents: arg.eventSource.meta
4206 });
4207 }
4208 };
4209 var ArrayEventSourcePlugin = createPlugin({
4210 eventSourceDefs: [eventSourceDef]
4211 });
4212
4213 var eventSourceDef$1 = {
4214 parseMeta: function (raw) {
4215 if (typeof raw === 'function') { // short form
4216 return raw;
4217 }
4218 else if (typeof raw.events === 'function') {
4219 return raw.events;
4220 }
4221 return null;
4222 },
4223 fetch: function (arg, success, failure) {
4224 var dateEnv = arg.calendar.dateEnv;
4225 var func = arg.eventSource.meta;
4226 unpromisify(func.bind(null, {
4227 start: dateEnv.toDate(arg.range.start),
4228 end: dateEnv.toDate(arg.range.end),
4229 startStr: dateEnv.formatIso(arg.range.start),
4230 endStr: dateEnv.formatIso(arg.range.end),
4231 timeZone: dateEnv.timeZone
4232 }), function (rawEvents) {
4233 success({ rawEvents: rawEvents }); // needs an object response
4234 }, failure // send errorObj directly to failure callback
4235 );
4236 }
4237 };
4238 var FuncEventSourcePlugin = createPlugin({
4239 eventSourceDefs: [eventSourceDef$1]
4240 });
4241
4242 function requestJson(method, url, params, successCallback, failureCallback) {
4243 method = method.toUpperCase();
4244 var body = null;
4245 if (method === 'GET') {
4246 url = injectQueryStringParams(url, params);
4247 }
4248 else {
4249 body = encodeParams(params);
4250 }
4251 var xhr = new XMLHttpRequest();
4252 xhr.open(method, url, true);
4253 if (method !== 'GET') {
4254 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
4255 }
4256 xhr.onload = function () {
4257 if (xhr.status >= 200 && xhr.status < 400) {
4258 try {
4259 var res = JSON.parse(xhr.responseText);
4260 successCallback(res, xhr);
4261 }
4262 catch (err) {
4263 failureCallback('Failure parsing JSON', xhr);
4264 }
4265 }
4266 else {
4267 failureCallback('Request failed', xhr);
4268 }
4269 };
4270 xhr.onerror = function () {
4271 failureCallback('Request failed', xhr);
4272 };
4273 xhr.send(body);
4274 }
4275 function injectQueryStringParams(url, params) {
4276 return url +
4277 (url.indexOf('?') === -1 ? '?' : '&') +
4278 encodeParams(params);
4279 }
4280 function encodeParams(params) {
4281 var parts = [];
4282 for (var key in params) {
4283 parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key]));
4284 }
4285 return parts.join('&');
4286 }
4287
4288 var eventSourceDef$2 = {
4289 parseMeta: function (raw) {
4290 if (typeof raw === 'string') { // short form
4291 raw = { url: raw };
4292 }
4293 else if (!raw || typeof raw !== 'object' || !raw.url) {
4294 return null;
4295 }
4296 return {
4297 url: raw.url,
4298 method: (raw.method || 'GET').toUpperCase(),
4299 extraParams: raw.extraParams,
4300 startParam: raw.startParam,
4301 endParam: raw.endParam,
4302 timeZoneParam: raw.timeZoneParam
4303 };
4304 },
4305 fetch: function (arg, success, failure) {
4306 var meta = arg.eventSource.meta;
4307 var requestParams = buildRequestParams(meta, arg.range, arg.calendar);
4308 requestJson(meta.method, meta.url, requestParams, function (rawEvents, xhr) {
4309 success({ rawEvents: rawEvents, xhr: xhr });
4310 }, function (errorMessage, xhr) {
4311 failure({ message: errorMessage, xhr: xhr });
4312 });
4313 }
4314 };
4315 var JsonFeedEventSourcePlugin = createPlugin({
4316 eventSourceDefs: [eventSourceDef$2]
4317 });
4318 function buildRequestParams(meta, range, calendar) {
4319 var dateEnv = calendar.dateEnv;
4320 var startParam;
4321 var endParam;
4322 var timeZoneParam;
4323 var customRequestParams;
4324 var params = {};
4325 startParam = meta.startParam;
4326 if (startParam == null) {
4327 startParam = calendar.opt('startParam');
4328 }
4329 endParam = meta.endParam;
4330 if (endParam == null) {
4331 endParam = calendar.opt('endParam');
4332 }
4333 timeZoneParam = meta.timeZoneParam;
4334 if (timeZoneParam == null) {
4335 timeZoneParam = calendar.opt('timeZoneParam');
4336 }
4337 // retrieve any outbound GET/POST data from the options
4338 if (typeof meta.extraParams === 'function') {
4339 // supplied as a function that returns a key/value object
4340 customRequestParams = meta.extraParams();
4341 }
4342 else {
4343 // probably supplied as a straight key/value object
4344 customRequestParams = meta.extraParams || {};
4345 }
4346 __assign(params, customRequestParams);
4347 params[startParam] = dateEnv.formatIso(range.start);
4348 params[endParam] = dateEnv.formatIso(range.end);
4349 if (dateEnv.timeZone !== 'local') {
4350 params[timeZoneParam] = dateEnv.timeZone;
4351 }
4352 return params;
4353 }
4354
4355 var recurring = {
4356 parse: function (rawEvent, leftoverProps, dateEnv) {
4357 var createMarker = dateEnv.createMarker.bind(dateEnv);
4358 var processors = {
4359 daysOfWeek: null,
4360 startTime: createDuration,
4361 endTime: createDuration,
4362 startRecur: createMarker,
4363 endRecur: createMarker
4364 };
4365 var props = refineProps(rawEvent, processors, {}, leftoverProps);
4366 var anyValid = false;
4367 for (var propName in props) {
4368 if (props[propName] != null) {
4369 anyValid = true;
4370 break;
4371 }
4372 }
4373 if (anyValid) {
4374 var duration = null;
4375 if ('duration' in leftoverProps) {
4376 duration = createDuration(leftoverProps.duration);
4377 delete leftoverProps.duration;
4378 }
4379 if (!duration && props.startTime && props.endTime) {
4380 duration = subtractDurations(props.endTime, props.startTime);
4381 }
4382 return {
4383 allDayGuess: Boolean(!props.startTime && !props.endTime),
4384 duration: duration,
4385 typeData: props // doesn't need endTime anymore but oh well
4386 };
4387 }
4388 return null;
4389 },
4390 expand: function (typeData, framingRange, dateEnv) {
4391 var clippedFramingRange = intersectRanges(framingRange, { start: typeData.startRecur, end: typeData.endRecur });
4392 if (clippedFramingRange) {
4393 return expandRanges(typeData.daysOfWeek, typeData.startTime, clippedFramingRange, dateEnv);
4394 }
4395 else {
4396 return [];
4397 }
4398 }
4399 };
4400 var SimpleRecurrencePlugin = createPlugin({
4401 recurringTypes: [recurring]
4402 });
4403 function expandRanges(daysOfWeek, startTime, framingRange, dateEnv) {
4404 var dowHash = daysOfWeek ? arrayToHash(daysOfWeek) : null;
4405 var dayMarker = startOfDay(framingRange.start);
4406 var endMarker = framingRange.end;
4407 var instanceStarts = [];
4408 while (dayMarker < endMarker) {
4409 var instanceStart
4410 // if everyday, or this particular day-of-week
4411 = void 0;
4412 // if everyday, or this particular day-of-week
4413 if (!dowHash || dowHash[dayMarker.getUTCDay()]) {
4414 if (startTime) {
4415 instanceStart = dateEnv.add(dayMarker, startTime);
4416 }
4417 else {
4418 instanceStart = dayMarker;
4419 }
4420 instanceStarts.push(instanceStart);
4421 }
4422 dayMarker = addDays(dayMarker, 1);
4423 }
4424 return instanceStarts;
4425 }
4426
4427 var DefaultOptionChangeHandlers = createPlugin({
4428 optionChangeHandlers: {
4429 events: function (events, calendar, deepEqual) {
4430 handleEventSources([events], calendar, deepEqual);
4431 },
4432 eventSources: handleEventSources,
4433 plugins: handlePlugins
4434 }
4435 });
4436 function handleEventSources(inputs, calendar, deepEqual) {
4437 var unfoundSources = hashValuesToArray(calendar.state.eventSources);
4438 var newInputs = [];
4439 for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) {
4440 var input = inputs_1[_i];
4441 var inputFound = false;
4442 for (var i = 0; i < unfoundSources.length; i++) {
4443 if (deepEqual(unfoundSources[i]._raw, input)) {
4444 unfoundSources.splice(i, 1); // delete
4445 inputFound = true;
4446 break;
4447 }
4448 }
4449 if (!inputFound) {
4450 newInputs.push(input);
4451 }
4452 }
4453 for (var _a = 0, unfoundSources_1 = unfoundSources; _a < unfoundSources_1.length; _a++) {
4454 var unfoundSource = unfoundSources_1[_a];
4455 calendar.dispatch({
4456 type: 'REMOVE_EVENT_SOURCE',
4457 sourceId: unfoundSource.sourceId
4458 });
4459 }
4460 for (var _b = 0, newInputs_1 = newInputs; _b < newInputs_1.length; _b++) {
4461 var newInput = newInputs_1[_b];
4462 calendar.addEventSource(newInput);
4463 }
4464 }
4465 // shortcoming: won't remove plugins
4466 function handlePlugins(inputs, calendar) {
4467 calendar.addPluginInputs(inputs); // will gracefully handle duplicates
4468 }
4469
4470 var config = {}; // TODO: make these options
4471 var globalDefaults = {
4472 defaultRangeSeparator: ' - ',
4473 titleRangeSeparator: ' \u2013 ',
4474 defaultTimedEventDuration: '01:00:00',
4475 defaultAllDayEventDuration: { day: 1 },
4476 forceEventDuration: false,
4477 nextDayThreshold: '00:00:00',
4478 // display
4479 columnHeader: true,
4480 defaultView: '',
4481 aspectRatio: 1.35,
4482 header: {
4483 left: 'title',
4484 center: '',
4485 right: 'today prev,next'
4486 },
4487 weekends: true,
4488 weekNumbers: false,
4489 weekNumberCalculation: 'local',
4490 editable: false,
4491 // nowIndicator: false,
4492 scrollTime: '06:00:00',
4493 minTime: '00:00:00',
4494 maxTime: '24:00:00',
4495 showNonCurrentDates: true,
4496 // event ajax
4497 lazyFetching: true,
4498 startParam: 'start',
4499 endParam: 'end',
4500 timeZoneParam: 'timeZone',
4501 timeZone: 'local',
4502 // allDayDefault: undefined,
4503 // locale
4504 locales: [],
4505 locale: '',
4506 // dir: will get this from the default locale
4507 // buttonIcons: null,
4508 // allows setting a min-height to the event segment to prevent short events overlapping each other
4509 timeGridEventMinHeight: 0,
4510 themeSystem: 'standard',
4511 // eventResizableFromStart: false,
4512 dragRevertDuration: 500,
4513 dragScroll: true,
4514 allDayMaintainDuration: false,
4515 // selectable: false,
4516 unselectAuto: true,
4517 // selectMinDistance: 0,
4518 dropAccept: '*',
4519 eventOrder: 'start,-duration,allDay,title',
4520 // ^ if start tie, longer events go before shorter. final tie-breaker is title text
4521 // rerenderDelay: null,
4522 eventLimit: false,
4523 eventLimitClick: 'popover',
4524 dayPopoverFormat: { month: 'long', day: 'numeric', year: 'numeric' },
4525 handleWindowResize: true,
4526 windowResizeDelay: 100,
4527 longPressDelay: 1000,
4528 eventDragMinDistance: 5 // only applies to mouse
4529 };
4530 var rtlDefaults = {
4531 header: {
4532 left: 'next,prev today',
4533 center: '',
4534 right: 'title'
4535 },
4536 buttonIcons: {
4537 // TODO: make RTL support the responibility of the theme
4538 prev: 'fc-icon-chevron-right',
4539 next: 'fc-icon-chevron-left',
4540 prevYear: 'fc-icon-chevrons-right',
4541 nextYear: 'fc-icon-chevrons-left'
4542 }
4543 };
4544 var complexOptions = [
4545 'header',
4546 'footer',
4547 'buttonText',
4548 'buttonIcons'
4549 ];
4550 // Merges an array of option objects into a single object
4551 function mergeOptions(optionObjs) {
4552 return mergeProps(optionObjs, complexOptions);
4553 }
4554 // TODO: move this stuff to a "plugin"-related file...
4555 var INTERNAL_PLUGINS = [
4556 ArrayEventSourcePlugin,
4557 FuncEventSourcePlugin,
4558 JsonFeedEventSourcePlugin,
4559 SimpleRecurrencePlugin,
4560 DefaultOptionChangeHandlers
4561 ];
4562 function refinePluginDefs(pluginInputs) {
4563 var plugins = [];
4564 for (var _i = 0, pluginInputs_1 = pluginInputs; _i < pluginInputs_1.length; _i++) {
4565 var pluginInput = pluginInputs_1[_i];
4566 if (typeof pluginInput === 'string') {
4567 var globalName = 'FullCalendar' + capitaliseFirstLetter(pluginInput);
4568 if (!window[globalName]) {
4569 console.warn('Plugin file not loaded for ' + pluginInput);
4570 }
4571 else {
4572 plugins.push(window[globalName].default); // is an ES6 module
4573 }
4574 }
4575 else {
4576 plugins.push(pluginInput);
4577 }
4578 }
4579 return INTERNAL_PLUGINS.concat(plugins);
4580 }
4581
4582 var RAW_EN_LOCALE = {
4583 code: 'en',
4584 week: {
4585 dow: 0,
4586 doy: 4 // 4 days need to be within the year to be considered the first week
4587 },
4588 dir: 'ltr',
4589 buttonText: {
4590 prev: 'prev',
4591 next: 'next',
4592 prevYear: 'prev year',
4593 nextYear: 'next year',
4594 year: 'year',
4595 today: 'today',
4596 month: 'month',
4597 week: 'week',
4598 day: 'day',
4599 list: 'list'
4600 },
4601 weekLabel: 'W',
4602 allDayText: 'all-day',
4603 eventLimitText: 'more',
4604 noEventsMessage: 'No events to display'
4605 };
4606 function parseRawLocales(explicitRawLocales) {
4607 var defaultCode = explicitRawLocales.length > 0 ? explicitRawLocales[0].code : 'en';
4608 var globalArray = window['FullCalendarLocalesAll'] || []; // from locales-all.js
4609 var globalObject = window['FullCalendarLocales'] || {}; // from locales/*.js. keys are meaningless
4610 var allRawLocales = globalArray.concat(// globalArray is low prio
4611 hashValuesToArray(globalObject), // medium prio
4612 explicitRawLocales // highest prio
4613 );
4614 var rawLocaleMap = {
4615 en: RAW_EN_LOCALE // necessary?
4616 };
4617 for (var _i = 0, allRawLocales_1 = allRawLocales; _i < allRawLocales_1.length; _i++) {
4618 var rawLocale = allRawLocales_1[_i];
4619 rawLocaleMap[rawLocale.code] = rawLocale;
4620 }
4621 return {
4622 map: rawLocaleMap,
4623 defaultCode: defaultCode
4624 };
4625 }
4626 function buildLocale(inputSingular, available) {
4627 if (typeof inputSingular === 'object' && !Array.isArray(inputSingular)) {
4628 return parseLocale(inputSingular.code, [inputSingular.code], inputSingular);
4629 }
4630 else {
4631 return queryLocale(inputSingular, available);
4632 }
4633 }
4634 function queryLocale(codeArg, available) {
4635 var codes = [].concat(codeArg || []); // will convert to array
4636 var raw = queryRawLocale(codes, available) || RAW_EN_LOCALE;
4637 return parseLocale(codeArg, codes, raw);
4638 }
4639 function queryRawLocale(codes, available) {
4640 for (var i = 0; i < codes.length; i++) {
4641 var parts = codes[i].toLocaleLowerCase().split('-');
4642 for (var j = parts.length; j > 0; j--) {
4643 var simpleId = parts.slice(0, j).join('-');
4644 if (available[simpleId]) {
4645 return available[simpleId];
4646 }
4647 }
4648 }
4649 return null;
4650 }
4651 function parseLocale(codeArg, codes, raw) {
4652 var merged = mergeProps([RAW_EN_LOCALE, raw], ['buttonText']);
4653 delete merged.code; // don't want this part of the options
4654 var week = merged.week;
4655 delete merged.week;
4656 return {
4657 codeArg: codeArg,
4658 codes: codes,
4659 week: week,
4660 simpleNumberFormat: new Intl.NumberFormat(codeArg),
4661 options: merged
4662 };
4663 }
4664
4665 var OptionsManager = /** @class */ (function () {
4666 function OptionsManager(overrides) {
4667 this.overrides = __assign({}, overrides); // make a copy
4668 this.dynamicOverrides = {};
4669 this.compute();
4670 }
4671 OptionsManager.prototype.mutate = function (updates, removals, isDynamic) {
4672 var overrideHash = isDynamic ? this.dynamicOverrides : this.overrides;
4673 __assign(overrideHash, updates);
4674 for (var _i = 0, removals_1 = removals; _i < removals_1.length; _i++) {
4675 var propName = removals_1[_i];
4676 delete overrideHash[propName];
4677 }
4678 this.compute();
4679 };
4680 // Computes the flattened options hash for the calendar and assigns to `this.options`.
4681 // Assumes this.overrides and this.dynamicOverrides have already been initialized.
4682 OptionsManager.prototype.compute = function () {
4683 // TODO: not a very efficient system
4684 var locales = firstDefined(// explicit locale option given?
4685 this.dynamicOverrides.locales, this.overrides.locales, globalDefaults.locales);
4686 var locale = firstDefined(// explicit locales option given?
4687 this.dynamicOverrides.locale, this.overrides.locale, globalDefaults.locale);
4688 var available = parseRawLocales(locales);
4689 var localeDefaults = buildLocale(locale || available.defaultCode, available.map).options;
4690 var dir = firstDefined(// based on options computed so far, is direction RTL?
4691 this.dynamicOverrides.dir, this.overrides.dir, localeDefaults.dir);
4692 var dirDefaults = dir === 'rtl' ? rtlDefaults : {};
4693 this.dirDefaults = dirDefaults;
4694 this.localeDefaults = localeDefaults;
4695 this.computed = mergeOptions([
4696 globalDefaults,
4697 dirDefaults,
4698 localeDefaults,
4699 this.overrides,
4700 this.dynamicOverrides
4701 ]);
4702 };
4703 return OptionsManager;
4704 }());
4705
4706 var calendarSystemClassMap = {};
4707 function registerCalendarSystem(name, theClass) {
4708 calendarSystemClassMap[name] = theClass;
4709 }
4710 function createCalendarSystem(name) {
4711 return new calendarSystemClassMap[name]();
4712 }
4713 var GregorianCalendarSystem = /** @class */ (function () {
4714 function GregorianCalendarSystem() {
4715 }
4716 GregorianCalendarSystem.prototype.getMarkerYear = function (d) {
4717 return d.getUTCFullYear();
4718 };
4719 GregorianCalendarSystem.prototype.getMarkerMonth = function (d) {
4720 return d.getUTCMonth();
4721 };
4722 GregorianCalendarSystem.prototype.getMarkerDay = function (d) {
4723 return d.getUTCDate();
4724 };
4725 GregorianCalendarSystem.prototype.arrayToMarker = function (arr) {
4726 return arrayToUtcDate(arr);
4727 };
4728 GregorianCalendarSystem.prototype.markerToArray = function (marker) {
4729 return dateToUtcArray(marker);
4730 };
4731 return GregorianCalendarSystem;
4732 }());
4733 registerCalendarSystem('gregory', GregorianCalendarSystem);
4734
4735 var ISO_RE = /^\s*(\d{4})(-(\d{2})(-(\d{2})([T ](\d{2}):(\d{2})(:(\d{2})(\.(\d+))?)?(Z|(([-+])(\d{2})(:?(\d{2}))?))?)?)?)?$/;
4736 function parse(str) {
4737 var m = ISO_RE.exec(str);
4738 if (m) {
4739 var marker = new Date(Date.UTC(Number(m[1]), m[3] ? Number(m[3]) - 1 : 0, Number(m[5] || 1), Number(m[7] || 0), Number(m[8] || 0), Number(m[10] || 0), m[12] ? Number('0.' + m[12]) * 1000 : 0));
4740 if (isValidDate(marker)) {
4741 var timeZoneOffset = null;
4742 if (m[13]) {
4743 timeZoneOffset = (m[15] === '-' ? -1 : 1) * (Number(m[16] || 0) * 60 +
4744 Number(m[18] || 0));
4745 }
4746 return {
4747 marker: marker,
4748 isTimeUnspecified: !m[6],
4749 timeZoneOffset: timeZoneOffset
4750 };
4751 }
4752 }
4753 return null;
4754 }
4755
4756 var DateEnv = /** @class */ (function () {
4757 function DateEnv(settings) {
4758 var timeZone = this.timeZone = settings.timeZone;
4759 var isNamedTimeZone = timeZone !== 'local' && timeZone !== 'UTC';
4760 if (settings.namedTimeZoneImpl && isNamedTimeZone) {
4761 this.namedTimeZoneImpl = new settings.namedTimeZoneImpl(timeZone);
4762 }
4763 this.canComputeOffset = Boolean(!isNamedTimeZone || this.namedTimeZoneImpl);
4764 this.calendarSystem = createCalendarSystem(settings.calendarSystem);
4765 this.locale = settings.locale;
4766 this.weekDow = settings.locale.week.dow;
4767 this.weekDoy = settings.locale.week.doy;
4768 if (settings.weekNumberCalculation === 'ISO') {
4769 this.weekDow = 1;
4770 this.weekDoy = 4;
4771 }
4772 if (typeof settings.firstDay === 'number') {
4773 this.weekDow = settings.firstDay;
4774 }
4775 if (typeof settings.weekNumberCalculation === 'function') {
4776 this.weekNumberFunc = settings.weekNumberCalculation;
4777 }
4778 this.weekLabel = settings.weekLabel != null ? settings.weekLabel : settings.locale.options.weekLabel;
4779 this.cmdFormatter = settings.cmdFormatter;
4780 }
4781 // Creating / Parsing
4782 DateEnv.prototype.createMarker = function (input) {
4783 var meta = this.createMarkerMeta(input);
4784 if (meta === null) {
4785 return null;
4786 }
4787 return meta.marker;
4788 };
4789 DateEnv.prototype.createNowMarker = function () {
4790 if (this.canComputeOffset) {
4791 return this.timestampToMarker(new Date().valueOf());
4792 }
4793 else {
4794 // if we can't compute the current date val for a timezone,
4795 // better to give the current local date vals than UTC
4796 return arrayToUtcDate(dateToLocalArray(new Date()));
4797 }
4798 };
4799 DateEnv.prototype.createMarkerMeta = function (input) {
4800 if (typeof input === 'string') {
4801 return this.parse(input);
4802 }
4803 var marker = null;
4804 if (typeof input === 'number') {
4805 marker = this.timestampToMarker(input);
4806 }
4807 else if (input instanceof Date) {
4808 input = input.valueOf();
4809 if (!isNaN(input)) {
4810 marker = this.timestampToMarker(input);
4811 }
4812 }
4813 else if (Array.isArray(input)) {
4814 marker = arrayToUtcDate(input);
4815 }
4816 if (marker === null || !isValidDate(marker)) {
4817 return null;
4818 }
4819 return { marker: marker, isTimeUnspecified: false, forcedTzo: null };
4820 };
4821 DateEnv.prototype.parse = function (s) {
4822 var parts = parse(s);
4823 if (parts === null) {
4824 return null;
4825 }
4826 var marker = parts.marker;
4827 var forcedTzo = null;
4828 if (parts.timeZoneOffset !== null) {
4829 if (this.canComputeOffset) {
4830 marker = this.timestampToMarker(marker.valueOf() - parts.timeZoneOffset * 60 * 1000);
4831 }
4832 else {
4833 forcedTzo = parts.timeZoneOffset;
4834 }
4835 }
4836 return { marker: marker, isTimeUnspecified: parts.isTimeUnspecified, forcedTzo: forcedTzo };
4837 };
4838 // Accessors
4839 DateEnv.prototype.getYear = function (marker) {
4840 return this.calendarSystem.getMarkerYear(marker);
4841 };
4842 DateEnv.prototype.getMonth = function (marker) {
4843 return this.calendarSystem.getMarkerMonth(marker);
4844 };
4845 // Adding / Subtracting
4846 DateEnv.prototype.add = function (marker, dur) {
4847 var a = this.calendarSystem.markerToArray(marker);
4848 a[0] += dur.years;
4849 a[1] += dur.months;
4850 a[2] += dur.days;
4851 a[6] += dur.milliseconds;
4852 return this.calendarSystem.arrayToMarker(a);
4853 };
4854 DateEnv.prototype.subtract = function (marker, dur) {
4855 var a = this.calendarSystem.markerToArray(marker);
4856 a[0] -= dur.years;
4857 a[1] -= dur.months;
4858 a[2] -= dur.days;
4859 a[6] -= dur.milliseconds;
4860 return this.calendarSystem.arrayToMarker(a);
4861 };
4862 DateEnv.prototype.addYears = function (marker, n) {
4863 var a = this.calendarSystem.markerToArray(marker);
4864 a[0] += n;
4865 return this.calendarSystem.arrayToMarker(a);
4866 };
4867 DateEnv.prototype.addMonths = function (marker, n) {
4868 var a = this.calendarSystem.markerToArray(marker);
4869 a[1] += n;
4870 return this.calendarSystem.arrayToMarker(a);
4871 };
4872 // Diffing Whole Units
4873 DateEnv.prototype.diffWholeYears = function (m0, m1) {
4874 var calendarSystem = this.calendarSystem;
4875 if (timeAsMs(m0) === timeAsMs(m1) &&
4876 calendarSystem.getMarkerDay(m0) === calendarSystem.getMarkerDay(m1) &&
4877 calendarSystem.getMarkerMonth(m0) === calendarSystem.getMarkerMonth(m1)) {
4878 return calendarSystem.getMarkerYear(m1) - calendarSystem.getMarkerYear(m0);
4879 }
4880 return null;
4881 };
4882 DateEnv.prototype.diffWholeMonths = function (m0, m1) {
4883 var calendarSystem = this.calendarSystem;
4884 if (timeAsMs(m0) === timeAsMs(m1) &&
4885 calendarSystem.getMarkerDay(m0) === calendarSystem.getMarkerDay(m1)) {
4886 return (calendarSystem.getMarkerMonth(m1) - calendarSystem.getMarkerMonth(m0)) +
4887 (calendarSystem.getMarkerYear(m1) - calendarSystem.getMarkerYear(m0)) * 12;
4888 }
4889 return null;
4890 };
4891 // Range / Duration
4892 DateEnv.prototype.greatestWholeUnit = function (m0, m1) {
4893 var n = this.diffWholeYears(m0, m1);
4894 if (n !== null) {
4895 return { unit: 'year', value: n };
4896 }
4897 n = this.diffWholeMonths(m0, m1);
4898 if (n !== null) {
4899 return { unit: 'month', value: n };
4900 }
4901 n = diffWholeWeeks(m0, m1);
4902 if (n !== null) {
4903 return { unit: 'week', value: n };
4904 }
4905 n = diffWholeDays(m0, m1);
4906 if (n !== null) {
4907 return { unit: 'day', value: n };
4908 }
4909 n = diffHours(m0, m1);
4910 if (isInt(n)) {
4911 return { unit: 'hour', value: n };
4912 }
4913 n = diffMinutes(m0, m1);
4914 if (isInt(n)) {
4915 return { unit: 'minute', value: n };
4916 }
4917 n = diffSeconds(m0, m1);
4918 if (isInt(n)) {
4919 return { unit: 'second', value: n };
4920 }
4921 return { unit: 'millisecond', value: m1.valueOf() - m0.valueOf() };
4922 };
4923 DateEnv.prototype.countDurationsBetween = function (m0, m1, d) {
4924 // TODO: can use greatestWholeUnit
4925 var diff;
4926 if (d.years) {
4927 diff = this.diffWholeYears(m0, m1);
4928 if (diff !== null) {
4929 return diff / asRoughYears(d);
4930 }
4931 }
4932 if (d.months) {
4933 diff = this.diffWholeMonths(m0, m1);
4934 if (diff !== null) {
4935 return diff / asRoughMonths(d);
4936 }
4937 }
4938 if (d.days) {
4939 diff = diffWholeDays(m0, m1);
4940 if (diff !== null) {
4941 return diff / asRoughDays(d);
4942 }
4943 }
4944 return (m1.valueOf() - m0.valueOf()) / asRoughMs(d);
4945 };
4946 // Start-Of
4947 DateEnv.prototype.startOf = function (m, unit) {
4948 if (unit === 'year') {
4949 return this.startOfYear(m);
4950 }
4951 else if (unit === 'month') {
4952 return this.startOfMonth(m);
4953 }
4954 else if (unit === 'week') {
4955 return this.startOfWeek(m);
4956 }
4957 else if (unit === 'day') {
4958 return startOfDay(m);
4959 }
4960 else if (unit === 'hour') {
4961 return startOfHour(m);
4962 }
4963 else if (unit === 'minute') {
4964 return startOfMinute(m);
4965 }
4966 else if (unit === 'second') {
4967 return startOfSecond(m);
4968 }
4969 };
4970 DateEnv.prototype.startOfYear = function (m) {
4971 return this.calendarSystem.arrayToMarker([
4972 this.calendarSystem.getMarkerYear(m)
4973 ]);
4974 };
4975 DateEnv.prototype.startOfMonth = function (m) {
4976 return this.calendarSystem.arrayToMarker([
4977 this.calendarSystem.getMarkerYear(m),
4978 this.calendarSystem.getMarkerMonth(m)
4979 ]);
4980 };
4981 DateEnv.prototype.startOfWeek = function (m) {
4982 return this.calendarSystem.arrayToMarker([
4983 this.calendarSystem.getMarkerYear(m),
4984 this.calendarSystem.getMarkerMonth(m),
4985 m.getUTCDate() - ((m.getUTCDay() - this.weekDow + 7) % 7)
4986 ]);
4987 };
4988 // Week Number
4989 DateEnv.prototype.computeWeekNumber = function (marker) {
4990 if (this.weekNumberFunc) {
4991 return this.weekNumberFunc(this.toDate(marker));
4992 }
4993 else {
4994 return weekOfYear(marker, this.weekDow, this.weekDoy);
4995 }
4996 };
4997 // TODO: choke on timeZoneName: long
4998 DateEnv.prototype.format = function (marker, formatter, dateOptions) {
4999 if (dateOptions === void 0) { dateOptions = {}; }
5000 return formatter.format({
…文件过长,仅显示前 5000 行