@ebarooni/capacitor-calendar 8.7.1 → 8.9.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 (86) hide show
  1. package/README.md +202 -137
  2. package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +72 -25
  3. package/android/src/main/java/dev/barooni/capacitor/calendar/PluginError.kt +8 -0
  4. package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/CreateEventWithPromptResult.kt +1 -0
  5. package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/GetDefaultCalendarResult.kt +1 -0
  6. package/android/src/main/java/dev/barooni/capacitor/calendar/models/results/ListCalendarsResult.kt +1 -0
  7. package/android/src/main/java/dev/barooni/capacitor/calendar/utils/DeclarationCheck.kt +59 -0
  8. package/dist/docs.json +463 -81
  9. package/dist/esm/index.d.ts +7 -2
  10. package/dist/esm/index.js +2 -1
  11. package/dist/esm/index.js.map +1 -1
  12. package/dist/esm/schemas/enums/calendar-permission-scope.d.ts +1 -1
  13. package/dist/esm/schemas/enums/calendar-permission-scope.js +1 -1
  14. package/dist/esm/schemas/enums/calendar-permission-scope.js.map +1 -1
  15. package/dist/esm/schemas/enums/capacitor-calendar-error-code.d.ts +13 -0
  16. package/dist/esm/schemas/enums/capacitor-calendar-error-code.js +15 -0
  17. package/dist/esm/schemas/enums/capacitor-calendar-error-code.js.map +1 -0
  18. package/dist/esm/schemas/interfaces/calendar.d.ts +10 -2
  19. package/dist/esm/schemas/interfaces/calendar.js.map +1 -1
  20. package/dist/esm/schemas/interfaces/create-calendar-options.d.ts +6 -4
  21. package/dist/esm/schemas/interfaces/create-calendar-options.js.map +1 -1
  22. package/dist/esm/schemas/interfaces/create-event-options.d.ts +10 -1
  23. package/dist/esm/schemas/interfaces/create-event-options.js.map +1 -1
  24. package/dist/esm/schemas/interfaces/create-event-result.d.ts +0 -2
  25. package/dist/esm/schemas/interfaces/create-event-result.js.map +1 -1
  26. package/dist/esm/schemas/interfaces/create-event-with-prompt-options.d.ts +36 -10
  27. package/dist/esm/schemas/interfaces/create-event-with-prompt-options.js.map +1 -1
  28. package/dist/esm/schemas/interfaces/create-event-with-prompt-result.d.ts +10 -1
  29. package/dist/esm/schemas/interfaces/create-event-with-prompt-result.js.map +1 -1
  30. package/dist/esm/schemas/interfaces/create-reminder-options.d.ts +2 -0
  31. package/dist/esm/schemas/interfaces/create-reminder-options.js.map +1 -1
  32. package/dist/esm/schemas/interfaces/create-reminders-list-options.d.ts +12 -7
  33. package/dist/esm/schemas/interfaces/create-reminders-list-options.js.map +1 -1
  34. package/dist/esm/schemas/interfaces/delete-reminder-with-prompt-result.d.ts +12 -0
  35. package/dist/esm/schemas/interfaces/delete-reminder-with-prompt-result.js +2 -0
  36. package/dist/esm/schemas/interfaces/delete-reminder-with-prompt-result.js.map +1 -0
  37. package/dist/esm/schemas/interfaces/event-recurrence-rule.d.ts +9 -9
  38. package/dist/esm/schemas/interfaces/event-recurrence-rule.js.map +1 -1
  39. package/dist/esm/schemas/interfaces/get-default-reminders-list-result.d.ts +13 -0
  40. package/dist/esm/schemas/interfaces/get-default-reminders-list-result.js +2 -0
  41. package/dist/esm/schemas/interfaces/get-default-reminders-list-result.js.map +1 -0
  42. package/dist/esm/schemas/interfaces/get-reminders-lists-result.d.ts +13 -0
  43. package/dist/esm/schemas/interfaces/get-reminders-lists-result.js +2 -0
  44. package/dist/esm/schemas/interfaces/get-reminders-lists-result.js.map +1 -0
  45. package/dist/esm/schemas/interfaces/modify-calendar-options.d.ts +6 -2
  46. package/dist/esm/schemas/interfaces/modify-calendar-options.js.map +1 -1
  47. package/dist/esm/schemas/interfaces/modify-event-with-prompt-options.d.ts +77 -2
  48. package/dist/esm/schemas/interfaces/modify-event-with-prompt-options.js.map +1 -1
  49. package/dist/esm/schemas/interfaces/modify-reminder-options.d.ts +3 -0
  50. package/dist/esm/schemas/interfaces/modify-reminder-options.js.map +1 -1
  51. package/dist/esm/schemas/interfaces/reminder.d.ts +2 -0
  52. package/dist/esm/schemas/interfaces/reminder.js.map +1 -1
  53. package/dist/esm/schemas/interfaces/reminders-list.d.ts +6 -0
  54. package/dist/esm/schemas/interfaces/reminders-list.js.map +1 -1
  55. package/dist/esm/schemas/interfaces/update-reminders-list-options.d.ts +8 -5
  56. package/dist/esm/schemas/interfaces/update-reminders-list-options.js.map +1 -1
  57. package/dist/esm/schemas/types/system-color-name.d.ts +6 -0
  58. package/dist/esm/schemas/types/system-color-name.js +2 -0
  59. package/dist/esm/schemas/types/system-color-name.js.map +1 -0
  60. package/dist/esm/sub-definitions/event-operations.d.ts +7 -10
  61. package/dist/esm/sub-definitions/event-operations.js.map +1 -1
  62. package/dist/esm/sub-definitions/reminders-access.d.ts +1 -1
  63. package/dist/esm/sub-definitions/reminders-access.js.map +1 -1
  64. package/dist/esm/sub-definitions/reminders-operations.d.ts +41 -16
  65. package/dist/esm/sub-definitions/reminders-operations.js.map +1 -1
  66. package/dist/esm/web/ics.d.ts +8 -2
  67. package/dist/esm/web/ics.js +64 -22
  68. package/dist/esm/web/ics.js.map +1 -1
  69. package/dist/esm/web.d.ts +8 -15
  70. package/dist/esm/web.js +100 -5
  71. package/dist/esm/web.js.map +1 -1
  72. package/dist/plugin.cjs.js +180 -29
  73. package/dist/plugin.cjs.js.map +1 -1
  74. package/dist/plugin.js +180 -29
  75. package/dist/plugin.js.map +1 -1
  76. package/ios/Plugin/CapacitorCalendarPlugin.swift +68 -22
  77. package/ios/Plugin/Models/Inputs/CreateCalendarInput.swift +5 -2
  78. package/ios/Plugin/Models/Inputs/CreateRemindersListInput.swift +4 -18
  79. package/ios/Plugin/Models/Inputs/ModifyCalendarInput.swift +2 -2
  80. package/ios/Plugin/Models/Inputs/UpdateRemindersListInput.swift +4 -18
  81. package/ios/Plugin/Models/Results/CreateEventWithPromptResult.swift +1 -0
  82. package/ios/Plugin/PluginError.swift +13 -0
  83. package/ios/Plugin/Utils/DeclarationCheck.swift +63 -0
  84. package/ios/Plugin/Utils/ImplementationHelper.swift +44 -0
  85. package/ios/Plugin/Utils/UIColorFromHexExtension.swift +5 -0
  86. package/package.json +1 -1
