@sunsama/event-calendar 0.2.0
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/LICENSE +20 -0
- package/README.md +105 -0
- package/lib/commonjs/components/all-day-events.js +117 -0
- package/lib/commonjs/components/all-day-events.js.map +1 -0
- package/lib/commonjs/components/background-hours-content.js +43 -0
- package/lib/commonjs/components/background-hours-content.js.map +1 -0
- package/lib/commonjs/components/background-hours-layout.js +57 -0
- package/lib/commonjs/components/background-hours-layout.js.map +1 -0
- package/lib/commonjs/components/drag-bar.js +84 -0
- package/lib/commonjs/components/drag-bar.js.map +1 -0
- package/lib/commonjs/components/edit-event-container.js +114 -0
- package/lib/commonjs/components/edit-event-container.js.map +1 -0
- package/lib/commonjs/components/event-container.js +37 -0
- package/lib/commonjs/components/event-container.js.map +1 -0
- package/lib/commonjs/components/new-event-container.js +73 -0
- package/lib/commonjs/components/new-event-container.js.map +1 -0
- package/lib/commonjs/components/time-indicator.js +64 -0
- package/lib/commonjs/components/time-indicator.js.map +1 -0
- package/lib/commonjs/components/timed-event-container.js +91 -0
- package/lib/commonjs/components/timed-event-container.js.map +1 -0
- package/lib/commonjs/components/timed-events.js +68 -0
- package/lib/commonjs/components/timed-events.js.map +1 -0
- package/lib/commonjs/components/zoom-provider.js +109 -0
- package/lib/commonjs/components/zoom-provider.js.map +1 -0
- package/lib/commonjs/enums.js +2 -0
- package/lib/commonjs/enums.js.map +1 -0
- package/lib/commonjs/hooks/use-cloned-events.js +25 -0
- package/lib/commonjs/hooks/use-cloned-events.js.map +1 -0
- package/lib/commonjs/hooks/use-events-layout.js +34 -0
- package/lib/commonjs/hooks/use-events-layout.js.map +1 -0
- package/lib/commonjs/hooks/use-is-editing.js +83 -0
- package/lib/commonjs/hooks/use-is-editing.js.map +1 -0
- package/lib/commonjs/index.js +129 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/types.js +24 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils/calendar-layout.js +113 -0
- package/lib/commonjs/utils/calendar-layout.js.map +1 -0
- package/lib/commonjs/utils/compute-positioning.js +33 -0
- package/lib/commonjs/utils/compute-positioning.js.map +1 -0
- package/lib/commonjs/utils/date-utils.js +152 -0
- package/lib/commonjs/utils/date-utils.js.map +1 -0
- package/lib/commonjs/utils/double-tap-reset-zoom-gesture.js +19 -0
- package/lib/commonjs/utils/double-tap-reset-zoom-gesture.js.map +1 -0
- package/lib/commonjs/utils/generate-event-layouts.js +198 -0
- package/lib/commonjs/utils/generate-event-layouts.js.map +1 -0
- package/lib/commonjs/utils/globals.js +11 -0
- package/lib/commonjs/utils/globals.js.map +1 -0
- package/lib/commonjs/utils/pan-edit-event-gesture.js +41 -0
- package/lib/commonjs/utils/pan-edit-event-gesture.js.map +1 -0
- package/lib/module/components/all-day-events.js +110 -0
- package/lib/module/components/all-day-events.js.map +1 -0
- package/lib/module/components/background-hours-content.js +37 -0
- package/lib/module/components/background-hours-content.js.map +1 -0
- package/lib/module/components/background-hours-layout.js +51 -0
- package/lib/module/components/background-hours-layout.js.map +1 -0
- package/lib/module/components/drag-bar.js +78 -0
- package/lib/module/components/drag-bar.js.map +1 -0
- package/lib/module/components/edit-event-container.js +107 -0
- package/lib/module/components/edit-event-container.js.map +1 -0
- package/lib/module/components/event-container.js +33 -0
- package/lib/module/components/event-container.js.map +1 -0
- package/lib/module/components/new-event-container.js +67 -0
- package/lib/module/components/new-event-container.js.map +1 -0
- package/lib/module/components/time-indicator.js +57 -0
- package/lib/module/components/time-indicator.js.map +1 -0
- package/lib/module/components/timed-event-container.js +84 -0
- package/lib/module/components/timed-event-container.js.map +1 -0
- package/lib/module/components/timed-events.js +63 -0
- package/lib/module/components/timed-events.js.map +1 -0
- package/lib/module/components/zoom-provider.js +102 -0
- package/lib/module/components/zoom-provider.js.map +1 -0
- package/lib/module/enums.js +2 -0
- package/lib/module/enums.js.map +1 -0
- package/lib/module/hooks/use-cloned-events.js +21 -0
- package/lib/module/hooks/use-cloned-events.js.map +1 -0
- package/lib/module/hooks/use-events-layout.js +29 -0
- package/lib/module/hooks/use-events-layout.js.map +1 -0
- package/lib/module/hooks/use-is-editing.js +75 -0
- package/lib/module/hooks/use-is-editing.js.map +1 -0
- package/lib/module/index.js +124 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/types.js +20 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/calendar-layout.js +108 -0
- package/lib/module/utils/calendar-layout.js.map +1 -0
- package/lib/module/utils/compute-positioning.js +28 -0
- package/lib/module/utils/compute-positioning.js.map +1 -0
- package/lib/module/utils/date-utils.js +139 -0
- package/lib/module/utils/date-utils.js.map +1 -0
- package/lib/module/utils/double-tap-reset-zoom-gesture.js +15 -0
- package/lib/module/utils/double-tap-reset-zoom-gesture.js.map +1 -0
- package/lib/module/utils/generate-event-layouts.js +192 -0
- package/lib/module/utils/generate-event-layouts.js.map +1 -0
- package/lib/module/utils/globals.js +7 -0
- package/lib/module/utils/globals.js.map +1 -0
- package/lib/module/utils/pan-edit-event-gesture.js +37 -0
- package/lib/module/utils/pan-edit-event-gesture.js.map +1 -0
- package/lib/typescript/commonjs/components/all-day-events.d.ts +3 -0
- package/lib/typescript/commonjs/components/all-day-events.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/background-hours-content.d.ts +7 -0
- package/lib/typescript/commonjs/components/background-hours-content.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/background-hours-layout.d.ts +7 -0
- package/lib/typescript/commonjs/components/background-hours-layout.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/drag-bar.d.ts +14 -0
- package/lib/typescript/commonjs/components/drag-bar.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/edit-event-container.d.ts +7 -0
- package/lib/typescript/commonjs/components/edit-event-container.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/event-container.d.ts +7 -0
- package/lib/typescript/commonjs/components/event-container.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/new-event-container.d.ts +3 -0
- package/lib/typescript/commonjs/components/new-event-container.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/time-indicator.d.ts +3 -0
- package/lib/typescript/commonjs/components/time-indicator.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/timed-event-container.d.ts +9 -0
- package/lib/typescript/commonjs/components/timed-event-container.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/timed-events.d.ts +7 -0
- package/lib/typescript/commonjs/components/timed-events.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/zoom-provider.d.ts +7 -0
- package/lib/typescript/commonjs/components/zoom-provider.d.ts.map +1 -0
- package/lib/typescript/commonjs/enums.d.ts +2 -0
- package/lib/typescript/commonjs/enums.d.ts.map +1 -0
- package/lib/typescript/commonjs/hooks/use-cloned-events.d.ts +11 -0
- package/lib/typescript/commonjs/hooks/use-cloned-events.d.ts.map +1 -0
- package/lib/typescript/commonjs/hooks/use-events-layout.d.ts +13 -0
- package/lib/typescript/commonjs/hooks/use-events-layout.d.ts.map +1 -0
- package/lib/typescript/commonjs/hooks/use-is-editing.d.ts +17 -0
- package/lib/typescript/commonjs/hooks/use-is-editing.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +27 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/types.d.ts +128 -0
- package/lib/typescript/commonjs/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/__tests___/compute-positioning.test.d.ts +2 -0
- package/lib/typescript/commonjs/utils/__tests___/compute-positioning.test.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/__tests___/date-utils.test.d.ts +2 -0
- package/lib/typescript/commonjs/utils/__tests___/date-utils.test.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/__tests___/generate-event-layout.test.d.ts +2 -0
- package/lib/typescript/commonjs/utils/__tests___/generate-event-layout.test.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/calendar-layout.d.ts +36 -0
- package/lib/typescript/commonjs/utils/calendar-layout.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/compute-positioning.d.ts +10 -0
- package/lib/typescript/commonjs/utils/compute-positioning.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/date-utils.d.ts +30 -0
- package/lib/typescript/commonjs/utils/date-utils.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/double-tap-reset-zoom-gesture.d.ts +5 -0
- package/lib/typescript/commonjs/utils/double-tap-reset-zoom-gesture.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/generate-event-layouts.d.ts +15 -0
- package/lib/typescript/commonjs/utils/generate-event-layouts.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/globals.d.ts +5 -0
- package/lib/typescript/commonjs/utils/globals.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/pan-edit-event-gesture.d.ts +6 -0
- package/lib/typescript/commonjs/utils/pan-edit-event-gesture.d.ts.map +1 -0
- package/lib/typescript/module/components/all-day-events.d.ts +3 -0
- package/lib/typescript/module/components/all-day-events.d.ts.map +1 -0
- package/lib/typescript/module/components/background-hours-content.d.ts +7 -0
- package/lib/typescript/module/components/background-hours-content.d.ts.map +1 -0
- package/lib/typescript/module/components/background-hours-layout.d.ts +7 -0
- package/lib/typescript/module/components/background-hours-layout.d.ts.map +1 -0
- package/lib/typescript/module/components/drag-bar.d.ts +14 -0
- package/lib/typescript/module/components/drag-bar.d.ts.map +1 -0
- package/lib/typescript/module/components/edit-event-container.d.ts +7 -0
- package/lib/typescript/module/components/edit-event-container.d.ts.map +1 -0
- package/lib/typescript/module/components/event-container.d.ts +7 -0
- package/lib/typescript/module/components/event-container.d.ts.map +1 -0
- package/lib/typescript/module/components/new-event-container.d.ts +3 -0
- package/lib/typescript/module/components/new-event-container.d.ts.map +1 -0
- package/lib/typescript/module/components/time-indicator.d.ts +3 -0
- package/lib/typescript/module/components/time-indicator.d.ts.map +1 -0
- package/lib/typescript/module/components/timed-event-container.d.ts +9 -0
- package/lib/typescript/module/components/timed-event-container.d.ts.map +1 -0
- package/lib/typescript/module/components/timed-events.d.ts +7 -0
- package/lib/typescript/module/components/timed-events.d.ts.map +1 -0
- package/lib/typescript/module/components/zoom-provider.d.ts +7 -0
- package/lib/typescript/module/components/zoom-provider.d.ts.map +1 -0
- package/lib/typescript/module/enums.d.ts +2 -0
- package/lib/typescript/module/enums.d.ts.map +1 -0
- package/lib/typescript/module/hooks/use-cloned-events.d.ts +11 -0
- package/lib/typescript/module/hooks/use-cloned-events.d.ts.map +1 -0
- package/lib/typescript/module/hooks/use-events-layout.d.ts +13 -0
- package/lib/typescript/module/hooks/use-events-layout.d.ts.map +1 -0
- package/lib/typescript/module/hooks/use-is-editing.d.ts +17 -0
- package/lib/typescript/module/hooks/use-is-editing.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +27 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/types.d.ts +128 -0
- package/lib/typescript/module/types.d.ts.map +1 -0
- package/lib/typescript/module/utils/__tests___/compute-positioning.test.d.ts +2 -0
- package/lib/typescript/module/utils/__tests___/compute-positioning.test.d.ts.map +1 -0
- package/lib/typescript/module/utils/__tests___/date-utils.test.d.ts +2 -0
- package/lib/typescript/module/utils/__tests___/date-utils.test.d.ts.map +1 -0
- package/lib/typescript/module/utils/__tests___/generate-event-layout.test.d.ts +2 -0
- package/lib/typescript/module/utils/__tests___/generate-event-layout.test.d.ts.map +1 -0
- package/lib/typescript/module/utils/calendar-layout.d.ts +36 -0
- package/lib/typescript/module/utils/calendar-layout.d.ts.map +1 -0
- package/lib/typescript/module/utils/compute-positioning.d.ts +10 -0
- package/lib/typescript/module/utils/compute-positioning.d.ts.map +1 -0
- package/lib/typescript/module/utils/date-utils.d.ts +30 -0
- package/lib/typescript/module/utils/date-utils.d.ts.map +1 -0
- package/lib/typescript/module/utils/double-tap-reset-zoom-gesture.d.ts +5 -0
- package/lib/typescript/module/utils/double-tap-reset-zoom-gesture.d.ts.map +1 -0
- package/lib/typescript/module/utils/generate-event-layouts.d.ts +15 -0
- package/lib/typescript/module/utils/generate-event-layouts.d.ts.map +1 -0
- package/lib/typescript/module/utils/globals.d.ts +5 -0
- package/lib/typescript/module/utils/globals.d.ts.map +1 -0
- package/lib/typescript/module/utils/pan-edit-event-gesture.d.ts +6 -0
- package/lib/typescript/module/utils/pan-edit-event-gesture.d.ts.map +1 -0
- package/package.json +195 -0
- package/src/components/all-day-events.tsx +134 -0
- package/src/components/background-hours-content.tsx +51 -0
- package/src/components/background-hours-layout.tsx +61 -0
- package/src/components/drag-bar.tsx +120 -0
- package/src/components/edit-event-container.tsx +158 -0
- package/src/components/event-container.tsx +44 -0
- package/src/components/new-event-container.tsx +90 -0
- package/src/components/time-indicator.tsx +72 -0
- package/src/components/timed-event-container.tsx +124 -0
- package/src/components/timed-events.tsx +72 -0
- package/src/components/zoom-provider.tsx +146 -0
- package/src/enums.ts +0 -0
- package/src/hooks/use-cloned-events.ts +26 -0
- package/src/hooks/use-events-layout.ts +55 -0
- package/src/hooks/use-is-editing.tsx +109 -0
- package/src/index.tsx +165 -0
- package/src/types.ts +163 -0
- package/src/utils/__tests___/compute-positioning.test.ts +255 -0
- package/src/utils/__tests___/date-utils.test.ts +41 -0
- package/src/utils/__tests___/generate-event-layout.test.ts +277 -0
- package/src/utils/calendar-layout.ts +139 -0
- package/src/utils/compute-positioning.ts +44 -0
- package/src/utils/date-utils.ts +238 -0
- package/src/utils/double-tap-reset-zoom-gesture.ts +23 -0
- package/src/utils/generate-event-layouts.ts +314 -0
- package/src/utils/globals.ts +8 -0
- package/src/utils/pan-edit-event-gesture.ts +64 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { Moment } from "moment-timezone";
|
|
2
|
+
import { TextStyle, ViewStyle } from "react-native";
|
|
3
|
+
import { DerivedValue, SharedValue } from "react-native-reanimated";
|
|
4
|
+
import { ReactNode } from "react";
|
|
5
|
+
|
|
6
|
+
export type CalendarEvent = {
|
|
7
|
+
id: string;
|
|
8
|
+
calendarId: string;
|
|
9
|
+
title: string;
|
|
10
|
+
start: string;
|
|
11
|
+
end: string;
|
|
12
|
+
isAllDay?: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type AllDayEventLayoutType = {
|
|
16
|
+
event: CalendarEvent;
|
|
17
|
+
rowIndex?: number;
|
|
18
|
+
visibleWidthDays?: number;
|
|
19
|
+
extend: EventExtend;
|
|
20
|
+
isPrimaryRendered?: boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type PartDayEventLayoutType = {
|
|
24
|
+
event: CalendarEvent;
|
|
25
|
+
collisions?: {
|
|
26
|
+
total: number;
|
|
27
|
+
order: number;
|
|
28
|
+
};
|
|
29
|
+
position: EventPosition;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export interface CollisionObject {
|
|
33
|
+
event: CalendarEvent;
|
|
34
|
+
collisions?: { total: number; order: number };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type EventPosition = {
|
|
38
|
+
top: number;
|
|
39
|
+
height: number;
|
|
40
|
+
width: string;
|
|
41
|
+
marginLeft: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type FullCalendarEventLayout = {
|
|
45
|
+
allDayEventsLayout: AllDayEventLayoutType[];
|
|
46
|
+
partDayEventsLayout: PartDayEventLayoutType[];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type ThemeStyle = {
|
|
50
|
+
// Main container style
|
|
51
|
+
container?: ViewStyle;
|
|
52
|
+
// Vertical scroll view
|
|
53
|
+
scrollView?: ViewStyle;
|
|
54
|
+
// Timed events main container
|
|
55
|
+
timedEventsContainer?: ViewStyle;
|
|
56
|
+
// Border container used to separate the hours and the main grid
|
|
57
|
+
borderContainer?: ViewStyle;
|
|
58
|
+
// Background hours container
|
|
59
|
+
backgroundHoursContainer?: ViewStyle;
|
|
60
|
+
// Background hours inner container
|
|
61
|
+
backgroundHoursInnerContainer?: ViewStyle;
|
|
62
|
+
// Background hours text
|
|
63
|
+
backgroundHoursText?: TextStyle;
|
|
64
|
+
// Background hours layout container
|
|
65
|
+
backgroundHoursLayoutContainer?: ViewStyle;
|
|
66
|
+
// New event inner container, if you don't want to use the `renderNewEventContainer` prop
|
|
67
|
+
newEventContainer?: ViewStyle;
|
|
68
|
+
// Event container title
|
|
69
|
+
eventTitle?: TextStyle;
|
|
70
|
+
// Event container subtitle
|
|
71
|
+
eventSubtitle?: TextStyle;
|
|
72
|
+
// Event container main container
|
|
73
|
+
eventContainer?: ViewStyle;
|
|
74
|
+
// Style the time indicator
|
|
75
|
+
timeIndicator?: ViewStyle;
|
|
76
|
+
// All day main container
|
|
77
|
+
allDayContainer?: ViewStyle;
|
|
78
|
+
// All day event container
|
|
79
|
+
allDayEventContainer?: ViewStyle;
|
|
80
|
+
// Container showing when there are too many all day events to show
|
|
81
|
+
allDayShowMoreContainer?: ViewStyle;
|
|
82
|
+
// Text showing when there are too many all day events to show
|
|
83
|
+
allDayShowMoreText?: TextStyle;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export type OnCreateEventProps = {
|
|
87
|
+
hour?: number;
|
|
88
|
+
minute?: number;
|
|
89
|
+
isAllDay?: boolean;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export type onCreateEvent = (arg: OnCreateEventProps) => void;
|
|
93
|
+
|
|
94
|
+
export type Config = {
|
|
95
|
+
timezone: string;
|
|
96
|
+
timeFormat: string;
|
|
97
|
+
dayDate: Moment;
|
|
98
|
+
theme?: ThemeStyle;
|
|
99
|
+
zoomLevel: SharedValue<number>;
|
|
100
|
+
layout: FullCalendarEventLayout;
|
|
101
|
+
createY: SharedValue<number>;
|
|
102
|
+
maximumHour: SharedValue<number>;
|
|
103
|
+
onCreateEvent?: onCreateEvent;
|
|
104
|
+
initialZoomLevel: number;
|
|
105
|
+
renderEvent: (
|
|
106
|
+
event: CalendarEvent,
|
|
107
|
+
extended: EventExtend,
|
|
108
|
+
eventHeight?: SharedValue<number>,
|
|
109
|
+
updatedTimes?: {
|
|
110
|
+
updatedStart: DerivedValue<number>;
|
|
111
|
+
updatedEnd: DerivedValue<number>;
|
|
112
|
+
}
|
|
113
|
+
) => ReactNode;
|
|
114
|
+
onEventEdit?: (params: {
|
|
115
|
+
event: CalendarEvent;
|
|
116
|
+
status: EditStatus;
|
|
117
|
+
updatedTimes?: {
|
|
118
|
+
updatedStart: string;
|
|
119
|
+
updatedEnd: string;
|
|
120
|
+
};
|
|
121
|
+
}) => void;
|
|
122
|
+
onPressEvent?: (event: CalendarEvent) => void;
|
|
123
|
+
showTimeIndicator?: boolean;
|
|
124
|
+
maxAllDayEvents: number;
|
|
125
|
+
canCreateEvents: boolean;
|
|
126
|
+
canEditEvent: boolean | ((event: CalendarEvent) => boolean);
|
|
127
|
+
renderNewEventContainer?: (hour: number, minute: number) => ReactNode;
|
|
128
|
+
fiveMinuteInterval?: boolean;
|
|
129
|
+
renderDragBars?: { top?: () => ReactNode; bottom?: () => ReactNode };
|
|
130
|
+
updateLocalStateAfterEdit: boolean;
|
|
131
|
+
extraTimedComponents?: (zoomLevel: SharedValue<number>) => ReactNode;
|
|
132
|
+
onZoomChange?: (zoomLevel: number) => void;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export type PrefabHour = {
|
|
136
|
+
increment: number;
|
|
137
|
+
hourFormatted: string;
|
|
138
|
+
hourMoment: Moment;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export type CalendarViewIntervalType =
|
|
142
|
+
| "month"
|
|
143
|
+
| "workweek"
|
|
144
|
+
| "3day"
|
|
145
|
+
| "1day"
|
|
146
|
+
| "week";
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Tells us if an event extends into the next day, the previous day, or both.
|
|
150
|
+
* Used for all day events.
|
|
151
|
+
*/
|
|
152
|
+
export enum EventExtend {
|
|
153
|
+
// Keep None as value 0
|
|
154
|
+
None,
|
|
155
|
+
Past,
|
|
156
|
+
Future,
|
|
157
|
+
Both,
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export enum EditStatus {
|
|
161
|
+
Start,
|
|
162
|
+
Finish,
|
|
163
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import computePositioning from "src/utils/compute-positioning";
|
|
2
|
+
import moment from "moment-timezone";
|
|
3
|
+
import { PartDayEventLayoutType } from "src/types";
|
|
4
|
+
|
|
5
|
+
describe("computePositioning", () => {
|
|
6
|
+
it("should compute positioning correctly without collisions", () => {
|
|
7
|
+
const layout: PartDayEventLayoutType = {
|
|
8
|
+
event: {
|
|
9
|
+
start: "2023-10-01T09:00:00Z",
|
|
10
|
+
end: "2023-10-01T10:00:00Z",
|
|
11
|
+
id: "test",
|
|
12
|
+
title: "",
|
|
13
|
+
calendarId: "",
|
|
14
|
+
},
|
|
15
|
+
// We don't have to test this
|
|
16
|
+
position: {
|
|
17
|
+
top: 540,
|
|
18
|
+
height: 60,
|
|
19
|
+
width: "100%",
|
|
20
|
+
marginLeft: "0%",
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
const startOfDayMoment = moment
|
|
24
|
+
.tz(layout.event.start, "UTC")
|
|
25
|
+
.startOf("day");
|
|
26
|
+
|
|
27
|
+
const result = computePositioning({
|
|
28
|
+
collisionObject: layout,
|
|
29
|
+
startOfDayMoment,
|
|
30
|
+
timezone: "UTC",
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
expect(result).toEqual({
|
|
34
|
+
top: 540,
|
|
35
|
+
height: 60,
|
|
36
|
+
width: "100%",
|
|
37
|
+
marginLeft: "0%",
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should compute positioning correctly with collisions (total: 3, order: 0)", () => {
|
|
42
|
+
const layout = {
|
|
43
|
+
event: {
|
|
44
|
+
start: "2023-10-01T09:00:00Z",
|
|
45
|
+
end: "2023-10-01T10:00:00Z",
|
|
46
|
+
id: "test",
|
|
47
|
+
title: "",
|
|
48
|
+
calendarId: "",
|
|
49
|
+
},
|
|
50
|
+
collisions: { total: 3, order: 0 },
|
|
51
|
+
// We don't have to test this
|
|
52
|
+
position: {
|
|
53
|
+
top: 540,
|
|
54
|
+
height: 60,
|
|
55
|
+
width: "100%",
|
|
56
|
+
marginLeft: "0%",
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const startOfDayMoment = moment
|
|
60
|
+
.tz(layout.event.start, "UTC")
|
|
61
|
+
.startOf("day");
|
|
62
|
+
|
|
63
|
+
const result = computePositioning({
|
|
64
|
+
collisionObject: layout,
|
|
65
|
+
startOfDayMoment,
|
|
66
|
+
timezone: "UTC",
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(result).toEqual({
|
|
70
|
+
top: 540,
|
|
71
|
+
height: 60,
|
|
72
|
+
width: "64%",
|
|
73
|
+
marginLeft: "0%",
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("should compute positioning correctly with collisions (total: 3, order: 1)", () => {
|
|
78
|
+
const layout = {
|
|
79
|
+
event: {
|
|
80
|
+
start: "2023-10-01T09:00:00Z",
|
|
81
|
+
end: "2023-10-01T10:00:00Z",
|
|
82
|
+
id: "test",
|
|
83
|
+
title: "",
|
|
84
|
+
calendarId: "",
|
|
85
|
+
},
|
|
86
|
+
collisions: { total: 3, order: 1 },
|
|
87
|
+
// We don't have to test this
|
|
88
|
+
position: {
|
|
89
|
+
top: 540,
|
|
90
|
+
height: 60,
|
|
91
|
+
width: "100%",
|
|
92
|
+
marginLeft: "0%",
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
const startOfDayMoment = moment
|
|
96
|
+
.tz(layout.event.start, "UTC")
|
|
97
|
+
.startOf("day");
|
|
98
|
+
|
|
99
|
+
const result = computePositioning({
|
|
100
|
+
collisionObject: layout,
|
|
101
|
+
startOfDayMoment,
|
|
102
|
+
timezone: "UTC",
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
expect(result).toEqual({
|
|
106
|
+
top: 540,
|
|
107
|
+
height: 60,
|
|
108
|
+
width: "64%",
|
|
109
|
+
marginLeft: "33.333333333333336%",
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("should compute positioning correctly with collisions (total: 3, order: 2)", () => {
|
|
114
|
+
const layout = {
|
|
115
|
+
event: {
|
|
116
|
+
start: "2023-10-01T09:00:00Z",
|
|
117
|
+
end: "2023-10-01T10:00:00Z",
|
|
118
|
+
id: "test",
|
|
119
|
+
title: "",
|
|
120
|
+
calendarId: "",
|
|
121
|
+
},
|
|
122
|
+
collisions: { total: 3, order: 2 },
|
|
123
|
+
// We don't have to test this
|
|
124
|
+
position: {
|
|
125
|
+
top: 540,
|
|
126
|
+
height: 60,
|
|
127
|
+
width: "100%",
|
|
128
|
+
marginLeft: "0%",
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
const startOfDayMoment = moment
|
|
132
|
+
.tz(layout.event.start, "UTC")
|
|
133
|
+
.startOf("day");
|
|
134
|
+
|
|
135
|
+
const result = computePositioning({
|
|
136
|
+
collisionObject: layout,
|
|
137
|
+
startOfDayMoment,
|
|
138
|
+
timezone: "UTC",
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
expect(result).toEqual({
|
|
142
|
+
top: 540,
|
|
143
|
+
height: 60,
|
|
144
|
+
width: "33.333333333333336%",
|
|
145
|
+
marginLeft: "66.66666666666667%",
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("should compute positioning correctly with collisions (total: 4, order: 3)", () => {
|
|
150
|
+
const layout = {
|
|
151
|
+
event: {
|
|
152
|
+
start: "2023-10-01T09:00:00Z",
|
|
153
|
+
end: "2023-10-01T10:00:00Z",
|
|
154
|
+
id: "test",
|
|
155
|
+
title: "",
|
|
156
|
+
calendarId: "",
|
|
157
|
+
},
|
|
158
|
+
collisions: { total: 4, order: 3 },
|
|
159
|
+
// We don't have to test this
|
|
160
|
+
position: {
|
|
161
|
+
top: 540,
|
|
162
|
+
height: 60,
|
|
163
|
+
width: "100%",
|
|
164
|
+
marginLeft: "0%",
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
const startOfDayMoment = moment
|
|
168
|
+
.tz(layout.event.start, "UTC")
|
|
169
|
+
.startOf("day");
|
|
170
|
+
|
|
171
|
+
const result = computePositioning({
|
|
172
|
+
collisionObject: layout,
|
|
173
|
+
startOfDayMoment,
|
|
174
|
+
timezone: "UTC",
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
expect(result).toEqual({
|
|
178
|
+
top: 540,
|
|
179
|
+
height: 60,
|
|
180
|
+
width: "25%",
|
|
181
|
+
marginLeft: "75%",
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("should compute positioning correctly with collisions", () => {
|
|
186
|
+
const layout = {
|
|
187
|
+
event: {
|
|
188
|
+
start: "2023-10-01T09:00:00Z",
|
|
189
|
+
end: "2023-10-01T10:00:00Z",
|
|
190
|
+
id: "test",
|
|
191
|
+
title: "",
|
|
192
|
+
calendarId: "",
|
|
193
|
+
},
|
|
194
|
+
collisions: { total: 2, order: 1 },
|
|
195
|
+
// We don't have to test this
|
|
196
|
+
position: {
|
|
197
|
+
top: 540,
|
|
198
|
+
height: 60,
|
|
199
|
+
width: "100%",
|
|
200
|
+
marginLeft: "0%",
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
const startOfDayMoment = moment
|
|
204
|
+
.tz(layout.event.start, "UTC")
|
|
205
|
+
.startOf("day");
|
|
206
|
+
|
|
207
|
+
const result = computePositioning({
|
|
208
|
+
collisionObject: layout,
|
|
209
|
+
startOfDayMoment,
|
|
210
|
+
timezone: "UTC",
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
expect(result).toEqual({
|
|
214
|
+
top: 540,
|
|
215
|
+
height: 60,
|
|
216
|
+
width: "50%",
|
|
217
|
+
marginLeft: "50%",
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("should handle minimum height correctly", () => {
|
|
222
|
+
const layout = {
|
|
223
|
+
event: {
|
|
224
|
+
start: "2023-10-01T09:00:00Z",
|
|
225
|
+
end: "2023-10-01T09:15:00Z",
|
|
226
|
+
id: "test",
|
|
227
|
+
title: "",
|
|
228
|
+
calendarId: "",
|
|
229
|
+
},
|
|
230
|
+
// We don't have to test this
|
|
231
|
+
position: {
|
|
232
|
+
top: 540,
|
|
233
|
+
height: 60,
|
|
234
|
+
width: "100%",
|
|
235
|
+
marginLeft: "0%",
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
const startOfDayMoment = moment
|
|
239
|
+
.tz(layout.event.start, "UTC")
|
|
240
|
+
.startOf("day");
|
|
241
|
+
|
|
242
|
+
const result = computePositioning({
|
|
243
|
+
collisionObject: layout,
|
|
244
|
+
startOfDayMoment,
|
|
245
|
+
timezone: "UTC",
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
expect(result).toEqual({
|
|
249
|
+
top: 540,
|
|
250
|
+
height: 30,
|
|
251
|
+
width: "100%",
|
|
252
|
+
marginLeft: "0%",
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import moment from "moment-timezone";
|
|
2
|
+
import { generatePrefabHours } from "../date-utils";
|
|
3
|
+
|
|
4
|
+
describe("generatePrefabHours", () => {
|
|
5
|
+
it("should generate 24 hours with default format", () => {
|
|
6
|
+
const hours = generatePrefabHours();
|
|
7
|
+
expect(hours.length).toBe(24);
|
|
8
|
+
expect(hours[0]!.hourFormatted).toBe(
|
|
9
|
+
moment().startOf("day").format("HH:mm")
|
|
10
|
+
);
|
|
11
|
+
expect(hours[23]!.hourFormatted).toBe(
|
|
12
|
+
moment().startOf("day").hour(23).format("HH:mm")
|
|
13
|
+
);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should generate 24 hours with US format", () => {
|
|
17
|
+
const customFormat = "h A";
|
|
18
|
+
const hours = generatePrefabHours(customFormat);
|
|
19
|
+
expect(hours.length).toBe(24);
|
|
20
|
+
expect(hours[0]!.hourFormatted).toBe(
|
|
21
|
+
moment().startOf("day").format(customFormat)
|
|
22
|
+
);
|
|
23
|
+
expect(hours[23]!.hourFormatted).toBe(
|
|
24
|
+
moment().startOf("day").hour(23).format(customFormat)
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should generate correct hour moments", () => {
|
|
29
|
+
const hours = generatePrefabHours();
|
|
30
|
+
hours.forEach((hour, index) => {
|
|
31
|
+
expect(hour.hourMoment.hour()).toBe(index);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should generate correct increments", () => {
|
|
36
|
+
const hours = generatePrefabHours();
|
|
37
|
+
hours.forEach((hour, index) => {
|
|
38
|
+
expect(hour.increment).toBe(index);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|