@ebarooni/capacitor-calendar 0.5.0 → 0.6.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 (30) hide show
  1. package/README.md +9 -9
  2. package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendar.kt +50 -44
  3. package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +46 -38
  4. package/dist/esm/definitions.d.ts +6 -6
  5. package/dist/esm/definitions.js.map +1 -1
  6. package/dist/esm/index.js +1 -1
  7. package/dist/esm/index.js.map +1 -1
  8. package/dist/esm/schemas/enums/calendar-chooser-display-style.js.map +1 -1
  9. package/dist/esm/schemas/enums/calendar-chooser-selection-style.js.map +1 -1
  10. package/dist/esm/schemas/enums/plugin-permission.js.map +1 -1
  11. package/dist/esm/schemas/enums/reminder-recurrence-frequency.js.map +1 -1
  12. package/dist/esm/schemas/interfaces/calendar.js.map +1 -1
  13. package/dist/esm/schemas/interfaces/plugin-permissions-map.js.map +1 -1
  14. package/dist/esm/schemas/interfaces/reminder-recurrence-rule.d.ts +1 -1
  15. package/dist/esm/schemas/interfaces/reminder-recurrence-rule.js.map +1 -1
  16. package/dist/esm/schemas/interfaces/reminders-list.js.map +1 -1
  17. package/dist/esm/web.d.ts +3 -3
  18. package/dist/esm/web.js +1 -0
  19. package/dist/esm/web.js.map +1 -1
  20. package/dist/plugin.cjs.js +2 -1
  21. package/dist/plugin.cjs.js.map +1 -1
  22. package/dist/plugin.js +2 -1
  23. package/dist/plugin.js.map +1 -1
  24. package/ios/Plugin/CapacitorCalendar.swift +50 -45
  25. package/ios/Plugin/CapacitorCalendarPlugin.swift +79 -64
  26. package/ios/Plugin/CapacitorReminders.swift +90 -57
  27. package/ios/Plugin/EventCreationParameters.swift +18 -0
  28. package/ios/Plugin/RecurrenceParameters.swift +15 -0
  29. package/ios/Plugin/ReminderCreationParameters.swift +23 -0
  30. package/package.json +30 -20
@@ -17,23 +17,23 @@ public class CapacitorReminders: NSObject {
17
17
  2: .monthly,
18
18
  3: .yearly
19
19
  ]
20
-
20
+
21
21
  init(eventStore: EKEventStore) {
22
22
  self.eventStore = eventStore
23
23
  }
