No Description

main.esm.js 4.2KB

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