main.esm.js 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  1. /*!
  2. FullCalendar Time Grid Plugin v4.4.0
  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. All rights reserved.
  10. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  11. this file except in compliance with the License. You may obtain a copy of the
  12. License at http://www.apache.org/licenses/LICENSE-2.0
  13. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  15. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  16. MERCHANTABLITY OR NON-INFRINGEMENT.
  17. See the Apache Version 2.0 License for specific language governing permissions
  18. and limitations under the License.
  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. this.timeGrid.receiveProps(__assign({}, this.slicer.sliceProps(props, dateProfile, null, context.calendar, this.timeGrid, dayRanges), { dateProfile: dateProfile, cells: dayTable.cells[0] }), context);
  1233. };
  1234. SimpleTimeGrid.prototype.renderNowIndicator = function (date) {
  1235. this.timeGrid.renderNowIndicator(this.slicer.sliceNowDate(date, this.timeGrid, this.dayRanges), date);
  1236. };
  1237. SimpleTimeGrid.prototype.buildPositionCaches = function () {
  1238. this.timeGrid.buildPositionCaches();
  1239. };
  1240. SimpleTimeGrid.prototype.queryHit = function (positionLeft, positionTop) {
  1241. var rawHit = this.timeGrid.positionToHit(positionLeft, positionTop);
  1242. if (rawHit) {
  1243. return {
  1244. component: this.timeGrid,
  1245. dateSpan: rawHit.dateSpan,
  1246. dayEl: rawHit.dayEl,
  1247. rect: {
  1248. left: rawHit.relativeRect.left,
  1249. right: rawHit.relativeRect.right,
  1250. top: rawHit.relativeRect.top,
  1251. bottom: rawHit.relativeRect.bottom
  1252. },
  1253. layer: 0
  1254. };
  1255. }
  1256. };
  1257. return SimpleTimeGrid;
  1258. }(DateComponent));
  1259. function buildDayRanges(dayTable, dateProfile, dateEnv) {
  1260. var ranges = [];
  1261. for (var _i = 0, _a = dayTable.headerDates; _i < _a.length; _i++) {
  1262. var date = _a[_i];
  1263. ranges.push({
  1264. start: dateEnv.add(date, dateProfile.minTime),
  1265. end: dateEnv.add(date, dateProfile.maxTime)
  1266. });
  1267. }
  1268. return ranges;
  1269. }
  1270. var TimeGridSlicer = /** @class */ (function (_super) {
  1271. __extends(TimeGridSlicer, _super);
  1272. function TimeGridSlicer() {
  1273. return _super !== null && _super.apply(this, arguments) || this;
  1274. }
  1275. TimeGridSlicer.prototype.sliceRange = function (range, dayRanges) {
  1276. var segs = [];
  1277. for (var col = 0; col < dayRanges.length; col++) {
  1278. var segRange = intersectRanges(range, dayRanges[col]);
  1279. if (segRange) {
  1280. segs.push({
  1281. start: segRange.start,
  1282. end: segRange.end,
  1283. isStart: segRange.start.valueOf() === range.start.valueOf(),
  1284. isEnd: segRange.end.valueOf() === range.end.valueOf(),
  1285. col: col
  1286. });
  1287. }
  1288. }
  1289. return segs;
  1290. };
  1291. return TimeGridSlicer;
  1292. }(Slicer));
  1293. var TimeGridView = /** @class */ (function (_super) {
  1294. __extends(TimeGridView, _super);
  1295. function TimeGridView() {
  1296. var _this = _super !== null && _super.apply(this, arguments) || this;
  1297. _this.buildDayTable = memoize(buildDayTable);
  1298. return _this;
  1299. }
  1300. TimeGridView.prototype.render = function (props, context) {
  1301. _super.prototype.render.call(this, props, context); // for flags for updateSize. also _renderSkeleton/_unrenderSkeleton
  1302. var _a = this.props, dateProfile = _a.dateProfile, dateProfileGenerator = _a.dateProfileGenerator;
  1303. var nextDayThreshold = context.nextDayThreshold;
  1304. var dayTable = this.buildDayTable(dateProfile, dateProfileGenerator);
  1305. var splitProps = this.splitter.splitProps(props);
  1306. if (this.header) {
  1307. this.header.receiveProps({
  1308. dateProfile: dateProfile,
  1309. dates: dayTable.headerDates,
  1310. datesRepDistinctDays: true,
  1311. renderIntroHtml: this.renderHeadIntroHtml
  1312. }, context);
  1313. }
  1314. this.simpleTimeGrid.receiveProps(__assign({}, splitProps['timed'], { dateProfile: dateProfile,
  1315. dayTable: dayTable }), context);
  1316. if (this.simpleDayGrid) {
  1317. this.simpleDayGrid.receiveProps(__assign({}, splitProps['allDay'], { dateProfile: dateProfile,
  1318. dayTable: dayTable,
  1319. nextDayThreshold: nextDayThreshold, isRigid: false }), context);
  1320. }
  1321. this.startNowIndicator(dateProfile, dateProfileGenerator);
  1322. };
  1323. TimeGridView.prototype._renderSkeleton = function (context) {
  1324. _super.prototype._renderSkeleton.call(this, context);
  1325. if (context.options.columnHeader) {
  1326. this.header = new DayHeader(this.el.querySelector('.fc-head-container'));
  1327. }
  1328. this.simpleTimeGrid = new SimpleTimeGrid(this.timeGrid);
  1329. if (this.dayGrid) {
  1330. this.simpleDayGrid = new SimpleDayGrid(this.dayGrid);
  1331. }
  1332. };
  1333. TimeGridView.prototype._unrenderSkeleton = function () {
  1334. _super.prototype._unrenderSkeleton.call(this);
  1335. if (this.header) {
  1336. this.header.destroy();
  1337. }
  1338. this.simpleTimeGrid.destroy();
  1339. if (this.simpleDayGrid) {
  1340. this.simpleDayGrid.destroy();
  1341. }
  1342. };
  1343. TimeGridView.prototype.renderNowIndicator = function (date) {
  1344. this.simpleTimeGrid.renderNowIndicator(date);
  1345. };
  1346. return TimeGridView;
  1347. }(AbstractTimeGridView));
  1348. function buildDayTable(dateProfile, dateProfileGenerator) {
  1349. var daySeries = new DaySeries(dateProfile.renderRange, dateProfileGenerator);
  1350. return new DayTable(daySeries, false);
  1351. }
  1352. var main = createPlugin({
  1353. defaultView: 'timeGridWeek',
  1354. views: {
  1355. timeGrid: {
  1356. class: TimeGridView,
  1357. allDaySlot: true,
  1358. slotDuration: '00:30:00',
  1359. slotEventOverlap: true // a bad name. confused with overlap/constraint system
  1360. },
  1361. timeGridDay: {
  1362. type: 'timeGrid',
  1363. duration: { days: 1 }
  1364. },
  1365. timeGridWeek: {
  1366. type: 'timeGrid',
  1367. duration: { weeks: 1 }
  1368. }
  1369. }
  1370. });
  1371. export default main;
  1372. export { AbstractTimeGridView, TimeGrid, TimeGridSlicer, TimeGridView, buildDayRanges, buildDayTable };