@ebarooni/capacitor-calendar 0.4.0 → 0.5.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.
Files changed (45) hide show
  1. package/README.md +95 -24
  2. package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +18 -0
  3. package/dist/docs.json +290 -42
  4. package/dist/esm/definitions.d.ts +108 -55
  5. package/dist/esm/definitions.js +1 -31
  6. package/dist/esm/definitions.js.map +1 -1
  7. package/dist/esm/index.d.ts +10 -1
  8. package/dist/esm/index.js +5 -1
  9. package/dist/esm/index.js.map +1 -1
  10. package/dist/esm/schemas/enums/calendar-chooser-display-style.d.ts +15 -0
  11. package/dist/esm/schemas/enums/calendar-chooser-display-style.js +17 -0
  12. package/dist/esm/schemas/enums/calendar-chooser-display-style.js.map +1 -0
  13. package/dist/esm/schemas/enums/calendar-chooser-selection-style.d.ts +15 -0
  14. package/dist/esm/schemas/enums/calendar-chooser-selection-style.js +17 -0
  15. package/dist/esm/schemas/enums/calendar-chooser-selection-style.js.map +1 -0
  16. package/dist/esm/schemas/enums/plugin-permission.d.ts +22 -0
  17. package/dist/esm/schemas/enums/plugin-permission.js +24 -0
  18. package/dist/esm/schemas/enums/plugin-permission.js.map +1 -0
  19. package/dist/esm/schemas/enums/reminder-recurrence-frequency.d.ts +6 -0
  20. package/dist/esm/schemas/enums/reminder-recurrence-frequency.js +8 -0
  21. package/dist/esm/schemas/enums/reminder-recurrence-frequency.js.map +1 -0
  22. package/dist/esm/schemas/interfaces/calendar.d.ts +12 -0
  23. package/dist/esm/schemas/interfaces/calendar.js +2 -0
  24. package/dist/esm/schemas/interfaces/calendar.js.map +1 -0
  25. package/dist/esm/schemas/interfaces/plugin-permissions-map.d.ts +4 -0
  26. package/dist/esm/schemas/interfaces/plugin-permissions-map.js +2 -0
  27. package/dist/esm/schemas/interfaces/plugin-permissions-map.js.map +1 -0
  28. package/dist/esm/schemas/interfaces/reminder-recurrence-rule.d.ts +36 -0
  29. package/dist/esm/schemas/interfaces/reminder-recurrence-rule.js +2 -0
  30. package/dist/esm/schemas/interfaces/reminder-recurrence-rule.js.map +1 -0
  31. package/dist/esm/schemas/interfaces/reminders-list.d.ts +3 -0
  32. package/dist/esm/schemas/interfaces/reminders-list.js +2 -0
  33. package/dist/esm/schemas/interfaces/reminders-list.js.map +1 -0
  34. package/dist/esm/web.d.ts +31 -5
  35. package/dist/esm/web.js +9 -0
  36. package/dist/esm/web.js.map +1 -1
  37. package/dist/plugin.cjs.js +55 -14
  38. package/dist/plugin.cjs.js.map +1 -1
  39. package/dist/plugin.js +55 -14
  40. package/dist/plugin.js.map +1 -1
  41. package/ios/Plugin/CapacitorCalendarPlugin.m +3 -0
  42. package/ios/Plugin/CapacitorCalendarPlugin.swift +104 -23
  43. package/ios/Plugin/CapacitorReminders.swift +177 -0
  44. package/package.json +4 -4
  45. package/ios/Plugin/Calendar.swift +0 -14
