main.esm.js 64 KB

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