main.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*!
  2. FullCalendar RRule Plugin v4.3.0
  3. Docs & License: https://fullcalendar.io/
  4. (c) 2019 Adam Shaw
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rrule'), require('@fullcalendar/core')) :
  8. typeof define === 'function' && define.amd ? define(['exports', 'rrule', '@fullcalendar/core'], factory) :
  9. (global = global || self, factory(global.FullCalendarRrule = {}, global.rrule, global.FullCalendar));
  10. }(this, function (exports, rrule, core) {
  11. 'use strict';
  12. /*! *****************************************************************************
  13. Copyright (c) Microsoft Corporation. All rights reserved.
  14. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  15. this file except in compliance with the License. You may obtain a copy of the
  16. License at http://www.apache.org/licenses/LICENSE-2.0
  17. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  19. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  20. MERCHANTABLITY OR NON-INFRINGEMENT.
  21. See the Apache Version 2.0 License for specific language governing permissions
  22. and limitations under the License.
  23. ***************************************************************************** */
  24. var __assign = function () {
  25. __assign = Object.assign || function __assign(t) {
  26. for (var s, i = 1, n = arguments.length; i < n; i++) {
  27. s = arguments[i];
  28. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  29. }
  30. return t;
  31. };
  32. return __assign.apply(this, arguments);
  33. };
  34. var EVENT_DEF_PROPS = {
  35. rrule: null,
  36. duration: core.createDuration
  37. };
  38. var recurring = {
  39. parse: function (rawEvent, leftoverProps, dateEnv) {
  40. if (rawEvent.rrule != null) {
  41. var props = core.refineProps(rawEvent, EVENT_DEF_PROPS, {}, leftoverProps);
  42. var parsed = parseRRule(props.rrule, dateEnv);
  43. if (parsed) {
  44. return {
  45. typeData: parsed.rrule,
  46. allDayGuess: parsed.allDayGuess,
  47. duration: props.duration
  48. };
  49. }
  50. }
  51. return null;
  52. },
  53. expand: function (rrule, framingRange) {
  54. // we WANT an inclusive start and in exclusive end, but the js rrule lib will only do either BOTH
  55. // inclusive or BOTH exclusive, which is stupid: https://github.com/jakubroztocil/rrule/issues/84
  56. // Workaround: make inclusive, which will generate extra occurences, and then trim.
  57. return rrule.between(framingRange.start, framingRange.end, true)
  58. .filter(function (date) {
  59. return date.valueOf() < framingRange.end.valueOf();
  60. });
  61. }
  62. };
  63. var main = core.createPlugin({
  64. recurringTypes: [recurring]
  65. });
  66. function parseRRule(input, dateEnv) {
  67. var allDayGuess = null;
  68. var rrule$1;
  69. if (typeof input === 'string') {
  70. rrule$1 = rrule.rrulestr(input);
  71. } else if (typeof input === 'object' && input) { // non-null object
  72. var refined = __assign({}, input); // copy
  73. if (typeof refined.dtstart === 'string') {
  74. var dtstartMeta = dateEnv.createMarkerMeta(refined.dtstart);
  75. if (dtstartMeta) {
  76. refined.dtstart = dtstartMeta.marker;
  77. allDayGuess = dtstartMeta.isTimeUnspecified;
  78. } else {
  79. delete refined.dtstart;
  80. }
  81. }
  82. if (typeof refined.until === 'string') {
  83. refined.until = dateEnv.createMarker(refined.until);
  84. }
  85. if (refined.freq != null) {
  86. refined.freq = convertConstant(refined.freq);
  87. }
  88. if (refined.wkst != null) {
  89. refined.wkst = convertConstant(refined.wkst);
  90. } else {
  91. refined.wkst = (dateEnv.weekDow - 1 + 7) % 7; // convert Sunday-first to Monday-first
  92. }
  93. if (refined.byweekday != null) {
  94. refined.byweekday = convertConstants(refined.byweekday); // the plural version
  95. }
  96. rrule$1 = new rrule.RRule(refined);
  97. }
  98. if (rrule$1) {
  99. return {rrule: rrule$1, allDayGuess: allDayGuess};
  100. }
  101. return null;
  102. }
  103. function convertConstants(input) {
  104. if (Array.isArray(input)) {
  105. return input.map(convertConstant);
  106. }
  107. return convertConstant(input);
  108. }
  109. function convertConstant(input) {
  110. if (typeof input === 'string') {
  111. return rrule.RRule[input.toUpperCase()];
  112. }
  113. return input;
  114. }
  115. exports.default = main;
  116. Object.defineProperty(exports, '__esModule', {value: true});
  117. }));