@@ -0,0 +1,177 @@
1
+ //
2
+ // CapacitorReminders.swift
3
+ // Plugin
4
+ //
5
+ // Created by Ehsan Barooni on 15.03.24.
6
+ // Copyright © 2024 Max Lynch. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+ import EventKit
11
+
12
+ public class CapacitorReminders: NSObject {
13
+ private let eventStore: EKEventStore
14
+ private let recurrenceFrequencyMapping: [Int: EKRecurrenceFrequency] = [
15
+ 0: .daily,
16
+ 1: .weekly,
17
+ 2: .monthly,
18
+ 3: .yearly
19
+ ]
20
+
21
+ init(eventStore: EKEventStore) {
22
+ self.eventStore = eventStore
23
+ }
24
+
25
+ public func getDefaultRemindersList() throws -> [String: String] {
26
+ let defaultRemindersList = eventStore.defaultCalendarForNewReminders()
27
+ if (defaultRemindersList != nil) {
28
+ return [
29
+ "id": defaultRemindersList!.calendarIdentifier,
30
+ "title": defaultRemindersList!.title
31
+ ]
32
+ } else {
33
+ throw CapacitorCalendarPluginError.noDefaultCalendar
34
+ }
35
+ }
36
+
37
+ public func checkAllPermissions() async throws -> [String: String] {
38
+ return try await withCheckedThrowingContinuation { continuation in
39
+ var permissionsState: [String: String]
40
+ switch EKEventStore.authorizationStatus(for: .reminder) {
41
+ case .authorized, .fullAccess:
42
+ permissionsState = [
43
+ "writeReminders": PermissionState.granted.rawValue,
44
+ "readReminders": PermissionState.granted.rawValue,
45
+ ]
46
+ case .denied, .restricted:
47
+ permissionsState = [
48
+ "writeReminders": PermissionState.denied.rawValue,
49
+ "readReminders": PermissionState.denied.rawValue,
50
+ ]
51
+ case .writeOnly, .notDetermined:
52
+ permissionsState = [
53
+ "writeReminders": PermissionState.prompt.rawValue,
54
+ "readReminders": PermissionState.prompt.rawValue,
55
+ ]
56
+ @unknown default:
57
+ continuation.resume(throwing: CapacitorCalendarPluginError.unknownPermissionStatus)
58
+ return
59
+ }
60
+ continuation.resume(returning: permissionsState)
61
+ }
62
+ }
63
+
64
+ public func getRemindersLists() -> [[String: String]] {
65
+ return convertEKCalendarsToDictionaries(calendars: Set(eventStore.calendars(for: .reminder)))
66
+ }
67
+
68
+ public func createReminder(title: String, listId: String?, priority: Int?, isCompleted: Bool?, startDate: Double?, dueDate: Double?, completionDate: Double?, notes: String?, url: String?, location: String?, frequency: Int?, interval: Int?, end: Double?) throws -> Void {
69
+ let newReminder = EKReminder(eventStore: eventStore)
70
+ newReminder.title = title
71
+ if let listId = listId, let list = eventStore.calendar(withIdentifier: listId) {
72
+ newReminder.calendar = list
73
+ } else {
74
+ newReminder.calendar = eventStore.defaultCalendarForNewReminders()
75
+ }
76
+ if let priority = priority {
77
+ if priority > 9 {
78
+ newReminder.priority = 9
79
+ } else if priority < 0 {
80
+ newReminder.priority = 0
81
+ } else {
82
+ newReminder.priority = priority
83
+ }
84
+ }
85
+ if let isCompleted = isCompleted {
86
+ newReminder.isCompleted = isCompleted
87
+ }
88
+ if let startDate = startDate {
89
+ newReminder.startDateComponents = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute], from: Date(timeIntervalSince1970: startDate / 1000))
90
+ newReminder.startDateComponents?.timeZone = Calendar.current.timeZone
91
+ }
92
+ if let dueDate = dueDate {
93
+ newReminder.dueDateComponents = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute], from: Date(timeIntervalSince1970: dueDate / 1000))
94
+ newReminder.dueDateComponents?.timeZone = Calendar.current.timeZone
95
+ }
96
+ if let completionDate = completionDate {
97
+ newReminder.completionDate = Date(timeIntervalSince1970: completionDate / 1000)
98
+ newReminder.timeZone = Calendar.current.timeZone
99
+ }
100
+ if let notes = notes {
101
+ newReminder.notes = notes
102
+ }
103
+ if let url = url {
104
+ newReminder.url = URL(string: url)
105
+ }
106
+ if let location = location {
107
+ newReminder.location = location
108
+ }
109
+ if let frequency = frequency, let interval = interval {
110
+ var endDate: EKRecurrenceEnd? = nil
111
+ if let end = end {
112
+ endDate = EKRecurrenceEnd(end: Date(timeIntervalSince1970: end / 1000))
113
+ }
114
+ newReminder.recurrenceRules = [EKRecurrenceRule(
115
+ recurrenceWith: recurrenceFrequencyMapping[frequency]!,
116
+ interval: interval,
117
+ end: endDate
118
+ )]
119
+ }
120
+
121
+ do {
122
+ try eventStore.save(newReminder, commit: true)
123
+ } catch {
124
+ throw CapacitorCalendarPluginError.unknownActionEventCreationPrompt
125
+ }
126
+ }
127
+
128
+ public func requestFullAccessToReminders() async throws -> String {
129
+ return try await withCheckedThrowingContinuation { continuation in
130
+ if #available(iOS 17.0, *) {
131
+ eventStore.requestFullAccessToReminders { granted, error in
132
+ if let error = error {
133
+ continuation.resume(throwing: CapacitorCalendarPluginError.eventStoreAuthorization)
134
+ return
135
+ }
136
+
137
+ var permissionState: String
138
+ if granted {
139
+ permissionState = PermissionState.granted.rawValue
140
+ } else {
141
+ permissionState = PermissionState.denied.rawValue
142
+ }
143
+ continuation.resume(returning: permissionState)
144
+ }
145
+ } else {
146
+ eventStore.requestAccess(to: .reminder) { granted, error in
147
+ if let error = error {
148
+ continuation.resume(throwing: CapacitorCalendarPluginError.eventStoreAuthorization)
149
+ return
150
+ }
151
+
152
+ var permissionState: String
153
+ if granted {
154
+ permissionState = PermissionState.granted.rawValue
155
+ } else {
156
+ permissionState = PermissionState.denied.rawValue
157
+ }
158
+ continuation.resume(returning: permissionState)
159
+ }
160
+ }
161
+ }
162
+ }
163
+
164
+ private func convertEKCalendarsToDictionaries(calendars: Set<EKCalendar>) -> [[String: String]] {
165
+ var result: [[String: String]] = []
166
+
167
+ for calendar in calendars {
168
+ let calendarDict: [String: String] = [
169
+ "id": calendar.calendarIdentifier,
170
+ "title": calendar.title
171
+ ]
172
+ result.append(calendarDict)
173
+ }
174
+
175
+ return result
176
+ }
177
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ebarooni/capacitor-calendar",
3
- "version": "0.4.0",
4
- "description": "The Capacitor Calendar Plugin exposes functionalities for interacting with the calendar of iOS and Android devices.",
3
+ "version": "0.5.0",
4
+ "description": "The Capacitor Calendar Plugin enables full calendar functionality on iOS and Android, with added reminder support for iOS devices.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/esm/index.d.ts",
@@ -45,7 +45,7 @@
45
45
  "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
46
46
  "swiftlint": "node-swiftlint",
47
47
  "docgen": "docgen --api CapacitorCalendarPlugin --output-readme README.md --output-json dist/docs.json",
48
- "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
48
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
49
49
  "clean": "rimraf ./dist",
50
50
  "watch": "tsc --watch",
51
51
  "prepublishOnly": "npm run build"
@@ -64,7 +64,7 @@
64
64
  "prettier": "~2.3.0",
65
65
  "prettier-plugin-java": "~1.0.2",
66
66
  "rimraf": "^3.0.2",
67
- "rollup": "^2.32.0",
67
+ "rollup": "^4.13.0",
68
68
  "swiftlint": "^1.0.1",
69
69
  "typescript": "~5.3.3"
70
70
  },
@@ -1,14 +0,0 @@
1
- //
2
- // Calendar.swift
3
- // Plugin
4
- //
5
- // Created by Ehsan Barooni on 01.03.24.
6
- // Copyright © 2024 Max Lynch. All rights reserved.
7
- //
8
-
9
- import Foundation
10
-
11
- public struct Calendar {
12
- let id: String
13
- let title: String
14
- }