@octane-xplat/calendar 0.0.0-nightly.g52542a7
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 +21 -0
- package/README.md +25 -0
- package/package.json +94 -0
- package/platforms/android/AndroidManifest.xml +4 -0
- package/platforms/ios/Info.plist +10 -0
- package/src/calendar.linux.ts +1 -0
- package/src/calendar.macos.ts +15 -0
- package/src/calendar.ts +310 -0
- package/src/calendar.web.ts +20 -0
- package/src/calendar.windows.ts +15 -0
- package/src/index.macos.ts +2 -0
- package/src/index.ts +2 -0
- package/src/index.web.ts +2 -0
- package/src/types.ts +46 -0
- package/types/generated/.tsrx-typegen-manifest.json +14 -0
- package/types/generated/calendar.d.ts +2 -0
- package/types/generated/calendar.linux.d.ts +1 -0
- package/types/generated/calendar.macos.d.ts +2 -0
- package/types/generated/calendar.web.d.ts +2 -0
- package/types/generated/calendar.windows.d.ts +2 -0
- package/types/generated/index.d.ts +2 -0
- package/types/generated/index.macos.d.ts +2 -0
- package/types/generated/index.web.d.ts +2 -0
- package/types/generated/types.d.ts +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alec Larson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# `@octane-xplat/calendar`
|
|
2
|
+
|
|
3
|
+
```sh
|
|
4
|
+
pnpm add @octane-xplat/calendar
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Device calendar — list calendars, query events by range, create/update/
|
|
8
|
+
delete. Custom bridge: EventKit `EKEventStore` on iOS, CalendarContract on
|
|
9
|
+
Android (the `nativescript-calendar` plugin is stale). Web and desktop
|
|
10
|
+
report `supported: false` — `.ics` file generation is userland.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { calendar } from '@octane-xplat/calendar'
|
|
14
|
+
|
|
15
|
+
if ((await calendar.ensure()) === 'granted') {
|
|
16
|
+
const cals = await calendar.getCalendars()
|
|
17
|
+
const thisWeek = await calendar.getEvents(start, end)
|
|
18
|
+
const id = await calendar.createEvent(undefined, {
|
|
19
|
+
title: 'Flight', startDate, endDate, location: 'SFO',
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Reminders, attendees, and recurring-edit modes are out of scope (Expo models
|
|
25
|
+
reminders as a separate entity).
|
package/package.json
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@octane-xplat/calendar",
|
|
3
|
+
"version": "0.0.0-nightly.g52542a7",
|
|
4
|
+
"description": "Device calendar for Octane xplat — event store reads and writes via EventKit/CalendarContract",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"android",
|
|
7
|
+
"cross-platform",
|
|
8
|
+
"nativescript",
|
|
9
|
+
"octane",
|
|
10
|
+
"xplat",
|
|
11
|
+
"calendar",
|
|
12
|
+
"events"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/calendar",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/octane-xplat/octane-xplat",
|
|
19
|
+
"directory": "packages/calendar"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"src",
|
|
23
|
+
"platforms",
|
|
24
|
+
"types",
|
|
25
|
+
"!src/**/*.test.*",
|
|
26
|
+
"!src/**/*.spec.*"
|
|
27
|
+
],
|
|
28
|
+
"type": "module",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"macos": {
|
|
32
|
+
"types": "./types/generated/index.macos.d.ts",
|
|
33
|
+
"default": "./src/index.macos.ts"
|
|
34
|
+
},
|
|
35
|
+
"web": {
|
|
36
|
+
"types": "./types/generated/index.web.d.ts",
|
|
37
|
+
"default": "./src/index.web.ts"
|
|
38
|
+
},
|
|
39
|
+
"native": {
|
|
40
|
+
"types": "./types/generated/index.d.ts",
|
|
41
|
+
"default": "./src/index.ts"
|
|
42
|
+
},
|
|
43
|
+
"types": "./types/generated/index.d.ts",
|
|
44
|
+
"default": "./src/index.ts"
|
|
45
|
+
},
|
|
46
|
+
"./*": {
|
|
47
|
+
"types": "./types/generated/*.d.ts",
|
|
48
|
+
"default": "./src/*"
|
|
49
|
+
},
|
|
50
|
+
"./*.ts": {
|
|
51
|
+
"types": "./types/generated/*.d.ts",
|
|
52
|
+
"default": "./src/*.ts"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@nativescript-community/octane": "0.2.5",
|
|
60
|
+
"@nativescript/core": "9.1.3",
|
|
61
|
+
"@nativescript/types": "9.1.4",
|
|
62
|
+
"@tsrx/typescript-plugin": "0.4.11",
|
|
63
|
+
"octane": "0.14.0",
|
|
64
|
+
"tsrx-typegen": "0.4.0",
|
|
65
|
+
"typescript": "5.9.3"
|
|
66
|
+
},
|
|
67
|
+
"peerDependencies": {
|
|
68
|
+
"@nativescript-community/octane": ">=0.2.1 <1",
|
|
69
|
+
"@nativescript/core": ">=9.1.0 <10",
|
|
70
|
+
"octane": ">=0.6.3 <1"
|
|
71
|
+
},
|
|
72
|
+
"peerDependenciesMeta": {
|
|
73
|
+
"@nativescript-community/octane": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"@nativescript/core": {
|
|
77
|
+
"optional": true
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"nativescript": {
|
|
81
|
+
"platforms": {
|
|
82
|
+
"android": "9.1.0",
|
|
83
|
+
"ios": "9.1.0"
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"dependencies": {
|
|
87
|
+
"@octane-xplat/platform": "0.0.0-nightly.g52542a7"
|
|
88
|
+
},
|
|
89
|
+
"scripts": {
|
|
90
|
+
"typegen": "tsrx-typegen --target octane",
|
|
91
|
+
"pack:check": "tsrx-typegen --pack-check",
|
|
92
|
+
"typecheck": "node ../../scripts/typecheck.ts"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>NSCalendarsUsageDescription</key>
|
|
6
|
+
<string>Calendar access is required to read and write events.</string>
|
|
7
|
+
<key>NSCalendarsWriteOnlyAccessUsageDescription</key>
|
|
8
|
+
<string>Calendar access is required to create events.</string>
|
|
9
|
+
</dict>
|
|
10
|
+
</plist>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { calendar } from './calendar.web'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Calendar, PermissionResult } from './types'
|
|
2
|
+
|
|
3
|
+
const unsupported = () => Promise.reject(new Error('unsupported: calendar is not wired on this platform'))
|
|
4
|
+
|
|
5
|
+
export const calendar: Calendar = {
|
|
6
|
+
supported: false,
|
|
7
|
+
ensure: async (): Promise<PermissionResult> => 'unsupported',
|
|
8
|
+
getCalendars: unsupported,
|
|
9
|
+
getDefaultCalendar: unsupported,
|
|
10
|
+
getEvents: unsupported,
|
|
11
|
+
getEvent: unsupported,
|
|
12
|
+
createEvent: unsupported,
|
|
13
|
+
updateEvent: unsupported,
|
|
14
|
+
deleteEvent: unsupported,
|
|
15
|
+
}
|
package/src/calendar.ts
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
// Calendar — native leaf, custom bridge (nativescript-calendar is stale).
|
|
2
|
+
// iOS: EventKit EKEventStore via declare-const bridging (auth-session
|
|
3
|
+
// pattern). Android: CalendarContract through the content provider.
|
|
4
|
+
import { Application, Utils, isIOS } from '@nativescript/core'
|
|
5
|
+
import { android } from '@octane-xplat/platform/android'
|
|
6
|
+
import type { Calendar, CalendarEvent, CalendarInfo, NewEvent, PermissionResult } from './types'
|
|
7
|
+
|
|
8
|
+
declare const EKEventStore: any
|
|
9
|
+
declare const EKEntityTypeEvent: number | undefined
|
|
10
|
+
declare const EKAuthorizationStatus: any
|
|
11
|
+
declare const EKEvent: any
|
|
12
|
+
declare const NSPredicate: any
|
|
13
|
+
declare const NSDate: any
|
|
14
|
+
|
|
15
|
+
let store: any = null
|
|
16
|
+
const eventStore = () => {
|
|
17
|
+
if (!store && typeof EKEventStore !== 'undefined') {
|
|
18
|
+
store = EKEventStore.new()
|
|
19
|
+
}
|
|
20
|
+
return store
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function iosEnsure(): Promise<PermissionResult> {
|
|
24
|
+
const s = eventStore()
|
|
25
|
+
if (!s || typeof EKEntityTypeEvent === 'undefined') {
|
|
26
|
+
return Promise.resolve('unsupported')
|
|
27
|
+
}
|
|
28
|
+
const status = EKEventStore.authorizationStatusForEntityType(EKEntityTypeEvent)
|
|
29
|
+
// 0 notDetermined 1 restricted 2 denied 3 fullAccess/authorized 4 writeOnly
|
|
30
|
+
if (status === 3 || status === 4) {
|
|
31
|
+
return Promise.resolve('granted')
|
|
32
|
+
}
|
|
33
|
+
if (status === 1 || status === 2) {
|
|
34
|
+
return Promise.resolve('denied')
|
|
35
|
+
}
|
|
36
|
+
return new Promise((resolve) => {
|
|
37
|
+
if (typeof s.requestFullAccessToEventsWithCompletion === 'function') {
|
|
38
|
+
s.requestFullAccessToEventsWithCompletion((granted: boolean) =>
|
|
39
|
+
resolve(granted ? 'granted' : 'denied'),
|
|
40
|
+
)
|
|
41
|
+
} else {
|
|
42
|
+
s.requestAccessToEntityTypeCompletion(EKEntityTypeEvent, (granted: boolean) =>
|
|
43
|
+
resolve(granted ? 'granted' : 'denied'),
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let calRequestCode = 7731
|
|
50
|
+
|
|
51
|
+
function androidEnsure(): Promise<PermissionResult> {
|
|
52
|
+
const perm = 'android.permission.READ_CALENDAR'
|
|
53
|
+
const activity = Application.android.foregroundActivity ?? Application.android.startActivity
|
|
54
|
+
try {
|
|
55
|
+
if (
|
|
56
|
+
activity?.checkSelfPermission?.(perm) === android.content.pm.PackageManager.PERMISSION_GRANTED
|
|
57
|
+
) {
|
|
58
|
+
return Promise.resolve('granted')
|
|
59
|
+
}
|
|
60
|
+
if (!activity) {
|
|
61
|
+
return Promise.resolve('denied')
|
|
62
|
+
}
|
|
63
|
+
return new Promise<PermissionResult>((resolve) => {
|
|
64
|
+
const requestCode = calRequestCode++
|
|
65
|
+
const event = Application.android.activityRequestPermissionsEvent
|
|
66
|
+
const onResult = (args: any) => {
|
|
67
|
+
if (args.requestCode !== requestCode) {
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
Application.android.off(event, onResult)
|
|
71
|
+
resolve(
|
|
72
|
+
args.grantResults?.[0] === android.content.pm.PackageManager.PERMISSION_GRANTED
|
|
73
|
+
? 'granted'
|
|
74
|
+
: 'denied',
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
Application.android.on(event, onResult)
|
|
78
|
+
try {
|
|
79
|
+
activity.requestPermissions([perm, 'android.permission.WRITE_CALENDAR'], requestCode)
|
|
80
|
+
} catch {
|
|
81
|
+
Application.android.off(event, onResult)
|
|
82
|
+
resolve('denied')
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
} catch {
|
|
86
|
+
return Promise.resolve('denied')
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function iosCalendars(): CalendarInfo[] {
|
|
91
|
+
const s = eventStore()
|
|
92
|
+
const out: CalendarInfo[] = []
|
|
93
|
+
const list = s?.calendarsForEntityType?.(EKEntityTypeEvent ?? 0)
|
|
94
|
+
for (let i = 0; i < (list?.count ?? 0); i++) {
|
|
95
|
+
const c = list.objectAtIndex(i)
|
|
96
|
+
out.push({
|
|
97
|
+
id: String(c.calendarIdentifier ?? ''),
|
|
98
|
+
title: String(c.title ?? ''),
|
|
99
|
+
color: c.CGColor ? String(c.CGColor) : undefined,
|
|
100
|
+
source: c.source?.title ? String(c.source.title) : undefined,
|
|
101
|
+
allowsModifications: !!c.allowsContentModifications,
|
|
102
|
+
isPrimary: false,
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
return out
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function iosEvent(e: any): CalendarEvent {
|
|
109
|
+
return {
|
|
110
|
+
id: String(e.eventIdentifier ?? ''),
|
|
111
|
+
calendarId: e.calendar?.calendarIdentifier ? String(e.calendar.calendarIdentifier) : undefined,
|
|
112
|
+
title: String(e.title ?? ''),
|
|
113
|
+
startDate: new Date((e.startDate?.timeIntervalSince1970 ?? 0) * 1000),
|
|
114
|
+
endDate: new Date((e.endDate?.timeIntervalSince1970 ?? 0) * 1000),
|
|
115
|
+
allDay: !!e.allDay,
|
|
116
|
+
location: e.location ? String(e.location) : undefined,
|
|
117
|
+
notes: e.notes ? String(e.notes) : undefined,
|
|
118
|
+
timeZone: e.timeZone?.name ? String(e.timeZone.name) : undefined,
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const androidUtils = Utils.android as any
|
|
123
|
+
const resolver = () => androidUtils?.getApplicationContext?.()?.getContentResolver()
|
|
124
|
+
|
|
125
|
+
function androidQuery(uri: any, projection: string[], selection: string, args: string[], sort: string): any[] {
|
|
126
|
+
const cursor = resolver()?.query(uri, projection, selection, args, sort)
|
|
127
|
+
const out: any[] = []
|
|
128
|
+
if (!cursor) {
|
|
129
|
+
return out
|
|
130
|
+
}
|
|
131
|
+
while (cursor.moveToNext()) {
|
|
132
|
+
const row: Record<string, any> = {}
|
|
133
|
+
for (let i = 0; i < cursor.getColumnCount(); i++) {
|
|
134
|
+
row[cursor.getColumnName(i)] = cursor.getString(i)
|
|
135
|
+
}
|
|
136
|
+
out.push(row)
|
|
137
|
+
}
|
|
138
|
+
cursor.close()
|
|
139
|
+
return out
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const CAL_URI = () => android.provider.CalendarContract.Calendars.CONTENT_URI
|
|
143
|
+
const EVENTS_URI = () => android.provider.CalendarContract.Events.CONTENT_URI
|
|
144
|
+
const INSTANCES_URI = () => android.provider.CalendarContract.Instances.CONTENT_URI
|
|
145
|
+
|
|
146
|
+
function androidCalendars(): CalendarInfo[] {
|
|
147
|
+
return androidQuery(CAL_URI(), ['_id', 'calendar_displayName', 'calendar_color', 'account_name', 'calendar_access_level', 'isPrimary'], '', [], 'calendar_displayName ASC').map((row) => ({
|
|
148
|
+
id: String(row._id),
|
|
149
|
+
title: String(row.calendar_displayName ?? ''),
|
|
150
|
+
color: row.calendar_color,
|
|
151
|
+
source: row.account_name,
|
|
152
|
+
allowsModifications: Number(row.calendar_access_level) >= 500,
|
|
153
|
+
isPrimary: row.isPrimary === '1' || row.isPrimary === 'true',
|
|
154
|
+
}))
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function androidEvent(row: any): CalendarEvent {
|
|
158
|
+
return {
|
|
159
|
+
id: String(row._id ?? row.event_id ?? ''),
|
|
160
|
+
calendarId: row.calendar_id ? String(row.calendar_id) : undefined,
|
|
161
|
+
title: String(row.title ?? ''),
|
|
162
|
+
startDate: new Date(Number(row.dtstart ?? row.begin ?? 0)),
|
|
163
|
+
endDate: new Date(Number(row.dtend ?? row.end ?? 0)),
|
|
164
|
+
allDay: row.allDay === '1' || row.allDay === 1,
|
|
165
|
+
location: row.eventLocation,
|
|
166
|
+
notes: row.description,
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export const calendar: Calendar = {
|
|
171
|
+
supported: isIOS ? typeof EKEventStore !== 'undefined' : true,
|
|
172
|
+
|
|
173
|
+
ensure(): Promise<PermissionResult> {
|
|
174
|
+
return isIOS ? iosEnsure() : androidEnsure()
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
async getCalendars(): Promise<CalendarInfo[]> {
|
|
178
|
+
return isIOS ? iosCalendars() : androidCalendars()
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
async getDefaultCalendar(): Promise<CalendarInfo | null> {
|
|
182
|
+
if (isIOS) {
|
|
183
|
+
const s = eventStore()
|
|
184
|
+
const def = s?.defaultCalendarForNewEvents
|
|
185
|
+
return def ? { id: String(def.calendarIdentifier), title: String(def.title ?? ''), allowsModifications: !!def.allowsContentModifications } : null
|
|
186
|
+
}
|
|
187
|
+
return androidCalendars().find((c) => c.isPrimary) ?? androidCalendars()[0] ?? null
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
async getEvents(startDate: Date, endDate: Date, calendarIds?: string[]): Promise<CalendarEvent[]> {
|
|
191
|
+
if (isIOS) {
|
|
192
|
+
const s = eventStore()
|
|
193
|
+
const begin = NSDate.dateWithTimeIntervalSince1970(startDate.getTime() / 1000)
|
|
194
|
+
const end = NSDate.dateWithTimeIntervalSince1970(endDate.getTime() / 1000)
|
|
195
|
+
const predicate = s.predicateForEventsWithStartDateEndDateCalendars(begin, end, null)
|
|
196
|
+
const list = s.eventsMatchingPredicate(predicate)
|
|
197
|
+
const out: CalendarEvent[] = []
|
|
198
|
+
for (let i = 0; i < (list?.count ?? 0); i++) {
|
|
199
|
+
const e = iosEvent(list.objectAtIndex(i))
|
|
200
|
+
if (!calendarIds?.length || calendarIds.includes(e.calendarId ?? '')) {
|
|
201
|
+
out.push(e)
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return out
|
|
205
|
+
}
|
|
206
|
+
const selection = calendarIds?.length
|
|
207
|
+
? `calendar_id IN (${calendarIds.map(() => '?').join(',')})`
|
|
208
|
+
: ''
|
|
209
|
+
const args = calendarIds ?? []
|
|
210
|
+
return androidQuery(
|
|
211
|
+
INSTANCES_URI(),
|
|
212
|
+
['event_id', 'calendar_id', 'title', 'begin', 'end', 'allDay', 'eventLocation', 'description'],
|
|
213
|
+
selection,
|
|
214
|
+
args,
|
|
215
|
+
'begin ASC',
|
|
216
|
+
)
|
|
217
|
+
.map((row) => androidEvent(row))
|
|
218
|
+
.filter((e) => e.startDate <= endDate && e.endDate >= startDate)
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
async getEvent(id: string): Promise<CalendarEvent | null> {
|
|
222
|
+
if (isIOS) {
|
|
223
|
+
const e = eventStore()?.eventWithIdentifier?.(id)
|
|
224
|
+
return e ? iosEvent(e) : null
|
|
225
|
+
}
|
|
226
|
+
const rows = androidQuery(
|
|
227
|
+
(android.net.Uri as any).withAppendedId(EVENTS_URI(), Number(id)),
|
|
228
|
+
['_id', 'calendar_id', 'title', 'dtstart', 'dtend', 'allDay', 'eventLocation', 'description'],
|
|
229
|
+
'', [], '',
|
|
230
|
+
)
|
|
231
|
+
return rows.length ? androidEvent(rows[0]) : null
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
async createEvent(calendarId: string | undefined, event: NewEvent): Promise<string> {
|
|
235
|
+
if (isIOS) {
|
|
236
|
+
const s = eventStore()
|
|
237
|
+
const e = EKEvent.eventWithEventStore(s)
|
|
238
|
+
e.title = event.title
|
|
239
|
+
e.startDate = NSDate.dateWithTimeIntervalSince1970(event.startDate.getTime() / 1000)
|
|
240
|
+
e.endDate = NSDate.dateWithTimeIntervalSince1970(event.endDate.getTime() / 1000)
|
|
241
|
+
e.allDay = !!event.allDay
|
|
242
|
+
e.location = event.location
|
|
243
|
+
e.notes = event.notes
|
|
244
|
+
e.calendar = calendarId
|
|
245
|
+
? s.calendarWithIdentifier?.(calendarId) ?? s.defaultCalendarForNewEvents
|
|
246
|
+
: s.defaultCalendarForNewEvents
|
|
247
|
+
if (!s.saveEventSpanError(e, 0, null)) {
|
|
248
|
+
throw new Error('calendar.createEvent: EKEventStore.saveEvent failed')
|
|
249
|
+
}
|
|
250
|
+
return String(e.eventIdentifier ?? '')
|
|
251
|
+
}
|
|
252
|
+
const values = new android.content.ContentValues()
|
|
253
|
+
const def = await calendar.getDefaultCalendar()
|
|
254
|
+
values.put('calendar_id', java.lang.Long.valueOf(calendarId ?? def?.id ?? '0'))
|
|
255
|
+
values.put('title', event.title)
|
|
256
|
+
values.put('dtstart', java.lang.Long.valueOf(event.startDate.getTime()))
|
|
257
|
+
values.put('dtend', java.lang.Long.valueOf(event.endDate.getTime()))
|
|
258
|
+
values.put('allDay', java.lang.Integer.valueOf(event.allDay ? 1 : 0))
|
|
259
|
+
if (event.location) {
|
|
260
|
+
values.put('eventLocation', event.location)
|
|
261
|
+
}
|
|
262
|
+
if (event.notes) {
|
|
263
|
+
values.put('description', event.notes)
|
|
264
|
+
}
|
|
265
|
+
values.put('eventTimezone', event.timeZone ?? 'UTC')
|
|
266
|
+
const uri = resolver()?.insert(EVENTS_URI(), values)
|
|
267
|
+
return uri ? String(uri.getLastPathSegment()) : ''
|
|
268
|
+
},
|
|
269
|
+
|
|
270
|
+
async updateEvent(id: string, patch: Partial<NewEvent>): Promise<string> {
|
|
271
|
+
if (isIOS) {
|
|
272
|
+
const s = eventStore()
|
|
273
|
+
const e = s.eventWithIdentifier?.(id)
|
|
274
|
+
if (!e) {
|
|
275
|
+
throw new Error(`calendar.updateEvent: no event ${id}`)
|
|
276
|
+
}
|
|
277
|
+
if (patch.title !== undefined) {e.title = patch.title}
|
|
278
|
+
if (patch.startDate) {e.startDate = NSDate.dateWithTimeIntervalSince1970(patch.startDate.getTime() / 1000)}
|
|
279
|
+
if (patch.endDate) {e.endDate = NSDate.dateWithTimeIntervalSince1970(patch.endDate.getTime() / 1000)}
|
|
280
|
+
if (patch.allDay !== undefined) {e.allDay = patch.allDay}
|
|
281
|
+
if (patch.location !== undefined) {e.location = patch.location}
|
|
282
|
+
if (patch.notes !== undefined) {e.notes = patch.notes}
|
|
283
|
+
s.saveEventSpanError(e, 0, null)
|
|
284
|
+
return id
|
|
285
|
+
}
|
|
286
|
+
const values = new android.content.ContentValues()
|
|
287
|
+
if (patch.title !== undefined) {values.put('title', patch.title)}
|
|
288
|
+
if (patch.startDate) {values.put('dtstart', java.lang.Long.valueOf(patch.startDate.getTime()))}
|
|
289
|
+
if (patch.endDate) {values.put('dtend', java.lang.Long.valueOf(patch.endDate.getTime()))}
|
|
290
|
+
if (patch.location !== undefined) {values.put('eventLocation', patch.location)}
|
|
291
|
+
if (patch.notes !== undefined) {values.put('description', patch.notes)}
|
|
292
|
+
resolver()?.update((android.net.Uri as any).withAppendedId(EVENTS_URI(), Number(id)), values, null, null)
|
|
293
|
+
return id
|
|
294
|
+
},
|
|
295
|
+
|
|
296
|
+
async deleteEvent(id: string): Promise<void> {
|
|
297
|
+
if (isIOS) {
|
|
298
|
+
const s = eventStore()
|
|
299
|
+
const e = s.eventWithIdentifier?.(id)
|
|
300
|
+
if (e) {
|
|
301
|
+
s.removeEventSpanError(e, 0, null)
|
|
302
|
+
}
|
|
303
|
+
return
|
|
304
|
+
}
|
|
305
|
+
resolver()?.delete((android.net.Uri as any).withAppendedId(EVENTS_URI(), Number(id)), null, null)
|
|
306
|
+
},
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
|
|
310
|
+
permissionOwners.calendar = () => calendar.ensure()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Calendar — no web calendar API exists; .ics generation is userland/library
|
|
2
|
+
// territory. Honest unsupported leaf.
|
|
3
|
+
import type { Calendar, PermissionResult } from './types'
|
|
4
|
+
|
|
5
|
+
const unsupported = () => Promise.reject(new Error('unsupported: no calendar API on web'))
|
|
6
|
+
|
|
7
|
+
export const calendar: Calendar = {
|
|
8
|
+
supported: false,
|
|
9
|
+
ensure: async (): Promise<PermissionResult> => 'unsupported',
|
|
10
|
+
getCalendars: unsupported,
|
|
11
|
+
getDefaultCalendar: unsupported,
|
|
12
|
+
getEvents: unsupported,
|
|
13
|
+
getEvent: unsupported,
|
|
14
|
+
createEvent: unsupported,
|
|
15
|
+
updateEvent: unsupported,
|
|
16
|
+
deleteEvent: unsupported,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const permissionOwners = ((globalThis as any).__xplatPermissionOwners ??= {})
|
|
20
|
+
permissionOwners.calendar = () => calendar.ensure()
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Calendar, PermissionResult } from './types'
|
|
2
|
+
|
|
3
|
+
const unsupported = () => Promise.reject(new Error('unsupported: calendar is not wired on this platform'))
|
|
4
|
+
|
|
5
|
+
export const calendar: Calendar = {
|
|
6
|
+
supported: false,
|
|
7
|
+
ensure: async (): Promise<PermissionResult> => 'unsupported',
|
|
8
|
+
getCalendars: unsupported,
|
|
9
|
+
getDefaultCalendar: unsupported,
|
|
10
|
+
getEvents: unsupported,
|
|
11
|
+
getEvent: unsupported,
|
|
12
|
+
createEvent: unsupported,
|
|
13
|
+
updateEvent: unsupported,
|
|
14
|
+
deleteEvent: unsupported,
|
|
15
|
+
}
|
package/src/index.ts
ADDED
package/src/index.web.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export type PermissionResult = 'granted' | 'denied' | 'unsupported'
|
|
2
|
+
|
|
3
|
+
export interface CalendarInfo {
|
|
4
|
+
id: string
|
|
5
|
+
title: string
|
|
6
|
+
color?: string
|
|
7
|
+
source?: string
|
|
8
|
+
allowsModifications?: boolean
|
|
9
|
+
isPrimary?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface CalendarEvent {
|
|
13
|
+
id: string
|
|
14
|
+
calendarId?: string
|
|
15
|
+
title: string
|
|
16
|
+
startDate: Date
|
|
17
|
+
endDate: Date
|
|
18
|
+
allDay?: boolean
|
|
19
|
+
location?: string
|
|
20
|
+
notes?: string
|
|
21
|
+
timeZone?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface NewEvent {
|
|
25
|
+
title: string
|
|
26
|
+
startDate: Date
|
|
27
|
+
endDate: Date
|
|
28
|
+
allDay?: boolean
|
|
29
|
+
location?: string
|
|
30
|
+
notes?: string
|
|
31
|
+
timeZone?: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface Calendar {
|
|
35
|
+
readonly supported: boolean
|
|
36
|
+
ensure(): Promise<PermissionResult>
|
|
37
|
+
getCalendars(): Promise<CalendarInfo[]>
|
|
38
|
+
getDefaultCalendar(): Promise<CalendarInfo | null>
|
|
39
|
+
getEvents(startDate: Date, endDate: Date, calendarIds?: string[]): Promise<CalendarEvent[]>
|
|
40
|
+
getEvent(id: string): Promise<CalendarEvent | null>
|
|
41
|
+
createEvent(calendarId: string | undefined, event: NewEvent): Promise<string>
|
|
42
|
+
updateEvent(id: string, patch: Partial<NewEvent>): Promise<string>
|
|
43
|
+
deleteEvent(id: string): Promise<void>
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export declare const calendar: Calendar
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { calendar } from './calendar.web.js';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export type PermissionResult = 'granted' | 'denied' | 'unsupported';
|
|
2
|
+
export interface CalendarInfo {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
color?: string;
|
|
6
|
+
source?: string;
|
|
7
|
+
allowsModifications?: boolean;
|
|
8
|
+
isPrimary?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface CalendarEvent {
|
|
11
|
+
id: string;
|
|
12
|
+
calendarId?: string;
|
|
13
|
+
title: string;
|
|
14
|
+
startDate: Date;
|
|
15
|
+
endDate: Date;
|
|
16
|
+
allDay?: boolean;
|
|
17
|
+
location?: string;
|
|
18
|
+
notes?: string;
|
|
19
|
+
timeZone?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface NewEvent {
|
|
22
|
+
title: string;
|
|
23
|
+
startDate: Date;
|
|
24
|
+
endDate: Date;
|
|
25
|
+
allDay?: boolean;
|
|
26
|
+
location?: string;
|
|
27
|
+
notes?: string;
|
|
28
|
+
timeZone?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface Calendar {
|
|
31
|
+
readonly supported: boolean;
|
|
32
|
+
ensure(): Promise<PermissionResult>;
|
|
33
|
+
getCalendars(): Promise<CalendarInfo[]>;
|
|
34
|
+
getDefaultCalendar(): Promise<CalendarInfo | null>;
|
|
35
|
+
getEvents(startDate: Date, endDate: Date, calendarIds?: string[]): Promise<CalendarEvent[]>;
|
|
36
|
+
getEvent(id: string): Promise<CalendarEvent | null>;
|
|
37
|
+
createEvent(calendarId: string | undefined, event: NewEvent): Promise<string>;
|
|
38
|
+
updateEvent(id: string, patch: Partial<NewEvent>): Promise<string>;
|
|
39
|
+
deleteEvent(id: string): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export declare const calendar: Calendar;
|