@koine/react 1.0.9 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Alert/Alert.js +7 -13
- package/Animations/Reveal.js +12 -10
- package/Animations/Underline.js +3 -13
- package/Animations/useReveal.js +18 -17
- package/Autocomplete/AutocompleteDownshift.js +1 -1
- package/Autocomplete/AutocompleteDownshiftMultiselect.js +1 -1
- package/Autocomplete/AutocompleteMui.js +61 -56
- package/Autocomplete/AutocompleteReach.js +1 -1
- package/Autocomplete/components.js +17 -72
- package/Autocomplete/helpers.js +1 -1
- package/Bg/BgColor.js +14 -24
- package/Bg/BgPhoto.js +11 -54
- package/Bg/BgSvg.js +6 -9
- package/Breadcrumbs/Breadcrumbs.js +14 -54
- package/Buttons/Button.js +8 -73
- package/Buttons/ButtonComposite.js +20 -41
- package/Buttons/ButtonFab.js +4 -6
- package/Buttons/ButtonLink.js +7 -6
- package/Buttons/IconButton.js +5 -17
- package/Calendar/CalendarDaygridCell.js +20 -14
- package/Calendar/CalendarDaygridNav.js +10 -9
- package/Calendar/CalendarDaygridTable.js +32 -30
- package/Calendar/CalendarLegend.js +7 -2
- package/Calendar/calendar-api-google.js +101 -68
- package/Calendar/useCalendar.js +114 -113
- package/Calendar/utils.js +73 -74
- package/Carousel/Carousel.js +1 -1
- package/Carousel/CarouselCss.js +14 -27
- package/Collapsable/Collapsable.d.ts +1 -1
- package/Collapsable/Collapsable.js +1 -1
- package/Collapsable/CollapsableReach.d.ts +4 -64
- package/Collapsable/CollapsableReach.js +247 -129
- package/Collapsable/index.d.ts +1 -1
- package/Collapsable/index.js +2 -1
- package/Debug/Debug.js +5 -17
- package/Details/Details.d.ts +114 -0
- package/Details/Details.js +65 -0
- package/Details/index.d.ts +1 -0
- package/Details/index.js +1 -0
- package/{Forms/Form → Details}/package.json +1 -1
- package/Dialog/DialogMui.d.ts +1 -1
- package/Dialog/DialogMui.js +22 -20
- package/Dialog/css/bare.js +17 -15
- package/Dialog/m/bare.js +17 -13
- package/Dialog/m/basic.js +2 -2
- package/Dialog/m/index.js +4 -4
- package/Dialog/sc/bare.js +25 -43
- package/Dialog/sc/framer.js +6 -6
- package/Dialog/sc/framerMaterial.js +6 -6
- package/Dialog/sc/material.js +17 -37
- package/Dialog/tw/bare.js +25 -19
- package/Dialog/tw/elegant.js +17 -15
- package/Dialog/tw/framer.js +6 -6
- package/Dialog/tw/framerMaterial.js +6 -6
- package/Dialog/tw/material.js +17 -15
- package/Editor/Editor--tiptap.js +14 -11
- package/Editor/components.js +6 -24
- package/Favicon/FaviconTags.js +2 -1
- package/Form/Form.d.ts +111 -0
- package/Form/Form.js +61 -0
- package/{Forms/Form → Form}/index.d.ts +0 -0
- package/{Forms/Form → Form}/index.js +0 -0
- package/Form/package.json +6 -0
- package/Form/sc/bare.d.ts +33 -0
- package/Form/sc/bare.js +20 -0
- package/Forms/Checkbox/Checkbox.js +9 -15
- package/Forms/Feedback/Feedback.js +6 -7
- package/Forms/Field/Field.js +15 -26
- package/Forms/Field/FieldControl.js +19 -15
- package/Forms/Field/FieldHint.js +3 -5
- package/Forms/Input/Input.js +10 -16
- package/Forms/InputGroup/InputGroup.js +9 -36
- package/Forms/Label/Label.js +5 -23
- package/Forms/Password/Password.js +10 -23
- package/Forms/Radio/Radio.js +15 -18
- package/Forms/Switch/Switch.js +9 -39
- package/Forms/Textarea/Textarea.js +6 -7
- package/Forms/Textarea/TextareaRich.js +10 -24
- package/Forms/Toggle/Toggle.js +21 -68
- package/Forms/Toggle/useToggle.js +29 -29
- package/Forms/antispam.js +12 -12
- package/Forms/helpers.js +8 -7
- package/Forms/index.d.ts +0 -1
- package/Forms/index.js +0 -1
- package/Forms/styles.js +12 -43
- package/Gauge/Gauge.js +1 -1
- package/Grid/Grid.js +25 -51
- package/Hamburger/Hamburger.js +35 -47
- package/Header/useHeader.js +12 -12
- package/Hidden/Hidden.js +9 -13
- package/Img/sc/bare.js +3 -1
- package/Link/Link.js +3 -1
- package/Link/LinkBlank.js +8 -17
- package/Menu/Menu.js +3 -10
- package/MenuItem/MenuItem.js +3 -19
- package/Meta/Meta.js +3 -2
- package/NoJs/NoJs.js +2 -2
- package/Pagination/PaginationNav.js +26 -48
- package/Pagination/PaginationResults.js +7 -6
- package/Pill/Pill.js +6 -36
- package/Progress/ProgressCircular.js +9 -30
- package/Progress/ProgressLinear.js +8 -16
- package/Progress/ProgressOverlay.js +11 -27
- package/Rating/Rating.js +26 -45
- package/Rating/index.js +19 -15
- package/Select/SelectDownshift.js +1 -1
- package/Select/components.js +6 -12
- package/Sidebar/Sidebar.js +13 -38
- package/Spacing/Spacing.js +12 -12
- package/Sticky/Sticky.js +1 -1
- package/Sticky/StickyCss.js +4 -2
- package/Tabs/TabsMui.d.ts +244 -0
- package/Tabs/TabsMui.js +46 -0
- package/Tabs/index.d.ts +1 -1
- package/Tabs/index.js +1 -1
- package/Tabs/sc/bare.d.ts +5 -0
- package/Tabs/sc/bare.js +87 -0
- package/Tabs/tw/bare.d.ts +248 -0
- package/Tabs/tw/bare.js +17 -0
- package/Tabs/tw/material.d.ts +472 -0
- package/Tabs/tw/material.js +18 -0
- package/Tabs/useTabs.d.ts +43 -0
- package/Tabs/useTabs.js +44 -0
- package/Typography/CopyPasteVisible.js +3 -5
- package/Typography/Native.js +12 -45
- package/Typography/ReadMore.js +26 -52
- package/Typography/TextLoop.js +19 -22
- package/Typography/TypeStairs.js +20 -16
- package/css/index.js +1 -0
- package/helpers/classed.js +22 -18
- package/helpers/extend-component.js +6 -6
- package/hooks/index.d.ts +8 -0
- package/hooks/index.js +8 -0
- package/hooks/types.d.ts +8 -0
- package/hooks/types.js +1 -0
- package/hooks/useAsyncFn.d.ts +26 -0
- package/hooks/useAsyncFn.js +36 -0
- package/hooks/useDateLocale.js +22 -13
- package/hooks/useEffectOnce.d.ts +5 -0
- package/hooks/useEffectOnce.js +8 -0
- package/hooks/useFirstMountState.d.ts +4 -0
- package/hooks/useFirstMountState.js +12 -0
- package/hooks/useFocus.js +3 -3
- package/hooks/useId.d.ts +4 -0
- package/hooks/useId.js +8 -0
- package/hooks/useIsomorphicLayoutEffect.d.ts +5 -0
- package/hooks/useIsomorphicLayoutEffect.js +8 -0
- package/hooks/useMount.d.ts +4 -0
- package/hooks/useMount.js +9 -0
- package/hooks/useMountedState.d.ts +4 -0
- package/hooks/useMountedState.js +15 -0
- package/hooks/usePrevious.js +2 -2
- package/hooks/useScrollPosition.js +21 -16
- package/hooks/useScrollTo.js +7 -5
- package/hooks/useTraceUpdate.js +4 -3
- package/hooks/useUpdateEffect.d.ts +5 -0
- package/hooks/useUpdateEffect.js +14 -0
- package/hooks/useWindowSize.js +3 -3
- package/m/MotionProvider.js +4 -2
- package/node/Alert/Alert.js +9 -16
- package/node/Alert/index.js +1 -1
- package/node/Animations/Reveal.js +15 -13
- package/node/Animations/Underline.js +5 -16
- package/node/Animations/index.js +1 -1
- package/node/Animations/useReveal.js +19 -18
- package/node/Autocomplete/AutocompleteMui.js +69 -64
- package/node/Autocomplete/components.js +26 -82
- package/node/Autocomplete/helpers.js +2 -2
- package/node/Bg/BgColor.js +18 -29
- package/node/Bg/BgPhoto.js +15 -59
- package/node/Bg/BgSvg.js +8 -12
- package/node/Bg/index.js +1 -1
- package/node/Breadcrumbs/Breadcrumbs.js +20 -61
- package/node/Breadcrumbs/index.js +1 -1
- package/node/Buttons/Button.js +10 -76
- package/node/Buttons/ButtonComposite.js +23 -45
- package/node/Buttons/ButtonFab.js +6 -9
- package/node/Buttons/ButtonLink.js +10 -10
- package/node/Buttons/IconButton.js +7 -20
- package/node/Buttons/index.js +1 -1
- package/node/Calendar/CalendarDaygridCell.js +24 -18
- package/node/Calendar/CalendarDaygridNav.js +14 -13
- package/node/Calendar/CalendarDaygridTable.js +39 -38
- package/node/Calendar/CalendarLegend.js +8 -3
- package/node/Calendar/calendar-api-google.js +105 -73
- package/node/Calendar/index.js +1 -1
- package/node/Calendar/useCalendar.js +117 -116
- package/node/Calendar/utils.js +82 -84
- package/node/Carousel/CarouselCss.js +17 -31
- package/node/Carousel/index.js +1 -1
- package/node/Collapsable/Collapsable.js +2 -2
- package/node/Collapsable/CollapsableReach.js +246 -134
- package/node/Collapsable/index.js +3 -2
- package/node/Debug/Debug.js +7 -20
- package/node/Debug/index.js +1 -1
- package/node/Details/Details.js +67 -0
- package/node/Details/index.js +4 -0
- package/node/Dialog/DialogMui.js +12 -11
- package/node/Dialog/css/bare.js +11 -10
- package/node/Dialog/m/bare.js +18 -14
- package/node/Dialog/m/basic.js +1 -1
- package/node/Dialog/m/index.js +4 -4
- package/node/Dialog/sc/bare.js +22 -41
- package/node/Dialog/sc/framer.js +5 -5
- package/node/Dialog/sc/framerMaterial.js +5 -5
- package/node/Dialog/sc/material.js +12 -33
- package/node/Dialog/tw/bare.js +19 -14
- package/node/Dialog/tw/elegant.js +11 -9
- package/node/Dialog/tw/framer.js +5 -5
- package/node/Dialog/tw/framerMaterial.js +5 -5
- package/node/Dialog/tw/material.js +11 -9
- package/node/Editor/Editor--tiptap.js +19 -17
- package/node/Editor/components.js +9 -28
- package/node/Editor/index.js +1 -1
- package/node/Favicon/FaviconTags.js +3 -2
- package/node/Favicon/index.js +1 -1
- package/node/Form/Form.js +65 -0
- package/node/{Forms/Form → Form}/index.js +1 -1
- package/node/Form/sc/bare.js +23 -0
- package/node/Forms/Checkbox/Checkbox.js +13 -20
- package/node/Forms/Checkbox/index.js +1 -1
- package/node/Forms/Feedback/Feedback.js +8 -10
- package/node/Forms/Feedback/index.js +1 -1
- package/node/Forms/Field/Field.js +18 -30
- package/node/Forms/Field/FieldControl.js +26 -22
- package/node/Forms/Field/FieldHint.js +4 -7
- package/node/Forms/Field/index.js +1 -1
- package/node/Forms/Input/Input.js +15 -22
- package/node/Forms/Input/index.js +1 -1
- package/node/Forms/InputGroup/InputGroup.js +14 -42
- package/node/Forms/InputGroup/index.js +1 -1
- package/node/Forms/Label/Label.js +6 -25
- package/node/Forms/Label/index.js +1 -1
- package/node/Forms/Password/Password.js +16 -30
- package/node/Forms/Password/index.js +1 -1
- package/node/Forms/Radio/Radio.js +21 -25
- package/node/Forms/Radio/index.js +1 -1
- package/node/Forms/Switch/Switch.js +15 -46
- package/node/Forms/Switch/index.js +1 -1
- package/node/Forms/Textarea/Textarea.js +11 -13
- package/node/Forms/Textarea/TextareaRich.js +16 -31
- package/node/Forms/Textarea/index.js +1 -1
- package/node/Forms/Toggle/Toggle.js +24 -72
- package/node/Forms/Toggle/index.js +1 -1
- package/node/Forms/Toggle/useToggle.js +33 -33
- package/node/Forms/antispam.js +14 -14
- package/node/Forms/helpers.js +9 -8
- package/node/Forms/index.js +1 -2
- package/node/Forms/styles.js +16 -48
- package/node/Gauge/Gauge.js +1 -1
- package/node/Grid/Grid.js +24 -51
- package/node/Grid/index.js +1 -1
- package/node/Hamburger/Hamburger.js +37 -50
- package/node/Hamburger/index.js +1 -1
- package/node/Header/index.js +1 -1
- package/node/Header/useHeader.js +16 -16
- package/node/Hidden/Hidden.js +10 -15
- package/node/Hidden/index.js +1 -1
- package/node/Img/index.js +1 -1
- package/node/Img/sc/bare.js +4 -3
- package/node/Link/Link.js +4 -3
- package/node/Link/LinkBlank.js +11 -21
- package/node/Link/index.js +1 -1
- package/node/Menu/Menu.js +4 -12
- package/node/Menu/index.js +1 -1
- package/node/MenuItem/MenuItem.js +4 -21
- package/node/MenuItem/index.js +1 -1
- package/node/Meta/Meta.js +4 -3
- package/node/Meta/index.js +1 -1
- package/node/NoJs/NoJs.js +3 -3
- package/node/NoJs/index.js +1 -1
- package/node/Pagination/PaginationNav.js +30 -53
- package/node/Pagination/PaginationResults.js +10 -10
- package/node/Pagination/index.js +1 -1
- package/node/Pill/Pill.js +7 -38
- package/node/Pill/index.js +1 -1
- package/node/Progress/ProgressCircular.js +11 -33
- package/node/Progress/ProgressLinear.js +11 -20
- package/node/Progress/ProgressOverlay.js +18 -35
- package/node/Progress/index.js +1 -1
- package/node/Rating/Rating.js +28 -48
- package/node/Rating/index.js +20 -16
- package/node/Select/components.js +11 -18
- package/node/Sidebar/Sidebar.js +21 -47
- package/node/Sidebar/index.js +1 -1
- package/node/Spacing/Spacing.js +16 -17
- package/node/Spacing/index.js +1 -1
- package/node/Sticky/StickyCss.js +5 -3
- package/node/Sticky/index.js +1 -1
- package/node/Tabs/TabsMui.js +49 -0
- package/node/Tabs/index.js +2 -2
- package/node/Tabs/sc/bare.js +87 -0
- package/node/Tabs/tw/bare.js +20 -0
- package/node/Tabs/tw/material.js +21 -0
- package/node/Tabs/useTabs.js +48 -0
- package/node/Typography/CopyPasteVisible.js +4 -7
- package/node/Typography/Native.js +14 -48
- package/node/Typography/ReadMore.js +30 -57
- package/node/Typography/TextLoop.js +22 -25
- package/node/Typography/TypeStairs.js +22 -18
- package/node/Typography/index.js +1 -1
- package/node/css/index.js +2 -1
- package/node/helpers/classed.js +23 -19
- package/node/helpers/extend-component.js +7 -7
- package/node/helpers/index.js +1 -1
- package/node/hooks/index.js +9 -1
- package/node/hooks/types.js +2 -0
- package/node/hooks/useAsyncFn.js +40 -0
- package/node/hooks/useDateLocale.js +23 -37
- package/node/hooks/useEffectOnce.js +12 -0
- package/node/hooks/useFirstMountState.js +16 -0
- package/node/hooks/useFocus.js +4 -4
- package/node/hooks/useId.js +12 -0
- package/node/hooks/useIsomorphicLayoutEffect.js +11 -0
- package/node/hooks/useMount.js +13 -0
- package/node/hooks/useMountedState.js +19 -0
- package/node/hooks/usePrevious.js +3 -3
- package/node/hooks/useScrollPosition.js +23 -19
- package/node/hooks/useScrollTo.js +9 -7
- package/node/hooks/useTraceUpdate.js +5 -4
- package/node/hooks/useUpdateEffect.js +18 -0
- package/node/hooks/useWindowSize.js +4 -4
- package/node/index.js +1 -1
- package/node/m/MotionProvider.js +6 -4
- package/node/m/index.js +1 -1
- package/node/m/lite.js +1 -1
- package/node/m/max.js +1 -1
- package/node/sc/index.js +4 -2
- package/node/scm/index.js +2 -1
- package/node/shared/index.js +1 -1
- package/node/styles/Body.js +5 -10
- package/node/styles/Global.js +5 -37
- package/node/styles/index.js +1 -1
- package/node/styles/media.js +42 -38
- package/node/styles/spacing.js +15 -16
- package/node/styles/styled.js +7 -21
- package/node/styles/theme--vanilla.js +21 -19
- package/node/styles/theme.js +9 -9
- package/node/tw/index.js +2 -1
- package/node/twm/index.js +2 -1
- package/package.json +20 -9
- package/sc/index.d.ts +1 -0
- package/sc/index.js +1 -0
- package/scm/index.js +1 -0
- package/styles/Body.js +4 -8
- package/styles/Global.js +4 -36
- package/styles/media.js +41 -36
- package/styles/spacing.js +15 -16
- package/styles/styled.js +7 -21
- package/styles/theme--vanilla.js +21 -19
- package/styles/theme.js +11 -11
- package/tw/index.js +1 -0
- package/twm/index.js +1 -0
- package/Forms/Form/Form.d.ts +0 -31
- package/Forms/Form/Form.js +0 -62
- package/Tabs/Tabs.d.ts +0 -27
- package/Tabs/Tabs.js +0 -62
- package/node/Forms/Form/Form.js +0 -67
- package/node/Tabs/Tabs.js +0 -67
|
@@ -1,72 +1,105 @@
|
|
|
1
|
+
import { __assign, __awaiter, __generator, __rest } from "tslib";
|
|
1
2
|
import { arrayToLookup, isString, isUndefined } from "@koine/utils";
|
|
2
3
|
import differenceInDays from "date-fns/differenceInDays";
|
|
3
4
|
import subDays from "date-fns/subDays";
|
|
4
5
|
import { getEventTimestamp, addCalendarEvents } from "./utils";
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
var baseURL = "https://www.googleapis.com/calendar/v3/calendars/";
|
|
7
|
+
export function getCalendarsEventsFromGoogle(_a) {
|
|
8
|
+
var calendars = _a.calendars, options = __rest(_a, ["calendars"]);
|
|
9
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
10
|
+
var allEvents;
|
|
11
|
+
var _this = this;
|
|
12
|
+
return __generator(this, function (_b) {
|
|
13
|
+
switch (_b.label) {
|
|
14
|
+
case 0:
|
|
15
|
+
allEvents = {};
|
|
16
|
+
return [4 /*yield*/, Promise.all(calendars.map(function (calendar) { return __awaiter(_this, void 0, void 0, function () {
|
|
17
|
+
var events;
|
|
18
|
+
return __generator(this, function (_a) {
|
|
19
|
+
switch (_a.label) {
|
|
20
|
+
case 0: return [4 /*yield*/, getCalendarEventsFromGoogle(__assign({ calendar: calendar }, options))];
|
|
21
|
+
case 1:
|
|
22
|
+
events = _a.sent();
|
|
23
|
+
addCalendarEvents(events, allEvents);
|
|
24
|
+
return [2 /*return*/];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}); }))];
|
|
28
|
+
case 1:
|
|
29
|
+
_b.sent();
|
|
30
|
+
return [2 /*return*/, allEvents];
|
|
31
|
+
}
|
|
12
32
|
});
|
|
13
|
-
|
|
14
|
-
}));
|
|
15
|
-
return allEvents;
|
|
33
|
+
});
|
|
16
34
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
function getCalendarEventsFromGoogle(_a) {
|
|
36
|
+
var apiKey = _a.apiKey, calendar = _a.calendar, _b = _a.timeZone, timeZone = _b === void 0 ? "" : _b, start = _a.start, end = _a.end;
|
|
37
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
38
|
+
var events, params, url, response, data, e_1;
|
|
39
|
+
return __generator(this, function (_c) {
|
|
40
|
+
switch (_c.label) {
|
|
41
|
+
case 0:
|
|
42
|
+
events = {};
|
|
43
|
+
params = new URLSearchParams({
|
|
44
|
+
calendarId: calendar.id,
|
|
45
|
+
timeZone: timeZone,
|
|
46
|
+
singleEvents: "true",
|
|
47
|
+
maxAttendees: "1",
|
|
48
|
+
maxResults: "9999",
|
|
49
|
+
sanitizeHtml: "true",
|
|
50
|
+
timeMin: start.toISOString(),
|
|
51
|
+
timeMax: end.toISOString(),
|
|
52
|
+
key: apiKey || process.env["GOOGLE_CALENDAR_API_KEY"] || "",
|
|
53
|
+
}).toString();
|
|
54
|
+
url = baseURL + calendar.id + "/events?" + params;
|
|
55
|
+
_c.label = 1;
|
|
56
|
+
case 1:
|
|
57
|
+
_c.trys.push([1, 4, , 5]);
|
|
58
|
+
return [4 /*yield*/, fetch(url, { method: "GET" })];
|
|
59
|
+
case 2:
|
|
60
|
+
response = _c.sent();
|
|
61
|
+
return [4 /*yield*/, response.json()];
|
|
62
|
+
case 3:
|
|
63
|
+
data = (_c.sent());
|
|
64
|
+
calendar.name = calendar.name || data.summary;
|
|
65
|
+
data.items.forEach(function (googleEvent) {
|
|
66
|
+
var event = transformCalendarEventFromGoogle(googleEvent, calendar);
|
|
67
|
+
events[event.uid] = event;
|
|
68
|
+
});
|
|
69
|
+
return [3 /*break*/, 5];
|
|
70
|
+
case 4:
|
|
71
|
+
e_1 = _c.sent();
|
|
72
|
+
return [3 /*break*/, 5];
|
|
73
|
+
case 5: return [2 /*return*/, events];
|
|
74
|
+
}
|
|
38
75
|
});
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
// if (onError) onError(e);
|
|
42
|
-
}
|
|
43
|
-
return events;
|
|
76
|
+
});
|
|
44
77
|
}
|
|
45
78
|
function transformCalendarEventFromGoogle(event, calendar) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
79
|
+
var created = new Date(event.created);
|
|
80
|
+
var link = event.htmlLink;
|
|
81
|
+
var title = event.summary;
|
|
82
|
+
var status = event.status;
|
|
83
|
+
var start = new Date(event.start.date || event.start.dateTime);
|
|
84
|
+
var end = new Date(event.end.date || event.end.dateTime);
|
|
85
|
+
var color = calendar.color;
|
|
86
|
+
var allDay = isUndefined(event.end.dateTime) && isString(event.end.date);
|
|
87
|
+
var location = event.location || "";
|
|
88
|
+
var description = event.description || ""; // FIXME: he.decode(event.description || '');
|
|
89
|
+
var uid = created.getTime() + "" + start.getTime();
|
|
57
90
|
// multi-days all day events has as end date the date after to what we actually
|
|
58
91
|
// mean, hence we subtract one day. @see https://support.google.com/calendar/thread/10074544/google-calendar-all-day-events-are-showing-up-as-a-24-hr-event-across-time-zones?hl=en
|
|
59
92
|
if (allDay && end > start) {
|
|
60
93
|
end = subDays(end, 1);
|
|
61
94
|
end.setHours(23, 59, 59);
|
|
62
95
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
96
|
+
var days = getDays();
|
|
97
|
+
var daysMap = arrayToLookup(days);
|
|
98
|
+
var multi = days.length > 1;
|
|
66
99
|
function getDays() {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
100
|
+
var from = new Date(start);
|
|
101
|
+
var to = new Date(end);
|
|
102
|
+
var days = [getEventTimestamp(from)];
|
|
70
103
|
while (differenceInDays(to, from)) {
|
|
71
104
|
// console.log(title, differenceInDays(to, from))
|
|
72
105
|
from.setDate(from.getDate() + 1);
|
|
@@ -75,20 +108,20 @@ function transformCalendarEventFromGoogle(event, calendar) {
|
|
|
75
108
|
return days;
|
|
76
109
|
}
|
|
77
110
|
return {
|
|
78
|
-
calendar,
|
|
79
|
-
created,
|
|
80
|
-
link,
|
|
81
|
-
title,
|
|
82
|
-
status,
|
|
83
|
-
start,
|
|
84
|
-
end,
|
|
85
|
-
days,
|
|
86
|
-
daysMap,
|
|
87
|
-
multi,
|
|
88
|
-
color,
|
|
89
|
-
allDay,
|
|
90
|
-
location,
|
|
91
|
-
description,
|
|
92
|
-
uid,
|
|
111
|
+
calendar: calendar,
|
|
112
|
+
created: created,
|
|
113
|
+
link: link,
|
|
114
|
+
title: title,
|
|
115
|
+
status: status,
|
|
116
|
+
start: start,
|
|
117
|
+
end: end,
|
|
118
|
+
days: days,
|
|
119
|
+
daysMap: daysMap,
|
|
120
|
+
multi: multi,
|
|
121
|
+
color: color,
|
|
122
|
+
allDay: allDay,
|
|
123
|
+
location: location,
|
|
124
|
+
description: description,
|
|
125
|
+
uid: uid,
|
|
93
126
|
};
|
|
94
127
|
}
|
package/Calendar/useCalendar.js
CHANGED
|
@@ -1,45 +1,39 @@
|
|
|
1
|
+
import { __assign, __awaiter, __generator } from "tslib";
|
|
1
2
|
import { useCallback, useEffect, useReducer, useState } from "react";
|
|
2
3
|
import { getCalendarsEventsFromGoogle } from "./calendar-api-google";
|
|
3
4
|
import { getStartDate, getEndDate, getPrevDate, getNextDate, isTodayInView, } from "./utils";
|
|
4
|
-
export function useCalendar(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
export function useCalendar(_a) {
|
|
6
|
+
var _this = this;
|
|
7
|
+
var locale = _a.locale, apiKey = _a.apiKey, calendars = _a.calendars, initialEvents = _a.events, initialStart = _a.start, initialEnd = _a.end, _b = _a.view, initialView = _b === void 0 ? "month" : _b, _c = _a.timeZone, timeZone = _c === void 0 ? "" : _c, onError = _a.onError;
|
|
8
|
+
var _d = useState(initialView), view = _d[0], setView = _d[1];
|
|
9
|
+
var start = initialStart || getStartDate(new Date(), view);
|
|
10
|
+
var end = initialEnd || getEndDate(start, view);
|
|
11
|
+
var _e = useState([start, end]), range = _e[0], setRange = _e[1];
|
|
12
|
+
var _f = useState(isTodayInView(start, end)), todayInView = _f[0], setTodayInView = _f[1];
|
|
13
|
+
var _g = useState(initialEvents || {}), events = _g[0], setEvents = _g[1];
|
|
14
|
+
var _h = useState(null), eventHovered = _h[0], setEventHovered = _h[1];
|
|
15
|
+
var _j = useState(null), eventClicked = _j[0], setEventClicked = _j[1];
|
|
16
|
+
var _k = useReducer(function (state, action) {
|
|
17
|
+
var _a;
|
|
18
|
+
var type = action.type;
|
|
15
19
|
switch (type) {
|
|
16
20
|
case "events": {
|
|
17
|
-
|
|
18
|
-
return Object.entries(state).reduce((map,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
events: events[id] || 0,
|
|
22
|
-
};
|
|
21
|
+
var events_1 = action.payload;
|
|
22
|
+
return Object.entries(state).reduce(function (map, _a) {
|
|
23
|
+
var id = _a[0], calendar = _a[1];
|
|
24
|
+
map[id] = __assign(__assign({}, calendar), { events: events_1[id] || 0 });
|
|
23
25
|
return map;
|
|
24
26
|
}, {});
|
|
25
27
|
}
|
|
26
28
|
case "visibility": {
|
|
27
|
-
|
|
28
|
-
if (typeof
|
|
29
|
-
return {
|
|
30
|
-
...state,
|
|
31
|
-
[visible]: {
|
|
32
|
-
...state[visible],
|
|
33
|
-
on: !state[visible].on,
|
|
34
|
-
},
|
|
35
|
-
};
|
|
29
|
+
var visible_1 = action.payload;
|
|
30
|
+
if (typeof visible_1 === "string") {
|
|
31
|
+
return __assign(__assign({}, state), (_a = {}, _a[visible_1] = __assign(__assign({}, state[visible_1]), { on: !state[visible_1].on }), _a));
|
|
36
32
|
}
|
|
37
33
|
else {
|
|
38
|
-
return Object.entries(state).reduce((map,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
on: visible.indexOf(id) > -1,
|
|
42
|
-
};
|
|
34
|
+
return Object.entries(state).reduce(function (map, _a) {
|
|
35
|
+
var id = _a[0], calendar = _a[1];
|
|
36
|
+
map[id] = __assign(__assign({}, calendar), { on: visible_1.indexOf(id) > -1 });
|
|
43
37
|
return map;
|
|
44
38
|
}, {});
|
|
45
39
|
}
|
|
@@ -49,48 +43,53 @@ export function useCalendar({ locale, apiKey, calendars, events: initialEvents,
|
|
|
49
43
|
}
|
|
50
44
|
},
|
|
51
45
|
// initial state
|
|
52
|
-
calendars.reduce((map, calendar)
|
|
53
|
-
map[calendar.id] = {
|
|
54
|
-
...calendar,
|
|
55
|
-
name: calendar.name || "",
|
|
56
|
-
on: true,
|
|
57
|
-
events: 0,
|
|
58
|
-
};
|
|
46
|
+
calendars.reduce(function (map, calendar) {
|
|
47
|
+
map[calendar.id] = __assign(__assign({}, calendar), { name: calendar.name || "", on: true, events: 0 });
|
|
59
48
|
return map;
|
|
60
|
-
}, {}));
|
|
61
|
-
|
|
49
|
+
}, {})), calendarsMap = _k[0], updateCalendars = _k[1];
|
|
50
|
+
var toggleCalendarVisibility = useCallback(function (idOrIds) {
|
|
62
51
|
updateCalendars({ type: "visibility", payload: idOrIds });
|
|
63
52
|
}, [updateCalendars]);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
for (
|
|
67
|
-
|
|
53
|
+
var updateCalendarsBasedOnEvents = useCallback(function (events) {
|
|
54
|
+
var payload = {};
|
|
55
|
+
for (var uid in events) {
|
|
56
|
+
var id = events[uid].calendar.id;
|
|
68
57
|
payload[id] = payload[id] || 0;
|
|
69
58
|
payload[id]++;
|
|
70
59
|
}
|
|
71
|
-
updateCalendars({ type: "events", payload });
|
|
60
|
+
updateCalendars({ type: "events", payload: payload });
|
|
72
61
|
}, []);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
62
|
+
var loadCalendars = useCallback(function (calendars, start, end) { return __awaiter(_this, void 0, void 0, function () {
|
|
63
|
+
var newEvents, e_1;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
switch (_a.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
_a.trys.push([0, 2, , 3]);
|
|
68
|
+
return [4 /*yield*/, getCalendarsEventsFromGoogle({
|
|
69
|
+
apiKey: apiKey,
|
|
70
|
+
calendars: calendars,
|
|
71
|
+
timeZone: timeZone,
|
|
72
|
+
start: start,
|
|
73
|
+
end: end,
|
|
74
|
+
})];
|
|
75
|
+
case 1:
|
|
76
|
+
newEvents = _a.sent();
|
|
77
|
+
// setEvents(mergeCalendarEvents(events, newEvents));
|
|
78
|
+
setEvents(newEvents);
|
|
79
|
+
return [3 /*break*/, 3];
|
|
80
|
+
case 2:
|
|
81
|
+
e_1 = _a.sent();
|
|
82
|
+
if (onError)
|
|
83
|
+
onError(e_1);
|
|
84
|
+
return [3 /*break*/, 3];
|
|
85
|
+
case 3: return [2 /*return*/];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}); }, [setEvents, apiKey, timeZone, onError]);
|
|
89
|
+
var handleToday = useCallback(function () {
|
|
90
|
+
var start = range[0], end = range[1];
|
|
91
|
+
var newStart = getStartDate(new Date(), view);
|
|
92
|
+
var newEnd = getEndDate(newStart, view);
|
|
94
93
|
setRange([newStart, newEnd]);
|
|
95
94
|
// reset event only if we are not on the current view already
|
|
96
95
|
if (start.getTime() !== newStart.getTime() ||
|
|
@@ -99,46 +98,48 @@ export function useCalendar({ locale, apiKey, calendars, events: initialEvents,
|
|
|
99
98
|
setEventHovered(null);
|
|
100
99
|
}
|
|
101
100
|
}, [view, range]);
|
|
102
|
-
|
|
103
|
-
setRange((
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
var handlePrev = useCallback(function () {
|
|
102
|
+
setRange(function (_a) {
|
|
103
|
+
var start = _a[0];
|
|
104
|
+
var newStart = getPrevDate(start, view);
|
|
105
|
+
var newEnd = getEndDate(newStart, view);
|
|
106
106
|
return [newStart, newEnd];
|
|
107
107
|
});
|
|
108
108
|
setEventClicked(null);
|
|
109
109
|
setEventHovered(null);
|
|
110
110
|
}, [view]);
|
|
111
|
-
|
|
112
|
-
setRange((
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
var handleNext = useCallback(function () {
|
|
112
|
+
setRange(function (_a) {
|
|
113
|
+
var start = _a[0];
|
|
114
|
+
var newStart = getNextDate(start, view);
|
|
115
|
+
var newEnd = getEndDate(newStart, view);
|
|
115
116
|
return [newStart, newEnd];
|
|
116
117
|
});
|
|
117
118
|
setEventClicked(null);
|
|
118
119
|
setEventHovered(null);
|
|
119
120
|
}, [view]);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
var handleView = useCallback(function (newView) {
|
|
122
|
+
var newStart = getStartDate(start, newView);
|
|
123
|
+
var newEnd = getEndDate(newStart, newView);
|
|
123
124
|
setRange([newStart, newEnd]);
|
|
124
125
|
setView(newView);
|
|
125
126
|
setEventClicked(null);
|
|
126
127
|
setEventHovered(null);
|
|
127
128
|
}, [start]);
|
|
128
|
-
useEffect(()
|
|
129
|
-
|
|
129
|
+
useEffect(function () {
|
|
130
|
+
var start = range[0], end = range[1];
|
|
130
131
|
loadCalendars(calendars, start, end);
|
|
131
132
|
setTodayInView(isTodayInView(start, end));
|
|
132
133
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
133
134
|
}, [range]);
|
|
134
|
-
useEffect(()
|
|
135
|
+
useEffect(function () {
|
|
135
136
|
if (events) {
|
|
136
137
|
updateCalendarsBasedOnEvents(events);
|
|
137
138
|
}
|
|
138
139
|
}, [events, updateCalendarsBasedOnEvents]);
|
|
139
140
|
// when toggling a calendar we also remove the clicked event if that belongs
|
|
140
141
|
// to a now hidden calendar
|
|
141
|
-
useEffect(()
|
|
142
|
+
useEffect(function () {
|
|
142
143
|
if (eventClicked) {
|
|
143
144
|
if (!calendarsMap[eventClicked.calendar.id].on) {
|
|
144
145
|
setEventClicked(null);
|
|
@@ -146,37 +147,37 @@ export function useCalendar({ locale, apiKey, calendars, events: initialEvents,
|
|
|
146
147
|
}
|
|
147
148
|
}, [calendarsMap, eventClicked, setEventClicked]);
|
|
148
149
|
return {
|
|
149
|
-
view,
|
|
150
|
-
eventClicked,
|
|
151
|
-
setEventClicked,
|
|
152
|
-
eventHovered,
|
|
153
|
-
setEventHovered,
|
|
154
|
-
getDaygridNavProps: ()
|
|
155
|
-
locale,
|
|
156
|
-
handlePrev,
|
|
157
|
-
handleNext,
|
|
158
|
-
handleToday,
|
|
159
|
-
handleView,
|
|
160
|
-
todayInView,
|
|
161
|
-
range,
|
|
162
|
-
view,
|
|
163
|
-
}),
|
|
164
|
-
getDaygridTableProps: ()
|
|
165
|
-
locale,
|
|
166
|
-
events,
|
|
167
|
-
eventClicked,
|
|
168
|
-
setEventClicked,
|
|
169
|
-
eventHovered,
|
|
170
|
-
setEventHovered,
|
|
171
|
-
handlePrev,
|
|
172
|
-
handleNext,
|
|
173
|
-
calendarsMap,
|
|
174
|
-
range,
|
|
175
|
-
view,
|
|
176
|
-
}),
|
|
177
|
-
getLegendProps: ()
|
|
178
|
-
calendarsMap,
|
|
179
|
-
toggleCalendarVisibility,
|
|
180
|
-
}),
|
|
150
|
+
view: view,
|
|
151
|
+
eventClicked: eventClicked,
|
|
152
|
+
setEventClicked: setEventClicked,
|
|
153
|
+
eventHovered: eventHovered,
|
|
154
|
+
setEventHovered: setEventHovered,
|
|
155
|
+
getDaygridNavProps: function () { return ({
|
|
156
|
+
locale: locale,
|
|
157
|
+
handlePrev: handlePrev,
|
|
158
|
+
handleNext: handleNext,
|
|
159
|
+
handleToday: handleToday,
|
|
160
|
+
handleView: handleView,
|
|
161
|
+
todayInView: todayInView,
|
|
162
|
+
range: range,
|
|
163
|
+
view: view,
|
|
164
|
+
}); },
|
|
165
|
+
getDaygridTableProps: function () { return ({
|
|
166
|
+
locale: locale,
|
|
167
|
+
events: events,
|
|
168
|
+
eventClicked: eventClicked,
|
|
169
|
+
setEventClicked: setEventClicked,
|
|
170
|
+
eventHovered: eventHovered,
|
|
171
|
+
setEventHovered: setEventHovered,
|
|
172
|
+
handlePrev: handlePrev,
|
|
173
|
+
handleNext: handleNext,
|
|
174
|
+
calendarsMap: calendarsMap,
|
|
175
|
+
range: range,
|
|
176
|
+
view: view,
|
|
177
|
+
}); },
|
|
178
|
+
getLegendProps: function () { return ({
|
|
179
|
+
calendarsMap: calendarsMap,
|
|
180
|
+
toggleCalendarVisibility: toggleCalendarVisibility,
|
|
181
|
+
}); },
|
|
181
182
|
};
|
|
182
183
|
}
|