@koine/react 2.0.0-beta.21 → 2.0.0-beta.23

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.
@@ -0,0 +1,26 @@
1
+ export declare namespace Polymorphic {
2
+ type AsProp<TComponent extends React.ElementType> = {
3
+ as?: TComponent;
4
+ };
5
+ type ComponentTypes = React.ComponentClass<any> | React.FunctionComponent<any> | keyof JSX.IntrinsicElements;
6
+ type Merge<P1 = {}, P2 = {}> = Omit<P1, keyof P2> & P2;
7
+ type ForwardRefExoticComponent<TComponent, TOwnProps> = React.ForwardRefExoticComponent<Merge<TComponent extends React.ElementType ? React.ComponentPropsWithRef<TComponent> : never, TOwnProps & {
8
+ as?: TComponent;
9
+ }>>;
10
+ type InferProps<TComponent extends ComponentTypes> = TComponent extends React.ComponentClass<infer Props> ? Props : TComponent extends React.FunctionComponent<infer Props> ? Props : TComponent extends React.ForwardRefExoticComponent<infer Props> ? Props : TComponent extends keyof JSX.IntrinsicElements ? React.ComponentPropsWithoutRef<TComponent> : never;
11
+ export type Ref<TComponent extends React.ElementType> = React.ComponentPropsWithRef<TComponent>["ref"];
12
+ export type Props<TComponent extends React.ElementType, TProps = {}> = InferProps<TComponent> & AsProp<TComponent> & TProps;
13
+ export type PropsWithRef<TComponent extends React.ElementType, TProps = {}> = Props<TComponent, TProps> & {
14
+ ref?: Ref<TComponent>;
15
+ };
16
+ export interface ComponentForwarded<TComponent, TProps = {}> extends ForwardRefExoticComponent<TComponent, TProps> {
17
+ <As = TComponent>(props: As extends "" ? {
18
+ as: keyof JSX.IntrinsicElements;
19
+ } : As extends React.ComponentType<infer P> ? Merge<P, TProps & {
20
+ as: As;
21
+ }> : As extends keyof JSX.IntrinsicElements ? Merge<JSX.IntrinsicElements[As], TProps & {
22
+ as: As;
23
+ }> : never): React.ReactElement | null;
24
+ }
25
+ export {};
26
+ }
package/Polymorphic.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ import type { KoineComponent, KoineComponentProps } from "../types.js";
2
+ import type { CalendarView, CalendarViewDayProps, CalendarViewEvent, CalendarsMap } from "./types.js";
3
+ import { UseCalendarReturn } from "./useCalendar.js";
4
+ export type KoineCalendarDaygridCellProps = {
5
+ eventClicked?: UseCalendarReturn["eventClicked"];
6
+ setEventClicked: UseCalendarReturn["setEventClicked"];
7
+ eventHovered?: UseCalendarReturn["eventHovered"];
8
+ setEventHovered: UseCalendarReturn["setEventHovered"];
9
+ view: CalendarView;
10
+ maxEvents: number;
11
+ events: CalendarViewEvent[];
12
+ calendarsMap: CalendarsMap;
13
+ };
14
+ export type CalendarDaygridCellStyledProps = CalendarViewDayProps & {
15
+ $view: CalendarView;
16
+ $selected?: boolean;
17
+ $past?: boolean;
18
+ $color: string;
19
+ };
20
+ export type CalendarDaygridCellEventProps = React.ComponentPropsWithoutRef<"div"> & ((CalendarDaygridCellStyledProps & {
21
+ $placeholder?: false;
22
+ }) | {
23
+ $placeholder: true;
24
+ });
25
+ export type CalendarDaygridCellEventBtnProps = CalendarDaygridCellEventProps;
26
+ export type CalendarDaygridCellComponents = {
27
+ Cell?: KoineComponent;
28
+ CellOverflow?: KoineComponent;
29
+ CellEvent?: KoineComponent<CalendarDaygridCellEventProps>;
30
+ CellEventBtn?: KoineComponent<CalendarDaygridCellEventBtnProps>;
31
+ CellEventTitle?: KoineComponent;
32
+ CellEventStart?: KoineComponent;
33
+ };
34
+ export type CalendarDaygridCellProps = KoineComponentProps<KoineCalendarDaygridCellProps, CalendarDaygridCellComponents>;
35
+ export declare const CalendarDaygridCell: ({ eventClicked, setEventClicked, setEventHovered, view, maxEvents, events, calendarsMap, Cell, CellOverflow, CellEvent, CellEventBtn, CellEventTitle, CellEventStart, }: CalendarDaygridCellProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,48 @@
1
+ import { __assign, __read } from "tslib";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { Fragment, useState } from "react";
4
+ import { getDisplayTime } from "./utils.js";
5
+ var IconExpand = function (props) {
6
+ return (_jsxs("svg", __assign({ viewBox: "0 0 24 24", fill: "currentColor", stroke: "none" }, props, { children: [_jsx("path", { d: "M0 0h24v24H0z" }), _jsx("path", { d: "M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" })] })));
7
+ };
8
+ var styleBtn = {
9
+ overflow: "hidden",
10
+ whiteSpace: "nowrap",
11
+ textOverflow: "ellipsis",
12
+ };
13
+ export var CalendarDaygridCell = function (_a) {
14
+ var eventClicked = _a.eventClicked, setEventClicked = _a.setEventClicked, setEventHovered = _a.setEventHovered, view = _a.view, maxEvents = _a.maxEvents, events = _a.events, calendarsMap = _a.calendarsMap, _b = _a.Cell, Cell = _b === void 0 ? "div" : _b, _c = _a.CellOverflow, CellOverflow = _c === void 0 ? "div" : _c, _d = _a.CellEvent, CellEvent = _d === void 0 ? "div" : _d, _e = _a.CellEventBtn, CellEventBtn = _e === void 0 ? "div" : _e, _f = _a.CellEventTitle, CellEventTitle = _f === void 0 ? "span" : _f, _g = _a.CellEventStart, CellEventStart = _g === void 0 ? "span" : _g;
15
+ var _h = __read(useState(false), 2), isExpanded = _h[0], expand = _h[1];
16
+ var eventsWithoutPlaceholders = events.filter(function (event) { return !event.placeholder; });
17
+ return (_jsx(Cell, { children: events.map(function (event, i) {
18
+ if (i === maxEvents && !isExpanded) {
19
+ return (_jsxs(CellOverflow, { onClick: function () { return expand(true); }, children: [_jsx(IconExpand, {}), eventsWithoutPlaceholders.length - maxEvents] }, "overflowMessage" + i));
20
+ }
21
+ if (i > maxEvents && !isExpanded)
22
+ return null;
23
+ if (event.placeholder) {
24
+ return (_jsx(Fragment, { children: _jsx(CellEvent, { "$placeholder": true, children: _jsx(CellEventBtn, { "aria-hidden": "true", style: { visibility: "hidden" }, "$placeholder": true, children: _jsx(CellEventTitle, { children: "\u00A0" }) }) }) }, event.key));
25
+ }
26
+ var styleEvent = {
27
+ zIndex: event.firstOfMulti ? 1 : 0,
28
+ position: "relative",
29
+ width: event.firstOfMulti ? "".concat(100 * event.width, "%") : "100%",
30
+ };
31
+ if (!calendarsMap[event.calendar.id].on) {
32
+ styleBtn.display = "none";
33
+ }
34
+ var styledProps = {
35
+ $view: view,
36
+ $selected: (eventClicked === null || eventClicked === void 0 ? void 0 : eventClicked.uid) === event.uid,
37
+ $past: event.isPast,
38
+ $color: event.color,
39
+ $isOutOfRange: event.$isOutOfRange,
40
+ $isToday: event.$isToday,
41
+ };
42
+ return (_jsx(Fragment, { children: _jsx(CellEvent, __assign({ style: styleEvent }, styledProps, { children: _jsx(CellEventBtn, __assign({ role: "button", style: styleBtn }, styledProps, { onClick: function () {
43
+ return setEventClicked(function (prev) {
44
+ return (prev === null || prev === void 0 ? void 0 : prev.uid) === event.uid ? null : event;
45
+ });
46
+ }, onMouseEnter: function () { return setEventHovered(event); }, onMouseLeave: function () { return setEventHovered(null); }, children: event.allDay ? (_jsx(CellEventTitle, { children: event.title })) : (_jsxs(_Fragment, { children: [_jsx(CellEventStart, { children: getDisplayTime(event.start) }), _jsx(CellEventTitle, { children: event.title })] })) })) })) }, event.key));
47
+ }) }));
48
+ };
@@ -0,0 +1,27 @@
1
+ import type { KoineComponent, KoineComponentProps } from "../types.js";
2
+ import type { CalendarRange, CalendarView } from "./types.js";
3
+ export type KoineCalendarDaygridNavProps = {
4
+ locale: string;
5
+ range: CalendarRange;
6
+ view: CalendarView;
7
+ todayInView?: boolean;
8
+ handlePrev: () => any;
9
+ handleNext: () => any;
10
+ handleToday: () => any;
11
+ handleView: (view: CalendarView) => any;
12
+ };
13
+ export type CalendarDaygridNavTitleProps = {
14
+ range: CalendarRange;
15
+ formatted: string;
16
+ };
17
+ export type CalendarDaygridNavProps = KoineComponentProps<KoineCalendarDaygridNavProps, {
18
+ NavRoot?: KoineComponent;
19
+ NavTitle?: KoineComponent<CalendarDaygridNavTitleProps>;
20
+ NavBtns?: KoineComponent;
21
+ NavBtnPrev?: KoineComponent;
22
+ NavBtnNext?: KoineComponent;
23
+ NavBtnToday?: KoineComponent;
24
+ NavBtnViewMonth?: KoineComponent;
25
+ NavBtnViewWeek?: KoineComponent;
26
+ }>;
27
+ export declare const KoineCalendarDaygridNav: ({ range, view, todayInView, handlePrev, handleNext, handleToday, handleView, locale: localeCode, NavRoot, NavTitle, NavBtns, NavBtnPrev, NavBtnNext, NavBtnToday, NavBtnViewMonth, NavBtnViewWeek, }: CalendarDaygridNavProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,24 @@
1
+ import { __read } from "tslib";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { format } from "date-fns/format";
4
+ import { useDateLocale } from "../useDateLocale.js";
5
+ export var KoineCalendarDaygridNav = function (_a) {
6
+ var range = _a.range, view = _a.view, todayInView = _a.todayInView, handlePrev = _a.handlePrev, handleNext = _a.handleNext, handleToday = _a.handleToday, handleView = _a.handleView, localeCode = _a.locale, _b = _a.NavRoot, NavRoot = _b === void 0 ? "nav" : _b, _c = _a.NavTitle, NavTitle = _c === void 0 ? "div" : _c, _d = _a.NavBtns, NavBtns = _d === void 0 ? "div" : _d, _e = _a.NavBtnPrev, NavBtnPrev = _e === void 0 ? "button" : _e, _f = _a.NavBtnNext, NavBtnNext = _f === void 0 ? "button" : _f, _g = _a.NavBtnToday, NavBtnToday = _g === void 0 ? "button" : _g, _h = _a.NavBtnViewMonth, NavBtnViewMonth = _h === void 0 ? "button" : _h, _j = _a.NavBtnViewWeek, NavBtnViewWeek = _j === void 0 ? "button" : _j;
7
+ var _k = __read(range, 2), start = _k[0], end = _k[1];
8
+ var locale = useDateLocale(localeCode);
9
+ var opts = { locale: locale };
10
+ var formatted = "";
11
+ if (view === "month") {
12
+ formatted = format(start, "MMMM yyyy", opts);
13
+ }
14
+ if (view === "week") {
15
+ var inSameMonth = start.getMonth() === end.getMonth();
16
+ if (inSameMonth) {
17
+ formatted = format(start, "# MMMM yyyy", opts).replace("#", "".concat(start.getDate(), "-").concat(end.getDate()));
18
+ }
19
+ else {
20
+ formatted = "".concat(format(start, "d MMMM", opts), " - ").concat(format(end, "d MMMM yyyy", opts));
21
+ }
22
+ }
23
+ return (_jsxs(NavRoot, { children: [_jsxs(NavBtns, { children: [_jsx(NavBtnPrev, { onClick: handlePrev }), _jsx(NavBtnNext, { onClick: handleNext }), _jsx(NavBtnToday, { onClick: handleToday, disabled: todayInView }), _jsx(NavBtnViewMonth, { onClick: function () { return handleView("month"); }, disabled: view === "month" }), _jsx(NavBtnViewWeek, { onClick: function () { return handleView("week"); }, disabled: view === "week" })] }), _jsx(NavTitle, { range: range, formatted: formatted })] }));
24
+ };
@@ -0,0 +1,25 @@
1
+ import type { KoineComponent, KoineComponentProps } from "../types.js";
2
+ import { CalendarDaygridCellComponents, CalendarDaygridCellProps } from "./CalendarDaygridCell.js";
3
+ import type { CalendarEventsMap, CalendarRange, CalendarView, CalendarViewDayProps } from "./types.js";
4
+ export type CalendarDaygridTableBodyCellProps = CalendarViewDayProps;
5
+ export type CalendarDaygridTableBodyCellDateProps = CalendarViewDayProps;
6
+ export type KoineCalendarDaygridTableProps = {
7
+ maxEvents?: CalendarDaygridCellProps["maxEvents"];
8
+ locale: string;
9
+ events: CalendarEventsMap;
10
+ handlePrev: () => any;
11
+ handleNext: () => any;
12
+ view: CalendarView;
13
+ range: CalendarRange;
14
+ dayLabels?: string[];
15
+ } & Pick<CalendarDaygridCellProps, "eventClicked" | "setEventClicked" | "eventHovered" | "setEventHovered" | "calendarsMap">;
16
+ export type CalendarDaygridTableProps = KoineComponentProps<KoineCalendarDaygridTableProps, {
17
+ Table?: KoineComponent;
18
+ TableHead?: KoineComponent;
19
+ TableHeadCell?: KoineComponent;
20
+ TableBody?: KoineComponent;
21
+ TableBodyCell?: KoineComponent<CalendarDaygridTableBodyCellProps>;
22
+ TableBodyCellDate?: KoineComponent<CalendarDaygridTableBodyCellDateProps>;
23
+ TableBodyRow?: KoineComponent;
24
+ } & CalendarDaygridCellComponents>;
25
+ export declare const KoineCalendarDaygridTable: ({ locale: localeCode, handlePrev, handleNext, events, dayLabels, view, range, eventClicked, setEventClicked, eventHovered, setEventHovered, calendarsMap, maxEvents, Table, TableHead, TableHeadCell, TableBody, TableBodyRow, TableBodyCell, TableBodyCellDate, Cell, CellOverflow, CellEvent, CellEventBtn, CellEventTitle, CellEventStart, }: CalendarDaygridTableProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,45 @@
1
+ import { __assign, __read } from "tslib";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { eachWeekOfInterval } from "date-fns/eachWeekOfInterval";
4
+ import { useEffect, useMemo, useState } from "react";
5
+ import { useSwipeable } from "react-swipeable";
6
+ import { useDateLocale } from "../useDateLocale.js";
7
+ import { CalendarDaygridCell, } from "./CalendarDaygridCell.js";
8
+ import { processEventsInView } from "./utils.js";
9
+ function getView(range) {
10
+ var _a = __read(range, 2), start = _a[0], end = _a[1];
11
+ var weeks = eachWeekOfInterval({ start: start, end: end }, { weekStartsOn: 1 });
12
+ return {
13
+ month: start.getMonth(),
14
+ weeks: weeks,
15
+ };
16
+ }
17
+ export var KoineCalendarDaygridTable = function (_a) {
18
+ var localeCode = _a.locale, handlePrev = _a.handlePrev, handleNext = _a.handleNext, events = _a.events, dayLabels = _a.dayLabels, view = _a.view, range = _a.range, eventClicked = _a.eventClicked, setEventClicked = _a.setEventClicked, eventHovered = _a.eventHovered, setEventHovered = _a.setEventHovered, _b = _a.calendarsMap, calendarsMap = _b === void 0 ? {} : _b, _c = _a.maxEvents, maxEvents = _c === void 0 ? 5 : _c, _d = _a.Table, Table = _d === void 0 ? "table" : _d, _e = _a.TableHead, TableHead = _e === void 0 ? "thead" : _e, _f = _a.TableHeadCell, TableHeadCell = _f === void 0 ? "th" : _f, _g = _a.TableBody, TableBody = _g === void 0 ? "tbody" : _g, _h = _a.TableBodyRow, TableBodyRow = _h === void 0 ? "tr" : _h, _j = _a.TableBodyCell, TableBodyCell = _j === void 0 ? "td" : _j, _k = _a.TableBodyCellDate, TableBodyCellDate = _k === void 0 ? "div" : _k, Cell = _a.Cell, CellOverflow = _a.CellOverflow, CellEvent = _a.CellEvent, CellEventBtn = _a.CellEventBtn, CellEventTitle = _a.CellEventTitle, CellEventStart = _a.CellEventStart;
19
+ var restKoine = {
20
+ Cell: Cell,
21
+ CellOverflow: CellOverflow,
22
+ CellEvent: CellEvent,
23
+ CellEventBtn: CellEventBtn,
24
+ CellEventTitle: CellEventTitle,
25
+ CellEventStart: CellEventStart,
26
+ };
27
+ var _l = __read(useState(dayLabels || [0, 1, 2, 3, 4, 5, 6]), 2), days = _l[0], setDays = _l[1];
28
+ var _m = __read(useState([]), 2), weeksEvents = _m[0], setWeeksEvents = _m[1];
29
+ var locale = useDateLocale(localeCode);
30
+ var _o = useMemo(function () { return getView(range); }, [range]), month = _o.month, weeks = _o.weeks;
31
+ var swipeableHandlers = useSwipeable({
32
+ onSwipedLeft: handleNext,
33
+ onSwipedRight: handlePrev,
34
+ });
35
+ useEffect(function () {
36
+ setWeeksEvents(processEventsInView(events, view, month, weeks));
37
+ }, [events, view, month, weeks]);
38
+ useEffect(function () {
39
+ if (locale && locale.localize && !dayLabels) {
40
+ setDays([1, 2, 3, 4, 5, 6, 0].map(function (i) { return locale.localize.day(i, { width: "abbreviated" }); }));
41
+ }
42
+ }, [locale, dayLabels]);
43
+ return (_jsxs(Table, __assign({}, swipeableHandlers, { children: [_jsx(TableHead, { children: _jsx("tr", { children: days.map(function (day) { return (_jsx(TableHeadCell, { scope: "column", children: day }, day)); }) }) }), _jsx(TableBody, { children: weeksEvents.map(function (week, i) { return (_jsx(TableBodyRow, __assign({}, week.props, { children: week.days.map(function (day) { return (_jsxs(TableBodyCell, __assign({}, day.props, { children: [_jsx(TableBodyCellDate, __assign({}, day.props, { children: day.label })), day.events.length > 0 && (_jsx(CalendarDaygridCell, __assign({ eventClicked: eventClicked, setEventClicked: setEventClicked, eventHovered: eventHovered, setEventHovered: setEventHovered, view: view, maxEvents: maxEvents, events: day.events,
44
+ timestamp: day.timestamp, calendarsMap: calendarsMap }, restKoine)))] }))); }) }))); }) })] })));
45
+ };
@@ -0,0 +1,18 @@
1
+ import type { KoineComponent, KoineComponentProps } from "../types.js";
2
+ import type { CalendarsMap } from "./types.js";
3
+ export type KoineCalendarLegendProps = {
4
+ toggleCalendarVisibility: (id: string) => void;
5
+ calendarsMap: CalendarsMap;
6
+ };
7
+ export type CalendarLegendItemProps = React.ComponentPropsWithoutRef<"div"> & {
8
+ $color: string;
9
+ $empty: boolean;
10
+ disabled: boolean;
11
+ };
12
+ export type CalendarLegendProps = KoineComponentProps<KoineCalendarLegendProps, {
13
+ LegendItem?: KoineComponent<CalendarLegendItemProps>;
14
+ LegendItemStatus?: KoineComponent;
15
+ LegendItemLabel?: KoineComponent;
16
+ LegendItemEvents?: KoineComponent;
17
+ }>;
18
+ export declare const KoineCalendarLegend: ({ calendarsMap, toggleCalendarVisibility, LegendItem, LegendItemStatus, LegendItemLabel, LegendItemEvents, }: CalendarLegendProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { __read } from "tslib";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ export var KoineCalendarLegend = function (_a) {
4
+ var _b = _a.calendarsMap, calendarsMap = _b === void 0 ? {} : _b, toggleCalendarVisibility = _a.toggleCalendarVisibility, _c = _a.LegendItem, LegendItem = _c === void 0 ? "div" : _c, _d = _a.LegendItemStatus, LegendItemStatus = _d === void 0 ? "span" : _d, _e = _a.LegendItemLabel, LegendItemLabel = _e === void 0 ? "span" : _e, _f = _a.LegendItemEvents, LegendItemEvents = _f === void 0 ? "span" : _f;
5
+ return (_jsx(_Fragment, { children: Object.entries(calendarsMap).map(function (_a) {
6
+ var _b = __read(_a, 2), id = _b[0], calendar = _b[1];
7
+ return (_jsxs(LegendItem, { onClick: function () { return toggleCalendarVisibility(id); }, "$color": calendar.color, "$empty": calendar.events === 0, disabled: calendar.events === 0, children: [_jsx(LegendItemStatus, { children: calendar.on ? "\u2b24" : "\u2b58" }), _jsx(LegendItemLabel, { children: calendar.name }), _jsx(LegendItemEvents, { children: calendar.events })] }, "CalendarLegend." + id));
8
+ }) }));
9
+ };
@@ -0,0 +1,10 @@
1
+ import type { CalendarEventsMap, Calendars } from "./types.js";
2
+ type GetCalendarsEventsFromGoogleOptions = {
3
+ apiKey?: string;
4
+ start: Date;
5
+ end: Date;
6
+ timeZone?: string;
7
+ calendars: Calendars;
8
+ };
9
+ export declare function getCalendarsEventsFromGoogle({ calendars, ...options }: GetCalendarsEventsFromGoogleOptions): Promise<CalendarEventsMap>;
10
+ export {};
@@ -0,0 +1,124 @@
1
+ import { __assign, __awaiter, __generator, __rest } from "tslib";
2
+ import { differenceInDays } from "date-fns/differenceInDays";
3
+ import { subDays } from "date-fns/subDays";
4
+ import { arrayToLookup, isString, isUndefined } from "@koine/utils";
5
+ import { addCalendarEvents, getEventTimestamp } from "./utils.js";
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, 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, getCalendarEventsFromGoogle(__assign({ calendar: calendar }, options))];
21
+ case 1:
22
+ events = _a.sent();
23
+ addCalendarEvents(events, allEvents);
24
+ return [2];
25
+ }
26
+ });
27
+ }); }))];
28
+ case 1:
29
+ _b.sent();
30
+ return [2, allEvents];
31
+ }
32
+ });
33
+ });
34
+ }
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, fetch(url, { method: "GET" })];
59
+ case 2:
60
+ response = _c.sent();
61
+ return [4, 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, 5];
70
+ case 4:
71
+ e_1 = _c.sent();
72
+ return [3, 5];
73
+ case 5: return [2, events];
74
+ }
75
+ });
76
+ });
77
+ }
78
+ function transformCalendarEventFromGoogle(event, calendar) {
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 || "";
89
+ var uid = created.getTime() + "" + start.getTime();
90
+ if (allDay && end > start) {
91
+ end = subDays(end, 1);
92
+ end.setHours(23, 59, 59);
93
+ }
94
+ var days = getDays();
95
+ var daysMap = arrayToLookup(days);
96
+ var multi = days.length > 1;
97
+ function getDays() {
98
+ var from = new Date(start);
99
+ var to = new Date(end);
100
+ var days = [getEventTimestamp(from)];
101
+ while (differenceInDays(to, from)) {
102
+ from.setDate(from.getDate() + 1);
103
+ days.push(getEventTimestamp(from));
104
+ }
105
+ return days;
106
+ }
107
+ return {
108
+ calendar: calendar,
109
+ created: created,
110
+ link: link,
111
+ title: title,
112
+ status: status,
113
+ start: start,
114
+ end: end,
115
+ days: days,
116
+ daysMap: daysMap,
117
+ multi: multi,
118
+ color: color,
119
+ allDay: allDay,
120
+ location: location,
121
+ description: description,
122
+ uid: uid,
123
+ };
124
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./CalendarDaygridCell.js";
2
+ export * from "./CalendarDaygridNav.js";
3
+ export * from "./CalendarDaygridTable.js";
4
+ export * from "./CalendarLegend.js";
5
+ export * from "./useCalendar.js";
6
+ export * from "./types.js";
@@ -0,0 +1,6 @@
1
+ export * from "./CalendarDaygridCell.js";
2
+ export * from "./CalendarDaygridNav.js";
3
+ export * from "./CalendarDaygridTable.js";
4
+ export * from "./CalendarLegend.js";
5
+ export * from "./useCalendar.js";
6
+ export * from "./types.js";
@@ -0,0 +1,62 @@
1
+ export type Calendar = {
2
+ id: string;
3
+ color: string;
4
+ name?: string;
5
+ };
6
+ export type Calendars = Calendar[];
7
+ export type CalendarsMap = Record<Calendar["id"], Required<Calendar> & {
8
+ on?: boolean;
9
+ events?: number;
10
+ }>;
11
+ export type CalendarRange = [Date, Date];
12
+ export type CalendarView = "month" | "week";
13
+ export type CalendarEvent = {
14
+ calendar: Calendar;
15
+ days: number[];
16
+ daysMap: Record<number, 1>;
17
+ multi: boolean;
18
+ allDay: boolean;
19
+ link: string;
20
+ title: string;
21
+ status: string;
22
+ created: Date;
23
+ start: Date;
24
+ end: Date;
25
+ color: string;
26
+ location: string;
27
+ description: string;
28
+ uid: string;
29
+ };
30
+ export type CalendarEventsByTimestamp = Record<number, CalendarEventsMap>;
31
+ export type CalendarEventsMap = Record<CalendarEvent["uid"], CalendarEvent>;
32
+ export type CalendarViewWeeks = CalendarViewWeek[];
33
+ export type CalendarViewWeek = {
34
+ props: {
35
+ key: string;
36
+ };
37
+ days: CalendarViewDay[];
38
+ };
39
+ export type CalendarViewDay = {
40
+ props: {
41
+ key: string;
42
+ } & CalendarViewDayProps;
43
+ label: string;
44
+ timestamp: string;
45
+ events: CalendarViewEvent[];
46
+ };
47
+ export type CalendarViewDayProps = {
48
+ $isToday?: boolean;
49
+ $isOutOfRange?: boolean;
50
+ };
51
+ export type CalendarViewEvent = {
52
+ key: string;
53
+ placeholder: true;
54
+ top: number;
55
+ } | (CalendarEvent & CalendarViewDayProps & {
56
+ key: string;
57
+ placeholder?: false;
58
+ top: number;
59
+ width: number;
60
+ firstOfMulti?: boolean;
61
+ isPast?: boolean;
62
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ import type { KoineCalendarDaygridNavProps } from "./CalendarDaygridNav.js";
2
+ import type { KoineCalendarDaygridTableProps } from "./CalendarDaygridTable.js";
3
+ import type { KoineCalendarLegendProps } from "./CalendarLegend.js";
4
+ import type { CalendarEvent, CalendarEventsMap, CalendarView, Calendars } from "./types.js";
5
+ export type UseCalendarProps = {
6
+ locale: string;
7
+ calendars: Calendars;
8
+ apiKey?: string;
9
+ events?: CalendarEventsMap;
10
+ start?: Date;
11
+ end?: Date;
12
+ view?: CalendarView;
13
+ timeZone?: string;
14
+ onError?: (e: any) => void;
15
+ };
16
+ export type UseCalendarReturn = ReturnType<typeof useCalendar>;
17
+ export type CalendarsUpdateActionEvents = {
18
+ type: "events";
19
+ payload: Record<string, number>;
20
+ };
21
+ export type CalendarsUpdateActionVisibility = {
22
+ type: "visibility";
23
+ payload: string | string[];
24
+ };
25
+ export type CalendarsUpdateAction = CalendarsUpdateActionEvents | CalendarsUpdateActionVisibility;
26
+ export declare function useCalendar({ locale, apiKey, calendars, events: initialEvents, start: initialStart, end: initialEnd, view: initialView, timeZone, onError, }: UseCalendarProps): {
27
+ view: "month" | "week";
28
+ eventClicked: CalendarEvent | null;
29
+ setEventClicked: import("react").Dispatch<import("react").SetStateAction<CalendarEvent | null>>;
30
+ eventHovered: CalendarEvent | null;
31
+ setEventHovered: import("react").Dispatch<import("react").SetStateAction<CalendarEvent | null>>;
32
+ getDaygridNavProps: () => KoineCalendarDaygridNavProps;
33
+ getDaygridTableProps: () => KoineCalendarDaygridTableProps;
34
+ getLegendProps: () => KoineCalendarLegendProps;
35
+ };