@ebarooni/capacitor-calendar 8.0.2 → 8.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/README.md +272 -14
- package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +15 -0
- package/dist/docs.json +397 -0
- package/dist/esm/index.d.ts +6 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/schemas/interfaces/create-reminders-list-options.d.ts +41 -0
- package/dist/esm/schemas/interfaces/create-reminders-list-options.js +2 -0
- package/dist/esm/schemas/interfaces/create-reminders-list-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/create-reminders-list-result.d.ts +12 -0
- package/dist/esm/schemas/interfaces/create-reminders-list-result.js +2 -0
- package/dist/esm/schemas/interfaces/create-reminders-list-result.js.map +1 -0
- package/dist/esm/schemas/interfaces/delete-reminders-list-options.d.ts +23 -0
- package/dist/esm/schemas/interfaces/delete-reminders-list-options.js +2 -0
- package/dist/esm/schemas/interfaces/delete-reminders-list-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/update-reminders-list-options.d.ts +40 -0
- package/dist/esm/schemas/interfaces/update-reminders-list-options.js +2 -0
- package/dist/esm/schemas/interfaces/update-reminders-list-options.js.map +1 -0
- package/dist/esm/schemas/interfaces/update-reminders-list-result.d.ts +12 -0
- package/dist/esm/schemas/interfaces/update-reminders-list-result.js +2 -0
- package/dist/esm/schemas/interfaces/update-reminders-list-result.js.map +1 -0
- package/dist/esm/sub-definitions/reminders-operations.d.ts +26 -0
- package/dist/esm/sub-definitions/reminders-operations.js.map +1 -1
- package/dist/esm/web.d.ts +8 -0
- package/dist/esm/web.js +9 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +9 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +9 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorCalendarPlugin.swift +45 -0
- package/ios/Plugin/Implementation/CapacitorCalendar.swift +63 -0
- package/ios/Plugin/Models/Inputs/CreateRemindersListInput.swift +57 -0
- package/ios/Plugin/Models/Inputs/DeleteRemindersListInput.swift +22 -0
- package/ios/Plugin/Models/Inputs/UpdateRemindersListInput.swift +55 -0
- package/ios/Plugin/Models/Results/CreateRemindersListResult.swift +15 -0
- package/ios/Plugin/Models/Results/UpdateRemindersListResult.swift +15 -0
- package/ios/Plugin/PluginConfig.swift +30 -27
- package/ios/Plugin/PluginError.swift +3 -0
- package/package.json +3 -2
|
@@ -51,6 +51,44 @@ class CapacitorCalendar: NSObject {
|
|
|
51
51
|
return CheckAllPermissionsResult(statesDict: permissionsResult)
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
func createRemindersList(_ input: CreateRemindersListInput, completion: @escaping (CreateRemindersListResult?, Error?) -> Void) {
|
|
55
|
+
let calendar = EKCalendar(for: .reminder, eventStore: eventStore)
|
|
56
|
+
calendar.title = input.getTitle()
|
|
57
|
+
if let color = input.getColor() {
|
|
58
|
+
calendar.cgColor = color
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let sources = eventStore.sources
|
|
62
|
+
if let sourceId = input.getSourceId(), let customSource = sources.first(where: { $0.sourceIdentifier == sourceId }) {
|
|
63
|
+
calendar.source = customSource
|
|
64
|
+
} else if let iCloudSource = sources.first(where: { $0.sourceType == .calDAV && $0.title == "iCloud" }) {
|
|
65
|
+
calendar.source = iCloudSource
|
|
66
|
+
} else if let localSource = sources.first(where: { $0.sourceType == .local }) {
|
|
67
|
+
calendar.source = localSource
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
do {
|
|
71
|
+
try eventStore.saveCalendar(calendar, commit: input.getCommit())
|
|
72
|
+
completion(CreateRemindersListResult(id: calendar.calendarIdentifier), nil)
|
|
73
|
+
} catch {
|
|
74
|
+
completion(nil, error)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
func deleteRemindersList(_ input: DeleteRemindersListInput, completion: @escaping (Error?) -> Void) throws {
|
|
79
|
+
guard let list = eventStore.calendar(withIdentifier: input.getId()) else {
|
|
80
|
+
completion(PluginError.listNotFound)
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
do {
|
|
85
|
+
try eventStore.removeCalendar(list, commit: input.getCommit())
|
|
86
|
+
completion(nil)
|
|
87
|
+
} catch {
|
|
88
|
+
completion(error)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
54
92
|
func requestionPermission(input: RequestPermissionInput) async throws -> RequestPermissionResult {
|
|
55
93
|
let scope = input.getScope()
|
|
56
94
|
var state: CAPPermissionState
|
|
@@ -533,6 +571,31 @@ class CapacitorCalendar: NSObject {
|
|
|
533
571
|
viewController.present(alert, animated: true)
|
|
534
572
|
}
|
|
535
573
|
}
|
|
574
|
+
|
|
575
|
+
func updateRemindersList(_ input: UpdateRemindersListInput, completion: @escaping (UpdateRemindersListResult?, Error?) -> Void) throws {
|
|
576
|
+
guard let calendar = eventStore.calendar(withIdentifier: input.getId()) else {
|
|
577
|
+
completion(nil, PluginError.listNotFound)
|
|
578
|
+
return
|
|
579
|
+
}
|
|
580
|
+
guard calendar.allowsContentModifications else {
|
|
581
|
+
completion(nil, PluginError.listNotModifiable)
|
|
582
|
+
return
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
if let title = input.getTitle() {
|
|
586
|
+
calendar.title = title
|
|
587
|
+
}
|
|
588
|
+
if let color = input.getColor() {
|
|
589
|
+
calendar.cgColor = color
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
do {
|
|
593
|
+
try eventStore.saveCalendar(calendar, commit: input.getCommit())
|
|
594
|
+
completion(UpdateRemindersListResult(id: calendar.calendarIdentifier), nil)
|
|
595
|
+
} catch {
|
|
596
|
+
completion(nil, error)
|
|
597
|
+
}
|
|
598
|
+
}
|
|
536
599
|
}
|
|
537
600
|
|
|
538
601
|
extension CapacitorCalendar: EKCalendarChooserDelegate {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import Capacitor
|
|
2
|
+
|
|
3
|
+
struct CreateRemindersListInput {
|
|
4
|
+
private var color: CGColor?
|
|
5
|
+
private let commit: Bool
|
|
6
|
+
private var sourceId: String?
|
|
7
|
+
private let title: String
|
|
8
|
+
|
|
9
|
+
init(call: CAPPluginCall) throws {
|
|
10
|
+
guard let title = call.getString("title") else {
|
|
11
|
+
throw PluginError.titleMissing
|
|
12
|
+
}
|
|
13
|
+
self.title = title
|
|
14
|
+
self.color = CreateRemindersListInput.getListColorFromCall(call)
|
|
15
|
+
self.commit = call.getBool("commit", true)
|
|
16
|
+
if let sourceId = call.getString("sourceId") {
|
|
17
|
+
self.sourceId = sourceId
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func getColor() -> CGColor? {
|
|
22
|
+
return color
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
func getCommit() -> Bool {
|
|
26
|
+
return commit
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
func getSourceId() -> String? {
|
|
30
|
+
return sourceId
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
func getTitle() -> String {
|
|
34
|
+
return title
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private static func getListColorFromCall(_ call: CAPPluginCall) -> CGColor? {
|
|
38
|
+
guard let colorName = call.getString("color") else {
|
|
39
|
+
return nil
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
switch colorName.lowercased() {
|
|
43
|
+
case "blue": return UIColor.systemBlue.cgColor
|
|
44
|
+
case "brown": return UIColor.systemBrown.cgColor
|
|
45
|
+
case "gray": return UIColor.systemGray.cgColor
|
|
46
|
+
case "green": return UIColor.systemGreen.cgColor
|
|
47
|
+
case "indigo": return UIColor.systemIndigo.cgColor
|
|
48
|
+
case "orange": return UIColor.systemOrange.cgColor
|
|
49
|
+
case "pink": return UIColor.systemPink.cgColor
|
|
50
|
+
case "purple": return UIColor.systemPurple.cgColor
|
|
51
|
+
case "red": return UIColor.systemRed.cgColor
|
|
52
|
+
case "teal": return UIColor.systemTeal.cgColor
|
|
53
|
+
case "yellow": return UIColor.systemYellow.cgColor
|
|
54
|
+
default: return nil
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Capacitor
|
|
2
|
+
|
|
3
|
+
struct DeleteRemindersListInput {
|
|
4
|
+
private let commit: Bool
|
|
5
|
+
private let id: String
|
|
6
|
+
|
|
7
|
+
init(call: CAPPluginCall) throws {
|
|
8
|
+
self.commit = call.getBool("commit", true)
|
|
9
|
+
guard let id = call.getString("id") else {
|
|
10
|
+
throw PluginError.idMissing
|
|
11
|
+
}
|
|
12
|
+
self.id = id
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
func getCommit() -> Bool {
|
|
16
|
+
return commit
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
func getId() -> String {
|
|
20
|
+
return id
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import Capacitor
|
|
2
|
+
|
|
3
|
+
struct UpdateRemindersListInput {
|
|
4
|
+
private let color: CGColor?
|
|
5
|
+
private let commit: Bool
|
|
6
|
+
private let id: String
|
|
7
|
+
private let title: String?
|
|
8
|
+
|
|
9
|
+
init(call: CAPPluginCall) throws {
|
|
10
|
+
guard let id = call.getString("id") else {
|
|
11
|
+
throw PluginError.idMissing
|
|
12
|
+
}
|
|
13
|
+
self.id = id
|
|
14
|
+
self.title = call.getString("title")
|
|
15
|
+
self.color = UpdateRemindersListInput.getListColorFromCall(call)
|
|
16
|
+
self.commit = call.getBool("commit", true)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
func getColor() -> CGColor? {
|
|
20
|
+
return color
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func getCommit() -> Bool {
|
|
24
|
+
return commit
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
func getId() -> String {
|
|
28
|
+
return id
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
func getTitle() -> String? {
|
|
32
|
+
return title
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private static func getListColorFromCall(_ call: CAPPluginCall) -> CGColor? {
|
|
36
|
+
guard let colorName = call.getString("color") else {
|
|
37
|
+
return nil
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
switch colorName.lowercased() {
|
|
41
|
+
case "blue": return UIColor.systemBlue.cgColor
|
|
42
|
+
case "brown": return UIColor.systemBrown.cgColor
|
|
43
|
+
case "gray": return UIColor.systemGray.cgColor
|
|
44
|
+
case "green": return UIColor.systemGreen.cgColor
|
|
45
|
+
case "indigo": return UIColor.systemIndigo.cgColor
|
|
46
|
+
case "orange": return UIColor.systemOrange.cgColor
|
|
47
|
+
case "pink": return UIColor.systemPink.cgColor
|
|
48
|
+
case "purple": return UIColor.systemPurple.cgColor
|
|
49
|
+
case "red": return UIColor.systemRed.cgColor
|
|
50
|
+
case "teal": return UIColor.systemTeal.cgColor
|
|
51
|
+
case "yellow": return UIColor.systemYellow.cgColor
|
|
52
|
+
default: return nil
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -4,41 +4,44 @@ struct PluginConfig {
|
|
|
4
4
|
static let identifier = "CapacitorCalendarPlugin"
|
|
5
5
|
static let jsName = "CapacitorCalendar"
|
|
6
6
|
static let methods: [CAPPluginMethod] = [
|
|
7
|
-
CAPPluginMethod(name: "createEventWithPrompt", returnType: CAPPluginReturnPromise),
|
|
8
|
-
CAPPluginMethod(name: "checkPermission", returnType: CAPPluginReturnPromise),
|
|
9
7
|
CAPPluginMethod(name: "checkAllPermissions", returnType: CAPPluginReturnPromise),
|
|
10
|
-
CAPPluginMethod(name: "
|
|
11
|
-
CAPPluginMethod(name: "
|
|
12
|
-
CAPPluginMethod(name: "
|
|
13
|
-
CAPPluginMethod(name: "listCalendars", returnType: CAPPluginReturnPromise),
|
|
14
|
-
CAPPluginMethod(name: "getDefaultCalendar", returnType: CAPPluginReturnPromise),
|
|
8
|
+
CAPPluginMethod(name: "checkPermission", returnType: CAPPluginReturnPromise),
|
|
9
|
+
CAPPluginMethod(name: "commit", returnType: CAPPluginReturnPromise),
|
|
10
|
+
CAPPluginMethod(name: "createCalendar", returnType: CAPPluginReturnPromise),
|
|
15
11
|
CAPPluginMethod(name: "createEvent", returnType: CAPPluginReturnPromise),
|
|
16
|
-
CAPPluginMethod(name: "
|
|
17
|
-
CAPPluginMethod(name: "getRemindersLists", returnType: CAPPluginReturnPromise),
|
|
12
|
+
CAPPluginMethod(name: "createEventWithPrompt", returnType: CAPPluginReturnPromise),
|
|
18
13
|
CAPPluginMethod(name: "createReminder", returnType: CAPPluginReturnPromise),
|
|
19
|
-
CAPPluginMethod(name: "
|
|
20
|
-
CAPPluginMethod(name: "openReminders", returnType: CAPPluginReturnPromise),
|
|
21
|
-
CAPPluginMethod(name: "listEventsInRange", returnType: CAPPluginReturnPromise),
|
|
22
|
-
CAPPluginMethod(name: "deleteEventsById", returnType: CAPPluginReturnPromise),
|
|
23
|
-
CAPPluginMethod(name: "createCalendar", returnType: CAPPluginReturnPromise),
|
|
14
|
+
CAPPluginMethod(name: "createRemindersList", returnType: CAPPluginReturnPromise),
|
|
24
15
|
CAPPluginMethod(name: "deleteCalendar", returnType: CAPPluginReturnPromise),
|
|
25
|
-
CAPPluginMethod(name: "
|
|
16
|
+
CAPPluginMethod(name: "deleteEvent", returnType: CAPPluginReturnPromise),
|
|
17
|
+
CAPPluginMethod(name: "deleteEventWithPrompt", returnType: CAPPluginReturnPromise),
|
|
18
|
+
CAPPluginMethod(name: "deleteEventsById", returnType: CAPPluginReturnPromise),
|
|
19
|
+
CAPPluginMethod(name: "deleteReminder", returnType: CAPPluginReturnPromise),
|
|
20
|
+
CAPPluginMethod(name: "deleteRemindersList", returnType: CAPPluginReturnPromise),
|
|
21
|
+
CAPPluginMethod(name: "deleteReminderWithPrompt", returnType: CAPPluginReturnPromise),
|
|
26
22
|
CAPPluginMethod(name: "deleteRemindersById", returnType: CAPPluginReturnPromise),
|
|
27
|
-
CAPPluginMethod(name: "requestWriteOnlyCalendarAccess", returnType: CAPPluginReturnPromise),
|
|
28
|
-
CAPPluginMethod(name: "requestFullCalendarAccess", returnType: CAPPluginReturnPromise),
|
|
29
|
-
CAPPluginMethod(name: "requestFullRemindersAccess", returnType: CAPPluginReturnPromise),
|
|
30
|
-
CAPPluginMethod(name: "requestReadOnlyCalendarAccess", returnType: CAPPluginReturnPromise),
|
|
31
|
-
CAPPluginMethod(name: "modifyEventWithPrompt", returnType: CAPPluginReturnPromise),
|
|
32
|
-
CAPPluginMethod(name: "modifyEvent", returnType: CAPPluginReturnPromise),
|
|
33
23
|
CAPPluginMethod(name: "fetchAllCalendarSources", returnType: CAPPluginReturnPromise),
|
|
34
24
|
CAPPluginMethod(name: "fetchAllRemindersSources", returnType: CAPPluginReturnPromise),
|
|
35
|
-
CAPPluginMethod(name: "
|
|
36
|
-
CAPPluginMethod(name: "
|
|
37
|
-
CAPPluginMethod(name: "deleteReminder", returnType: CAPPluginReturnPromise),
|
|
25
|
+
CAPPluginMethod(name: "getDefaultCalendar", returnType: CAPPluginReturnPromise),
|
|
26
|
+
CAPPluginMethod(name: "getDefaultRemindersList", returnType: CAPPluginReturnPromise),
|
|
38
27
|
CAPPluginMethod(name: "getReminderById", returnType: CAPPluginReturnPromise),
|
|
39
|
-
CAPPluginMethod(name: "
|
|
40
|
-
CAPPluginMethod(name: "
|
|
28
|
+
CAPPluginMethod(name: "getRemindersFromLists", returnType: CAPPluginReturnPromise),
|
|
29
|
+
CAPPluginMethod(name: "getRemindersLists", returnType: CAPPluginReturnPromise),
|
|
30
|
+
CAPPluginMethod(name: "listCalendars", returnType: CAPPluginReturnPromise),
|
|
31
|
+
CAPPluginMethod(name: "listEventsInRange", returnType: CAPPluginReturnPromise),
|
|
41
32
|
CAPPluginMethod(name: "modifyCalendar", returnType: CAPPluginReturnPromise),
|
|
42
|
-
CAPPluginMethod(name: "
|
|
33
|
+
CAPPluginMethod(name: "modifyEvent", returnType: CAPPluginReturnPromise),
|
|
34
|
+
CAPPluginMethod(name: "modifyEventWithPrompt", returnType: CAPPluginReturnPromise),
|
|
35
|
+
CAPPluginMethod(name: "modifyReminder", returnType: CAPPluginReturnPromise),
|
|
36
|
+
CAPPluginMethod(name: "openCalendar", returnType: CAPPluginReturnPromise),
|
|
37
|
+
CAPPluginMethod(name: "openReminders", returnType: CAPPluginReturnPromise),
|
|
38
|
+
CAPPluginMethod(name: "requestAllPermissions", returnType: CAPPluginReturnPromise),
|
|
39
|
+
CAPPluginMethod(name: "requestFullCalendarAccess", returnType: CAPPluginReturnPromise),
|
|
40
|
+
CAPPluginMethod(name: "requestFullRemindersAccess", returnType: CAPPluginReturnPromise),
|
|
41
|
+
CAPPluginMethod(name: "requestPermission", returnType: CAPPluginReturnPromise),
|
|
42
|
+
CAPPluginMethod(name: "requestReadOnlyCalendarAccess", returnType: CAPPluginReturnPromise),
|
|
43
|
+
CAPPluginMethod(name: "requestWriteOnlyCalendarAccess", returnType: CAPPluginReturnPromise),
|
|
44
|
+
CAPPluginMethod(name: "selectCalendarsWithPrompt", returnType: CAPPluginReturnPromise),
|
|
45
|
+
CAPPluginMethod(name: "updateRemindersList", returnType: CAPPluginReturnPromise)
|
|
43
46
|
]
|
|
44
47
|
}
|
|
@@ -21,6 +21,7 @@ enum PluginError: LocalizedError {
|
|
|
21
21
|
case invalidColor
|
|
22
22
|
case calendarNotFound
|
|
23
23
|
case listNotFound
|
|
24
|
+
case listNotModifiable
|
|
24
25
|
case missingFrequency
|
|
25
26
|
case missingInterval
|
|
26
27
|
case fromDateMissing
|
|
@@ -58,6 +59,8 @@ enum PluginError: LocalizedError {
|
|
|
58
59
|
return NSLocalizedString("Calendar not found.", comment: "Calendar not found error")
|
|
59
60
|
case .listNotFound:
|
|
60
61
|
return NSLocalizedString("List not found.", comment: "List not found error")
|
|
62
|
+
case .listNotModifiable:
|
|
63
|
+
return NSLocalizedString("List is not modifiable.", comment: "List not modifiable error")
|
|
61
64
|
case .invalidUrl:
|
|
62
65
|
return NSLocalizedString("Invalid URL.", comment: "Invalid URL error")
|
|
63
66
|
case .unableToOpenUrl:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ebarooni/capacitor-calendar",
|
|
3
|
-
"version": "8.0
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"description": "A capacitor plugin for managing calendar events on iOS and Android, with reminders support on iOS.",
|
|
5
5
|
"author": "Ehsan Barooni",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"LICENSE"
|
|
39
39
|
],
|
|
40
40
|
"scripts": {
|
|
41
|
-
"bootstrap:app": "npm run build && npm run install:app && npm run build:app && npm run sync:app",
|
|
41
|
+
"bootstrap:app": "npm run install:lib && npm run build && npm run install:app && npm run build:app && npm run sync:app",
|
|
42
42
|
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
43
43
|
"build:app": "cd example-app && npm run build",
|
|
44
44
|
"clean": "rimraf ./dist",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"fmt": "npm run eslint -- --fix && npm run prettier:fix && npm run swiftlint -- --fix --format && npm run fmt:android",
|
|
48
48
|
"fmt:android": "npm run ktlint -- -F",
|
|
49
49
|
"install:app": "cd example-app && npm i",
|
|
50
|
+
"install:lib": "npm i",
|
|
50
51
|
"ktlint": "ktlint",
|
|
51
52
|
"lint": "npm run eslint && npm run prettier:check && npm run swiftlint -- lint && npm run lint:android",
|
|
52
53
|
"lint:android": "npm run ktlint",
|