You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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