@luckydye/calendar 1.3.2 → 1.4.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/dist/calendar.js +2344 -2061
- package/package.json +7 -1
- package/src/ActiveCalendarStore.ts +88 -88
- package/src/CalDAVConfig.ts +611 -514
- package/src/CalDAVSource.ts +561 -466
- package/src/CalendarIntegration.ts +64 -47
- package/src/CalendarInternal.ts +645 -614
- package/src/CalendarLayer.ts +1 -0
- package/src/CalendarStorage.ts +51 -48
- package/src/CalendarView.ts +883 -507
- package/src/Color.ts +48 -54
- package/src/GoogleCalendarSource.ts +758 -662
- package/src/ICal.ts +420 -348
- package/src/InMemorySource.ts +56 -48
- package/src/IndexedDBStorage.ts +444 -398
- package/src/InhouseBookingSource.ts +614 -523
- package/src/Keybinds.ts +6 -1
- package/src/NotificationScheduler.ts +11 -8
- package/src/StatusBar.ts +12 -8
- package/src/StatusMessage.ts +2 -2
- package/src/Theme.ts +21 -7
- package/src/TimeseriesJson.ts +98 -98
- package/src/app.ts +153 -78
- package/src/layers/EventsLayer.ts +530 -400
- package/src/layers/GridLayer.ts +45 -125
- package/src/layers/TimeseriesHeatmapLayer.ts +123 -120
- package/src/service-worker.js +3 -2
|
@@ -1,67 +1,84 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CalendarEvent, CalendarInternal } from "./CalendarInternal.js";
|
|
2
2
|
|
|
3
3
|
export interface Calendar {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
color: string;
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
locked?: boolean;
|
|
9
|
+
sourceId: string;
|
|
10
|
+
sourceType: string;
|
|
11
|
+
calendarUrl?: string;
|
|
12
|
+
fetchEvents(): Promise<CalendarEvent[]>;
|
|
13
|
+
createEvent?(
|
|
14
|
+
event: Omit<CalendarEvent, "calendar" | "color">,
|
|
15
|
+
): Promise<CalendarEvent>;
|
|
16
|
+
updateEvent?(
|
|
17
|
+
event: CalendarEvent,
|
|
18
|
+
updates: Partial<CalendarEvent>,
|
|
19
|
+
): Promise<CalendarEvent>;
|
|
20
|
+
deleteEvent?(id: string): Promise<void>;
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
export interface CalendarCredentials {
|
|
19
|
-
|
|
24
|
+
[key: string]: string;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
export interface CalendarSource {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
type: string;
|
|
31
|
+
credentials: CalendarCredentials;
|
|
32
|
+
color: string;
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
fetchEvents(): Promise<CalendarEvent[]>;
|
|
35
|
+
createEvent?(
|
|
36
|
+
event: Omit<CalendarEvent, "calendar" | "color">,
|
|
37
|
+
): Promise<CalendarEvent>;
|
|
38
|
+
updateEvent?(
|
|
39
|
+
event: CalendarEvent,
|
|
40
|
+
updates: Partial<CalendarEvent>,
|
|
41
|
+
): Promise<CalendarEvent>;
|
|
42
|
+
deleteEvent?(id: string): Promise<void>;
|
|
33
43
|
}
|
|
34
44
|
|
|
35
45
|
export class CalendarIntegration {
|
|
36
|
-
|
|
46
|
+
static SYNC_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
|
|
37
47
|
|
|
38
|
-
|
|
48
|
+
constructor(protected internals: CalendarInternal) {}
|
|
39
49
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
async shouldSync(calendar: Calendar): Promise<boolean> {
|
|
51
|
+
const metadata = await this.internals.storage.getSyncMetadata(calendar.id);
|
|
52
|
+
if (!metadata) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
45
55
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
const timeSinceLastSync = Date.now() - metadata.lastSync.getTime();
|
|
57
|
+
return timeSinceLastSync >= CalendarIntegration.SYNC_INTERVAL_MS;
|
|
58
|
+
}
|
|
49
59
|
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
async sync(
|
|
61
|
+
calendar: Calendar,
|
|
62
|
+
options?: { force?: boolean },
|
|
63
|
+
): Promise<CalendarEvent[]> {
|
|
64
|
+
if (!calendar.enabled) return [];
|
|
52
65
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
66
|
+
if (!options?.force && !(await this.shouldSync(calendar))) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
56
69
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
const events = await calendar.fetchEvents();
|
|
71
|
+
const syncTimestamp = new Date();
|
|
72
|
+
const updatedEvents = this.internals.sync(
|
|
73
|
+
calendar.name,
|
|
74
|
+
syncTimestamp,
|
|
75
|
+
events,
|
|
76
|
+
);
|
|
60
77
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
78
|
+
await this.internals.storage.setSyncMetadata(calendar.id, {
|
|
79
|
+
lastSync: new Date(),
|
|
80
|
+
});
|
|
64
81
|
|
|
65
|
-
|
|
66
|
-
|
|
82
|
+
return updatedEvents;
|
|
83
|
+
}
|
|
67
84
|
}
|