@@ -11,7 +11,7 @@ struct CreateRemindersListInput {
11
11
  throw PluginError.titleMissing
12
12
  }
13
13
  self.title = title
14
- self.color = CreateRemindersListInput.getListColorFromCall(call)
14
+ self.color = try CreateRemindersListInput.getListColorFromCall(call)
15
15
  self.commit = call.getBool("commit", true)
16
16
  if let sourceId = call.getString("sourceId") {
17
17
  self.sourceId = sourceId
@@ -34,24 +34,10 @@ struct CreateRemindersListInput {
34
34
  return title
35
35
  }
36
36
 
37
- private static func getListColorFromCall(_ call: CAPPluginCall) -> CGColor? {
38
- guard let colorName = call.getString("color") else {
37
+ private static func getListColorFromCall(_ call: CAPPluginCall) throws -> CGColor? {
38
+ guard let colorString = call.getString("color") else {
39
39
  return nil
40
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
- }
41
+ return try ImplementationHelper.listColor(from: colorString)
56
42
  }
57
43
  }
@@ -11,8 +11,8 @@ struct ModifyCalendarInput {
11
11
  }
12
12
  self.id = id
13
13
  self.title = call.getString("title")
14
- if let color = call.getString("color") {
15
- self.color = try UIColor.fromHex(color).cgColor
14
+ if let colorString = call.getString("color") {
15
+ self.color = try ImplementationHelper.listColor(from: colorString)
16
16
  } else {
17
17
  self.color = nil
18
18
  }
@@ -12,7 +12,7 @@ struct UpdateRemindersListInput {
12
12
  }
13
13
  self.id = id
14
14
  self.title = call.getString("title")
15
- self.color = UpdateRemindersListInput.getListColorFromCall(call)
15
+ self.color = try UpdateRemindersListInput.getListColorFromCall(call)
16
16
  self.commit = call.getBool("commit", true)
17
17
  }
18
18
 
@@ -32,24 +32,10 @@ struct UpdateRemindersListInput {
32
32
  return title
33
33
  }
34
34
 
35
- private static func getListColorFromCall(_ call: CAPPluginCall) -> CGColor? {
36
- guard let colorName = call.getString("color") else {
35
+ private static func getListColorFromCall(_ call: CAPPluginCall) throws -> CGColor? {
36
+ guard let colorString = call.getString("color") else {
37
37
  return nil
38
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
- }
39
+ return try ImplementationHelper.listColor(from: colorString)
54
40
  }
55
41
  }
@@ -9,6 +9,7 @@ struct CreateEventWithPromptResult: JSResult {
9
9
 
10
10
  func toJSON() -> JSObject {
11
11
  var result = JSObject()
12
+ result["ics"] = NSNull()
12
13
  result["id"] = id ?? NSNull()
13
14
  return result
14
15
  }
@@ -21,6 +21,7 @@ enum PluginError: LocalizedError {
21
21
  case listNotFound
22
22
  case listNotModifiable
23
23
  case messageMissing
24
+ case missingDeclaration(String)
24
25
  case missingFrequency
25
26
  case missingInterval
26
27
  case noFieldsToModify
@@ -76,6 +77,8 @@ enum PluginError: LocalizedError {
76
77
  return NSLocalizedString("List is not modifiable.", comment: "List not modifiable error")
77
78
  case .messageMissing:
78
79
  return NSLocalizedString("Message must be provided.", comment: "Message missing error")
80
+ case .missingDeclaration(let key):
81
+ return "Missing Info.plist usage description: \(key)."
79
82
  case .missingFrequency:
80
83
  return NSLocalizedString("Frequency must be provided.", comment: "Frequency missing error")
81
84
  case .missingInterval:
@@ -102,4 +105,14 @@ enum PluginError: LocalizedError {
102
105
  return NSLocalizedString("Missing view controller.", comment: "View controller missing error")
103
106
  }
104
107
  }
108
+
109
+ /// Cap-style reject code when this error provides one; nil for message-only cases.
110
+ var code: String? {
111
+ switch self {
112
+ case .missingDeclaration:
113
+ return "EB-CLDR-0100"
114
+ default:
115
+ return nil
116
+ }
117
+ }
105
118
  }
@@ -0,0 +1,63 @@
1
+ import Foundation
2
+
3
+ /// Early Info.plist usage-description checks for EB-CLDR-0100 MissingDeclaration.
4
+ /// Callers pass only the access level the method actually uses.
5
+ enum DeclarationCheck {
6
+ /// Throws `PluginError.missingDeclaration` when the Info.plist key for the scope is missing.
7
+ static func ensureUsageDescription(for scope: CalendarPermissionScope) throws {
8
+ switch scope {
9
+ case .writeCalendar:
10
+ try ensureWriteOnlyCalendarUsageDescription()
11
+ case .readCalendar:
12
+ try ensureFullCalendarUsageDescription()
13
+ case .writeReminders, .readReminders:
14
+ try ensureRemindersUsageDescription()
15
+ }
16
+ }
17
+
18
+ static func ensureWriteOnlyCalendarUsageDescription() throws {
19
+ try ensureUsageDescriptionKey(requiredWriteOnlyCalendarUsageDescriptionKey())
20
+ }
21
+
22
+ static func ensureFullCalendarUsageDescription() throws {
23
+ try ensureUsageDescriptionKey(requiredFullCalendarUsageDescriptionKey())
24
+ }
25
+
26
+ static func ensureRemindersUsageDescription() throws {
27
+ try ensureUsageDescriptionKey(requiredRemindersUsageDescriptionKey())
28
+ }
29
+
30
+ private static func ensureUsageDescriptionKey(_ key: String) throws {
31
+ guard hasUsageDescription(forKey: key) else {
32
+ throw PluginError.missingDeclaration(key)
33
+ }
34
+ }
35
+
36
+ private static func hasUsageDescription(forKey key: String) -> Bool {
37
+ guard let value = Bundle.main.object(forInfoDictionaryKey: key) as? String else {
38
+ return false
39
+ }
40
+ return !value.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
41
+ }
42
+
43
+ private static func requiredWriteOnlyCalendarUsageDescriptionKey() -> String {
44
+ if #available(iOS 17.0, *) {
45
+ return "NSCalendarsWriteOnlyAccessUsageDescription"
46
+ }
47
+ return "NSCalendarsUsageDescription"
48
+ }
49
+
50
+ private static func requiredFullCalendarUsageDescriptionKey() -> String {
51
+ if #available(iOS 17.0, *) {
52
+ return "NSCalendarsFullAccessUsageDescription"
53
+ }
54
+ return "NSCalendarsUsageDescription"
55
+ }
56
+
57
+ private static func requiredRemindersUsageDescriptionKey() -> String {
58
+ if #available(iOS 17.0, *) {
59
+ return "NSRemindersFullAccessUsageDescription"
60
+ }
61
+ return "NSRemindersUsageDescription"
62
+ }
63
+ }
@@ -1,5 +1,6 @@
1
1
  import EventKit
2
2
  import Capacitor
3
+ import UIKit
3
4
 
4
5
  struct ImplementationHelper {
5
6
  /// Default calendar color when `color` is omitted: `#007AFF` (light-mode iOS system blue).
@@ -147,6 +148,48 @@ struct ImplementationHelper {
147
148
  : String(format: "#%02lX%02lX%02lX%02lX", red, green, blue, alpha)
148
149
  }
149
150
 
151
+ /// Named system color or hex (`#RRGGBB` / `#RRGGBBAA`). Throws `invalidColor` when neither matches.
152
+ static func listColor(from colorString: String) throws -> CGColor {
153
+ if let namedColor = systemColor(named: colorString) {
154
+ return namedColor.cgColor
155
+ }
156
+ let trimmed = colorString.trimmingCharacters(in: .whitespacesAndNewlines)
157
+ guard trimmed.hasPrefix("#") else {
158
+ throw PluginError.invalidColor
159
+ }
160
+ return try UIColor.fromHex(trimmed).cgColor
161
+ }
162
+
163
+ /// Best-effort match of a stored calendar color to a known `UIColor.system*` name.
164
+ static func systemColorName(from color: CGColor) -> String? {
165
+ guard let hex = cgColorToHex(color) else { return nil }
166
+ for (name, systemColor) in systemColorPalette {
167
+ if cgColorToHex(systemColor.cgColor) == hex {
168
+ return name
169
+ }
170
+ }
171
+ return nil
172
+ }
173
+
174
+ private static let systemColorPalette: [(String, UIColor)] = [
175
+ ("blue", .systemBlue),
176
+ ("brown", .systemBrown),
177
+ ("gray", .systemGray),
178
+ ("green", .systemGreen),
179
+ ("indigo", .systemIndigo),
180
+ ("orange", .systemOrange),
181
+ ("pink", .systemPink),
182
+ ("purple", .systemPurple),
183
+ ("red", .systemRed),
184
+ ("teal", .systemTeal),
185
+ ("yellow", .systemYellow)
186
+ ]
187
+
188
+ private static func systemColor(named colorName: String) -> UIColor? {
189
+ let key = colorName.lowercased()
190
+ return systemColorPalette.first(where: { $0.0 == key })?.1
191
+ }
192
+
150
193
  static func deleteReminder(reminderId: String, eventStore: EKEventStore, commit: Bool = true) throws {
151
194
  guard let reminder = eventStore.calendarItem(withIdentifier: reminderId) as? EKReminder else {
152
195
  throw PluginError.reminderNotFound
@@ -179,6 +222,7 @@ struct ImplementationHelper {
179
222
  "id": calendar.calendarIdentifier,
180
223
  "title": calendar.title,
181
224
  "color": ImplementationHelper.cgColorToHex(calendar.cgColor) ?? NSNull(),
225
+ "colorName": ImplementationHelper.systemColorName(from: calendar.cgColor) ?? NSNull(),
182
226
  "isImmutable": calendar.isImmutable,
183
227
  "allowsContentModifications": calendar.allowsContentModifications,
184
228
  "type": calendar.type.rawValue,
@@ -10,6 +10,11 @@ extension UIColor {
10
10
 
11
11
  guard cleanedHex.count == 6 || cleanedHex.count == 8 else { throw PluginError.invalidColor }
12
12
 
13
+ let hexDigits = CharacterSet(charactersIn: "0123456789ABCDEF")
14
+ guard cleanedHex.unicodeScalars.allSatisfy({ hexDigits.contains($0) }) else {
15
+ throw PluginError.invalidColor
16
+ }
17
+
13
18
  var rgbValue: UInt64 = 0
14
19
  Scanner(string: cleanedHex).scanHexInt64(&rgbValue)
15
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebarooni/capacitor-calendar",
3
- "version": "8.7.1",
3
+ "version": "8.9.0",
4
4
  "description": "A Capacitor plugin for native calendar events on iOS and Android (with reminders on iOS), and .ics event creation on the web.",
5
5
  "author": "Ehsan Barooni",
6
6
  "license": "MIT",