Açıklama Yok

main.esm.js 61KB

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