仰望星辰工作室

better-staridc-MNBT

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