better-staridc-MNBT
1/*!
2FullCalendar Time Grid Plugin v4.3.0
3Docs & License: https://fullcalendar.io/
4(c) 2019 Adam Shaw
5*/
6
7import { createFormatter, removeElement, cssToStr, isMultiDayRange, htmlEscape, compareByFieldSpecs, applyStyle, FgEventRenderer, buildSegCompareObj, FillRenderer, memoizeRendering, createDuration, wholeDivideDurations, findElements, PositionCache, startOfDay, asRoughMs, formatIsoTimeString, addDurations, htmlToElement, createElement, multiplyDuration, DateComponent, hasBgRendering, Splitter, diffDays, buildGotoAnchorHtml, getAllDayHtml, ScrollComponent, matchCellWidths, uncompensateScroll, compensateScroll, subtractInnerElHeight, View, memoize, intersectRanges, Slicer, DayHeader, DaySeries, DayTable, createPlugin } from '@fullcalendar/core';
8import { DayBgRow, DayGrid, SimpleDayGrid } from '@fullcalendar/daygrid';
9
10/*! *****************************************************************************
11Copyright (c) Microsoft Corporation. All rights reserved.
12Licensed under the Apache License, Version 2.0 (the "License"); you may not use
13this file except in compliance with the License. You may obtain a copy of the
14License at http://www.apache.org/licenses/LICENSE-2.0
15
16THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
18WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
19MERCHANTABLITY OR NON-INFRINGEMENT.
20
21See the Apache Version 2.0 License for specific language governing permissions
22and limitations under the License.
23***************************************************************************** */
24/* global Reflect, Promise */
25
26var extendStatics = function(d, b) {
27 extendStatics = Object.setPrototypeOf ||
28 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
29 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
30 return extendStatics(d, b);
31};
32
33function __extends(d, b) {
34 extendStatics(d, b);
35 function __() { this.constructor = d; }
36 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
37}
38
39var __assign = function() {
40 __assign = Object.assign || function __assign(t) {
41 for (var s, i = 1, n = arguments.length; i < n; i++) {
42 s = arguments[i];
43 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
44 }
45 return t;
46 };
47 return __assign.apply(this, arguments);
48};
49
50/*
51Only handles foreground segs.
52Does not own rendering. Use for low-level util methods by TimeGrid.
53*/
54var TimeGridEventRenderer = /** @class */ (function (_super) {
55 __extends(TimeGridEventRenderer, _super);
56 function TimeGridEventRenderer(timeGrid) {
57 var _this = _super.call(this, timeGrid.context) || this;
58 _this.timeGrid = timeGrid;
59 _this.fullTimeFormat = createFormatter({
60 hour: 'numeric',
61 minute: '2-digit',
62 separator: _this.context.options.defaultRangeSeparator
63 });
64 return _this;
65 }
66 // Given an array of foreground segments, render a DOM element for each, computes position,
67 // and attaches to the column inner-container elements.
68 TimeGridEventRenderer.prototype.attachSegs = function (segs, mirrorInfo) {
69 var segsByCol = this.timeGrid.groupSegsByCol(segs);
70 // order the segs within each column
71 // TODO: have groupSegsByCol do this?
72 for (var col = 0; col < segsByCol.length; col++) {
73 segsByCol[col] = this.sortEventSegs(segsByCol[col]);
74 }
75 this.segsByCol = segsByCol;
76 this.timeGrid.attachSegsByCol(segsByCol, this.timeGrid.fgContainerEls);
77 };
78 TimeGridEventRenderer.prototype.detachSegs = function (segs) {
79 segs.forEach(function (seg) {
80 removeElement(seg.el);
81 });
82 this.segsByCol = null;
83 };
84 TimeGridEventRenderer.prototype.computeSegSizes = function (allSegs) {
85 var _a = this, timeGrid = _a.timeGrid, segsByCol = _a.segsByCol;
86 var colCnt = timeGrid.colCnt;
87 timeGrid.computeSegVerticals(allSegs); // horizontals relies on this
88 if (segsByCol) {
89 for (var col = 0; col < colCnt; col++) {
90 this.computeSegHorizontals(segsByCol[col]); // compute horizontal coordinates, z-index's, and reorder the array
91 }
92 }
93 };
94 TimeGridEventRenderer.prototype.assignSegSizes = function (allSegs) {
95 var _a = this, timeGrid = _a.timeGrid, segsByCol = _a.segsByCol;
96 var colCnt = timeGrid.colCnt;
97 timeGrid.assignSegVerticals(allSegs); // horizontals relies on this
98 if (segsByCol) {
99 for (var col = 0; col < colCnt; col++) {
100 this.assignSegCss(segsByCol[col]);
101 }
102 }
103 };
104 // Computes a default event time formatting string if `eventTimeFormat` is not explicitly defined
105 TimeGridEventRenderer.prototype.computeEventTimeFormat = function () {
106 return {
107 hour: 'numeric',
108 minute: '2-digit',
109 meridiem: false
110 };
111 };
112 // Computes a default `displayEventEnd` value if one is not expliclty defined
113 TimeGridEventRenderer.prototype.computeDisplayEventEnd = function () {
114 return true;
115 };
116 // Renders the HTML for a single event segment's default rendering
117 TimeGridEventRenderer.prototype.renderSegHtml = function (seg, mirrorInfo) {
118 var view = this.context.view;
119 var eventRange = seg.eventRange;
120 var eventDef = eventRange.def;
121 var eventUi = eventRange.ui;
122 var allDay = eventDef.allDay;
123 var isDraggable = view.computeEventDraggable(eventDef, eventUi);
124 var isResizableFromStart = seg.isStart && view.computeEventStartResizable(eventDef, eventUi);
125 var isResizableFromEnd = seg.isEnd && view.computeEventEndResizable(eventDef, eventUi);
126 var classes = this.getSegClasses(seg, isDraggable, isResizableFromStart || isResizableFromEnd, mirrorInfo);
127 var skinCss = cssToStr(this.getSkinCss(eventUi));
128 var timeText;
129 var fullTimeText; // more verbose time text. for the print stylesheet
130 var startTimeText; // just the start time text
131 classes.unshift('fc-time-grid-event');
132 // if the event appears to span more than one day...
133 if (isMultiDayRange(eventRange.range)) {
134 // Don't display time text on segments that run entirely through a day.
135 // That would appear as midnight-midnight and would look dumb.
136 // Otherwise, display the time text for the *segment's* times (like 6pm-midnight or midnight-10am)
137 if (seg.isStart || seg.isEnd) {
138 var unzonedStart = seg.start;
139 var unzonedEnd = seg.end;
140 timeText = this._getTimeText(unzonedStart, unzonedEnd, allDay); // TODO: give the timezones
141 fullTimeText = this._getTimeText(unzonedStart, unzonedEnd, allDay, this.fullTimeFormat);
142 startTimeText = this._getTimeText(unzonedStart, unzonedEnd, allDay, null, false); // displayEnd=false
143 }
144 }
145 else {
146 // Display the normal time text for the *event's* times
147 timeText = this.getTimeText(eventRange);
148 fullTimeText = this.getTimeText(eventRange, this.fullTimeFormat);
149 startTimeText = this.getTimeText(eventRange, null, false); // displayEnd=false
150 }
151 return '<a class="' + classes.join(' ') + '"' +
152 (eventDef.url ?
153 ' href="' + htmlEscape(eventDef.url) + '"' :
154 '') +
155 (skinCss ?
156 ' style="' + skinCss + '"' :
157 '') +
158 '>' +
159 '<div class="fc-content">' +
160 (timeText ?
161 '<div class="fc-time"' +
162 ' data-start="' + htmlEscape(startTimeText) + '"' +
163 ' data-full="' + htmlEscape(fullTimeText) + '"' +
164 '>' +
165 '<span>' + htmlEscape(timeText) + '</span>' +
166 '</div>' :
167 '') +
168 (eventDef.title ?
169 '<div class="fc-title">' +
170 htmlEscape(eventDef.title) +
171 '</div>' :
172 '') +
173 '</div>' +
174 /* TODO: write CSS for this
175 (isResizableFromStart ?
176 '<div class="fc-resizer fc-start-resizer"></div>' :
177 ''
178 ) +
179 */
180 (isResizableFromEnd ?
181 '<div class="fc-resizer fc-end-resizer"></div>' :
182 '') +
183 '</a>';
184 };
185 // Given an array of segments that are all in the same column, sets the backwardCoord and forwardCoord on each.
186 // Assumed the segs are already ordered.
187 // NOTE: Also reorders the given array by date!
188 TimeGridEventRenderer.prototype.computeSegHorizontals = function (segs) {
189 var levels;
190 var level0;
191 var i;
192 levels = buildSlotSegLevels(segs);
193 computeForwardSlotSegs(levels);
194 if ((level0 = levels[0])) {
195 for (i = 0; i < level0.length; i++) {
196 computeSlotSegPressures(level0[i]);
197 }
198 for (i = 0; i < level0.length; i++) {
199 this.computeSegForwardBack(level0[i], 0, 0);
200 }
201 }
202 };
203 // Calculate seg.forwardCoord and seg.backwardCoord for the segment, where both values range
204 // from 0 to 1. If the calendar is left-to-right, the seg.backwardCoord maps to "left" and
205 // seg.forwardCoord maps to "right" (via percentage). Vice-versa if the calendar is right-to-left.
206 //
207 // The segment might be part of a "series", which means consecutive segments with the same pressure
208 // who's width is unknown until an edge has been hit. `seriesBackwardPressure` is the number of
209 // segments behind this one in the current series, and `seriesBackwardCoord` is the starting
210 // coordinate of the first segment in the series.
211 TimeGridEventRenderer.prototype.computeSegForwardBack = function (seg, seriesBackwardPressure, seriesBackwardCoord) {
212 var forwardSegs = seg.forwardSegs;
213 var i;
214 if (seg.forwardCoord === undefined) { // not already computed
215 if (!forwardSegs.length) {
216 // if there are no forward segments, this segment should butt up against the edge
217 seg.forwardCoord = 1;
218 }
219 else {
220 // sort highest pressure first
221 this.sortForwardSegs(forwardSegs);
222 // this segment's forwardCoord will be calculated from the backwardCoord of the
223 // highest-pressure forward segment.
224 this.computeSegForwardBack(forwardSegs[0], seriesBackwardPressure + 1, seriesBackwardCoord);
225 seg.forwardCoord = forwardSegs[0].backwardCoord;
226 }
227 // calculate the backwardCoord from the forwardCoord. consider the series
228 seg.backwardCoord = seg.forwardCoord -
229 (seg.forwardCoord - seriesBackwardCoord) / // available width for series
230 (seriesBackwardPressure + 1); // # of segments in the series
231 // use this segment's coordinates to computed the coordinates of the less-pressurized
232 // forward segments
233 for (i = 0; i < forwardSegs.length; i++) {
234 this.computeSegForwardBack(forwardSegs[i], 0, seg.forwardCoord);
235 }
236 }
237 };
238 TimeGridEventRenderer.prototype.sortForwardSegs = function (forwardSegs) {
239 var objs = forwardSegs.map(buildTimeGridSegCompareObj);
240 var specs = [
241 // put higher-pressure first
242 { field: 'forwardPressure', order: -1 },
243 // put segments that are closer to initial edge first (and favor ones with no coords yet)
244 { field: 'backwardCoord', order: 1 }
245 ].concat(this.context.view.eventOrderSpecs);
246 objs.sort(function (obj0, obj1) {
247 return compareByFieldSpecs(obj0, obj1, specs);
248 });
249 return objs.map(function (c) {
250 return c._seg;
251 });
252 };
253 // Given foreground event segments that have already had their position coordinates computed,
254 // assigns position-related CSS values to their elements.
255 TimeGridEventRenderer.prototype.assignSegCss = function (segs) {
256 for (var _i = 0, segs_1 = segs; _i < segs_1.length; _i++) {
257 var seg = segs_1[_i];
258 applyStyle(seg.el, this.generateSegCss(seg));
259 if (seg.level > 0) {
260 seg.el.classList.add('fc-time-grid-event-inset');
261 }
262 // if the event is short that the title will be cut off,
263 // attach a className that condenses the title into the time area.
264 if (seg.eventRange.def.title && seg.bottom - seg.top < 30) {
265 seg.el.classList.add('fc-short'); // TODO: "condensed" is a better name
266 }
267 }
268 };
269 // Generates an object with CSS properties/values that should be applied to an event segment element.
270 // Contains important positioning-related properties that should be applied to any event element, customized or not.
271 TimeGridEventRenderer.prototype.generateSegCss = function (seg) {
272 var shouldOverlap = this.context.options.slotEventOverlap;
273 var backwardCoord = seg.backwardCoord; // the left side if LTR. the right side if RTL. floating-point
274 var forwardCoord = seg.forwardCoord; // the right side if LTR. the left side if RTL. floating-point
275 var props = this.timeGrid.generateSegVerticalCss(seg); // get top/bottom first
276 var isRtl = this.timeGrid.isRtl;
277 var left; // amount of space from left edge, a fraction of the total width
278 var right; // amount of space from right edge, a fraction of the total width
279 if (shouldOverlap) {
280 // double the width, but don't go beyond the maximum forward coordinate (1.0)
281 forwardCoord = Math.min(1, backwardCoord + (forwardCoord - backwardCoord) * 2);
282 }
283 if (isRtl) {
284 left = 1 - forwardCoord;
285 right = backwardCoord;
286 }
287 else {
288 left = backwardCoord;
289 right = 1 - forwardCoord;
290 }
291 props.zIndex = seg.level + 1; // convert from 0-base to 1-based
292 props.left = left * 100 + '%';
293 props.right = right * 100 + '%';
294 if (shouldOverlap && seg.forwardPressure) {
295 // add padding to the edge so that forward stacked events don't cover the resizer's icon
296 props[isRtl ? 'marginLeft' : 'marginRight'] = 10 * 2; // 10 is a guesstimate of the icon's width
297 }
298 return props;
299 };
300 return TimeGridEventRenderer;
301}(FgEventRenderer));
302// Builds an array of segments "levels". The first level will be the leftmost tier of segments if the calendar is
303// left-to-right, or the rightmost if the calendar is right-to-left. Assumes the segments are already ordered by date.
304function buildSlotSegLevels(segs) {
305 var levels = [];
306 var i;
307 var seg;
308 var j;
309 for (i = 0; i < segs.length; i++) {
310 seg = segs[i];
311 // go through all the levels and stop on the first level where there are no collisions
312 for (j = 0; j < levels.length; j++) {
313 if (!computeSlotSegCollisions(seg, levels[j]).length) {
314 break;
315 }
316 }
317 seg.level = j;
318 (levels[j] || (levels[j] = [])).push(seg);
319 }
320 return levels;
321}
322// For every segment, figure out the other segments that are in subsequent
323// levels that also occupy the same vertical space. Accumulate in seg.forwardSegs
324function computeForwardSlotSegs(levels) {
325 var i;
326 var level;
327 var j;
328 var seg;
329 var k;
330 for (i = 0; i < levels.length; i++) {
331 level = levels[i];
332 for (j = 0; j < level.length; j++) {
333 seg = level[j];
334 seg.forwardSegs = [];
335 for (k = i + 1; k < levels.length; k++) {
336 computeSlotSegCollisions(seg, levels[k], seg.forwardSegs);
337 }
338 }
339 }
340}
341// Figure out which path forward (via seg.forwardSegs) results in the longest path until
342// the furthest edge is reached. The number of segments in this path will be seg.forwardPressure
343function computeSlotSegPressures(seg) {
344 var forwardSegs = seg.forwardSegs;
345 var forwardPressure = 0;
346 var i;
347 var forwardSeg;
348 if (seg.forwardPressure === undefined) { // not already computed
349 for (i = 0; i < forwardSegs.length; i++) {
350 forwardSeg = forwardSegs[i];
351 // figure out the child's maximum forward path
352 computeSlotSegPressures(forwardSeg);
353 // either use the existing maximum, or use the child's forward pressure
354 // plus one (for the forwardSeg itself)
355 forwardPressure = Math.max(forwardPressure, 1 + forwardSeg.forwardPressure);
356 }
357 seg.forwardPressure = forwardPressure;
358 }
359}
360// Find all the segments in `otherSegs` that vertically collide with `seg`.
361// Append into an optionally-supplied `results` array and return.
362function computeSlotSegCollisions(seg, otherSegs, results) {
363 if (results === void 0) { results = []; }
364 for (var i = 0; i < otherSegs.length; i++) {
365 if (isSlotSegCollision(seg, otherSegs[i])) {
366 results.push(otherSegs[i]);
367 }
368 }
369 return results;
370}
371// Do these segments occupy the same vertical space?
372function isSlotSegCollision(seg1, seg2) {
373 return seg1.bottom > seg2.top && seg1.top < seg2.bottom;
374}
375function buildTimeGridSegCompareObj(seg) {
376 var obj = buildSegCompareObj(seg);
377 obj.forwardPressure = seg.forwardPressure;
378 obj.backwardCoord = seg.backwardCoord;
379 return obj;
380}
381
382var TimeGridMirrorRenderer = /** @class */ (function (_super) {
383 __extends(TimeGridMirrorRenderer, _super);
384 function TimeGridMirrorRenderer() {
385 return _super !== null && _super.apply(this, arguments) || this;
386 }
387 TimeGridMirrorRenderer.prototype.attachSegs = function (segs, mirrorInfo) {
388 this.segsByCol = this.timeGrid.groupSegsByCol(segs);
389 this.timeGrid.attachSegsByCol(this.segsByCol, this.timeGrid.mirrorContainerEls);
390 this.sourceSeg = mirrorInfo.sourceSeg;
391 };
392 TimeGridMirrorRenderer.prototype.generateSegCss = function (seg) {
393 var props = _super.prototype.generateSegCss.call(this, seg);
394 var sourceSeg = this.sourceSeg;
395 if (sourceSeg && sourceSeg.col === seg.col) {
396 var sourceSegProps = _super.prototype.generateSegCss.call(this, sourceSeg);
397 props.left = sourceSegProps.left;
398 props.right = sourceSegProps.right;
399 props.marginLeft = sourceSegProps.marginLeft;
400 props.marginRight = sourceSegProps.marginRight;
401 }
402 return props;
403 };
404 return TimeGridMirrorRenderer;
405}(TimeGridEventRenderer));
406
407var TimeGridFillRenderer = /** @class */ (function (_super) {
408 __extends(TimeGridFillRenderer, _super);
409 function TimeGridFillRenderer(timeGrid) {
410 var _this = _super.call(this, timeGrid.context) || this;
411 _this.timeGrid = timeGrid;
412 return _this;
413 }
414 TimeGridFillRenderer.prototype.attachSegs = function (type, segs) {
415 var timeGrid = this.timeGrid;
416 var containerEls;
417 // TODO: more efficient lookup
418 if (type === 'bgEvent') {
419 containerEls = timeGrid.bgContainerEls;
420 }
421 else if (type === 'businessHours') {
422 containerEls = timeGrid.businessContainerEls;
423 }
424 else if (type === 'highlight') {
425 containerEls = timeGrid.highlightContainerEls;
426 }
427 timeGrid.attachSegsByCol(timeGrid.groupSegsByCol(segs), containerEls);
428 return segs.map(function (seg) {
429 return seg.el;
430 });
431 };
432 TimeGridFillRenderer.prototype.computeSegSizes = function (segs) {
433 this.timeGrid.computeSegVerticals(segs);
434 };
435 TimeGridFillRenderer.prototype.assignSegSizes = function (segs) {
436 this.timeGrid.assignSegVerticals(segs);
437 };
438 return TimeGridFillRenderer;
439}(FillRenderer));
440
441/* A component that renders one or more columns of vertical time slots
442----------------------------------------------------------------------------------------------------------------------*/
443// potential nice values for the slot-duration and interval-duration
444// from largest to smallest
445var AGENDA_STOCK_SUB_DURATIONS = [
446 { hours: 1 },
447 { minutes: 30 },
448 { minutes: 15 },
449 { seconds: 30 },
450 { seconds: 15 }
451];
452var TimeGrid = /** @class */ (function (_super) {
453 __extends(TimeGrid, _super);
454 function TimeGrid(context, el, renderProps) {
455 var _this = _super.call(this, context, el) || this;
456 _this.isSlatSizesDirty = false;
457 _this.isColSizesDirty = false;
458 _this.renderSlats = memoizeRendering(_this._renderSlats);
459 var eventRenderer = _this.eventRenderer = new TimeGridEventRenderer(_this);
460 var fillRenderer = _this.fillRenderer = new TimeGridFillRenderer(_this);
461 _this.mirrorRenderer = new TimeGridMirrorRenderer(_this);
462 var renderColumns = _this.renderColumns = memoizeRendering(_this._renderColumns, _this._unrenderColumns);
463 _this.renderBusinessHours = memoizeRendering(fillRenderer.renderSegs.bind(fillRenderer, 'businessHours'), fillRenderer.unrender.bind(fillRenderer, 'businessHours'), [renderColumns]);
464 _this.renderDateSelection = memoizeRendering(_this._renderDateSelection, _this._unrenderDateSelection, [renderColumns]);
465 _this.renderFgEvents = memoizeRendering(eventRenderer.renderSegs.bind(eventRenderer), eventRenderer.unrender.bind(eventRenderer), [renderColumns]);
466 _this.renderBgEvents = memoizeRendering(fillRenderer.renderSegs.bind(fillRenderer, 'bgEvent'), fillRenderer.unrender.bind(fillRenderer, 'bgEvent'), [renderColumns]);
467 _this.renderEventSelection = memoizeRendering(eventRenderer.selectByInstanceId.bind(eventRenderer), eventRenderer.unselectByInstanceId.bind(eventRenderer), [_this.renderFgEvents]);
468 _this.renderEventDrag = memoizeRendering(_this._renderEventDrag, _this._unrenderEventDrag, [renderColumns]);
469 _this.renderEventResize = memoizeRendering(_this._renderEventResize, _this._unrenderEventResize, [renderColumns]);
470 _this.processOptions();
471 el.innerHTML =
472 '<div class="fc-bg"></div>' +
473 '<div class="fc-slats"></div>' +
474 '<hr class="fc-divider ' + _this.theme.getClass('widgetHeader') + '" style="display:none" />';
475 _this.rootBgContainerEl = el.querySelector('.fc-bg');
476 _this.slatContainerEl = el.querySelector('.fc-slats');
477 _this.bottomRuleEl = el.querySelector('.fc-divider');
478 _this.renderProps = renderProps;
479 return _this;
480 }
481 /* Options
482 ------------------------------------------------------------------------------------------------------------------*/
483 // Parses various options into properties of this object
484 TimeGrid.prototype.processOptions = function () {
485 var slotDuration = this.opt('slotDuration');
486 var snapDuration = this.opt('snapDuration');
487 var snapsPerSlot;
488 var input;
489 slotDuration = createDuration(slotDuration);
490 snapDuration = snapDuration ? createDuration(snapDuration) : slotDuration;
491 snapsPerSlot = wholeDivideDurations(slotDuration, snapDuration);
492 if (snapsPerSlot === null) {
493 snapDuration = slotDuration;
494 snapsPerSlot = 1;
495 // TODO: say warning?
496 }
497 this.slotDuration = slotDuration;
498 this.snapDuration = snapDuration;
499 this.snapsPerSlot = snapsPerSlot;
500 // might be an array value (for TimelineView).
501 // if so, getting the most granular entry (the last one probably).
502 input = this.opt('slotLabelFormat');
503 if (Array.isArray(input)) {
504 input = input[input.length - 1];
505 }
506 this.labelFormat = createFormatter(input || {
507 hour: 'numeric',
508 minute: '2-digit',
509 omitZeroMinute: true,
510 meridiem: 'short'
511 });
512 input = this.opt('slotLabelInterval');
513 this.labelInterval = input ?
514 createDuration(input) :
515 this.computeLabelInterval(slotDuration);
516 };
517 // Computes an automatic value for slotLabelInterval
518 TimeGrid.prototype.computeLabelInterval = function (slotDuration) {
519 var i;
520 var labelInterval;
521 var slotsPerLabel;
522 // find the smallest stock label interval that results in more than one slots-per-label
523 for (i = AGENDA_STOCK_SUB_DURATIONS.length - 1; i >= 0; i--) {
524 labelInterval = createDuration(AGENDA_STOCK_SUB_DURATIONS[i]);
525 slotsPerLabel = wholeDivideDurations(labelInterval, slotDuration);
526 if (slotsPerLabel !== null && slotsPerLabel > 1) {
527 return labelInterval;
528 }
529 }
530 return slotDuration; // fall back
531 };
532 /* Rendering
533 ------------------------------------------------------------------------------------------------------------------*/
534 TimeGrid.prototype.render = function (props) {
535 var cells = props.cells;
536 this.colCnt = cells.length;
537 this.renderSlats(props.dateProfile);
538 this.renderColumns(props.cells, props.dateProfile);
539 this.renderBusinessHours(props.businessHourSegs);
540 this.renderDateSelection(props.dateSelectionSegs);
541 this.renderFgEvents(props.fgEventSegs);
542 this.renderBgEvents(props.bgEventSegs);
543 this.renderEventSelection(props.eventSelection);
544 this.renderEventDrag(props.eventDrag);
545 this.renderEventResize(props.eventResize);
546 };
547 TimeGrid.prototype.destroy = function () {
548 _super.prototype.destroy.call(this);
549 // should unrender everything else too
550 this.renderSlats.unrender();
551 this.renderColumns.unrender();
552 };
553 TimeGrid.prototype.updateSize = function (isResize) {
554 var _a = this, fillRenderer = _a.fillRenderer, eventRenderer = _a.eventRenderer, mirrorRenderer = _a.mirrorRenderer;
555 if (isResize || this.isSlatSizesDirty) {
556 this.buildSlatPositions();
557 this.isSlatSizesDirty = false;
558 }
559 if (isResize || this.isColSizesDirty) {
560 this.buildColPositions();
561 this.isColSizesDirty = false;
562 }
563 fillRenderer.computeSizes(isResize);
564 eventRenderer.computeSizes(isResize);
565 mirrorRenderer.computeSizes(isResize);
566 fillRenderer.assignSizes(isResize);
567 eventRenderer.assignSizes(isResize);
568 mirrorRenderer.assignSizes(isResize);
569 };
570 TimeGrid.prototype._renderSlats = function (dateProfile) {
571 var theme = this.theme;
572 this.slatContainerEl.innerHTML =
573 '<table class="' + theme.getClass('tableGrid') + '">' +
574 this.renderSlatRowHtml(dateProfile) +
575 '</table>';
576 this.slatEls = findElements(this.slatContainerEl, 'tr');
577 this.slatPositions = new PositionCache(this.el, this.slatEls, false, true // vertical
578 );
579 this.isSlatSizesDirty = true;
580 };
581 // Generates the HTML for the horizontal "slats" that run width-wise. Has a time axis on a side. Depends on RTL.
582 TimeGrid.prototype.renderSlatRowHtml = function (dateProfile) {
583 var _a = this, dateEnv = _a.dateEnv, theme = _a.theme, isRtl = _a.isRtl;
584 var html = '';
585 var dayStart = startOfDay(dateProfile.renderRange.start);
586 var slotTime = dateProfile.minTime;
587 var slotIterator = createDuration(0);
588 var slotDate; // will be on the view's first day, but we only care about its time
589 var isLabeled;
590 var axisHtml;
591 // Calculate the time for each slot
592 while (asRoughMs(slotTime) < asRoughMs(dateProfile.maxTime)) {
593 slotDate = dateEnv.add(dayStart, slotTime);
594 isLabeled = wholeDivideDurations(slotIterator, this.labelInterval) !== null;
595 axisHtml =
596 '<td class="fc-axis fc-time ' + theme.getClass('widgetContent') + '">' +
597 (isLabeled ?
598 '<span>' + // for matchCellWidths
599 htmlEscape(dateEnv.format(slotDate, this.labelFormat)) +
600 '</span>' :
601 '') +
602 '</td>';
603 html +=
604 '<tr data-time="' + formatIsoTimeString(slotDate) + '"' +
605 (isLabeled ? '' : ' class="fc-minor"') +
606 '>' +
607 (!isRtl ? axisHtml : '') +
608 '<td class="' + theme.getClass('widgetContent') + '"></td>' +
609 (isRtl ? axisHtml : '') +
610 '</tr>';
611 slotTime = addDurations(slotTime, this.slotDuration);
612 slotIterator = addDurations(slotIterator, this.slotDuration);
613 }
614 return html;
615 };
616 TimeGrid.prototype._renderColumns = function (cells, dateProfile) {
617 var _a = this, theme = _a.theme, dateEnv = _a.dateEnv, view = _a.view;
618 var bgRow = new DayBgRow(this.context);
619 this.rootBgContainerEl.innerHTML =
620 '<table class="' + theme.getClass('tableGrid') + '">' +
621 bgRow.renderHtml({
622 cells: cells,
623 dateProfile: dateProfile,
624 renderIntroHtml: this.renderProps.renderBgIntroHtml
625 }) +
626 '</table>';
627 this.colEls = findElements(this.el, '.fc-day, .fc-disabled-day');
628 for (var col = 0; col < this.colCnt; col++) {
629 this.publiclyTrigger('dayRender', [
630 {
631 date: dateEnv.toDate(cells[col].date),
632 el: this.colEls[col],
633 view: view
634 }
635 ]);
636 }
637 if (this.isRtl) {
638 this.colEls.reverse();
639 }
640 this.colPositions = new PositionCache(this.el, this.colEls, true, // horizontal
641 false);
642 this.renderContentSkeleton();
643 this.isColSizesDirty = true;
644 };
645 TimeGrid.prototype._unrenderColumns = function () {
646 this.unrenderContentSkeleton();
647 };
648 /* Content Skeleton
649 ------------------------------------------------------------------------------------------------------------------*/
650 // Renders the DOM that the view's content will live in
651 TimeGrid.prototype.renderContentSkeleton = function () {
652 var parts = [];
653 var skeletonEl;
654 parts.push(this.renderProps.renderIntroHtml());
655 for (var i = 0; i < this.colCnt; i++) {
656 parts.push('<td>' +
657 '<div class="fc-content-col">' +
658 '<div class="fc-event-container fc-mirror-container"></div>' +
659 '<div class="fc-event-container"></div>' +
660 '<div class="fc-highlight-container"></div>' +
661 '<div class="fc-bgevent-container"></div>' +
662 '<div class="fc-business-container"></div>' +
663 '</div>' +
664 '</td>');
665 }
666 if (this.isRtl) {
667 parts.reverse();
668 }
669 skeletonEl = this.contentSkeletonEl = htmlToElement('<div class="fc-content-skeleton">' +
670 '<table>' +
671 '<tr>' + parts.join('') + '</tr>' +
672 '</table>' +
673 '</div>');
674 this.colContainerEls = findElements(skeletonEl, '.fc-content-col');
675 this.mirrorContainerEls = findElements(skeletonEl, '.fc-mirror-container');
676 this.fgContainerEls = findElements(skeletonEl, '.fc-event-container:not(.fc-mirror-container)');
677 this.bgContainerEls = findElements(skeletonEl, '.fc-bgevent-container');
678 this.highlightContainerEls = findElements(skeletonEl, '.fc-highlight-container');
679 this.businessContainerEls = findElements(skeletonEl, '.fc-business-container');
680 if (this.isRtl) {
681 this.colContainerEls.reverse();
682 this.mirrorContainerEls.reverse();
683 this.fgContainerEls.reverse();
684 this.bgContainerEls.reverse();
685 this.highlightContainerEls.reverse();
686 this.businessContainerEls.reverse();
687 }
688 this.el.appendChild(skeletonEl);
689 };
690 TimeGrid.prototype.unrenderContentSkeleton = function () {
691 removeElement(this.contentSkeletonEl);
692 };
693 // Given a flat array of segments, return an array of sub-arrays, grouped by each segment's col
694 TimeGrid.prototype.groupSegsByCol = function (segs) {
695 var segsByCol = [];
696 var i;
697 for (i = 0; i < this.colCnt; i++) {
698 segsByCol.push([]);
699 }
700 for (i = 0; i < segs.length; i++) {
701 segsByCol[segs[i].col].push(segs[i]);
702 }
703 return segsByCol;
704 };
705 // Given segments grouped by column, insert the segments' elements into a parallel array of container
706 // elements, each living within a column.
707 TimeGrid.prototype.attachSegsByCol = function (segsByCol, containerEls) {
708 var col;
709 var segs;
710 var i;
711 for (col = 0; col < this.colCnt; col++) { // iterate each column grouping
712 segs = segsByCol[col];
713 for (i = 0; i < segs.length; i++) {
714 containerEls[col].appendChild(segs[i].el);
715 }
716 }
717 };
718 /* Now Indicator
719 ------------------------------------------------------------------------------------------------------------------*/
720 TimeGrid.prototype.getNowIndicatorUnit = function () {
721 return 'minute'; // will refresh on the minute
722 };
723 TimeGrid.prototype.renderNowIndicator = function (segs, date) {
724 // HACK: if date columns not ready for some reason (scheduler)
725 if (!this.colContainerEls) {
726 return;
727 }
728 var top = this.computeDateTop(date);
729 var nodes = [];
730 var i;
731 // render lines within the columns
732 for (i = 0; i < segs.length; i++) {
733 var lineEl = createElement('div', { className: 'fc-now-indicator fc-now-indicator-line' });
734 lineEl.style.top = top + 'px';
735 this.colContainerEls[segs[i].col].appendChild(lineEl);
736 nodes.push(lineEl);
737 }
738 // render an arrow over the axis
739 if (segs.length > 0) { // is the current time in view?
740 var arrowEl = createElement('div', { className: 'fc-now-indicator fc-now-indicator-arrow' });
741 arrowEl.style.top = top + 'px';
742 this.contentSkeletonEl.appendChild(arrowEl);
743 nodes.push(arrowEl);
744 }
745 this.nowIndicatorEls = nodes;
746 };
747 TimeGrid.prototype.unrenderNowIndicator = function () {
748 if (this.nowIndicatorEls) {
749 this.nowIndicatorEls.forEach(removeElement);
750 this.nowIndicatorEls = null;
751 }
752 };
753 /* Coordinates
754 ------------------------------------------------------------------------------------------------------------------*/
755 TimeGrid.prototype.getTotalSlatHeight = function () {
756 return this.slatContainerEl.getBoundingClientRect().height;
757 };
758 // Computes the top coordinate, relative to the bounds of the grid, of the given date.
759 // A `startOfDayDate` must be given for avoiding ambiguity over how to treat midnight.
760 TimeGrid.prototype.computeDateTop = function (when, startOfDayDate) {
761 if (!startOfDayDate) {
762 startOfDayDate = startOfDay(when);
763 }
764 return this.computeTimeTop(createDuration(when.valueOf() - startOfDayDate.valueOf()));
765 };
766 // Computes the top coordinate, relative to the bounds of the grid, of the given time (a Duration).
767 TimeGrid.prototype.computeTimeTop = function (duration) {
768 var len = this.slatEls.length;
769 var dateProfile = this.props.dateProfile;
770 var slatCoverage = (duration.milliseconds - asRoughMs(dateProfile.minTime)) / asRoughMs(this.slotDuration); // floating-point value of # of slots covered
771 var slatIndex;
772 var slatRemainder;
773 // compute a floating-point number for how many slats should be progressed through.
774 // from 0 to number of slats (inclusive)
775 // constrained because minTime/maxTime might be customized.
776 slatCoverage = Math.max(0, slatCoverage);
777 slatCoverage = Math.min(len, slatCoverage);
778 // an integer index of the furthest whole slat
779 // from 0 to number slats (*exclusive*, so len-1)
780 slatIndex = Math.floor(slatCoverage);
781 slatIndex = Math.min(slatIndex, len - 1);
782 // how much further through the slatIndex slat (from 0.0-1.0) must be covered in addition.
783 // could be 1.0 if slatCoverage is covering *all* the slots
784 slatRemainder = slatCoverage - slatIndex;
785 return this.slatPositions.tops[slatIndex] +
786 this.slatPositions.getHeight(slatIndex) * slatRemainder;
787 };
788 // For each segment in an array, computes and assigns its top and bottom properties
789 TimeGrid.prototype.computeSegVerticals = function (segs) {
790 var eventMinHeight = this.opt('timeGridEventMinHeight');
791 var i;
792 var seg;
793 var dayDate;
794 for (i = 0; i < segs.length; i++) {
795 seg = segs[i];
796 dayDate = this.props.cells[seg.col].date;
797 seg.top = this.computeDateTop(seg.start, dayDate);
798 seg.bottom = Math.max(seg.top + eventMinHeight, this.computeDateTop(seg.end, dayDate));
799 }
800 };
801 // Given segments that already have their top/bottom properties computed, applies those values to
802 // the segments' elements.
803 TimeGrid.prototype.assignSegVerticals = function (segs) {
804 var i;
805 var seg;
806 for (i = 0; i < segs.length; i++) {
807 seg = segs[i];
808 applyStyle(seg.el, this.generateSegVerticalCss(seg));
809 }
810 };
811 // Generates an object with CSS properties for the top/bottom coordinates of a segment element
812 TimeGrid.prototype.generateSegVerticalCss = function (seg) {
813 return {
814 top: seg.top,
815 bottom: -seg.bottom // flipped because needs to be space beyond bottom edge of event container
816 };
817 };
818 /* Sizing
819 ------------------------------------------------------------------------------------------------------------------*/
820 TimeGrid.prototype.buildPositionCaches = function () {
821 this.buildColPositions();
822 this.buildSlatPositions();
823 };
824 TimeGrid.prototype.buildColPositions = function () {
825 this.colPositions.build();
826 };
827 TimeGrid.prototype.buildSlatPositions = function () {
828 this.slatPositions.build();
829 };
830 /* Hit System
831 ------------------------------------------------------------------------------------------------------------------*/
832 TimeGrid.prototype.positionToHit = function (positionLeft, positionTop) {
833 var _a = this, dateEnv = _a.dateEnv, snapsPerSlot = _a.snapsPerSlot, slatPositions = _a.slatPositions, colPositions = _a.colPositions;
834 var colIndex = colPositions.leftToIndex(positionLeft);
835 var slatIndex = slatPositions.topToIndex(positionTop);
836 if (colIndex != null && slatIndex != null) {
837 var slatTop = slatPositions.tops[slatIndex];
838 var slatHeight = slatPositions.getHeight(slatIndex);
839 var partial = (positionTop - slatTop) / slatHeight; // floating point number between 0 and 1
840 var localSnapIndex = Math.floor(partial * snapsPerSlot); // the snap # relative to start of slat
841 var snapIndex = slatIndex * snapsPerSlot + localSnapIndex;
842 var dayDate = this.props.cells[colIndex].date;
843 var time = addDurations(this.props.dateProfile.minTime, multiplyDuration(this.snapDuration, snapIndex));
844 var start = dateEnv.add(dayDate, time);
845 var end = dateEnv.add(start, this.snapDuration);
846 return {
847 col: colIndex,
848 dateSpan: {
849 range: { start: start, end: end },
850 allDay: false
851 },
852 dayEl: this.colEls[colIndex],
853 relativeRect: {
854 left: colPositions.lefts[colIndex],
855 right: colPositions.rights[colIndex],
856 top: slatTop,
857 bottom: slatTop + slatHeight
858 }
859 };
860 }
861 };
862 /* Event Drag Visualization
863 ------------------------------------------------------------------------------------------------------------------*/
864 TimeGrid.prototype._renderEventDrag = function (state) {
865 if (state) {
866 this.eventRenderer.hideByHash(state.affectedInstances);
867 if (state.isEvent) {
868 this.mirrorRenderer.renderSegs(state.segs, { isDragging: true, sourceSeg: state.sourceSeg });
869 }
870 else {
871 this.fillRenderer.renderSegs('highlight', state.segs);
872 }
873 }
874 };
875 TimeGrid.prototype._unrenderEventDrag = function (state) {
876 if (state) {
877 this.eventRenderer.showByHash(state.affectedInstances);
878 this.mirrorRenderer.unrender(state.segs, { isDragging: true, sourceSeg: state.sourceSeg });
879 this.fillRenderer.unrender('highlight');
880 }
881 };
882 /* Event Resize Visualization
883 ------------------------------------------------------------------------------------------------------------------*/
884 TimeGrid.prototype._renderEventResize = function (state) {
885 if (state) {
886 this.eventRenderer.hideByHash(state.affectedInstances);
887 this.mirrorRenderer.renderSegs(state.segs, { isResizing: true, sourceSeg: state.sourceSeg });
888 }
889 };
890 TimeGrid.prototype._unrenderEventResize = function (state) {
891 if (state) {
892 this.eventRenderer.showByHash(state.affectedInstances);
893 this.mirrorRenderer.unrender(state.segs, { isResizing: true, sourceSeg: state.sourceSeg });
894 }
895 };
896 /* Selection
897 ------------------------------------------------------------------------------------------------------------------*/
898 // Renders a visual indication of a selection. Overrides the default, which was to simply render a highlight.
899 TimeGrid.prototype._renderDateSelection = function (segs) {
900 if (segs) {
901 if (this.opt('selectMirror')) {
902 this.mirrorRenderer.renderSegs(segs, { isSelecting: true });
903 }
904 else {
905 this.fillRenderer.renderSegs('highlight', segs);
906 }
907 }
908 };
909 TimeGrid.prototype._unrenderDateSelection = function (segs) {
910 this.mirrorRenderer.unrender(segs, { isSelecting: true });
911 this.fillRenderer.unrender('highlight');
912 };
913 return TimeGrid;
914}(DateComponent));
915
916var AllDaySplitter = /** @class */ (function (_super) {
917 __extends(AllDaySplitter, _super);
918 function AllDaySplitter() {
919 return _super !== null && _super.apply(this, arguments) || this;
920 }
921 AllDaySplitter.prototype.getKeyInfo = function () {
922 return {
923 allDay: {},
924 timed: {}
925 };
926 };
927 AllDaySplitter.prototype.getKeysForDateSpan = function (dateSpan) {
928 if (dateSpan.allDay) {
929 return ['allDay'];
930 }
931 else {
932 return ['timed'];
933 }
934 };
935 AllDaySplitter.prototype.getKeysForEventDef = function (eventDef) {
936 if (!eventDef.allDay) {
937 return ['timed'];
938 }
939 else if (hasBgRendering(eventDef)) {
940 return ['timed', 'allDay'];
941 }
942 else {
943 return ['allDay'];
944 }
945 };
946 return AllDaySplitter;
947}(Splitter));
948
949var TIMEGRID_ALL_DAY_EVENT_LIMIT = 5;
950var WEEK_HEADER_FORMAT = createFormatter({ week: 'short' });
951/* An abstract class for all timegrid-related views. Displays one more columns with time slots running vertically.
952----------------------------------------------------------------------------------------------------------------------*/
953// Is a manager for the TimeGrid subcomponent and possibly the DayGrid subcomponent (if allDaySlot is on).
954// Responsible for managing width/height.
955var TimeGridView = /** @class */ (function (_super) {
956 __extends(TimeGridView, _super);
957 function TimeGridView(context, viewSpec, dateProfileGenerator, parentEl) {
958 var _this = _super.call(this, context, viewSpec, dateProfileGenerator, parentEl) || this;
959 _this.splitter = new AllDaySplitter();
960 /* Header Render Methods
961 ------------------------------------------------------------------------------------------------------------------*/
962 // Generates the HTML that will go before the day-of week header cells
963 _this.renderHeadIntroHtml = function () {
964 var _a = _this, theme = _a.theme, dateEnv = _a.dateEnv;
965 var range = _this.props.dateProfile.renderRange;
966 var dayCnt = diffDays(range.start, range.end);
967 var weekText;
968 if (_this.opt('weekNumbers')) {
969 weekText = dateEnv.format(range.start, WEEK_HEADER_FORMAT);
970 return '' +
971 '<th class="fc-axis fc-week-number ' + theme.getClass('widgetHeader') + '" ' + _this.axisStyleAttr() + '>' +
972 buildGotoAnchorHtml(// aside from link, important for matchCellWidths
973 _this, { date: range.start, type: 'week', forceOff: dayCnt > 1 }, htmlEscape(weekText) // inner HTML
974 ) +
975 '</th>';
976 }
977 else {
978 return '<th class="fc-axis ' + theme.getClass('widgetHeader') + '" ' + _this.axisStyleAttr() + '></th>';
979 }
980 };
981 /* Time Grid Render Methods
982 ------------------------------------------------------------------------------------------------------------------*/
983 // Generates the HTML that goes before the bg of the TimeGrid slot area. Long vertical column.
984 _this.renderTimeGridBgIntroHtml = function () {
985 var theme = _this.theme;
986 return '<td class="fc-axis ' + theme.getClass('widgetContent') + '" ' + _this.axisStyleAttr() + '></td>';
987 };
988 // Generates the HTML that goes before all other types of cells.
989 // Affects content-skeleton, mirror-skeleton, highlight-skeleton for both the time-grid and day-grid.
990 _this.renderTimeGridIntroHtml = function () {
991 return '<td class="fc-axis" ' + _this.axisStyleAttr() + '></td>';
992 };
993 /* Day Grid Render Methods
994 ------------------------------------------------------------------------------------------------------------------*/
995 // Generates the HTML that goes before the all-day cells
996 _this.renderDayGridBgIntroHtml = function () {
997 var theme = _this.theme;
998 return '' +
999 '<td class="fc-axis ' + theme.getClass('widgetContent') + '" ' + _this.axisStyleAttr() + '>' +
1000 '<span>' + // needed for matchCellWidths
1001 getAllDayHtml(_this) +
1002 '</span>' +
1003 '</td>';
1004 };
1005 // Generates the HTML that goes before all other types of cells.
1006 // Affects content-skeleton, mirror-skeleton, highlight-skeleton for both the time-grid and day-grid.
1007 _this.renderDayGridIntroHtml = function () {
1008 return '<td class="fc-axis" ' + _this.axisStyleAttr() + '></td>';
1009 };
1010 _this.el.classList.add('fc-timeGrid-view');
1011 _this.el.innerHTML = _this.renderSkeletonHtml();
1012 _this.scroller = new ScrollComponent('hidden', // overflow x
1013 'auto' // overflow y
1014 );
1015 var timeGridWrapEl = _this.scroller.el;
1016 _this.el.querySelector('.fc-body > tr > td').appendChild(timeGridWrapEl);
1017 timeGridWrapEl.classList.add('fc-time-grid-container');
1018 var timeGridEl = createElement('div', { className: 'fc-time-grid' });
1019 timeGridWrapEl.appendChild(timeGridEl);
1020 _this.timeGrid = new TimeGrid(_this.context, timeGridEl, {
1021 renderBgIntroHtml: _this.renderTimeGridBgIntroHtml,
1022 renderIntroHtml: _this.renderTimeGridIntroHtml
1023 });
1024 if (_this.opt('allDaySlot')) { // should we display the "all-day" area?
1025 _this.dayGrid = new DayGrid(// the all-day subcomponent of this view
1026 _this.context, _this.el.querySelector('.fc-day-grid'), {
1027 renderNumberIntroHtml: _this.renderDayGridIntroHtml,
1028 renderBgIntroHtml: _this.renderDayGridBgIntroHtml,
1029 renderIntroHtml: _this.renderDayGridIntroHtml,
1030 colWeekNumbersVisible: false,
1031 cellWeekNumbersVisible: false
1032 });
1033 // have the day-grid extend it's coordinate area over the <hr> dividing the two grids
1034 var dividerEl = _this.el.querySelector('.fc-divider');
1035 _this.dayGrid.bottomCoordPadding = dividerEl.getBoundingClientRect().height;
1036 }
1037 return _this;
1038 }
1039 TimeGridView.prototype.destroy = function () {
1040 _super.prototype.destroy.call(this);
1041 this.timeGrid.destroy();
1042 if (this.dayGrid) {
1043 this.dayGrid.destroy();
1044 }
1045 this.scroller.destroy();
1046 };
1047 /* Rendering
1048 ------------------------------------------------------------------------------------------------------------------*/
1049 // Builds the HTML skeleton for the view.
1050 // The day-grid and time-grid components will render inside containers defined by this HTML.
1051 TimeGridView.prototype.renderSkeletonHtml = function () {
1052 var theme = this.theme;
1053 return '' +
1054 '<table class="' + theme.getClass('tableGrid') + '">' +
1055 (this.opt('columnHeader') ?
1056 '<thead class="fc-head">' +
1057 '<tr>' +
1058 '<td class="fc-head-container ' + theme.getClass('widgetHeader') + '"> </td>' +
1059 '</tr>' +
1060 '</thead>' :
1061 '') +
1062 '<tbody class="fc-body">' +
1063 '<tr>' +
1064 '<td class="' + theme.getClass('widgetContent') + '">' +
1065 (this.opt('allDaySlot') ?
1066 '<div class="fc-day-grid"></div>' +
1067 '<hr class="fc-divider ' + theme.getClass('widgetHeader') + '" />' :
1068 '') +
1069 '</td>' +
1070 '</tr>' +
1071 '</tbody>' +
1072 '</table>';
1073 };
1074 /* Now Indicator
1075 ------------------------------------------------------------------------------------------------------------------*/
1076 TimeGridView.prototype.getNowIndicatorUnit = function () {
1077 return this.timeGrid.getNowIndicatorUnit();
1078 };
1079 // subclasses should implement
1080 // renderNowIndicator(date: DateMarker) {
1081 // }
1082 TimeGridView.prototype.unrenderNowIndicator = function () {
1083 this.timeGrid.unrenderNowIndicator();
1084 };
1085 /* Dimensions
1086 ------------------------------------------------------------------------------------------------------------------*/
1087 TimeGridView.prototype.updateSize = function (isResize, viewHeight, isAuto) {
1088 _super.prototype.updateSize.call(this, isResize, viewHeight, isAuto); // will call updateBaseSize. important that executes first
1089 this.timeGrid.updateSize(isResize);
1090 if (this.dayGrid) {
1091 this.dayGrid.updateSize(isResize);
1092 }
1093 };
1094 // Adjusts the vertical dimensions of the view to the specified values
1095 TimeGridView.prototype.updateBaseSize = function (isResize, viewHeight, isAuto) {
1096 var _this = this;
1097 var eventLimit;
1098 var scrollerHeight;
1099 var scrollbarWidths;
1100 // make all axis cells line up
1101 this.axisWidth = matchCellWidths(findElements(this.el, '.fc-axis'));
1102 // hack to give the view some height prior to timeGrid's columns being rendered
1103 // TODO: separate setting height from scroller VS timeGrid.
1104 if (!this.timeGrid.colEls) {
1105 if (!isAuto) {
1106 scrollerHeight = this.computeScrollerHeight(viewHeight);
1107 this.scroller.setHeight(scrollerHeight);
1108 }
1109 return;
1110 }
1111 // set of fake row elements that must compensate when scroller has scrollbars
1112 var noScrollRowEls = findElements(this.el, '.fc-row').filter(function (node) {
1113 return !_this.scroller.el.contains(node);
1114 });
1115 // reset all dimensions back to the original state
1116 this.timeGrid.bottomRuleEl.style.display = 'none'; // will be shown later if this <hr> is necessary
1117 this.scroller.clear(); // sets height to 'auto' and clears overflow
1118 noScrollRowEls.forEach(uncompensateScroll);
1119 // limit number of events in the all-day area
1120 if (this.dayGrid) {
1121 this.dayGrid.removeSegPopover(); // kill the "more" popover if displayed
1122 eventLimit = this.opt('eventLimit');
1123 if (eventLimit && typeof eventLimit !== 'number') {
1124 eventLimit = TIMEGRID_ALL_DAY_EVENT_LIMIT; // make sure "auto" goes to a real number
1125 }
1126 if (eventLimit) {
1127 this.dayGrid.limitRows(eventLimit);
1128 }
1129 }
1130 if (!isAuto) { // should we force dimensions of the scroll container?
1131 scrollerHeight = this.computeScrollerHeight(viewHeight);
1132 this.scroller.setHeight(scrollerHeight);
1133 scrollbarWidths = this.scroller.getScrollbarWidths();
1134 if (scrollbarWidths.left || scrollbarWidths.right) { // using scrollbars?
1135 // make the all-day and header rows lines up
1136 noScrollRowEls.forEach(function (rowEl) {
1137 compensateScroll(rowEl, scrollbarWidths);
1138 });
1139 // the scrollbar compensation might have changed text flow, which might affect height, so recalculate
1140 // and reapply the desired height to the scroller.
1141 scrollerHeight = this.computeScrollerHeight(viewHeight);
1142 this.scroller.setHeight(scrollerHeight);
1143 }
1144 // guarantees the same scrollbar widths
1145 this.scroller.lockOverflow(scrollbarWidths);
1146 // if there's any space below the slats, show the horizontal rule.
1147 // this won't cause any new overflow, because lockOverflow already called.
1148 if (this.timeGrid.getTotalSlatHeight() < scrollerHeight) {
1149 this.timeGrid.bottomRuleEl.style.display = '';
1150 }
1151 }
1152 };
1153 // given a desired total height of the view, returns what the height of the scroller should be
1154 TimeGridView.prototype.computeScrollerHeight = function (viewHeight) {
1155 return viewHeight -
1156 subtractInnerElHeight(this.el, this.scroller.el); // everything that's NOT the scroller
1157 };
1158 /* Scroll
1159 ------------------------------------------------------------------------------------------------------------------*/
1160 // Computes the initial pre-configured scroll state prior to allowing the user to change it
1161 TimeGridView.prototype.computeDateScroll = function (duration) {
1162 var top = this.timeGrid.computeTimeTop(duration);
1163 // zoom can give weird floating-point values. rather scroll a little bit further
1164 top = Math.ceil(top);
1165 if (top) {
1166 top++; // to overcome top border that slots beyond the first have. looks better
1167 }
1168 return { top: top };
1169 };
1170 TimeGridView.prototype.queryDateScroll = function () {
1171 return { top: this.scroller.getScrollTop() };
1172 };
1173 TimeGridView.prototype.applyDateScroll = function (scroll) {
1174 if (scroll.top !== undefined) {
1175 this.scroller.setScrollTop(scroll.top);
1176 }
1177 };
1178 // Generates an HTML attribute string for setting the width of the axis, if it is known
1179 TimeGridView.prototype.axisStyleAttr = function () {
1180 if (this.axisWidth != null) {
1181 return 'style="width:' + this.axisWidth + 'px"';
1182 }
1183 return '';
1184 };
1185 return TimeGridView;
1186}(View));
1187TimeGridView.prototype.usesMinMaxTime = true; // indicates that minTime/maxTime affects rendering
1188
1189var SimpleTimeGrid = /** @class */ (function (_super) {
1190 __extends(SimpleTimeGrid, _super);
1191 function SimpleTimeGrid(context, timeGrid) {
1192 var _this = _super.call(this, context, timeGrid.el) || this;
1193 _this.buildDayRanges = memoize(buildDayRanges);
1194 _this.slicer = new TimeGridSlicer();
1195 _this.timeGrid = timeGrid;
1196 context.calendar.registerInteractiveComponent(_this, {
1197 el: _this.timeGrid.el
1198 });
1199 return _this;
1200 }
1201 SimpleTimeGrid.prototype.destroy = function () {
1202 _super.prototype.destroy.call(this);
1203 this.calendar.unregisterInteractiveComponent(this);
1204 };
1205 SimpleTimeGrid.prototype.render = function (props) {
1206 var dateProfile = props.dateProfile, dayTable = props.dayTable;
1207 var dayRanges = this.dayRanges = this.buildDayRanges(dayTable, dateProfile, this.dateEnv);
1208 this.timeGrid.receiveProps(__assign({}, this.slicer.sliceProps(props, dateProfile, null, this.timeGrid, dayRanges), { dateProfile: dateProfile, cells: dayTable.cells[0] }));
1209 };
1210 SimpleTimeGrid.prototype.renderNowIndicator = function (date) {
1211 this.timeGrid.renderNowIndicator(this.slicer.sliceNowDate(date, this.timeGrid, this.dayRanges), date);
1212 };
1213 SimpleTimeGrid.prototype.buildPositionCaches = function () {
1214 this.timeGrid.buildPositionCaches();
1215 };
1216 SimpleTimeGrid.prototype.queryHit = function (positionLeft, positionTop) {
1217 var rawHit = this.timeGrid.positionToHit(positionLeft, positionTop);
1218 if (rawHit) {
1219 return {
1220 component: this.timeGrid,
1221 dateSpan: rawHit.dateSpan,
1222 dayEl: rawHit.dayEl,
1223 rect: {
1224 left: rawHit.relativeRect.left,
1225 right: rawHit.relativeRect.right,
1226 top: rawHit.relativeRect.top,
1227 bottom: rawHit.relativeRect.bottom
1228 },
1229 layer: 0
1230 };
1231 }
1232 };
1233 return SimpleTimeGrid;
1234}(DateComponent));
1235function buildDayRanges(dayTable, dateProfile, dateEnv) {
1236 var ranges = [];
1237 for (var _i = 0, _a = dayTable.headerDates; _i < _a.length; _i++) {
1238 var date = _a[_i];
1239 ranges.push({
1240 start: dateEnv.add(date, dateProfile.minTime),
1241 end: dateEnv.add(date, dateProfile.maxTime)
1242 });
1243 }
1244 return ranges;
1245}
1246var TimeGridSlicer = /** @class */ (function (_super) {
1247 __extends(TimeGridSlicer, _super);
1248 function TimeGridSlicer() {
1249 return _super !== null && _super.apply(this, arguments) || this;
1250 }
1251 TimeGridSlicer.prototype.sliceRange = function (range, dayRanges) {
1252 var segs = [];
1253 for (var col = 0; col < dayRanges.length; col++) {
1254 var segRange = intersectRanges(range, dayRanges[col]);
1255 if (segRange) {
1256 segs.push({
1257 start: segRange.start,
1258 end: segRange.end,
1259 isStart: segRange.start.valueOf() === range.start.valueOf(),
1260 isEnd: segRange.end.valueOf() === range.end.valueOf(),
1261 col: col
1262 });
1263 }
1264 }
1265 return segs;
1266 };
1267 return TimeGridSlicer;
1268}(Slicer));
1269
1270var TimeGridView$1 = /** @class */ (function (_super) {
1271 __extends(TimeGridView, _super);
1272 function TimeGridView(_context, viewSpec, dateProfileGenerator, parentEl) {
1273 var _this = _super.call(this, _context, viewSpec, dateProfileGenerator, parentEl) || this;
1274 _this.buildDayTable = memoize(buildDayTable);
1275 if (_this.opt('columnHeader')) {
1276 _this.header = new DayHeader(_this.context, _this.el.querySelector('.fc-head-container'));
1277 }
1278 _this.simpleTimeGrid = new SimpleTimeGrid(_this.context, _this.timeGrid);
1279 if (_this.dayGrid) {
1280 _this.simpleDayGrid = new SimpleDayGrid(_this.context, _this.dayGrid);
1281 }
1282 return _this;
1283 }
1284 TimeGridView.prototype.destroy = function () {
1285 _super.prototype.destroy.call(this);
1286 if (this.header) {
1287 this.header.destroy();
1288 }
1289 this.simpleTimeGrid.destroy();
1290 if (this.simpleDayGrid) {
1291 this.simpleDayGrid.destroy();
1292 }
1293 };
1294 TimeGridView.prototype.render = function (props) {
1295 _super.prototype.render.call(this, props); // for flags for updateSize
1296 var dateProfile = this.props.dateProfile;
1297 var dayTable = this.buildDayTable(dateProfile, this.dateProfileGenerator);
1298 var splitProps = this.splitter.splitProps(props);
1299 if (this.header) {
1300 this.header.receiveProps({
1301 dateProfile: dateProfile,
1302 dates: dayTable.headerDates,
1303 datesRepDistinctDays: true,
1304 renderIntroHtml: this.renderHeadIntroHtml
1305 });
1306 }
1307 this.simpleTimeGrid.receiveProps(__assign({}, splitProps['timed'], { dateProfile: dateProfile,
1308 dayTable: dayTable }));
1309 if (this.simpleDayGrid) {
1310 this.simpleDayGrid.receiveProps(__assign({}, splitProps['allDay'], { dateProfile: dateProfile,
1311 dayTable: dayTable, nextDayThreshold: this.nextDayThreshold, isRigid: false }));
1312 }
1313 };
1314 TimeGridView.prototype.renderNowIndicator = function (date) {
1315 this.simpleTimeGrid.renderNowIndicator(date);
1316 };
1317 return TimeGridView;
1318}(TimeGridView));
1319function buildDayTable(dateProfile, dateProfileGenerator) {
1320 var daySeries = new DaySeries(dateProfile.renderRange, dateProfileGenerator);
1321 return new DayTable(daySeries, false);
1322}
1323
1324var main = createPlugin({
1325 defaultView: 'timeGridWeek',
1326 views: {
1327 timeGrid: {
1328 class: TimeGridView$1,
1329 allDaySlot: true,
1330 slotDuration: '00:30:00',
1331 slotEventOverlap: true // a bad name. confused with overlap/constraint system
1332 },
1333 timeGridDay: {
1334 type: 'timeGrid',
1335 duration: { days: 1 }
1336 },
1337 timeGridWeek: {
1338 type: 'timeGrid',
1339 duration: { weeks: 1 }
1340 }
1341 }
1342});
1343
1344export default main;
1345export { TimeGridView as AbstractTimeGridView, TimeGrid, TimeGridSlicer, TimeGridView$1 as TimeGridView, buildDayRanges, buildDayTable };