24
-
24
+
25
25
  public func getDefaultRemindersList() throws -> [String: String] {
26
26
  let defaultRemindersList = eventStore.defaultCalendarForNewReminders()
27
- if (defaultRemindersList != nil) {
27
+ if let defaultRemindersList = defaultRemindersList {
28
28
  return [
29
- "id": defaultRemindersList!.calendarIdentifier,
30
- "title": defaultRemindersList!.title
29
+ "id": defaultRemindersList.calendarIdentifier,
30
+ "title": defaultRemindersList.title
31
31
  ]
32
32
  } else {
33
33
  throw CapacitorCalendarPluginError.noDefaultCalendar
34
34
  }
35
35
  }
36
-
36
+
37
37
  public func checkAllPermissions() async throws -> [String: String] {
38
38
  return try await withCheckedThrowingContinuation { continuation in
39
39
  var permissionsState: [String: String]
@@ -41,17 +41,17 @@ public class CapacitorReminders: NSObject {
41
41
  case .authorized, .fullAccess:
42
42
  permissionsState = [
43
43
  "writeReminders": PermissionState.granted.rawValue,
44
- "readReminders": PermissionState.granted.rawValue,
44
+ "readReminders": PermissionState.granted.rawValue
45
45
  ]
46
46
  case .denied, .restricted:
47
47
  permissionsState = [
48
48
  "writeReminders": PermissionState.denied.rawValue,
49
- "readReminders": PermissionState.denied.rawValue,
49
+ "readReminders": PermissionState.denied.rawValue
50
50
  ]
51
51
  case .writeOnly, .notDetermined:
52
52
  permissionsState = [
53
53
  "writeReminders": PermissionState.prompt.rawValue,
54
- "readReminders": PermissionState.prompt.rawValue,
54
+ "readReminders": PermissionState.prompt.rawValue
55
55
  ]
56
56
  @unknown default:
57
57
  continuation.resume(throwing: CapacitorCalendarPluginError.unknownPermissionStatus)
@@ -60,71 +60,56 @@ public class CapacitorReminders: NSObject {
60
60
  continuation.resume(returning: permissionsState)
61
61
  }
62
62
  }
63
-
63
+
64
64
  public func getRemindersLists() -> [[String: String]] {
65
65
  return convertEKCalendarsToDictionaries(calendars: Set(eventStore.calendars(for: .reminder)))
66
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
67
+
68
+ public func createReminder(with parameters: ReminderCreationParameters) throws {
69
+ func setCalendar() {
70
+ if let listId = parameters.listId, let list = eventStore.calendar(withIdentifier: listId) {
71
+ newReminder.calendar = list
81
72
  } else {
82
- newReminder.priority = priority
73
+ newReminder.calendar = eventStore.defaultCalendarForNewReminders()
83
74
  }
84
75
  }
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
76
+
77
+ func setPriority() {
78
+ guard let priority = parameters.priority else { return }
79
+ newReminder.priority = max(0, min(9, priority))
95
80
  }
96
- if let completionDate = completionDate {
97
- newReminder.completionDate = Date(timeIntervalSince1970: completionDate / 1000)
98
- newReminder.timeZone = Calendar.current.timeZone
81
+
82
+ let newReminder = EKReminder(eventStore: eventStore)
83
+ setCalendar()
84
+ setPriority()
85
+ setReminderDateComponents(
86
+ reminder: newReminder,
87
+ startDate: parameters.startDate,
88
+ dueDate: parameters.dueDate,
89
+ completionDate: parameters.completionDate
90
+ )
91
+ setReminderFrequency(reminder: newReminder, recurrence: parameters.recurrence)
92
+ newReminder.title = parameters.title
93
+ if let isCompleted = parameters.isCompleted {
94
+ newReminder.isCompleted = isCompleted
99
95
  }
100
- if let notes = notes {
96
+ if let notes = parameters.notes {
101
97
  newReminder.notes = notes
102
98
  }
103
- if let url = url {
99
+ if let url = parameters.url {
104
100
  newReminder.url = URL(string: url)
105
101
  }
106
- if let location = location {
102
+ if let location = parameters.location {
107
103
  newReminder.location = location
108
104
  }
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
-
105
+
121
106
  do {
122
107
  try eventStore.save(newReminder, commit: true)
123
108
  } catch {
124
109
  throw CapacitorCalendarPluginError.unknownActionEventCreationPrompt
125
110
  }
126
111
  }
127
-
112
+
128
113
  public func requestFullAccessToReminders() async throws -> String {
129
114
  return try await withCheckedThrowingContinuation { continuation in
130
115
  if #available(iOS 17.0, *) {
@@ -133,7 +118,7 @@ public class CapacitorReminders: NSObject {
133
118
  continuation.resume(throwing: CapacitorCalendarPluginError.eventStoreAuthorization)
134
119
  return
135
120
  }
136
-
121
+
137
122
  var permissionState: String
138
123
  if granted {
139
124
  permissionState = PermissionState.granted.rawValue
@@ -148,7 +133,7 @@ public class CapacitorReminders: NSObject {
148
133
  continuation.resume(throwing: CapacitorCalendarPluginError.eventStoreAuthorization)
149
134
  return
150
135
  }
151
-
136
+
152
137
  var permissionState: String
153
138
  if granted {
154
139
  permissionState = PermissionState.granted.rawValue
@@ -160,7 +145,7 @@ public class CapacitorReminders: NSObject {
160
145
  }
161
146
  }
162
147
  }
163
-
148
+
164
149
  private func convertEKCalendarsToDictionaries(calendars: Set<EKCalendar>) -> [[String: String]] {
165
150
  var result: [[String: String]] = []
166
151
 
@@ -174,4 +159,52 @@ public class CapacitorReminders: NSObject {
174
159
 
175
160
  return result
176
161
  }
162
+
163
+ private func setReminderFrequency(reminder: EKReminder, recurrence: RecurrenceParameters?) {
164
+ guard let frequency = recurrence?.frequency, let interval = recurrence?.interval else { return }
165
+ var endDate: EKRecurrenceEnd?
166
+ if let end = recurrence?.end {
167
+ endDate = EKRecurrenceEnd(end: Date(timeIntervalSince1970: end / 1000))
168
+ }
169
+ if let recurrenceFrequency = recurrenceFrequencyMapping[frequency] {
170
+ reminder.recurrenceRules = [EKRecurrenceRule(
171
+ recurrenceWith: recurrenceFrequency,
172
+ interval: interval,
173
+ end: endDate
174
+ )]
175
+ }
176
+ }
177
+
178
+ private func setReminderDateComponents(reminder: EKReminder, startDate: Double?, dueDate: Double?, completionDate: Double?) {
179
+ func setStartDate() {
180
+ if let startDate = startDate {
181
+ reminder.startDateComponents = Calendar.current.dateComponents(
182
+ [.year, .month, .day, .hour, .minute],
183
+ from: Date(timeIntervalSince1970: startDate / 1000)
184
+ )
185
+ reminder.startDateComponents?.timeZone = Calendar.current.timeZone
186
+ }
187
+ }
188
+
189
+ func setDueDate() {
190
+ if let dueDate = dueDate {
191
+ reminder.dueDateComponents = Calendar.current.dateComponents(
192
+ [.year, .month, .day, .hour, .minute],
193
+ from: Date(timeIntervalSince1970: dueDate / 1000)
194
+ )
195
+ reminder.dueDateComponents?.timeZone = Calendar.current.timeZone
196
+ }
197
+ }
198
+
199
+ func setCompletionDate() {
200
+ if let completionDate = completionDate {
201
+ reminder.completionDate = Date(timeIntervalSince1970: completionDate / 1000)
202
+ reminder.timeZone = Calendar.current.timeZone
203
+ }
204
+ }
205
+
206
+ setStartDate()
207
+ setDueDate()
208
+ setCompletionDate()
209
+ }
177
210
  }
@@ -0,0 +1,18 @@
1
+ //
2
+ // EventCreationParameters.swift
3
+ // Plugin
4
+ //
5
+ // Created by Ehsan Barooni on 22.03.24.
6
+ // Copyright © 2024 Max Lynch. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+
11
+ public struct EventCreationParameters {
12
+ public var title: String
13
+ public var calendarId: String?
14
+ public var location: String?
15
+ public var startDate: Date?
16
+ public var endDate: Date?
17
+ public var isAllDay: Bool?
18
+ }
@@ -0,0 +1,15 @@
1
+ //
2
+ // RecurrenceParameters.swift
3
+ // Plugin
4
+ //
5
+ // Created by Ehsan Barooni on 22.03.24.
6
+ // Copyright © 2024 Max Lynch. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+
11
+ struct RecurrenceParameters {
12
+ let frequency: Int
13
+ let interval: Int
14
+ let end: Double?
15
+ }
@@ -0,0 +1,23 @@
1
+ //
2
+ // ReminderCreationParameters.swift
3
+ // Plugin
4
+ //
5
+ // Created by Ehsan Barooni on 22.03.24.
6
+ // Copyright © 2024 Max Lynch. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+
11
+ public struct ReminderCreationParameters {
12
+ let title: String
13
+ let listId: String?
14
+ let priority: Int?
15
+ let isCompleted: Bool?
16
+ let startDate: Double?
17
+ let dueDate: Double?
18
+ let completionDate: Double?
19
+ let notes: String?
20
+ let url: String?
21
+ let location: String?
22
+ let recurrence: RecurrenceParameters?
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebarooni/capacitor-calendar",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
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",
@@ -34,48 +34,58 @@
34
34
  "ionic"
35
35
  ],
36
36
  "homepage": "https://capacitor-calendar.pages.dev",
37
+ "engines": {
38
+ "node": ">=18.19.0"
39
+ },
37
40
  "scripts": {
38
41
  "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
39
42
  "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
40
43
  "verify:android": "cd android && ./gradlew clean build test && cd ..",
41
44
  "verify:web": "npm run build",
42
- "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
43
- "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
44
- "eslint": "eslint . --ext ts",
45
- "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
46
45
  "swiftlint": "node-swiftlint",
46
+ "ktlint": "ktlint 'android/src/main/java/**'",
47
+ "lint:ts": "npx eslint . --ext .ts",
48
+ "lint:html": "npx eslint . --ext .html",
49
+ "lint:css": "npx stylelint \"**/*.(css|scss)\"",
50
+ "lint:swift": "npm run swiftlint -- lint",
51
+ "lint:kt": "npm run ktlint",
52
+ "lint": "npm run lint:ts && npm run lint:html && npm run lint:css && npm run lint:swift && npm run lint:kt",
53
+ "fmt:ts": "npx eslint . --ext .ts --fix",
54
+ "fmt:html": "npx eslint . --ext .html --fix",
55
+ "fmt:css": "npx stylelint \"**/*.(css|scss)\" --fix",
56
+ "fmt:swift": "npm run swiftlint -- --fix --format",
57
+ "fmt:md": "npx prettier --write \"**/*.md\"",
58
+ "fmt:kt": "npm run ktlint -- -F",
59
+ "fmt": "npm run fmt:ts && npm run fmt:html && npm run fmt:css && npm run fmt:swift && npm run fmt:md && npm run fmt:kt",
47
60
  "docgen": "docgen --api CapacitorCalendarPlugin --output-readme README.md --output-json dist/docs.json",
61
+ "clean": "rm -rf ./dist",
48
62
  "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
49
- "clean": "rimraf ./dist",
50
- "watch": "tsc --watch",
51
63
  "prepublishOnly": "npm run build"
52
64
  },
53
65
  "devDependencies": {
66
+ "@angular-eslint/eslint-plugin": "^17.3.0",
67
+ "@angular-eslint/eslint-plugin-template": "^17.3.0",
68
+ "@angular-eslint/template-parser": "^17.3.0",
54
69
  "@angular/cli": "^17.1.2",
55
70
  "@capacitor/android": "^5.0.0",
56
71
  "@capacitor/cli": "^5.6.0",
57
72
  "@capacitor/core": "^5.0.0",
58
73
  "@capacitor/docgen": "^0.0.18",
59
74
  "@capacitor/ios": "^5.0.0",
60
- "@ionic/eslint-config": "^0.3.0",
61
- "@ionic/prettier-config": "^1.0.1",
62
- "@ionic/swiftlint-config": "^1.1.2",
63
- "eslint": "^7.11.0",
64
- "prettier": "~2.3.0",
65
- "prettier-plugin-java": "~1.0.2",
66
- "rimraf": "^3.0.2",
75
+ "@typescript-eslint/eslint-plugin": "^7.3.0",
76
+ "@typescript-eslint/parser": "^7.3.0",
77
+ "eslint": "^8.57.0",
78
+ "eslint-config-prettier": "^9.1.0",
79
+ "eslint-plugin-prettier": "^5.1.3",
80
+ "prettier": "~3.2.5",
67
81
  "rollup": "^4.13.0",
82
+ "stylelint-prettier": "^5.0.0",
68
83
  "swiftlint": "^1.0.1",
69
- "typescript": "~5.3.3"
84
+ "typescript": "~5.4.2"
70
85
  },
71
86
  "peerDependencies": {
72
87
  "@capacitor/core": "^5.0.0"
73
88
  },
74
- "prettier": "@ionic/prettier-config",
75
- "swiftlint": "@ionic/swiftlint-config",
76
- "eslintConfig": {
77
- "extends": "@ionic/eslint-config/recommended"
78
- },
79
89
  "capacitor": {
80
90
  "ios": {
81
91
  "src": "ios"