interaction.js 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160
  1. /*!
  2. FullCalendar v5.11.5
  3. Docs & License: https://fullcalendar.io/
  4. (c) 2022 Adam Shaw
  5. */
  6. import { config, elementClosest, Emitter, applyStyle, whenTransitionDone, removeElement, ScrollController, ElementScrollController, computeInnerRect, WindowScrollController, getElRoot, preventSelection, preventContextMenu, allowSelection, allowContextMenu, ElementDragging, computeRect, getClippingParents, pointInsideRect, isDateSpansEqual, constrainPoint, intersectRects, getRectCenter, diffPoints, mapHash, rangeContainsRange, interactionSettingsToStore, Interaction, isDateSelectionValid, enableCursor, disableCursor, triggerDateSelect, compareNumbers, getElSeg, getRelevantEvents, EventApi, createEmptyEventStore, applyMutationToEventStore, isInteractionValid, buildEventApis, interactionSettingsStore, startOfDay, diffDates, createDuration, getEventTargetViaRoot, identity, eventTupleToStore, parseDragMeta, elementMatches, refineEventDef, parseEventDef, getDefaultEventEnd, createEventInstance, BASE_OPTION_DEFAULTS, createPlugin } from '@fullcalendar/common';
  7. import { __extends, __assign } from 'tslib';
  8. config.touchMouseIgnoreWait = 500;
  9. var ignoreMouseDepth = 0;
  10. var listenerCnt = 0;
  11. var isWindowTouchMoveCancelled = false;
  12. /*
  13. Uses a "pointer" abstraction, which monitors UI events for both mouse and touch.
  14. Tracks when the pointer "drags" on a certain element, meaning down+move+up.
  15. Also, tracks if there was touch-scrolling.
  16. Also, can prevent touch-scrolling from happening.
  17. Also, can fire pointermove events when scrolling happens underneath, even when no real pointer movement.
  18. emits:
  19. - pointerdown
  20. - pointermove
  21. - pointerup
  22. */
  23. var PointerDragging = /** @class */ (function () {
  24. function PointerDragging(containerEl) {
  25. var _this = this;
  26. this.subjectEl = null;
  27. // options that can be directly assigned by caller
  28. this.selector = ''; // will cause subjectEl in all emitted events to be this element
  29. this.handleSelector = '';
  30. this.shouldIgnoreMove = false;
  31. this.shouldWatchScroll = true; // for simulating pointermove on scroll
  32. // internal states
  33. this.isDragging = false;
  34. this.isTouchDragging = false;
  35. this.wasTouchScroll = false;
  36. // Mouse
  37. // ----------------------------------------------------------------------------------------------------
  38. this.handleMouseDown = function (ev) {
  39. if (!_this.shouldIgnoreMouse() &&
  40. isPrimaryMouseButton(ev) &&
  41. _this.tryStart(ev)) {
  42. var pev = _this.createEventFromMouse(ev, true);
  43. _this.emitter.trigger('pointerdown', pev);
  44. _this.initScrollWatch(pev);
  45. if (!_this.shouldIgnoreMove) {
  46. document.addEventListener('mousemove', _this.handleMouseMove);
  47. }
  48. document.addEventListener('mouseup', _this.handleMouseUp);
  49. }
  50. };
  51. this.handleMouseMove = function (ev) {
  52. var pev = _this.createEventFromMouse(ev);
  53. _this.recordCoords(pev);
  54. _this.emitter.trigger('pointermove', pev);
  55. };
  56. this.handleMouseUp = function (ev) {
  57. document.removeEventListener('mousemove', _this.handleMouseMove);
  58. document.removeEventListener('mouseup', _this.handleMouseUp);
  59. _this.emitter.trigger('pointerup', _this.createEventFromMouse(ev));
  60. _this.cleanup(); // call last so that pointerup has access to props
  61. };
  62. // Touch
  63. // ----------------------------------------------------------------------------------------------------
  64. this.handleTouchStart = function (ev) {
  65. if (_this.tryStart(ev)) {
  66. _this.isTouchDragging = true;
  67. var pev = _this.createEventFromTouch(ev, true);
  68. _this.emitter.trigger('pointerdown', pev);
  69. _this.initScrollWatch(pev);
  70. // unlike mouse, need to attach to target, not document
  71. // https://stackoverflow.com/a/45760014
  72. var targetEl = ev.target;
  73. if (!_this.shouldIgnoreMove) {
  74. targetEl.addEventListener('touchmove', _this.handleTouchMove);
  75. }
  76. targetEl.addEventListener('touchend', _this.handleTouchEnd);
  77. targetEl.addEventListener('touchcancel', _this.handleTouchEnd); // treat it as a touch end
  78. // attach a handler to get called when ANY scroll action happens on the page.
  79. // this was impossible to do with normal on/off because 'scroll' doesn't bubble.
  80. // http://stackoverflow.com/a/32954565/96342
  81. window.addEventListener('scroll', _this.handleTouchScroll, true);
  82. }
  83. };
  84. this.handleTouchMove = function (ev) {
  85. var pev = _this.createEventFromTouch(ev);
  86. _this.recordCoords(pev);
  87. _this.emitter.trigger('pointermove', pev);
  88. };
  89. this.handleTouchEnd = function (ev) {
  90. if (_this.isDragging) { // done to guard against touchend followed by touchcancel
  91. var targetEl = ev.target;
  92. targetEl.removeEventListener('touchmove', _this.handleTouchMove);
  93. targetEl.removeEventListener('touchend', _this.handleTouchEnd);
  94. targetEl.removeEventListener('touchcancel', _this.handleTouchEnd);
  95. window.removeEventListener('scroll', _this.handleTouchScroll, true); // useCaptured=true
  96. _this.emitter.trigger('pointerup', _this.createEventFromTouch(ev));
  97. _this.cleanup(); // call last so that pointerup has access to props
  98. _this.isTouchDragging = false;
  99. startIgnoringMouse();
  100. }
  101. };
  102. this.handleTouchScroll = function () {
  103. _this.wasTouchScroll = true;
  104. };
  105. this.handleScroll = function (ev) {
  106. if (!_this.shouldIgnoreMove) {
  107. var pageX = (window.pageXOffset - _this.prevScrollX) + _this.prevPageX;
  108. var pageY = (window.pageYOffset - _this.prevScrollY) + _this.prevPageY;
  109. _this.emitter.trigger('pointermove', {
  110. origEvent: ev,
  111. isTouch: _this.isTouchDragging,
  112. subjectEl: _this.subjectEl,
  113. pageX: pageX,
  114. pageY: pageY,
  115. deltaX: pageX - _this.origPageX,
  116. deltaY: pageY - _this.origPageY,
  117. });
  118. }
  119. };
  120. this.containerEl = containerEl;
  121. this.emitter = new Emitter();
  122. containerEl.addEventListener('mousedown', this.handleMouseDown);
  123. containerEl.addEventListener('touchstart', this.handleTouchStart, { passive: true });
  124. listenerCreated();
  125. }
  126. PointerDragging.prototype.destroy = function () {
  127. this.containerEl.removeEventListener('mousedown', this.handleMouseDown);
  128. this.containerEl.removeEventListener('touchstart', this.handleTouchStart, { passive: true });
  129. listenerDestroyed();
  130. };
  131. PointerDragging.prototype.tryStart = function (ev) {
  132. var subjectEl = this.querySubjectEl(ev);
  133. var downEl = ev.target;
  134. if (subjectEl &&
  135. (!this.handleSelector || elementClosest(downEl, this.handleSelector))) {
  136. this.subjectEl = subjectEl;
  137. this.isDragging = true; // do this first so cancelTouchScroll will work
  138. this.wasTouchScroll = false;
  139. return true;
  140. }
  141. return false;
  142. };
  143. PointerDragging.prototype.cleanup = function () {
  144. isWindowTouchMoveCancelled = false;
  145. this.isDragging = false;
  146. this.subjectEl = null;
  147. // keep wasTouchScroll around for later access
  148. this.destroyScrollWatch();
  149. };
  150. PointerDragging.prototype.querySubjectEl = function (ev) {
  151. if (this.selector) {
  152. return elementClosest(ev.target, this.selector);
  153. }
  154. return this.containerEl;
  155. };
  156. PointerDragging.prototype.shouldIgnoreMouse = function () {
  157. return ignoreMouseDepth || this.isTouchDragging;
  158. };
  159. // can be called by user of this class, to cancel touch-based scrolling for the current drag
  160. PointerDragging.prototype.cancelTouchScroll = function () {
  161. if (this.isDragging) {
  162. isWindowTouchMoveCancelled = true;
  163. }
  164. };
  165. // Scrolling that simulates pointermoves
  166. // ----------------------------------------------------------------------------------------------------
  167. PointerDragging.prototype.initScrollWatch = function (ev) {
  168. if (this.shouldWatchScroll) {
  169. this.recordCoords(ev);
  170. window.addEventListener('scroll', this.handleScroll, true); // useCapture=true
  171. }
  172. };
  173. PointerDragging.prototype.recordCoords = function (ev) {
  174. if (this.shouldWatchScroll) {
  175. this.prevPageX = ev.pageX;
  176. this.prevPageY = ev.pageY;
  177. this.prevScrollX = window.pageXOffset;
  178. this.prevScrollY = window.pageYOffset;
  179. }
  180. };
  181. PointerDragging.prototype.destroyScrollWatch = function () {
  182. if (this.shouldWatchScroll) {
  183. window.removeEventListener('scroll', this.handleScroll, true); // useCaptured=true
  184. }
  185. };
  186. // Event Normalization
  187. // ----------------------------------------------------------------------------------------------------
  188. PointerDragging.prototype.createEventFromMouse = function (ev, isFirst) {
  189. var deltaX = 0;
  190. var deltaY = 0;
  191. // TODO: repeat code
  192. if (isFirst) {
  193. this.origPageX = ev.pageX;
  194. this.origPageY = ev.pageY;
  195. }
  196. else {
  197. deltaX = ev.pageX - this.origPageX;
  198. deltaY = ev.pageY - this.origPageY;
  199. }
  200. return {
  201. origEvent: ev,
  202. isTouch: false,
  203. subjectEl: this.subjectEl,
  204. pageX: ev.pageX,
  205. pageY: ev.pageY,
  206. deltaX: deltaX,
  207. deltaY: deltaY,
  208. };
  209. };
  210. PointerDragging.prototype.createEventFromTouch = function (ev, isFirst) {
  211. var touches = ev.touches;
  212. var pageX;
  213. var pageY;
  214. var deltaX = 0;
  215. var deltaY = 0;
  216. // if touch coords available, prefer,
  217. // because FF would give bad ev.pageX ev.pageY
  218. if (touches && touches.length) {
  219. pageX = touches[0].pageX;
  220. pageY = touches[0].pageY;
  221. }
  222. else {
  223. pageX = ev.pageX;
  224. pageY = ev.pageY;
  225. }
  226. // TODO: repeat code
  227. if (isFirst) {
  228. this.origPageX = pageX;
  229. this.origPageY = pageY;
  230. }
  231. else {
  232. deltaX = pageX - this.origPageX;
  233. deltaY = pageY - this.origPageY;
  234. }
  235. return {
  236. origEvent: ev,
  237. isTouch: true,
  238. subjectEl: this.subjectEl,
  239. pageX: pageX,
  240. pageY: pageY,
  241. deltaX: deltaX,
  242. deltaY: deltaY,
  243. };
  244. };
  245. return PointerDragging;
  246. }());
  247. // Returns a boolean whether this was a left mouse click and no ctrl key (which means right click on Mac)
  248. function isPrimaryMouseButton(ev) {
  249. return ev.button === 0 && !ev.ctrlKey;
  250. }
  251. // Ignoring fake mouse events generated by touch
  252. // ----------------------------------------------------------------------------------------------------
  253. function startIgnoringMouse() {
  254. ignoreMouseDepth += 1;
  255. setTimeout(function () {
  256. ignoreMouseDepth -= 1;
  257. }, config.touchMouseIgnoreWait);
  258. }
  259. // We want to attach touchmove as early as possible for Safari
  260. // ----------------------------------------------------------------------------------------------------
  261. function listenerCreated() {
  262. listenerCnt += 1;
  263. if (listenerCnt === 1) {
  264. window.addEventListener('touchmove', onWindowTouchMove, { passive: false });
  265. }
  266. }
  267. function listenerDestroyed() {
  268. listenerCnt -= 1;
  269. if (!listenerCnt) {
  270. window.removeEventListener('touchmove', onWindowTouchMove, { passive: false });
  271. }
  272. }
  273. function onWindowTouchMove(ev) {
  274. if (isWindowTouchMoveCancelled) {
  275. ev.preventDefault();
  276. }
  277. }
  278. /*
  279. An effect in which an element follows the movement of a pointer across the screen.
  280. The moving element is a clone of some other element.
  281. Must call start + handleMove + stop.
  282. */
  283. var ElementMirror = /** @class */ (function () {
  284. function ElementMirror() {
  285. this.isVisible = false; // must be explicitly enabled
  286. this.sourceEl = null;
  287. this.mirrorEl = null;
  288. this.sourceElRect = null; // screen coords relative to viewport
  289. // options that can be set directly by caller
  290. this.parentNode = document.body; // HIGHLY SUGGESTED to set this to sidestep ShadowDOM issues
  291. this.zIndex = 9999;
  292. this.revertDuration = 0;
  293. }
  294. ElementMirror.prototype.start = function (sourceEl, pageX, pageY) {
  295. this.sourceEl = sourceEl;
  296. this.sourceElRect = this.sourceEl.getBoundingClientRect();
  297. this.origScreenX = pageX - window.pageXOffset;
  298. this.origScreenY = pageY - window.pageYOffset;
  299. this.deltaX = 0;
  300. this.deltaY = 0;
  301. this.updateElPosition();
  302. };
  303. ElementMirror.prototype.handleMove = function (pageX, pageY) {
  304. this.deltaX = (pageX - window.pageXOffset) - this.origScreenX;
  305. this.deltaY = (pageY - window.pageYOffset) - this.origScreenY;
  306. this.updateElPosition();
  307. };
  308. // can be called before start
  309. ElementMirror.prototype.setIsVisible = function (bool) {
  310. if (bool) {
  311. if (!this.isVisible) {
  312. if (this.mirrorEl) {
  313. this.mirrorEl.style.display = '';
  314. }
  315. this.isVisible = bool; // needs to happen before updateElPosition
  316. this.updateElPosition(); // because was not updating the position while invisible
  317. }
  318. }
  319. else if (this.isVisible) {
  320. if (this.mirrorEl) {
  321. this.mirrorEl.style.display = 'none';
  322. }
  323. this.isVisible = bool;
  324. }
  325. };
  326. // always async
  327. ElementMirror.prototype.stop = function (needsRevertAnimation, callback) {
  328. var _this = this;
  329. var done = function () {
  330. _this.cleanup();
  331. callback();
  332. };
  333. if (needsRevertAnimation &&
  334. this.mirrorEl &&
  335. this.isVisible &&
  336. this.revertDuration && // if 0, transition won't work
  337. (this.deltaX || this.deltaY) // if same coords, transition won't work
  338. ) {
  339. this.doRevertAnimation(done, this.revertDuration);
  340. }
  341. else {
  342. setTimeout(done, 0);
  343. }
  344. };
  345. ElementMirror.prototype.doRevertAnimation = function (callback, revertDuration) {
  346. var mirrorEl = this.mirrorEl;
  347. var finalSourceElRect = this.sourceEl.getBoundingClientRect(); // because autoscrolling might have happened
  348. mirrorEl.style.transition =
  349. 'top ' + revertDuration + 'ms,' +
  350. 'left ' + revertDuration + 'ms';
  351. applyStyle(mirrorEl, {
  352. left: finalSourceElRect.left,
  353. top: finalSourceElRect.top,
  354. });
  355. whenTransitionDone(mirrorEl, function () {
  356. mirrorEl.style.transition = '';
  357. callback();
  358. });
  359. };
  360. ElementMirror.prototype.cleanup = function () {
  361. if (this.mirrorEl) {
  362. removeElement(this.mirrorEl);
  363. this.mirrorEl = null;
  364. }
  365. this.sourceEl = null;
  366. };
  367. ElementMirror.prototype.updateElPosition = function () {
  368. if (this.sourceEl && this.isVisible) {
  369. applyStyle(this.getMirrorEl(), {
  370. left: this.sourceElRect.left + this.deltaX,
  371. top: this.sourceElRect.top + this.deltaY,
  372. });
  373. }
  374. };
  375. ElementMirror.prototype.getMirrorEl = function () {
  376. var sourceElRect = this.sourceElRect;
  377. var mirrorEl = this.mirrorEl;
  378. if (!mirrorEl) {
  379. mirrorEl = this.mirrorEl = this.sourceEl.cloneNode(true); // cloneChildren=true
  380. // we don't want long taps or any mouse interaction causing selection/menus.
  381. // would use preventSelection(), but that prevents selectstart, causing problems.
  382. mirrorEl.classList.add('fc-unselectable');
  383. mirrorEl.classList.add('fc-event-dragging');
  384. applyStyle(mirrorEl, {
  385. position: 'fixed',
  386. zIndex: this.zIndex,
  387. visibility: '',
  388. boxSizing: 'border-box',
  389. width: sourceElRect.right - sourceElRect.left,
  390. height: sourceElRect.bottom - sourceElRect.top,
  391. right: 'auto',
  392. bottom: 'auto',
  393. margin: 0,
  394. });
  395. this.parentNode.appendChild(mirrorEl);
  396. }
  397. return mirrorEl;
  398. };
  399. return ElementMirror;
  400. }());
  401. /*
  402. Is a cache for a given element's scroll information (all the info that ScrollController stores)
  403. in addition the "client rectangle" of the element.. the area within the scrollbars.
  404. The cache can be in one of two modes:
  405. - doesListening:false - ignores when the container is scrolled by someone else
  406. - doesListening:true - watch for scrolling and update the cache
  407. */
  408. var ScrollGeomCache = /** @class */ (function (_super) {
  409. __extends(ScrollGeomCache, _super);
  410. function ScrollGeomCache(scrollController, doesListening) {
  411. var _this = _super.call(this) || this;
  412. _this.handleScroll = function () {
  413. _this.scrollTop = _this.scrollController.getScrollTop();
  414. _this.scrollLeft = _this.scrollController.getScrollLeft();
  415. _this.handleScrollChange();
  416. };
  417. _this.scrollController = scrollController;
  418. _this.doesListening = doesListening;
  419. _this.scrollTop = _this.origScrollTop = scrollController.getScrollTop();
  420. _this.scrollLeft = _this.origScrollLeft = scrollController.getScrollLeft();
  421. _this.scrollWidth = scrollController.getScrollWidth();
  422. _this.scrollHeight = scrollController.getScrollHeight();
  423. _this.clientWidth = scrollController.getClientWidth();
  424. _this.clientHeight = scrollController.getClientHeight();
  425. _this.clientRect = _this.computeClientRect(); // do last in case it needs cached values
  426. if (_this.doesListening) {
  427. _this.getEventTarget().addEventListener('scroll', _this.handleScroll);
  428. }
  429. return _this;
  430. }
  431. ScrollGeomCache.prototype.destroy = function () {
  432. if (this.doesListening) {
  433. this.getEventTarget().removeEventListener('scroll', this.handleScroll);
  434. }
  435. };
  436. ScrollGeomCache.prototype.getScrollTop = function () {
  437. return this.scrollTop;
  438. };
  439. ScrollGeomCache.prototype.getScrollLeft = function () {
  440. return this.scrollLeft;
  441. };
  442. ScrollGeomCache.prototype.setScrollTop = function (top) {
  443. this.scrollController.setScrollTop(top);
  444. if (!this.doesListening) {
  445. // we are not relying on the element to normalize out-of-bounds scroll values
  446. // so we need to sanitize ourselves
  447. this.scrollTop = Math.max(Math.min(top, this.getMaxScrollTop()), 0);
  448. this.handleScrollChange();
  449. }
  450. };
  451. ScrollGeomCache.prototype.setScrollLeft = function (top) {
  452. this.scrollController.setScrollLeft(top);
  453. if (!this.doesListening) {
  454. // we are not relying on the element to normalize out-of-bounds scroll values
  455. // so we need to sanitize ourselves
  456. this.scrollLeft = Math.max(Math.min(top, this.getMaxScrollLeft()), 0);
  457. this.handleScrollChange();
  458. }
  459. };
  460. ScrollGeomCache.prototype.getClientWidth = function () {
  461. return this.clientWidth;
  462. };
  463. ScrollGeomCache.prototype.getClientHeight = function () {
  464. return this.clientHeight;
  465. };
  466. ScrollGeomCache.prototype.getScrollWidth = function () {
  467. return this.scrollWidth;
  468. };
  469. ScrollGeomCache.prototype.getScrollHeight = function () {
  470. return this.scrollHeight;
  471. };
  472. ScrollGeomCache.prototype.handleScrollChange = function () {
  473. };
  474. return ScrollGeomCache;
  475. }(ScrollController));
  476. var ElementScrollGeomCache = /** @class */ (function (_super) {
  477. __extends(ElementScrollGeomCache, _super);
  478. function ElementScrollGeomCache(el, doesListening) {
  479. return _super.call(this, new ElementScrollController(el), doesListening) || this;
  480. }
  481. ElementScrollGeomCache.prototype.getEventTarget = function () {
  482. return this.scrollController.el;
  483. };
  484. ElementScrollGeomCache.prototype.computeClientRect = function () {
  485. return computeInnerRect(this.scrollController.el);
  486. };
  487. return ElementScrollGeomCache;
  488. }(ScrollGeomCache));
  489. var WindowScrollGeomCache = /** @class */ (function (_super) {
  490. __extends(WindowScrollGeomCache, _super);
  491. function WindowScrollGeomCache(doesListening) {
  492. return _super.call(this, new WindowScrollController(), doesListening) || this;
  493. }
  494. WindowScrollGeomCache.prototype.getEventTarget = function () {
  495. return window;
  496. };
  497. WindowScrollGeomCache.prototype.computeClientRect = function () {
  498. return {
  499. left: this.scrollLeft,
  500. right: this.scrollLeft + this.clientWidth,
  501. top: this.scrollTop,
  502. bottom: this.scrollTop + this.clientHeight,
  503. };
  504. };
  505. // the window is the only scroll object that changes it's rectangle relative
  506. // to the document's topleft as it scrolls
  507. WindowScrollGeomCache.prototype.handleScrollChange = function () {
  508. this.clientRect = this.computeClientRect();
  509. };
  510. return WindowScrollGeomCache;
  511. }(ScrollGeomCache));
  512. // If available we are using native "performance" API instead of "Date"
  513. // Read more about it on MDN:
  514. // https://developer.mozilla.org/en-US/docs/Web/API/Performance
  515. var getTime = typeof performance === 'function' ? performance.now : Date.now;
  516. /*
  517. For a pointer interaction, automatically scrolls certain scroll containers when the pointer
  518. approaches the edge.
  519. The caller must call start + handleMove + stop.
  520. */
  521. var AutoScroller = /** @class */ (function () {
  522. function AutoScroller() {
  523. var _this = this;
  524. // options that can be set by caller
  525. this.isEnabled = true;
  526. this.scrollQuery = [window, '.fc-scroller'];
  527. this.edgeThreshold = 50; // pixels
  528. this.maxVelocity = 300; // pixels per second
  529. // internal state
  530. this.pointerScreenX = null;
  531. this.pointerScreenY = null;
  532. this.isAnimating = false;
  533. this.scrollCaches = null;
  534. // protect against the initial pointerdown being too close to an edge and starting the scroll
  535. this.everMovedUp = false;
  536. this.everMovedDown = false;
  537. this.everMovedLeft = false;
  538. this.everMovedRight = false;
  539. this.animate = function () {
  540. if (_this.isAnimating) { // wasn't cancelled between animation calls
  541. var edge = _this.computeBestEdge(_this.pointerScreenX + window.pageXOffset, _this.pointerScreenY + window.pageYOffset);
  542. if (edge) {
  543. var now = getTime();
  544. _this.handleSide(edge, (now - _this.msSinceRequest) / 1000);
  545. _this.requestAnimation(now);
  546. }
  547. else {
  548. _this.isAnimating = false; // will stop animation
  549. }
  550. }
  551. };
  552. }
  553. AutoScroller.prototype.start = function (pageX, pageY, scrollStartEl) {
  554. if (this.isEnabled) {
  555. this.scrollCaches = this.buildCaches(scrollStartEl);
  556. this.pointerScreenX = null;
  557. this.pointerScreenY = null;
  558. this.everMovedUp = false;
  559. this.everMovedDown = false;
  560. this.everMovedLeft = false;
  561. this.everMovedRight = false;
  562. this.handleMove(pageX, pageY);
  563. }
  564. };
  565. AutoScroller.prototype.handleMove = function (pageX, pageY) {
  566. if (this.isEnabled) {
  567. var pointerScreenX = pageX - window.pageXOffset;
  568. var pointerScreenY = pageY - window.pageYOffset;
  569. var yDelta = this.pointerScreenY === null ? 0 : pointerScreenY - this.pointerScreenY;
  570. var xDelta = this.pointerScreenX === null ? 0 : pointerScreenX - this.pointerScreenX;
  571. if (yDelta < 0) {
  572. this.everMovedUp = true;
  573. }
  574. else if (yDelta > 0) {
  575. this.everMovedDown = true;
  576. }
  577. if (xDelta < 0) {
  578. this.everMovedLeft = true;
  579. }
  580. else if (xDelta > 0) {
  581. this.everMovedRight = true;
  582. }
  583. this.pointerScreenX = pointerScreenX;
  584. this.pointerScreenY = pointerScreenY;
  585. if (!this.isAnimating) {
  586. this.isAnimating = true;
  587. this.requestAnimation(getTime());
  588. }
  589. }
  590. };
  591. AutoScroller.prototype.stop = function () {
  592. if (this.isEnabled) {
  593. this.isAnimating = false; // will stop animation
  594. for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
  595. var scrollCache = _a[_i];
  596. scrollCache.destroy();
  597. }
  598. this.scrollCaches = null;
  599. }
  600. };
  601. AutoScroller.prototype.requestAnimation = function (now) {
  602. this.msSinceRequest = now;
  603. requestAnimationFrame(this.animate);
  604. };
  605. AutoScroller.prototype.handleSide = function (edge, seconds) {
  606. var scrollCache = edge.scrollCache;
  607. var edgeThreshold = this.edgeThreshold;
  608. var invDistance = edgeThreshold - edge.distance;
  609. var velocity = // the closer to the edge, the faster we scroll
  610. ((invDistance * invDistance) / (edgeThreshold * edgeThreshold)) * // quadratic
  611. this.maxVelocity * seconds;
  612. var sign = 1;
  613. switch (edge.name) {
  614. case 'left':
  615. sign = -1;
  616. // falls through
  617. case 'right':
  618. scrollCache.setScrollLeft(scrollCache.getScrollLeft() + velocity * sign);
  619. break;
  620. case 'top':
  621. sign = -1;
  622. // falls through
  623. case 'bottom':
  624. scrollCache.setScrollTop(scrollCache.getScrollTop() + velocity * sign);
  625. break;
  626. }
  627. };
  628. // left/top are relative to document topleft
  629. AutoScroller.prototype.computeBestEdge = function (left, top) {
  630. var edgeThreshold = this.edgeThreshold;
  631. var bestSide = null;
  632. var scrollCaches = this.scrollCaches || [];
  633. for (var _i = 0, scrollCaches_1 = scrollCaches; _i < scrollCaches_1.length; _i++) {
  634. var scrollCache = scrollCaches_1[_i];
  635. var rect = scrollCache.clientRect;
  636. var leftDist = left - rect.left;
  637. var rightDist = rect.right - left;
  638. var topDist = top - rect.top;
  639. var bottomDist = rect.bottom - top;
  640. // completely within the rect?
  641. if (leftDist >= 0 && rightDist >= 0 && topDist >= 0 && bottomDist >= 0) {
  642. if (topDist <= edgeThreshold && this.everMovedUp && scrollCache.canScrollUp() &&
  643. (!bestSide || bestSide.distance > topDist)) {
  644. bestSide = { scrollCache: scrollCache, name: 'top', distance: topDist };
  645. }
  646. if (bottomDist <= edgeThreshold && this.everMovedDown && scrollCache.canScrollDown() &&
  647. (!bestSide || bestSide.distance > bottomDist)) {
  648. bestSide = { scrollCache: scrollCache, name: 'bottom', distance: bottomDist };
  649. }
  650. if (leftDist <= edgeThreshold && this.everMovedLeft && scrollCache.canScrollLeft() &&
  651. (!bestSide || bestSide.distance > leftDist)) {
  652. bestSide = { scrollCache: scrollCache, name: 'left', distance: leftDist };
  653. }
  654. if (rightDist <= edgeThreshold && this.everMovedRight && scrollCache.canScrollRight() &&
  655. (!bestSide || bestSide.distance > rightDist)) {
  656. bestSide = { scrollCache: scrollCache, name: 'right', distance: rightDist };
  657. }
  658. }
  659. }
  660. return bestSide;
  661. };
  662. AutoScroller.prototype.buildCaches = function (scrollStartEl) {
  663. return this.queryScrollEls(scrollStartEl).map(function (el) {
  664. if (el === window) {
  665. return new WindowScrollGeomCache(false); // false = don't listen to user-generated scrolls
  666. }
  667. return new ElementScrollGeomCache(el, false); // false = don't listen to user-generated scrolls
  668. });
  669. };
  670. AutoScroller.prototype.queryScrollEls = function (scrollStartEl) {
  671. var els = [];
  672. for (var _i = 0, _a = this.scrollQuery; _i < _a.length; _i++) {
  673. var query = _a[_i];
  674. if (typeof query === 'object') {
  675. els.push(query);
  676. }
  677. else {
  678. els.push.apply(els, Array.prototype.slice.call(getElRoot(scrollStartEl).querySelectorAll(query)));
  679. }
  680. }
  681. return els;
  682. };
  683. return AutoScroller;
  684. }());
  685. /*
  686. Monitors dragging on an element. Has a number of high-level features:
  687. - minimum distance required before dragging
  688. - minimum wait time ("delay") before dragging
  689. - a mirror element that follows the pointer
  690. */
  691. var FeaturefulElementDragging = /** @class */ (function (_super) {
  692. __extends(FeaturefulElementDragging, _super);
  693. function FeaturefulElementDragging(containerEl, selector) {
  694. var _this = _super.call(this, containerEl) || this;
  695. _this.containerEl = containerEl;
  696. // options that can be directly set by caller
  697. // the caller can also set the PointerDragging's options as well
  698. _this.delay = null;
  699. _this.minDistance = 0;
  700. _this.touchScrollAllowed = true; // prevents drag from starting and blocks scrolling during drag
  701. _this.mirrorNeedsRevert = false;
  702. _this.isInteracting = false; // is the user validly moving the pointer? lasts until pointerup
  703. _this.isDragging = false; // is it INTENTFULLY dragging? lasts until after revert animation
  704. _this.isDelayEnded = false;
  705. _this.isDistanceSurpassed = false;
  706. _this.delayTimeoutId = null;
  707. _this.onPointerDown = function (ev) {
  708. if (!_this.isDragging) { // so new drag doesn't happen while revert animation is going
  709. _this.isInteracting = true;
  710. _this.isDelayEnded = false;
  711. _this.isDistanceSurpassed = false;
  712. preventSelection(document.body);
  713. preventContextMenu(document.body);
  714. // prevent links from being visited if there's an eventual drag.
  715. // also prevents selection in older browsers (maybe?).
  716. // not necessary for touch, besides, browser would complain about passiveness.
  717. if (!ev.isTouch) {
  718. ev.origEvent.preventDefault();
  719. }
  720. _this.emitter.trigger('pointerdown', ev);
  721. if (_this.isInteracting && // not destroyed via pointerdown handler
  722. !_this.pointer.shouldIgnoreMove) {
  723. // actions related to initiating dragstart+dragmove+dragend...
  724. _this.mirror.setIsVisible(false); // reset. caller must set-visible
  725. _this.mirror.start(ev.subjectEl, ev.pageX, ev.pageY); // must happen on first pointer down
  726. _this.startDelay(ev);
  727. if (!_this.minDistance) {
  728. _this.handleDistanceSurpassed(ev);
  729. }
  730. }
  731. }
  732. };
  733. _this.onPointerMove = function (ev) {
  734. if (_this.isInteracting) {
  735. _this.emitter.trigger('pointermove', ev);
  736. if (!_this.isDistanceSurpassed) {
  737. var minDistance = _this.minDistance;
  738. var distanceSq = void 0; // current distance from the origin, squared
  739. var deltaX = ev.deltaX, deltaY = ev.deltaY;
  740. distanceSq = deltaX * deltaX + deltaY * deltaY;
  741. if (distanceSq >= minDistance * minDistance) { // use pythagorean theorem
  742. _this.handleDistanceSurpassed(ev);
  743. }
  744. }
  745. if (_this.isDragging) {
  746. // a real pointer move? (not one simulated by scrolling)
  747. if (ev.origEvent.type !== 'scroll') {
  748. _this.mirror.handleMove(ev.pageX, ev.pageY);
  749. _this.autoScroller.handleMove(ev.pageX, ev.pageY);
  750. }
  751. _this.emitter.trigger('dragmove', ev);
  752. }
  753. }
  754. };
  755. _this.onPointerUp = function (ev) {
  756. if (_this.isInteracting) {
  757. _this.isInteracting = false;
  758. allowSelection(document.body);
  759. allowContextMenu(document.body);
  760. _this.emitter.trigger('pointerup', ev); // can potentially set mirrorNeedsRevert
  761. if (_this.isDragging) {
  762. _this.autoScroller.stop();
  763. _this.tryStopDrag(ev); // which will stop the mirror
  764. }
  765. if (_this.delayTimeoutId) {
  766. clearTimeout(_this.delayTimeoutId);
  767. _this.delayTimeoutId = null;
  768. }
  769. }
  770. };
  771. var pointer = _this.pointer = new PointerDragging(containerEl);
  772. pointer.emitter.on('pointerdown', _this.onPointerDown);
  773. pointer.emitter.on('pointermove', _this.onPointerMove);
  774. pointer.emitter.on('pointerup', _this.onPointerUp);
  775. if (selector) {
  776. pointer.selector = selector;
  777. }
  778. _this.mirror = new ElementMirror();
  779. _this.autoScroller = new AutoScroller();
  780. return _this;
  781. }
  782. FeaturefulElementDragging.prototype.destroy = function () {
  783. this.pointer.destroy();
  784. // HACK: simulate a pointer-up to end the current drag
  785. // TODO: fire 'dragend' directly and stop interaction. discourage use of pointerup event (b/c might not fire)
  786. this.onPointerUp({});
  787. };
  788. FeaturefulElementDragging.prototype.startDelay = function (ev) {
  789. var _this = this;
  790. if (typeof this.delay === 'number') {
  791. this.delayTimeoutId = setTimeout(function () {
  792. _this.delayTimeoutId = null;
  793. _this.handleDelayEnd(ev);
  794. }, this.delay); // not assignable to number!
  795. }
  796. else {
  797. this.handleDelayEnd(ev);
  798. }
  799. };
  800. FeaturefulElementDragging.prototype.handleDelayEnd = function (ev) {
  801. this.isDelayEnded = true;
  802. this.tryStartDrag(ev);
  803. };
  804. FeaturefulElementDragging.prototype.handleDistanceSurpassed = function (ev) {
  805. this.isDistanceSurpassed = true;
  806. this.tryStartDrag(ev);
  807. };
  808. FeaturefulElementDragging.prototype.tryStartDrag = function (ev) {
  809. if (this.isDelayEnded && this.isDistanceSurpassed) {
  810. if (!this.pointer.wasTouchScroll || this.touchScrollAllowed) {
  811. this.isDragging = true;
  812. this.mirrorNeedsRevert = false;
  813. this.autoScroller.start(ev.pageX, ev.pageY, this.containerEl);
  814. this.emitter.trigger('dragstart', ev);
  815. if (this.touchScrollAllowed === false) {
  816. this.pointer.cancelTouchScroll();
  817. }
  818. }
  819. }
  820. };
  821. FeaturefulElementDragging.prototype.tryStopDrag = function (ev) {
  822. // .stop() is ALWAYS asynchronous, which we NEED because we want all pointerup events
  823. // that come from the document to fire beforehand. much more convenient this way.
  824. this.mirror.stop(this.mirrorNeedsRevert, this.stopDrag.bind(this, ev));
  825. };
  826. FeaturefulElementDragging.prototype.stopDrag = function (ev) {
  827. this.isDragging = false;
  828. this.emitter.trigger('dragend', ev);
  829. };
  830. // fill in the implementations...
  831. FeaturefulElementDragging.prototype.setIgnoreMove = function (bool) {
  832. this.pointer.shouldIgnoreMove = bool;
  833. };
  834. FeaturefulElementDragging.prototype.setMirrorIsVisible = function (bool) {
  835. this.mirror.setIsVisible(bool);
  836. };
  837. FeaturefulElementDragging.prototype.setMirrorNeedsRevert = function (bool) {
  838. this.mirrorNeedsRevert = bool;
  839. };
  840. FeaturefulElementDragging.prototype.setAutoScrollEnabled = function (bool) {
  841. this.autoScroller.isEnabled = bool;
  842. };
  843. return FeaturefulElementDragging;
  844. }(ElementDragging));
  845. /*
  846. When this class is instantiated, it records the offset of an element (relative to the document topleft),
  847. and continues to monitor scrolling, updating the cached coordinates if it needs to.
  848. Does not access the DOM after instantiation, so highly performant.
  849. Also keeps track of all scrolling/overflow:hidden containers that are parents of the given element
  850. and an determine if a given point is inside the combined clipping rectangle.
  851. */
  852. var OffsetTracker = /** @class */ (function () {
  853. function OffsetTracker(el) {
  854. this.origRect = computeRect(el);
  855. // will work fine for divs that have overflow:hidden
  856. this.scrollCaches = getClippingParents(el).map(function (scrollEl) { return new ElementScrollGeomCache(scrollEl, true); });
  857. }
  858. OffsetTracker.prototype.destroy = function () {
  859. for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
  860. var scrollCache = _a[_i];
  861. scrollCache.destroy();
  862. }
  863. };
  864. OffsetTracker.prototype.computeLeft = function () {
  865. var left = this.origRect.left;
  866. for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
  867. var scrollCache = _a[_i];
  868. left += scrollCache.origScrollLeft - scrollCache.getScrollLeft();
  869. }
  870. return left;
  871. };
  872. OffsetTracker.prototype.computeTop = function () {
  873. var top = this.origRect.top;
  874. for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
  875. var scrollCache = _a[_i];
  876. top += scrollCache.origScrollTop - scrollCache.getScrollTop();
  877. }
  878. return top;
  879. };
  880. OffsetTracker.prototype.isWithinClipping = function (pageX, pageY) {
  881. var point = { left: pageX, top: pageY };
  882. for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
  883. var scrollCache = _a[_i];
  884. if (!isIgnoredClipping(scrollCache.getEventTarget()) &&
  885. !pointInsideRect(point, scrollCache.clientRect)) {
  886. return false;
  887. }
  888. }
  889. return true;
  890. };
  891. return OffsetTracker;
  892. }());
  893. // certain clipping containers should never constrain interactions, like <html> and <body>
  894. // https://github.com/fullcalendar/fullcalendar/issues/3615
  895. function isIgnoredClipping(node) {
  896. var tagName = node.tagName;
  897. return tagName === 'HTML' || tagName === 'BODY';
  898. }
  899. /*
  900. Tracks movement over multiple droppable areas (aka "hits")
  901. that exist in one or more DateComponents.
  902. Relies on an existing draggable.
  903. emits:
  904. - pointerdown
  905. - dragstart
  906. - hitchange - fires initially, even if not over a hit
  907. - pointerup
  908. - (hitchange - again, to null, if ended over a hit)
  909. - dragend
  910. */
  911. var HitDragging = /** @class */ (function () {
  912. function HitDragging(dragging, droppableStore) {
  913. var _this = this;
  914. // options that can be set by caller
  915. this.useSubjectCenter = false;
  916. this.requireInitial = true; // if doesn't start out on a hit, won't emit any events
  917. this.initialHit = null;
  918. this.movingHit = null;
  919. this.finalHit = null; // won't ever be populated if shouldIgnoreMove
  920. this.handlePointerDown = function (ev) {
  921. var dragging = _this.dragging;
  922. _this.initialHit = null;
  923. _this.movingHit = null;
  924. _this.finalHit = null;
  925. _this.prepareHits();
  926. _this.processFirstCoord(ev);
  927. if (_this.initialHit || !_this.requireInitial) {
  928. dragging.setIgnoreMove(false);
  929. // TODO: fire this before computing processFirstCoord, so listeners can cancel. this gets fired by almost every handler :(
  930. _this.emitter.trigger('pointerdown', ev);
  931. }
  932. else {
  933. dragging.setIgnoreMove(true);
  934. }
  935. };
  936. this.handleDragStart = function (ev) {
  937. _this.emitter.trigger('dragstart', ev);
  938. _this.handleMove(ev, true); // force = fire even if initially null
  939. };
  940. this.handleDragMove = function (ev) {
  941. _this.emitter.trigger('dragmove', ev);
  942. _this.handleMove(ev);
  943. };
  944. this.handlePointerUp = function (ev) {
  945. _this.releaseHits();
  946. _this.emitter.trigger('pointerup', ev);
  947. };
  948. this.handleDragEnd = function (ev) {
  949. if (_this.movingHit) {
  950. _this.emitter.trigger('hitupdate', null, true, ev);
  951. }
  952. _this.finalHit = _this.movingHit;
  953. _this.movingHit = null;
  954. _this.emitter.trigger('dragend', ev);
  955. };
  956. this.droppableStore = droppableStore;
  957. dragging.emitter.on('pointerdown', this.handlePointerDown);
  958. dragging.emitter.on('dragstart', this.handleDragStart);
  959. dragging.emitter.on('dragmove', this.handleDragMove);
  960. dragging.emitter.on('pointerup', this.handlePointerUp);
  961. dragging.emitter.on('dragend', this.handleDragEnd);
  962. this.dragging = dragging;
  963. this.emitter = new Emitter();
  964. }
  965. // sets initialHit
  966. // sets coordAdjust
  967. HitDragging.prototype.processFirstCoord = function (ev) {
  968. var origPoint = { left: ev.pageX, top: ev.pageY };
  969. var adjustedPoint = origPoint;
  970. var subjectEl = ev.subjectEl;
  971. var subjectRect;
  972. if (subjectEl instanceof HTMLElement) { // i.e. not a Document/ShadowRoot
  973. subjectRect = computeRect(subjectEl);
  974. adjustedPoint = constrainPoint(adjustedPoint, subjectRect);
  975. }
  976. var initialHit = this.initialHit = this.queryHitForOffset(adjustedPoint.left, adjustedPoint.top);
  977. if (initialHit) {
  978. if (this.useSubjectCenter && subjectRect) {
  979. var slicedSubjectRect = intersectRects(subjectRect, initialHit.rect);
  980. if (slicedSubjectRect) {
  981. adjustedPoint = getRectCenter(slicedSubjectRect);
  982. }
  983. }
  984. this.coordAdjust = diffPoints(adjustedPoint, origPoint);
  985. }
  986. else {
  987. this.coordAdjust = { left: 0, top: 0 };
  988. }
  989. };
  990. HitDragging.prototype.handleMove = function (ev, forceHandle) {
  991. var hit = this.queryHitForOffset(ev.pageX + this.coordAdjust.left, ev.pageY + this.coordAdjust.top);
  992. if (forceHandle || !isHitsEqual(this.movingHit, hit)) {
  993. this.movingHit = hit;
  994. this.emitter.trigger('hitupdate', hit, false, ev);
  995. }
  996. };
  997. HitDragging.prototype.prepareHits = function () {
  998. this.offsetTrackers = mapHash(this.droppableStore, function (interactionSettings) {
  999. interactionSettings.component.prepareHits();
  1000. return new OffsetTracker(interactionSettings.el);
  1001. });
  1002. };
  1003. HitDragging.prototype.releaseHits = function () {
  1004. var offsetTrackers = this.offsetTrackers;
  1005. for (var id in offsetTrackers) {
  1006. offsetTrackers[id].destroy();
  1007. }
  1008. this.offsetTrackers = {};
  1009. };
  1010. HitDragging.prototype.queryHitForOffset = function (offsetLeft, offsetTop) {
  1011. var _a = this, droppableStore = _a.droppableStore, offsetTrackers = _a.offsetTrackers;
  1012. var bestHit = null;
  1013. for (var id in droppableStore) {
  1014. var component = droppableStore[id].component;
  1015. var offsetTracker = offsetTrackers[id];
  1016. if (offsetTracker && // wasn't destroyed mid-drag
  1017. offsetTracker.isWithinClipping(offsetLeft, offsetTop)) {
  1018. var originLeft = offsetTracker.computeLeft();
  1019. var originTop = offsetTracker.computeTop();
  1020. var positionLeft = offsetLeft - originLeft;
  1021. var positionTop = offsetTop - originTop;
  1022. var origRect = offsetTracker.origRect;
  1023. var width = origRect.right - origRect.left;
  1024. var height = origRect.bottom - origRect.top;
  1025. if (
  1026. // must be within the element's bounds
  1027. positionLeft >= 0 && positionLeft < width &&
  1028. positionTop >= 0 && positionTop < height) {
  1029. var hit = component.queryHit(positionLeft, positionTop, width, height);
  1030. if (hit && (
  1031. // make sure the hit is within activeRange, meaning it's not a dead cell
  1032. rangeContainsRange(hit.dateProfile.activeRange, hit.dateSpan.range)) &&
  1033. (!bestHit || hit.layer > bestHit.layer)) {
  1034. hit.componentId = id;
  1035. hit.context = component.context;
  1036. // TODO: better way to re-orient rectangle
  1037. hit.rect.left += originLeft;
  1038. hit.rect.right += originLeft;
  1039. hit.rect.top += originTop;
  1040. hit.rect.bottom += originTop;
  1041. bestHit = hit;
  1042. }
  1043. }
  1044. }
  1045. }
  1046. return bestHit;
  1047. };
  1048. return HitDragging;
  1049. }());
  1050. function isHitsEqual(hit0, hit1) {
  1051. if (!hit0 && !hit1) {
  1052. return true;
  1053. }
  1054. if (Boolean(hit0) !== Boolean(hit1)) {
  1055. return false;
  1056. }
  1057. return isDateSpansEqual(hit0.dateSpan, hit1.dateSpan);
  1058. }
  1059. function buildDatePointApiWithContext(dateSpan, context) {
  1060. var props = {};
  1061. for (var _i = 0, _a = context.pluginHooks.datePointTransforms; _i < _a.length; _i++) {
  1062. var transform = _a[_i];
  1063. __assign(props, transform(dateSpan, context));
  1064. }
  1065. __assign(props, buildDatePointApi(dateSpan, context.dateEnv));
  1066. return props;
  1067. }
  1068. function buildDatePointApi(span, dateEnv) {
  1069. return {
  1070. date: dateEnv.toDate(span.range.start),
  1071. dateStr: dateEnv.formatIso(span.range.start, { omitTime: span.allDay }),
  1072. allDay: span.allDay,
  1073. };
  1074. }
  1075. /*
  1076. Monitors when the user clicks on a specific date/time of a component.
  1077. A pointerdown+pointerup on the same "hit" constitutes a click.
  1078. */
  1079. var DateClicking = /** @class */ (function (_super) {
  1080. __extends(DateClicking, _super);
  1081. function DateClicking(settings) {
  1082. var _this = _super.call(this, settings) || this;
  1083. _this.handlePointerDown = function (pev) {
  1084. var dragging = _this.dragging;
  1085. var downEl = pev.origEvent.target;
  1086. // do this in pointerdown (not dragend) because DOM might be mutated by the time dragend is fired
  1087. dragging.setIgnoreMove(!_this.component.isValidDateDownEl(downEl));
  1088. };
  1089. // won't even fire if moving was ignored
  1090. _this.handleDragEnd = function (ev) {
  1091. var component = _this.component;
  1092. var pointer = _this.dragging.pointer;
  1093. if (!pointer.wasTouchScroll) {
  1094. var _a = _this.hitDragging, initialHit = _a.initialHit, finalHit = _a.finalHit;
  1095. if (initialHit && finalHit && isHitsEqual(initialHit, finalHit)) {
  1096. var context = component.context;
  1097. var arg = __assign(__assign({}, buildDatePointApiWithContext(initialHit.dateSpan, context)), { dayEl: initialHit.dayEl, jsEvent: ev.origEvent, view: context.viewApi || context.calendarApi.view });
  1098. context.emitter.trigger('dateClick', arg);
  1099. }
  1100. }
  1101. };
  1102. // we DO want to watch pointer moves because otherwise finalHit won't get populated
  1103. _this.dragging = new FeaturefulElementDragging(settings.el);
  1104. _this.dragging.autoScroller.isEnabled = false;
  1105. var hitDragging = _this.hitDragging = new HitDragging(_this.dragging, interactionSettingsToStore(settings));
  1106. hitDragging.emitter.on('pointerdown', _this.handlePointerDown);
  1107. hitDragging.emitter.on('dragend', _this.handleDragEnd);
  1108. return _this;
  1109. }
  1110. DateClicking.prototype.destroy = function () {
  1111. this.dragging.destroy();
  1112. };
  1113. return DateClicking;
  1114. }(Interaction));
  1115. /*
  1116. Tracks when the user selects a portion of time of a component,
  1117. constituted by a drag over date cells, with a possible delay at the beginning of the drag.
  1118. */
  1119. var DateSelecting = /** @class */ (function (_super) {
  1120. __extends(DateSelecting, _super);
  1121. function DateSelecting(settings) {
  1122. var _this = _super.call(this, settings) || this;
  1123. _this.dragSelection = null;
  1124. _this.handlePointerDown = function (ev) {
  1125. var _a = _this, component = _a.component, dragging = _a.dragging;
  1126. var options = component.context.options;
  1127. var canSelect = options.selectable &&
  1128. component.isValidDateDownEl(ev.origEvent.target);
  1129. // don't bother to watch expensive moves if component won't do selection
  1130. dragging.setIgnoreMove(!canSelect);
  1131. // if touch, require user to hold down
  1132. dragging.delay = ev.isTouch ? getComponentTouchDelay$1(component) : null;
  1133. };
  1134. _this.handleDragStart = function (ev) {
  1135. _this.component.context.calendarApi.unselect(ev); // unselect previous selections
  1136. };
  1137. _this.handleHitUpdate = function (hit, isFinal) {
  1138. var context = _this.component.context;
  1139. var dragSelection = null;
  1140. var isInvalid = false;
  1141. if (hit) {
  1142. var initialHit = _this.hitDragging.initialHit;
  1143. var disallowed = hit.componentId === initialHit.componentId
  1144. && _this.isHitComboAllowed
  1145. && !_this.isHitComboAllowed(initialHit, hit);
  1146. if (!disallowed) {
  1147. dragSelection = joinHitsIntoSelection(initialHit, hit, context.pluginHooks.dateSelectionTransformers);
  1148. }
  1149. if (!dragSelection || !isDateSelectionValid(dragSelection, hit.dateProfile, context)) {
  1150. isInvalid = true;
  1151. dragSelection = null;
  1152. }
  1153. }
  1154. if (dragSelection) {
  1155. context.dispatch({ type: 'SELECT_DATES', selection: dragSelection });
  1156. }
  1157. else if (!isFinal) { // only unselect if moved away while dragging
  1158. context.dispatch({ type: 'UNSELECT_DATES' });
  1159. }
  1160. if (!isInvalid) {
  1161. enableCursor();
  1162. }
  1163. else {
  1164. disableCursor();
  1165. }
  1166. if (!isFinal) {
  1167. _this.dragSelection = dragSelection; // only clear if moved away from all hits while dragging
  1168. }
  1169. };
  1170. _this.handlePointerUp = function (pev) {
  1171. if (_this.dragSelection) {
  1172. // selection is already rendered, so just need to report selection
  1173. triggerDateSelect(_this.dragSelection, pev, _this.component.context);
  1174. _this.dragSelection = null;
  1175. }
  1176. };
  1177. var component = settings.component;
  1178. var options = component.context.options;
  1179. var dragging = _this.dragging = new FeaturefulElementDragging(settings.el);
  1180. dragging.touchScrollAllowed = false;
  1181. dragging.minDistance = options.selectMinDistance || 0;
  1182. dragging.autoScroller.isEnabled = options.dragScroll;
  1183. var hitDragging = _this.hitDragging = new HitDragging(_this.dragging, interactionSettingsToStore(settings));
  1184. hitDragging.emitter.on('pointerdown', _this.handlePointerDown);
  1185. hitDragging.emitter.on('dragstart', _this.handleDragStart);
  1186. hitDragging.emitter.on('hitupdate', _this.handleHitUpdate);
  1187. hitDragging.emitter.on('pointerup', _this.handlePointerUp);
  1188. return _this;
  1189. }
  1190. DateSelecting.prototype.destroy = function () {
  1191. this.dragging.destroy();
  1192. };
  1193. return DateSelecting;
  1194. }(Interaction));
  1195. function getComponentTouchDelay$1(component) {
  1196. var options = component.context.options;
  1197. var delay = options.selectLongPressDelay;
  1198. if (delay == null) {
  1199. delay = options.longPressDelay;
  1200. }
  1201. return delay;
  1202. }
  1203. function joinHitsIntoSelection(hit0, hit1, dateSelectionTransformers) {
  1204. var dateSpan0 = hit0.dateSpan;
  1205. var dateSpan1 = hit1.dateSpan;
  1206. var ms = [
  1207. dateSpan0.range.start,
  1208. dateSpan0.range.end,
  1209. dateSpan1.range.start,
  1210. dateSpan1.range.end,
  1211. ];
  1212. ms.sort(compareNumbers);
  1213. var props = {};
  1214. for (var _i = 0, dateSelectionTransformers_1 = dateSelectionTransformers; _i < dateSelectionTransformers_1.length; _i++) {
  1215. var transformer = dateSelectionTransformers_1[_i];
  1216. var res = transformer(hit0, hit1);
  1217. if (res === false) {
  1218. return null;
  1219. }
  1220. if (res) {
  1221. __assign(props, res);
  1222. }
  1223. }
  1224. props.range = { start: ms[0], end: ms[3] };
  1225. props.allDay = dateSpan0.allDay;
  1226. return props;
  1227. }
  1228. var EventDragging = /** @class */ (function (_super) {
  1229. __extends(EventDragging, _super);
  1230. function EventDragging(settings) {
  1231. var _this = _super.call(this, settings) || this;
  1232. // internal state
  1233. _this.subjectEl = null;
  1234. _this.subjectSeg = null; // the seg being selected/dragged
  1235. _this.isDragging = false;
  1236. _this.eventRange = null;
  1237. _this.relevantEvents = null; // the events being dragged
  1238. _this.receivingContext = null;
  1239. _this.validMutation = null;
  1240. _this.mutatedRelevantEvents = null;
  1241. _this.handlePointerDown = function (ev) {
  1242. var origTarget = ev.origEvent.target;
  1243. var _a = _this, component = _a.component, dragging = _a.dragging;
  1244. var mirror = dragging.mirror;
  1245. var options = component.context.options;
  1246. var initialContext = component.context;
  1247. _this.subjectEl = ev.subjectEl;
  1248. var subjectSeg = _this.subjectSeg = getElSeg(ev.subjectEl);
  1249. var eventRange = _this.eventRange = subjectSeg.eventRange;
  1250. var eventInstanceId = eventRange.instance.instanceId;
  1251. _this.relevantEvents = getRelevantEvents(initialContext.getCurrentData().eventStore, eventInstanceId);
  1252. dragging.minDistance = ev.isTouch ? 0 : options.eventDragMinDistance;
  1253. dragging.delay =
  1254. // only do a touch delay if touch and this event hasn't been selected yet
  1255. (ev.isTouch && eventInstanceId !== component.props.eventSelection) ?
  1256. getComponentTouchDelay(component) :
  1257. null;
  1258. if (options.fixedMirrorParent) {
  1259. mirror.parentNode = options.fixedMirrorParent;
  1260. }
  1261. else {
  1262. mirror.parentNode = elementClosest(origTarget, '.fc');
  1263. }
  1264. mirror.revertDuration = options.dragRevertDuration;
  1265. var isValid = component.isValidSegDownEl(origTarget) &&
  1266. !elementClosest(origTarget, '.fc-event-resizer'); // NOT on a resizer
  1267. dragging.setIgnoreMove(!isValid);
  1268. // disable dragging for elements that are resizable (ie, selectable)
  1269. // but are not draggable
  1270. _this.isDragging = isValid &&
  1271. ev.subjectEl.classList.contains('fc-event-draggable');
  1272. };
  1273. _this.handleDragStart = function (ev) {
  1274. var initialContext = _this.component.context;
  1275. var eventRange = _this.eventRange;
  1276. var eventInstanceId = eventRange.instance.instanceId;
  1277. if (ev.isTouch) {
  1278. // need to select a different event?
  1279. if (eventInstanceId !== _this.component.props.eventSelection) {
  1280. initialContext.dispatch({ type: 'SELECT_EVENT', eventInstanceId: eventInstanceId });
  1281. }
  1282. }
  1283. else {
  1284. // if now using mouse, but was previous touch interaction, clear selected event
  1285. initialContext.dispatch({ type: 'UNSELECT_EVENT' });
  1286. }
  1287. if (_this.isDragging) {
  1288. initialContext.calendarApi.unselect(ev); // unselect *date* selection
  1289. initialContext.emitter.trigger('eventDragStart', {
  1290. el: _this.subjectEl,
  1291. event: new EventApi(initialContext, eventRange.def, eventRange.instance),
  1292. jsEvent: ev.origEvent,
  1293. view: initialContext.viewApi,
  1294. });
  1295. }
  1296. };
  1297. _this.handleHitUpdate = function (hit, isFinal) {
  1298. if (!_this.isDragging) {
  1299. return;
  1300. }
  1301. var relevantEvents = _this.relevantEvents;
  1302. var initialHit = _this.hitDragging.initialHit;
  1303. var initialContext = _this.component.context;
  1304. // states based on new hit
  1305. var receivingContext = null;
  1306. var mutation = null;
  1307. var mutatedRelevantEvents = null;
  1308. var isInvalid = false;
  1309. var interaction = {
  1310. affectedEvents: relevantEvents,
  1311. mutatedEvents: createEmptyEventStore(),
  1312. isEvent: true,
  1313. };
  1314. if (hit) {
  1315. receivingContext = hit.context;
  1316. var receivingOptions = receivingContext.options;
  1317. if (initialContext === receivingContext ||
  1318. (receivingOptions.editable && receivingOptions.droppable)) {
  1319. mutation = computeEventMutation(initialHit, hit, receivingContext.getCurrentData().pluginHooks.eventDragMutationMassagers);
  1320. if (mutation) {
  1321. mutatedRelevantEvents = applyMutationToEventStore(relevantEvents, receivingContext.getCurrentData().eventUiBases, mutation, receivingContext);
  1322. interaction.mutatedEvents = mutatedRelevantEvents;
  1323. if (!isInteractionValid(interaction, hit.dateProfile, receivingContext)) {
  1324. isInvalid = true;
  1325. mutation = null;
  1326. mutatedRelevantEvents = null;
  1327. interaction.mutatedEvents = createEmptyEventStore();
  1328. }
  1329. }
  1330. }
  1331. else {
  1332. receivingContext = null;
  1333. }
  1334. }
  1335. _this.displayDrag(receivingContext, interaction);
  1336. if (!isInvalid) {
  1337. enableCursor();
  1338. }
  1339. else {
  1340. disableCursor();
  1341. }
  1342. if (!isFinal) {
  1343. if (initialContext === receivingContext && // TODO: write test for this
  1344. isHitsEqual(initialHit, hit)) {
  1345. mutation = null;
  1346. }
  1347. _this.dragging.setMirrorNeedsRevert(!mutation);
  1348. // render the mirror if no already-rendered mirror
  1349. // TODO: wish we could somehow wait for dispatch to guarantee render
  1350. _this.dragging.setMirrorIsVisible(!hit || !getElRoot(_this.subjectEl).querySelector('.fc-event-mirror'));
  1351. // assign states based on new hit
  1352. _this.receivingContext = receivingContext;
  1353. _this.validMutation = mutation;
  1354. _this.mutatedRelevantEvents = mutatedRelevantEvents;
  1355. }
  1356. };
  1357. _this.handlePointerUp = function () {
  1358. if (!_this.isDragging) {
  1359. _this.cleanup(); // because handleDragEnd won't fire
  1360. }
  1361. };
  1362. _this.handleDragEnd = function (ev) {
  1363. if (_this.isDragging) {
  1364. var initialContext_1 = _this.component.context;
  1365. var initialView = initialContext_1.viewApi;
  1366. var _a = _this, receivingContext_1 = _a.receivingContext, validMutation = _a.validMutation;
  1367. var eventDef = _this.eventRange.def;
  1368. var eventInstance = _this.eventRange.instance;
  1369. var eventApi = new EventApi(initialContext_1, eventDef, eventInstance);
  1370. var relevantEvents_1 = _this.relevantEvents;
  1371. var mutatedRelevantEvents_1 = _this.mutatedRelevantEvents;
  1372. var finalHit = _this.hitDragging.finalHit;
  1373. _this.clearDrag(); // must happen after revert animation
  1374. initialContext_1.emitter.trigger('eventDragStop', {
  1375. el: _this.subjectEl,
  1376. event: eventApi,
  1377. jsEvent: ev.origEvent,
  1378. view: initialView,
  1379. });
  1380. if (validMutation) {
  1381. // dropped within same calendar
  1382. if (receivingContext_1 === initialContext_1) {
  1383. var updatedEventApi = new EventApi(initialContext_1, mutatedRelevantEvents_1.defs[eventDef.defId], eventInstance ? mutatedRelevantEvents_1.instances[eventInstance.instanceId] : null);
  1384. initialContext_1.dispatch({
  1385. type: 'MERGE_EVENTS',
  1386. eventStore: mutatedRelevantEvents_1,
  1387. });
  1388. var eventChangeArg = {
  1389. oldEvent: eventApi,
  1390. event: updatedEventApi,
  1391. relatedEvents: buildEventApis(mutatedRelevantEvents_1, initialContext_1, eventInstance),
  1392. revert: function () {
  1393. initialContext_1.dispatch({
  1394. type: 'MERGE_EVENTS',
  1395. eventStore: relevantEvents_1, // the pre-change data
  1396. });
  1397. },
  1398. };
  1399. var transformed = {};
  1400. for (var _i = 0, _b = initialContext_1.getCurrentData().pluginHooks.eventDropTransformers; _i < _b.length; _i++) {
  1401. var transformer = _b[_i];
  1402. __assign(transformed, transformer(validMutation, initialContext_1));
  1403. }
  1404. initialContext_1.emitter.trigger('eventDrop', __assign(__assign(__assign({}, eventChangeArg), transformed), { el: ev.subjectEl, delta: validMutation.datesDelta, jsEvent: ev.origEvent, view: initialView }));
  1405. initialContext_1.emitter.trigger('eventChange', eventChangeArg);
  1406. // dropped in different calendar
  1407. }
  1408. else if (receivingContext_1) {
  1409. var eventRemoveArg = {
  1410. event: eventApi,
  1411. relatedEvents: buildEventApis(relevantEvents_1, initialContext_1, eventInstance),
  1412. revert: function () {
  1413. initialContext_1.dispatch({
  1414. type: 'MERGE_EVENTS',
  1415. eventStore: relevantEvents_1,
  1416. });
  1417. },
  1418. };
  1419. initialContext_1.emitter.trigger('eventLeave', __assign(__assign({}, eventRemoveArg), { draggedEl: ev.subjectEl, view: initialView }));
  1420. initialContext_1.dispatch({
  1421. type: 'REMOVE_EVENTS',
  1422. eventStore: relevantEvents_1,
  1423. });
  1424. initialContext_1.emitter.trigger('eventRemove', eventRemoveArg);
  1425. var addedEventDef = mutatedRelevantEvents_1.defs[eventDef.defId];
  1426. var addedEventInstance = mutatedRelevantEvents_1.instances[eventInstance.instanceId];
  1427. var addedEventApi = new EventApi(receivingContext_1, addedEventDef, addedEventInstance);
  1428. receivingContext_1.dispatch({
  1429. type: 'MERGE_EVENTS',
  1430. eventStore: mutatedRelevantEvents_1,
  1431. });
  1432. var eventAddArg = {
  1433. event: addedEventApi,
  1434. relatedEvents: buildEventApis(mutatedRelevantEvents_1, receivingContext_1, addedEventInstance),
  1435. revert: function () {
  1436. receivingContext_1.dispatch({
  1437. type: 'REMOVE_EVENTS',
  1438. eventStore: mutatedRelevantEvents_1,
  1439. });
  1440. },
  1441. };
  1442. receivingContext_1.emitter.trigger('eventAdd', eventAddArg);
  1443. if (ev.isTouch) {
  1444. receivingContext_1.dispatch({
  1445. type: 'SELECT_EVENT',
  1446. eventInstanceId: eventInstance.instanceId,
  1447. });
  1448. }
  1449. receivingContext_1.emitter.trigger('drop', __assign(__assign({}, buildDatePointApiWithContext(finalHit.dateSpan, receivingContext_1)), { draggedEl: ev.subjectEl, jsEvent: ev.origEvent, view: finalHit.context.viewApi }));
  1450. receivingContext_1.emitter.trigger('eventReceive', __assign(__assign({}, eventAddArg), { draggedEl: ev.subjectEl, view: finalHit.context.viewApi }));
  1451. }
  1452. }
  1453. else {
  1454. initialContext_1.emitter.trigger('_noEventDrop');
  1455. }
  1456. }
  1457. _this.cleanup();
  1458. };
  1459. var component = _this.component;
  1460. var options = component.context.options;
  1461. var dragging = _this.dragging = new FeaturefulElementDragging(settings.el);
  1462. dragging.pointer.selector = EventDragging.SELECTOR;
  1463. dragging.touchScrollAllowed = false;
  1464. dragging.autoScroller.isEnabled = options.dragScroll;
  1465. var hitDragging = _this.hitDragging = new HitDragging(_this.dragging, interactionSettingsStore);
  1466. hitDragging.useSubjectCenter = settings.useEventCenter;
  1467. hitDragging.emitter.on('pointerdown', _this.handlePointerDown);
  1468. hitDragging.emitter.on('dragstart', _this.handleDragStart);
  1469. hitDragging.emitter.on('hitupdate', _this.handleHitUpdate);
  1470. hitDragging.emitter.on('pointerup', _this.handlePointerUp);
  1471. hitDragging.emitter.on('dragend', _this.handleDragEnd);
  1472. return _this;
  1473. }
  1474. EventDragging.prototype.destroy = function () {
  1475. this.dragging.destroy();
  1476. };
  1477. // render a drag state on the next receivingCalendar
  1478. EventDragging.prototype.displayDrag = function (nextContext, state) {
  1479. var initialContext = this.component.context;
  1480. var prevContext = this.receivingContext;
  1481. // does the previous calendar need to be cleared?
  1482. if (prevContext && prevContext !== nextContext) {
  1483. // does the initial calendar need to be cleared?
  1484. // if so, don't clear all the way. we still need to to hide the affectedEvents
  1485. if (prevContext === initialContext) {
  1486. prevContext.dispatch({
  1487. type: 'SET_EVENT_DRAG',
  1488. state: {
  1489. affectedEvents: state.affectedEvents,
  1490. mutatedEvents: createEmptyEventStore(),
  1491. isEvent: true,
  1492. },
  1493. });
  1494. // completely clear the old calendar if it wasn't the initial
  1495. }
  1496. else {
  1497. prevContext.dispatch({ type: 'UNSET_EVENT_DRAG' });
  1498. }
  1499. }
  1500. if (nextContext) {
  1501. nextContext.dispatch({ type: 'SET_EVENT_DRAG', state: state });
  1502. }
  1503. };
  1504. EventDragging.prototype.clearDrag = function () {
  1505. var initialCalendar = this.component.context;
  1506. var receivingContext = this.receivingContext;
  1507. if (receivingContext) {
  1508. receivingContext.dispatch({ type: 'UNSET_EVENT_DRAG' });
  1509. }
  1510. // the initial calendar might have an dummy drag state from displayDrag
  1511. if (initialCalendar !== receivingContext) {
  1512. initialCalendar.dispatch({ type: 'UNSET_EVENT_DRAG' });
  1513. }
  1514. };
  1515. EventDragging.prototype.cleanup = function () {
  1516. this.subjectSeg = null;
  1517. this.isDragging = false;
  1518. this.eventRange = null;
  1519. this.relevantEvents = null;
  1520. this.receivingContext = null;
  1521. this.validMutation = null;
  1522. this.mutatedRelevantEvents = null;
  1523. };
  1524. // TODO: test this in IE11
  1525. // QUESTION: why do we need it on the resizable???
  1526. EventDragging.SELECTOR = '.fc-event-draggable, .fc-event-resizable';
  1527. return EventDragging;
  1528. }(Interaction));
  1529. function computeEventMutation(hit0, hit1, massagers) {
  1530. var dateSpan0 = hit0.dateSpan;
  1531. var dateSpan1 = hit1.dateSpan;
  1532. var date0 = dateSpan0.range.start;
  1533. var date1 = dateSpan1.range.start;
  1534. var standardProps = {};
  1535. if (dateSpan0.allDay !== dateSpan1.allDay) {
  1536. standardProps.allDay = dateSpan1.allDay;
  1537. standardProps.hasEnd = hit1.context.options.allDayMaintainDuration;
  1538. if (dateSpan1.allDay) {
  1539. // means date1 is already start-of-day,
  1540. // but date0 needs to be converted
  1541. date0 = startOfDay(date0);
  1542. }
  1543. }
  1544. var delta = diffDates(date0, date1, hit0.context.dateEnv, hit0.componentId === hit1.componentId ?
  1545. hit0.largeUnit :
  1546. null);
  1547. if (delta.milliseconds) { // has hours/minutes/seconds
  1548. standardProps.allDay = false;
  1549. }
  1550. var mutation = {
  1551. datesDelta: delta,
  1552. standardProps: standardProps,
  1553. };
  1554. for (var _i = 0, massagers_1 = massagers; _i < massagers_1.length; _i++) {
  1555. var massager = massagers_1[_i];
  1556. massager(mutation, hit0, hit1);
  1557. }
  1558. return mutation;
  1559. }
  1560. function getComponentTouchDelay(component) {
  1561. var options = component.context.options;
  1562. var delay = options.eventLongPressDelay;
  1563. if (delay == null) {
  1564. delay = options.longPressDelay;
  1565. }
  1566. return delay;
  1567. }
  1568. var EventResizing = /** @class */ (function (_super) {
  1569. __extends(EventResizing, _super);
  1570. function EventResizing(settings) {
  1571. var _this = _super.call(this, settings) || this;
  1572. // internal state
  1573. _this.draggingSegEl = null;
  1574. _this.draggingSeg = null; // TODO: rename to resizingSeg? subjectSeg?
  1575. _this.eventRange = null;
  1576. _this.relevantEvents = null;
  1577. _this.validMutation = null;
  1578. _this.mutatedRelevantEvents = null;
  1579. _this.handlePointerDown = function (ev) {
  1580. var component = _this.component;
  1581. var segEl = _this.querySegEl(ev);
  1582. var seg = getElSeg(segEl);
  1583. var eventRange = _this.eventRange = seg.eventRange;
  1584. _this.dragging.minDistance = component.context.options.eventDragMinDistance;
  1585. // if touch, need to be working with a selected event
  1586. _this.dragging.setIgnoreMove(!_this.component.isValidSegDownEl(ev.origEvent.target) ||
  1587. (ev.isTouch && _this.component.props.eventSelection !== eventRange.instance.instanceId));
  1588. };
  1589. _this.handleDragStart = function (ev) {
  1590. var context = _this.component.context;
  1591. var eventRange = _this.eventRange;
  1592. _this.relevantEvents = getRelevantEvents(context.getCurrentData().eventStore, _this.eventRange.instance.instanceId);
  1593. var segEl = _this.querySegEl(ev);
  1594. _this.draggingSegEl = segEl;
  1595. _this.draggingSeg = getElSeg(segEl);
  1596. context.calendarApi.unselect();
  1597. context.emitter.trigger('eventResizeStart', {
  1598. el: segEl,
  1599. event: new EventApi(context, eventRange.def, eventRange.instance),
  1600. jsEvent: ev.origEvent,
  1601. view: context.viewApi,
  1602. });
  1603. };
  1604. _this.handleHitUpdate = function (hit, isFinal, ev) {
  1605. var context = _this.component.context;
  1606. var relevantEvents = _this.relevantEvents;
  1607. var initialHit = _this.hitDragging.initialHit;
  1608. var eventInstance = _this.eventRange.instance;
  1609. var mutation = null;
  1610. var mutatedRelevantEvents = null;
  1611. var isInvalid = false;
  1612. var interaction = {
  1613. affectedEvents: relevantEvents,
  1614. mutatedEvents: createEmptyEventStore(),
  1615. isEvent: true,
  1616. };
  1617. if (hit) {
  1618. var disallowed = hit.componentId === initialHit.componentId
  1619. && _this.isHitComboAllowed
  1620. && !_this.isHitComboAllowed(initialHit, hit);
  1621. if (!disallowed) {
  1622. mutation = computeMutation(initialHit, hit, ev.subjectEl.classList.contains('fc-event-resizer-start'), eventInstance.range);
  1623. }
  1624. }
  1625. if (mutation) {
  1626. mutatedRelevantEvents = applyMutationToEventStore(relevantEvents, context.getCurrentData().eventUiBases, mutation, context);
  1627. interaction.mutatedEvents = mutatedRelevantEvents;
  1628. if (!isInteractionValid(interaction, hit.dateProfile, context)) {
  1629. isInvalid = true;
  1630. mutation = null;
  1631. mutatedRelevantEvents = null;
  1632. interaction.mutatedEvents = null;
  1633. }
  1634. }
  1635. if (mutatedRelevantEvents) {
  1636. context.dispatch({
  1637. type: 'SET_EVENT_RESIZE',
  1638. state: interaction,
  1639. });
  1640. }
  1641. else {
  1642. context.dispatch({ type: 'UNSET_EVENT_RESIZE' });
  1643. }
  1644. if (!isInvalid) {
  1645. enableCursor();
  1646. }
  1647. else {
  1648. disableCursor();
  1649. }
  1650. if (!isFinal) {
  1651. if (mutation && isHitsEqual(initialHit, hit)) {
  1652. mutation = null;
  1653. }
  1654. _this.validMutation = mutation;
  1655. _this.mutatedRelevantEvents = mutatedRelevantEvents;
  1656. }
  1657. };
  1658. _this.handleDragEnd = function (ev) {
  1659. var context = _this.component.context;
  1660. var eventDef = _this.eventRange.def;
  1661. var eventInstance = _this.eventRange.instance;
  1662. var eventApi = new EventApi(context, eventDef, eventInstance);
  1663. var relevantEvents = _this.relevantEvents;
  1664. var mutatedRelevantEvents = _this.mutatedRelevantEvents;
  1665. context.emitter.trigger('eventResizeStop', {
  1666. el: _this.draggingSegEl,
  1667. event: eventApi,
  1668. jsEvent: ev.origEvent,
  1669. view: context.viewApi,
  1670. });
  1671. if (_this.validMutation) {
  1672. var updatedEventApi = new EventApi(context, mutatedRelevantEvents.defs[eventDef.defId], eventInstance ? mutatedRelevantEvents.instances[eventInstance.instanceId] : null);
  1673. context.dispatch({
  1674. type: 'MERGE_EVENTS',
  1675. eventStore: mutatedRelevantEvents,
  1676. });
  1677. var eventChangeArg = {
  1678. oldEvent: eventApi,
  1679. event: updatedEventApi,
  1680. relatedEvents: buildEventApis(mutatedRelevantEvents, context, eventInstance),
  1681. revert: function () {
  1682. context.dispatch({
  1683. type: 'MERGE_EVENTS',
  1684. eventStore: relevantEvents, // the pre-change events
  1685. });
  1686. },
  1687. };
  1688. context.emitter.trigger('eventResize', __assign(__assign({}, eventChangeArg), { el: _this.draggingSegEl, startDelta: _this.validMutation.startDelta || createDuration(0), endDelta: _this.validMutation.endDelta || createDuration(0), jsEvent: ev.origEvent, view: context.viewApi }));
  1689. context.emitter.trigger('eventChange', eventChangeArg);
  1690. }
  1691. else {
  1692. context.emitter.trigger('_noEventResize');
  1693. }
  1694. // reset all internal state
  1695. _this.draggingSeg = null;
  1696. _this.relevantEvents = null;
  1697. _this.validMutation = null;
  1698. // okay to keep eventInstance around. useful to set it in handlePointerDown
  1699. };
  1700. var component = settings.component;
  1701. var dragging = _this.dragging = new FeaturefulElementDragging(settings.el);
  1702. dragging.pointer.selector = '.fc-event-resizer';
  1703. dragging.touchScrollAllowed = false;
  1704. dragging.autoScroller.isEnabled = component.context.options.dragScroll;
  1705. var hitDragging = _this.hitDragging = new HitDragging(_this.dragging, interactionSettingsToStore(settings));
  1706. hitDragging.emitter.on('pointerdown', _this.handlePointerDown);
  1707. hitDragging.emitter.on('dragstart', _this.handleDragStart);
  1708. hitDragging.emitter.on('hitupdate', _this.handleHitUpdate);
  1709. hitDragging.emitter.on('dragend', _this.handleDragEnd);
  1710. return _this;
  1711. }
  1712. EventResizing.prototype.destroy = function () {
  1713. this.dragging.destroy();
  1714. };
  1715. EventResizing.prototype.querySegEl = function (ev) {
  1716. return elementClosest(ev.subjectEl, '.fc-event');
  1717. };
  1718. return EventResizing;
  1719. }(Interaction));
  1720. function computeMutation(hit0, hit1, isFromStart, instanceRange) {
  1721. var dateEnv = hit0.context.dateEnv;
  1722. var date0 = hit0.dateSpan.range.start;
  1723. var date1 = hit1.dateSpan.range.start;
  1724. var delta = diffDates(date0, date1, dateEnv, hit0.largeUnit);
  1725. if (isFromStart) {
  1726. if (dateEnv.add(instanceRange.start, delta) < instanceRange.end) {
  1727. return { startDelta: delta };
  1728. }
  1729. }
  1730. else if (dateEnv.add(instanceRange.end, delta) > instanceRange.start) {
  1731. return { endDelta: delta };
  1732. }
  1733. return null;
  1734. }
  1735. var UnselectAuto = /** @class */ (function () {
  1736. function UnselectAuto(context) {
  1737. var _this = this;
  1738. this.context = context;
  1739. this.isRecentPointerDateSelect = false; // wish we could use a selector to detect date selection, but uses hit system
  1740. this.matchesCancel = false;
  1741. this.matchesEvent = false;
  1742. this.onSelect = function (selectInfo) {
  1743. if (selectInfo.jsEvent) {
  1744. _this.isRecentPointerDateSelect = true;
  1745. }
  1746. };
  1747. this.onDocumentPointerDown = function (pev) {
  1748. var unselectCancel = _this.context.options.unselectCancel;
  1749. var downEl = getEventTargetViaRoot(pev.origEvent);
  1750. _this.matchesCancel = !!elementClosest(downEl, unselectCancel);
  1751. _this.matchesEvent = !!elementClosest(downEl, EventDragging.SELECTOR); // interaction started on an event?
  1752. };
  1753. this.onDocumentPointerUp = function (pev) {
  1754. var context = _this.context;
  1755. var documentPointer = _this.documentPointer;
  1756. var calendarState = context.getCurrentData();
  1757. // touch-scrolling should never unfocus any type of selection
  1758. if (!documentPointer.wasTouchScroll) {
  1759. if (calendarState.dateSelection && // an existing date selection?
  1760. !_this.isRecentPointerDateSelect // a new pointer-initiated date selection since last onDocumentPointerUp?
  1761. ) {
  1762. var unselectAuto = context.options.unselectAuto;
  1763. if (unselectAuto && (!unselectAuto || !_this.matchesCancel)) {
  1764. context.calendarApi.unselect(pev);
  1765. }
  1766. }
  1767. if (calendarState.eventSelection && // an existing event selected?
  1768. !_this.matchesEvent // interaction DIDN'T start on an event
  1769. ) {
  1770. context.dispatch({ type: 'UNSELECT_EVENT' });
  1771. }
  1772. }
  1773. _this.isRecentPointerDateSelect = false;
  1774. };
  1775. var documentPointer = this.documentPointer = new PointerDragging(document);
  1776. documentPointer.shouldIgnoreMove = true;
  1777. documentPointer.shouldWatchScroll = false;
  1778. documentPointer.emitter.on('pointerdown', this.onDocumentPointerDown);
  1779. documentPointer.emitter.on('pointerup', this.onDocumentPointerUp);
  1780. /*
  1781. TODO: better way to know about whether there was a selection with the pointer
  1782. */
  1783. context.emitter.on('select', this.onSelect);
  1784. }
  1785. UnselectAuto.prototype.destroy = function () {
  1786. this.context.emitter.off('select', this.onSelect);
  1787. this.documentPointer.destroy();
  1788. };
  1789. return UnselectAuto;
  1790. }());
  1791. var OPTION_REFINERS = {
  1792. fixedMirrorParent: identity,
  1793. };
  1794. var LISTENER_REFINERS = {
  1795. dateClick: identity,
  1796. eventDragStart: identity,
  1797. eventDragStop: identity,
  1798. eventDrop: identity,
  1799. eventResizeStart: identity,
  1800. eventResizeStop: identity,
  1801. eventResize: identity,
  1802. drop: identity,
  1803. eventReceive: identity,
  1804. eventLeave: identity,
  1805. };
  1806. /*
  1807. Given an already instantiated draggable object for one-or-more elements,
  1808. Interprets any dragging as an attempt to drag an events that lives outside
  1809. of a calendar onto a calendar.
  1810. */
  1811. var ExternalElementDragging = /** @class */ (function () {
  1812. function ExternalElementDragging(dragging, suppliedDragMeta) {
  1813. var _this = this;
  1814. this.receivingContext = null;
  1815. this.droppableEvent = null; // will exist for all drags, even if create:false
  1816. this.suppliedDragMeta = null;
  1817. this.dragMeta = null;
  1818. this.handleDragStart = function (ev) {
  1819. _this.dragMeta = _this.buildDragMeta(ev.subjectEl);
  1820. };
  1821. this.handleHitUpdate = function (hit, isFinal, ev) {
  1822. var dragging = _this.hitDragging.dragging;
  1823. var receivingContext = null;
  1824. var droppableEvent = null;
  1825. var isInvalid = false;
  1826. var interaction = {
  1827. affectedEvents: createEmptyEventStore(),
  1828. mutatedEvents: createEmptyEventStore(),
  1829. isEvent: _this.dragMeta.create,
  1830. };
  1831. if (hit) {
  1832. receivingContext = hit.context;
  1833. if (_this.canDropElOnCalendar(ev.subjectEl, receivingContext)) {
  1834. droppableEvent = computeEventForDateSpan(hit.dateSpan, _this.dragMeta, receivingContext);
  1835. interaction.mutatedEvents = eventTupleToStore(droppableEvent);
  1836. isInvalid = !isInteractionValid(interaction, hit.dateProfile, receivingContext);
  1837. if (isInvalid) {
  1838. interaction.mutatedEvents = createEmptyEventStore();
  1839. droppableEvent = null;
  1840. }
  1841. }
  1842. }
  1843. _this.displayDrag(receivingContext, interaction);
  1844. // show mirror if no already-rendered mirror element OR if we are shutting down the mirror (?)
  1845. // TODO: wish we could somehow wait for dispatch to guarantee render
  1846. dragging.setMirrorIsVisible(isFinal || !droppableEvent || !document.querySelector('.fc-event-mirror'));
  1847. if (!isInvalid) {
  1848. enableCursor();
  1849. }
  1850. else {
  1851. disableCursor();
  1852. }
  1853. if (!isFinal) {
  1854. dragging.setMirrorNeedsRevert(!droppableEvent);
  1855. _this.receivingContext = receivingContext;
  1856. _this.droppableEvent = droppableEvent;
  1857. }
  1858. };
  1859. this.handleDragEnd = function (pev) {
  1860. var _a = _this, receivingContext = _a.receivingContext, droppableEvent = _a.droppableEvent;
  1861. _this.clearDrag();
  1862. if (receivingContext && droppableEvent) {
  1863. var finalHit = _this.hitDragging.finalHit;
  1864. var finalView = finalHit.context.viewApi;
  1865. var dragMeta = _this.dragMeta;
  1866. receivingContext.emitter.trigger('drop', __assign(__assign({}, buildDatePointApiWithContext(finalHit.dateSpan, receivingContext)), { draggedEl: pev.subjectEl, jsEvent: pev.origEvent, view: finalView }));
  1867. if (dragMeta.create) {
  1868. var addingEvents_1 = eventTupleToStore(droppableEvent);
  1869. receivingContext.dispatch({
  1870. type: 'MERGE_EVENTS',
  1871. eventStore: addingEvents_1,
  1872. });
  1873. if (pev.isTouch) {
  1874. receivingContext.dispatch({
  1875. type: 'SELECT_EVENT',
  1876. eventInstanceId: droppableEvent.instance.instanceId,
  1877. });
  1878. }
  1879. // signal that an external event landed
  1880. receivingContext.emitter.trigger('eventReceive', {
  1881. event: new EventApi(receivingContext, droppableEvent.def, droppableEvent.instance),
  1882. relatedEvents: [],
  1883. revert: function () {
  1884. receivingContext.dispatch({
  1885. type: 'REMOVE_EVENTS',
  1886. eventStore: addingEvents_1,
  1887. });
  1888. },
  1889. draggedEl: pev.subjectEl,
  1890. view: finalView,
  1891. });
  1892. }
  1893. }
  1894. _this.receivingContext = null;
  1895. _this.droppableEvent = null;
  1896. };
  1897. var hitDragging = this.hitDragging = new HitDragging(dragging, interactionSettingsStore);
  1898. hitDragging.requireInitial = false; // will start outside of a component
  1899. hitDragging.emitter.on('dragstart', this.handleDragStart);
  1900. hitDragging.emitter.on('hitupdate', this.handleHitUpdate);
  1901. hitDragging.emitter.on('dragend', this.handleDragEnd);
  1902. this.suppliedDragMeta = suppliedDragMeta;
  1903. }
  1904. ExternalElementDragging.prototype.buildDragMeta = function (subjectEl) {
  1905. if (typeof this.suppliedDragMeta === 'object') {
  1906. return parseDragMeta(this.suppliedDragMeta);
  1907. }
  1908. if (typeof this.suppliedDragMeta === 'function') {
  1909. return parseDragMeta(this.suppliedDragMeta(subjectEl));
  1910. }
  1911. return getDragMetaFromEl(subjectEl);
  1912. };
  1913. ExternalElementDragging.prototype.displayDrag = function (nextContext, state) {
  1914. var prevContext = this.receivingContext;
  1915. if (prevContext && prevContext !== nextContext) {
  1916. prevContext.dispatch({ type: 'UNSET_EVENT_DRAG' });
  1917. }
  1918. if (nextContext) {
  1919. nextContext.dispatch({ type: 'SET_EVENT_DRAG', state: state });
  1920. }
  1921. };
  1922. ExternalElementDragging.prototype.clearDrag = function () {
  1923. if (this.receivingContext) {
  1924. this.receivingContext.dispatch({ type: 'UNSET_EVENT_DRAG' });
  1925. }
  1926. };
  1927. ExternalElementDragging.prototype.canDropElOnCalendar = function (el, receivingContext) {
  1928. var dropAccept = receivingContext.options.dropAccept;
  1929. if (typeof dropAccept === 'function') {
  1930. return dropAccept.call(receivingContext.calendarApi, el);
  1931. }
  1932. if (typeof dropAccept === 'string' && dropAccept) {
  1933. return Boolean(elementMatches(el, dropAccept));
  1934. }
  1935. return true;
  1936. };
  1937. return ExternalElementDragging;
  1938. }());
  1939. // Utils for computing event store from the DragMeta
  1940. // ----------------------------------------------------------------------------------------------------
  1941. function computeEventForDateSpan(dateSpan, dragMeta, context) {
  1942. var defProps = __assign({}, dragMeta.leftoverProps);
  1943. for (var _i = 0, _a = context.pluginHooks.externalDefTransforms; _i < _a.length; _i++) {
  1944. var transform = _a[_i];
  1945. __assign(defProps, transform(dateSpan, dragMeta));
  1946. }
  1947. var _b = refineEventDef(defProps, context), refined = _b.refined, extra = _b.extra;
  1948. var def = parseEventDef(refined, extra, dragMeta.sourceId, dateSpan.allDay, context.options.forceEventDuration || Boolean(dragMeta.duration), // hasEnd
  1949. context);
  1950. var start = dateSpan.range.start;
  1951. // only rely on time info if drop zone is all-day,
  1952. // otherwise, we already know the time
  1953. if (dateSpan.allDay && dragMeta.startTime) {
  1954. start = context.dateEnv.add(start, dragMeta.startTime);
  1955. }
  1956. var end = dragMeta.duration ?
  1957. context.dateEnv.add(start, dragMeta.duration) :
  1958. getDefaultEventEnd(dateSpan.allDay, start, context);
  1959. var instance = createEventInstance(def.defId, { start: start, end: end });
  1960. return { def: def, instance: instance };
  1961. }
  1962. // Utils for extracting data from element
  1963. // ----------------------------------------------------------------------------------------------------
  1964. function getDragMetaFromEl(el) {
  1965. var str = getEmbeddedElData(el, 'event');
  1966. var obj = str ?
  1967. JSON.parse(str) :
  1968. { create: false }; // if no embedded data, assume no event creation
  1969. return parseDragMeta(obj);
  1970. }
  1971. config.dataAttrPrefix = '';
  1972. function getEmbeddedElData(el, name) {
  1973. var prefix = config.dataAttrPrefix;
  1974. var prefixedName = (prefix ? prefix + '-' : '') + name;
  1975. return el.getAttribute('data-' + prefixedName) || '';
  1976. }
  1977. /*
  1978. Makes an element (that is *external* to any calendar) draggable.
  1979. Can pass in data that determines how an event will be created when dropped onto a calendar.
  1980. Leverages FullCalendar's internal drag-n-drop functionality WITHOUT a third-party drag system.
  1981. */
  1982. var ExternalDraggable = /** @class */ (function () {
  1983. function ExternalDraggable(el, settings) {
  1984. var _this = this;
  1985. if (settings === void 0) { settings = {}; }
  1986. this.handlePointerDown = function (ev) {
  1987. var dragging = _this.dragging;
  1988. var _a = _this.settings, minDistance = _a.minDistance, longPressDelay = _a.longPressDelay;
  1989. dragging.minDistance =
  1990. minDistance != null ?
  1991. minDistance :
  1992. (ev.isTouch ? 0 : BASE_OPTION_DEFAULTS.eventDragMinDistance);
  1993. dragging.delay =
  1994. ev.isTouch ? // TODO: eventually read eventLongPressDelay instead vvv
  1995. (longPressDelay != null ? longPressDelay : BASE_OPTION_DEFAULTS.longPressDelay) :
  1996. 0;
  1997. };
  1998. this.handleDragStart = function (ev) {
  1999. if (ev.isTouch &&
  2000. _this.dragging.delay &&
  2001. ev.subjectEl.classList.contains('fc-event')) {
  2002. _this.dragging.mirror.getMirrorEl().classList.add('fc-event-selected');
  2003. }
  2004. };
  2005. this.settings = settings;
  2006. var dragging = this.dragging = new FeaturefulElementDragging(el);
  2007. dragging.touchScrollAllowed = false;
  2008. if (settings.itemSelector != null) {
  2009. dragging.pointer.selector = settings.itemSelector;
  2010. }
  2011. if (settings.appendTo != null) {
  2012. dragging.mirror.parentNode = settings.appendTo; // TODO: write tests
  2013. }
  2014. dragging.emitter.on('pointerdown', this.handlePointerDown);
  2015. dragging.emitter.on('dragstart', this.handleDragStart);
  2016. new ExternalElementDragging(dragging, settings.eventData); // eslint-disable-line no-new
  2017. }
  2018. ExternalDraggable.prototype.destroy = function () {
  2019. this.dragging.destroy();
  2020. };
  2021. return ExternalDraggable;
  2022. }());
  2023. /*
  2024. Detects when a *THIRD-PARTY* drag-n-drop system interacts with elements.
  2025. The third-party system is responsible for drawing the visuals effects of the drag.
  2026. This class simply monitors for pointer movements and fires events.
  2027. It also has the ability to hide the moving element (the "mirror") during the drag.
  2028. */
  2029. var InferredElementDragging = /** @class */ (function (_super) {
  2030. __extends(InferredElementDragging, _super);
  2031. function InferredElementDragging(containerEl) {
  2032. var _this = _super.call(this, containerEl) || this;
  2033. _this.shouldIgnoreMove = false;
  2034. _this.mirrorSelector = '';
  2035. _this.currentMirrorEl = null;
  2036. _this.handlePointerDown = function (ev) {
  2037. _this.emitter.trigger('pointerdown', ev);
  2038. if (!_this.shouldIgnoreMove) {
  2039. // fire dragstart right away. does not support delay or min-distance
  2040. _this.emitter.trigger('dragstart', ev);
  2041. }
  2042. };
  2043. _this.handlePointerMove = function (ev) {
  2044. if (!_this.shouldIgnoreMove) {
  2045. _this.emitter.trigger('dragmove', ev);
  2046. }
  2047. };
  2048. _this.handlePointerUp = function (ev) {
  2049. _this.emitter.trigger('pointerup', ev);
  2050. if (!_this.shouldIgnoreMove) {
  2051. // fire dragend right away. does not support a revert animation
  2052. _this.emitter.trigger('dragend', ev);
  2053. }
  2054. };
  2055. var pointer = _this.pointer = new PointerDragging(containerEl);
  2056. pointer.emitter.on('pointerdown', _this.handlePointerDown);
  2057. pointer.emitter.on('pointermove', _this.handlePointerMove);
  2058. pointer.emitter.on('pointerup', _this.handlePointerUp);
  2059. return _this;
  2060. }
  2061. InferredElementDragging.prototype.destroy = function () {
  2062. this.pointer.destroy();
  2063. };
  2064. InferredElementDragging.prototype.setIgnoreMove = function (bool) {
  2065. this.shouldIgnoreMove = bool;
  2066. };
  2067. InferredElementDragging.prototype.setMirrorIsVisible = function (bool) {
  2068. if (bool) {
  2069. // restore a previously hidden element.
  2070. // use the reference in case the selector class has already been removed.
  2071. if (this.currentMirrorEl) {
  2072. this.currentMirrorEl.style.visibility = '';
  2073. this.currentMirrorEl = null;
  2074. }
  2075. }
  2076. else {
  2077. var mirrorEl = this.mirrorSelector
  2078. // TODO: somehow query FullCalendars WITHIN shadow-roots
  2079. ? document.querySelector(this.mirrorSelector)
  2080. : null;
  2081. if (mirrorEl) {
  2082. this.currentMirrorEl = mirrorEl;
  2083. mirrorEl.style.visibility = 'hidden';
  2084. }
  2085. }
  2086. };
  2087. return InferredElementDragging;
  2088. }(ElementDragging));
  2089. /*
  2090. Bridges third-party drag-n-drop systems with FullCalendar.
  2091. Must be instantiated and destroyed by caller.
  2092. */
  2093. var ThirdPartyDraggable = /** @class */ (function () {
  2094. function ThirdPartyDraggable(containerOrSettings, settings) {
  2095. var containerEl = document;
  2096. if (
  2097. // wish we could just test instanceof EventTarget, but doesn't work in IE11
  2098. containerOrSettings === document ||
  2099. containerOrSettings instanceof Element) {
  2100. containerEl = containerOrSettings;
  2101. settings = settings || {};
  2102. }
  2103. else {
  2104. settings = (containerOrSettings || {});
  2105. }
  2106. var dragging = this.dragging = new InferredElementDragging(containerEl);
  2107. if (typeof settings.itemSelector === 'string') {
  2108. dragging.pointer.selector = settings.itemSelector;
  2109. }
  2110. else if (containerEl === document) {
  2111. dragging.pointer.selector = '[data-event]';
  2112. }
  2113. if (typeof settings.mirrorSelector === 'string') {
  2114. dragging.mirrorSelector = settings.mirrorSelector;
  2115. }
  2116. new ExternalElementDragging(dragging, settings.eventData); // eslint-disable-line no-new
  2117. }
  2118. ThirdPartyDraggable.prototype.destroy = function () {
  2119. this.dragging.destroy();
  2120. };
  2121. return ThirdPartyDraggable;
  2122. }());
  2123. var main = createPlugin({
  2124. componentInteractions: [DateClicking, DateSelecting, EventDragging, EventResizing],
  2125. calendarInteractions: [UnselectAuto],
  2126. elementDraggingImpl: FeaturefulElementDragging,
  2127. optionRefiners: OPTION_REFINERS,
  2128. listenerRefiners: LISTENER_REFINERS,
  2129. });
  2130. export default main;
  2131. export { ExternalDraggable as Draggable, FeaturefulElementDragging, PointerDragging, ThirdPartyDraggable };
  2132. //# sourceMappingURL=main.js.map