@ebarooni/capacitor-calendar 6.5.0 → 6.6.1

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 (40) hide show
  1. package/README.md +61 -12
  2. package/android/build.gradle +2 -2
  3. package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendar.kt +178 -119
  4. package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +73 -0
  5. package/assets/images/text-logo.png +0 -0
  6. package/dist/docs.json +461 -60
  7. package/dist/esm/definitions.d.ts +174 -34
  8. package/dist/esm/definitions.js.map +1 -1
  9. package/dist/esm/index.d.ts +18 -14
  10. package/dist/esm/index.js +12 -9
  11. package/dist/esm/index.js.map +1 -1
  12. package/dist/esm/schemas/enums/calendar-source-type.d.ts +38 -0
  13. package/dist/esm/schemas/enums/calendar-source-type.js +40 -0
  14. package/dist/esm/schemas/enums/calendar-source-type.js.map +1 -0
  15. package/dist/esm/schemas/enums/calendar-type.d.ts +28 -0
  16. package/dist/esm/schemas/enums/calendar-type.js +30 -0
  17. package/dist/esm/schemas/enums/calendar-type.js.map +1 -0
  18. package/dist/esm/schemas/enums/event-span.d.ts +16 -0
  19. package/dist/esm/schemas/enums/event-span.js +18 -0
  20. package/dist/esm/schemas/enums/event-span.js.map +1 -0
  21. package/dist/esm/schemas/interfaces/calendar-event.d.ts +14 -3
  22. package/dist/esm/schemas/interfaces/calendar-event.js.map +1 -1
  23. package/dist/esm/schemas/interfaces/calendar-source.d.ts +15 -0
  24. package/dist/esm/schemas/interfaces/calendar-source.js +2 -0
  25. package/dist/esm/schemas/interfaces/calendar-source.js.map +1 -0
  26. package/dist/esm/schemas/interfaces/calendar.d.ts +43 -2
  27. package/dist/esm/schemas/interfaces/calendar.js.map +1 -1
  28. package/dist/esm/web.d.ts +49 -9
  29. package/dist/esm/web.js +13 -2
  30. package/dist/esm/web.js.map +1 -1
  31. package/dist/plugin.cjs.js +101 -2
  32. package/dist/plugin.cjs.js.map +1 -1
  33. package/dist/plugin.js +101 -2
  34. package/dist/plugin.js.map +1 -1
  35. package/ios/Plugin/CapacitorCalendar.swift +210 -17
  36. package/ios/Plugin/CapacitorCalendarPlugin.m +4 -0
  37. package/ios/Plugin/CapacitorCalendarPlugin.swift +111 -1
  38. package/ios/Plugin/CapacitorReminders.swift +63 -9
  39. package/ios/Plugin/EventCreationParameters.swift +1 -1
  40. package/package.json +32 -20
@@ -161,6 +161,55 @@ public class CapacitorCalendarPlugin: CAPPlugin {
161
161
  }
162
162
  }
163
163
 
164
+ @objc public func modifyEventWithPrompt(_ call: CAPPluginCall) {
165
+ guard let id = call.getString("id") else {
166
+ call.reject("[CapacitorCalendar.\(#function)] Missing event id")
167
+ return
168
+ }
169
+
170
+ Task {
171
+ do {
172
+ let result: [String]
173
+
174
+ if let update = call.getObject("update") {
175
+
176
+ let title = update["title"] as? String
177
+ let calendarId = update["calendarId"] as? String
178
+ let location = update["location"] as? String
179
+ let startDate = update["startDate"] as? Double
180
+ let endDate = update["endDate"] as? Double
181
+ let isAllDay = update["isAllDay"] as? Bool
182
+ let notes = update["notes"] as? String
183
+ let url = update["url"] as? String
184
+ let alertOffsetInMinutesSingle = update["alertOffsetInMinutes"] as? Double
185
+ let alertOffsetInMinutesMultiple = update["alertOffsetInMinutes"] as? [Double]
186
+
187
+ var eventParameters = EventCreationParameters(
188
+ title: title,
189
+ calendarId: calendarId,
190
+ location: location,
191
+ startDate: startDate,
192
+ endDate: endDate,
193
+ isAllDay: isAllDay,
194
+ alertOffsetInMinutesSingle: alertOffsetInMinutesSingle,
195
+ alertOffsetInMinutesMultiple: alertOffsetInMinutesMultiple,
196
+ notes: notes,
197
+ url: url
198
+ )
199
+
200
+ result = try await calendar.modifyEventWithPrompt(id: id, update: eventParameters)
201
+ } else {
202
+ result = try await calendar.modifyEventWithPrompt(id: id)
203
+ }
204
+
205
+ call.resolve(["result": result])
206
+ } catch {
207
+ call.reject("[CapacitorCalendar.\(#function)] Unable to modify event")
208
+ return
209
+ }
210
+ }
211
+ }
212
+
164
213
  @objc public func selectCalendarsWithPrompt(_ call: CAPPluginCall) {
165
214
  guard let selectionStyle = call.getInt("selectionStyle") else {
166
215
  call.reject("[CapacitorCalendar.\(#function)] Selection style was not provided")
@@ -234,6 +283,48 @@ public class CapacitorCalendarPlugin: CAPPlugin {
234
283
  }
235
284
  }
236
285
 
286
+ @objc public func modifyEvent(_ call: CAPPluginCall) {
287
+ guard let eventId = call.getString("id") else {
288
+ call.reject("[CapacitorCalendar.\(#function)] An id for the event was not provided")
289
+ return
290
+ }
291
+ guard let update = call.getObject("update") else {
292
+ call.reject("[CapacitorCalendar.\(#function)] An update for the event was not provided")
293
+ return
294
+ }
295
+ let span = call.getInt("span", 0)
296
+ let title = update["title"] as? String
297
+ let calendarId = update["calendarId"] as? String
298
+ let location = update["location"] as? String
299
+ let startDate = update["startDate"] as? Double
300
+ let endDate = update["endDate"] as? Double
301
+ let isAllDay = update["isAllDay"] as? Bool
302
+ let notes = update["notes"] as? String
303
+ let url = update["url"] as? String
304
+ let alertOffsetInMinutesSingle = update["alertOffsetInMinutes"] as? Double
305
+ let alertOffsetInMinutesMultiple = update["alertOffsetInMinutes"] as? [Double]
306
+
307
+ do {
308
+ var eventParameters = EventCreationParameters(
309
+ title: title,
310
+ calendarId: calendarId,
311
+ location: location,
312
+ startDate: startDate,
313
+ endDate: endDate,
314
+ isAllDay: isAllDay,
315
+ alertOffsetInMinutesSingle: alertOffsetInMinutesSingle,
316
+ alertOffsetInMinutesMultiple: alertOffsetInMinutesMultiple,
317
+ notes: notes,
318
+ url: url
319
+ )
320
+ let result: Void = try calendar.modifyEvent(id: eventId, span: EKSpan(rawValue: span) ?? .thisEvent, update: eventParameters)
321
+ call.resolve(["result": result])
322
+ } catch {
323
+ call.reject("[CapacitorCalendar.\(#function)] Unable to modify event")
324
+ return
325
+ }
326
+ }
327
+
237
328
  @objc public func getDefaultRemindersList(_ call: CAPPluginCall) {
238
329
  do {
239
330
  try call.resolve(["result": reminders.getDefaultRemindersList() ?? NSNull()])
@@ -377,9 +468,10 @@ public class CapacitorCalendarPlugin: CAPPlugin {
377
468
  return
378
469
  }
379
470
  let color = call.getString("color")
471
+ let sourceId = call.getString("sourceId")
380
472
 
381
473
  do {
382
- let id = try calendar.createCalendar(title: title, color: color)
474
+ let id = try calendar.createCalendar(title: title, color: color, sourceId: sourceId)
383
475
  call.resolve(["result": id])
384
476
  } catch {
385
477
  call.reject("[CapacitorCalendar.\(#function)] Could not create calendar")
@@ -477,4 +569,22 @@ public class CapacitorCalendarPlugin: CAPPlugin {
477
569
  }
478
570
  }
479
571
  }
572
+
573
+ @objc public func fetchAllCalendarSources(_ call: CAPPluginCall) {
574
+ do {
575
+ call.resolve(["result": try calendar.fetchAllCalendarSources()])
576
+ } catch {
577
+ call.reject("[CapacitorCalendar.\(#function)] Unable to fetch calendar sources")
578
+ return
579
+ }
580
+ }
581
+
582
+ @objc public func fetchAllRemindersSources(_ call: CAPPluginCall) {
583
+ do {
584
+ call.resolve(["result": try reminders.fetchAllRemindersSources()])
585
+ } catch {
586
+ call.reject("[CapacitorCalendar.\(#function)] Unable to fetch calendar sources")
587
+ return
588
+ }
589
+ }
480
590
  }
@@ -24,13 +24,26 @@ public class CapacitorReminders: NSObject {
24
24
  self.eventStore = eventStore
25
25
  }
26
26
 
27
- public func getDefaultRemindersList() throws -> [String: String]? {
27
+ public func getDefaultRemindersList() throws -> [String: Any]? {
28
28
  let defaultRemindersList = eventStore.defaultCalendarForNewReminders()
29
29
  if let defaultRemindersList = defaultRemindersList {
30
- return [
30
+ var calendarDict: [String: Any] = [
31
31
  "id": defaultRemindersList.calendarIdentifier,
32
- "title": defaultRemindersList.title
32
+ "title": defaultRemindersList.title,
33
+ "color": hexStringFromColor(color: defaultRemindersList.cgColor),
34
+ "isImmutable": defaultRemindersList.isImmutable,
35
+ "allowsContentModifications": defaultRemindersList.allowsContentModifications,
36
+ "type": defaultRemindersList.type.rawValue,
37
+ "isSubscribed": defaultRemindersList.isSubscribed
33
38
  ]
39
+ if let calendarSource = defaultRemindersList.source {
40
+ calendarDict["source"] = [
41
+ "type": calendarSource.sourceType.rawValue,
42
+ "id": calendarSource.sourceIdentifier,
43
+ "title": calendarSource.title
44
+ ]
45
+ }
46
+ return calendarDict
34
47
  } else {
35
48
  return nil
36
49
  }
@@ -63,7 +76,7 @@ public class CapacitorReminders: NSObject {
63
76
  }
64
77
  }
65
78
 
66
- public func getRemindersLists() -> [[String: String]] {
79
+ public func getRemindersLists() -> [[String: Any]] {
67
80
  return convertEKCalendarsToDictionaries(calendars: Set(eventStore.calendars(for: .reminder)))
68
81
  }
69
82
 
@@ -229,14 +242,41 @@ public class CapacitorReminders: NSObject {
229
242
  }
230
243
  }
231
244
 
232
- private func convertEKCalendarsToDictionaries(calendars: Set<EKCalendar>) -> [[String: String]] {
233
- var result: [[String: String]] = []
245
+ public func fetchAllRemindersSources() throws -> [[String: Any]] {
246
+ var result: [[String: Any]] = []
247
+
248
+ for source in eventStore.sources {
249
+ let sourceDict: [String: Any] = [
250
+ "id": source.sourceIdentifier,
251
+ "title": source.title,
252
+ "type": source.sourceType.rawValue
253
+ ]
254
+ result.append(sourceDict)
255
+ }
256
+
257
+ return result
258
+ }
259
+
260
+ private func convertEKCalendarsToDictionaries(calendars: Set<EKCalendar>) -> [[String: Any]] {
261
+ var result: [[String: Any]] = []
234
262
 
235
263
  for calendar in calendars {
236
- let calendarDict: [String: String] = [
264
+ var calendarDict: [String: Any] = [
237
265
  "id": calendar.calendarIdentifier,
238
- "title": calendar.title
266
+ "title": calendar.title,
267
+ "color": hexStringFromColor(color: calendar.cgColor),
268
+ "isImmutable": calendar.isImmutable,
269
+ "allowsContentModifications": calendar.allowsContentModifications,
270
+ "type": calendar.type.rawValue,
271
+ "isSubscribed": calendar.isSubscribed
239
272
  ]
273
+ if let calendarSource = calendar.source {
274
+ calendarDict["source"] = [
275
+ "type": calendarSource.sourceType.rawValue,
276
+ "id": calendarSource.sourceIdentifier,
277
+ "title": calendarSource.title
278
+ ]
279
+ }
240
280
  result.append(calendarDict)
241
281
  }
242
282
 
@@ -303,7 +343,7 @@ public class CapacitorReminders: NSObject {
303
343
  dict["title"] = title
304
344
  }
305
345
  if let url = event.url {
306
- dict["url"] = url
346
+ dict["url"] = url.absoluteString
307
347
  }
308
348
  if let notes = event.notes {
309
349
  dict["notes"] = notes
@@ -355,4 +395,18 @@ public class CapacitorReminders: NSObject {
355
395
  return obj
356
396
  }
357
397
  }
398
+
399
+ private func hexStringFromColor(color: CGColor) -> String {
400
+ guard let components = color.components, components.count >= 3 else {
401
+ return "#000000"
402
+ }
403
+
404
+ let red = Float(components[0])
405
+ let green = Float(components[1])
406
+ let blue = Float(components[2])
407
+ return String(format: "#%02lX%02lX%02lX",
408
+ lroundf(red * 255),
409
+ lroundf(green * 255),
410
+ lroundf(blue * 255))
411
+ }
358
412
  }
@@ -9,7 +9,7 @@
9
9
  import Foundation
10
10
 
11
11
  public struct EventCreationParameters {
12
- public var title: String
12
+ public var title: String?
13
13
  public var calendarId: String?
14
14
  public var location: String?
15
15
  public var startDate: Double?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebarooni/capacitor-calendar",
3
- "version": "6.5.0",
3
+ "version": "6.6.1",
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",
@@ -11,7 +11,9 @@
11
11
  "android/build.gradle",
12
12
  "dist/",
13
13
  "ios/Plugin/",
14
- "EbarooniCapacitorCalendar.podspec"
14
+ "EbarooniCapacitorCalendar.podspec",
15
+ "LICENSE.txt",
16
+ "assets/images/text-logo.png"
15
17
  ],
16
18
  "author": "Ehsan Barooni",
17
19
  "license": "MIT",
@@ -42,47 +44,56 @@
42
44
  "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
43
45
  "verify:android": "cd android && ./gradlew clean build test && cd ..",
44
46
  "verify:web": "npm run build",
47
+ "prettier:check": "npx prettier . --check",
48
+ "prettier:fix": "npx prettier . --write",
45
49
  "swiftlint": "node-swiftlint",
46
50
  "ktlint": "ktlint 'android/src/main/java/**'",
47
- "lint:ts": "npx eslint . --ext .ts",
48
- "lint:html": "npx eslint . --ext .html",
51
+ "lint:ts-html": "npx eslint",
49
52
  "lint:css": "npx stylelint \"**/*.(css|scss)\"",
50
53
  "lint:swift": "npm run swiftlint -- lint",
51
54
  "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
+ "lint": "npm run lint:ts-html && npm run lint:css && npm run lint:swift && npm run lint:kt",
56
+ "fmt:ts-html": "npx eslint --fix",
55
57
  "fmt:css": "npx stylelint \"**/*.(css|scss)\" --fix",
56
58
  "fmt:swift": "npm run swiftlint -- --fix --format",
57
59
  "fmt:md": "npx prettier --write \"**/*.md\"",
58
60
  "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",
60
- "docgen:api": "docgen --api CapacitorCalendarPlugin --output-readme documentation.md --output-json dist/docs.json",
61
+ "fmt": "npm run fmt:ts-html && npm run fmt:css && npm run fmt:swift && npm run fmt:md && npm run fmt:kt",
62
+ "docgen:api-reference": "docgen --api CapacitorCalendarPlugin --output-readme docs/api-reference.md --output-json dist/docs.json",
61
63
  "docgen:readme": "docgen --api CapacitorCalendarPlugin --output-readme README.md",
64
+ "typedoc:index": "npx typedoc",
62
65
  "clean": "rm -rf ./dist",
63
- "build": "npm run clean && npm run docgen:api && npm run docgen:readme && tsc && rollup -c rollup.config.mjs",
64
- "prepublishOnly": "npm run build"
66
+ "build": "npm run clean && npm run docgen:api-reference && npm run docgen:readme && tsc && rollup -c rollup.config.mjs",
67
+ "prepublishOnly": "npm run build",
68
+ "serve": "cd example && npx ng serve"
65
69
  },
66
70
  "devDependencies": {
67
- "@angular-eslint/eslint-plugin": "^17.3.0",
68
- "@angular-eslint/eslint-plugin-template": "^17.3.0",
69
- "@angular-eslint/template-parser": "^17.3.0",
70
71
  "@angular/cli": "^17.1.2",
71
72
  "@capacitor/android": "^6.0.0",
72
73
  "@capacitor/cli": "^6.0.0",
73
74
  "@capacitor/core": "^6.0.0",
74
75
  "@capacitor/docgen": "^0.0.18",
75
76
  "@capacitor/ios": "^6.0.0",
76
- "@typescript-eslint/eslint-plugin": "^7.3.0",
77
- "@typescript-eslint/parser": "^7.3.0",
78
- "eslint": "^8.57.0",
77
+ "@ebarooni/eslint-config": "^1.0.1",
78
+ "@ebarooni/prettier-config": "^1.1.0",
79
+ "@ebarooni/stylelint-config": "^1.1.0",
80
+ "@ebarooni/swiftlint-config": "^1.1.0",
81
+ "@eslint/js": "^9.4.0",
82
+ "@types/eslint__js": "^8.42.3",
83
+ "angular-eslint": "^18.0.1",
84
+ "eslint": "^9.4.0",
79
85
  "eslint-config-prettier": "^9.1.0",
80
86
  "eslint-plugin-prettier": "^5.1.3",
81
- "prettier": "~3.2.5",
87
+ "postcss": "^8.4.38",
88
+ "prettier": "^3.3.2",
82
89
  "rollup": "^4.17.0",
90
+ "stylelint": "^16.6.1",
91
+ "stylelint-config-standard-scss": "^13.1.0",
83
92
  "stylelint-prettier": "^5.0.0",
84
- "swiftlint": "^1.0.1",
85
- "typescript": "~5.4.2"
93
+ "swiftlint": "^1.0.2",
94
+ "typedoc": "^0.26.5",
95
+ "typescript": "~5.4.2",
96
+ "typescript-eslint": "^8.0.1"
86
97
  },
87
98
  "peerDependencies": {
88
99
  "@capacitor/core": "^6.0.0"
@@ -95,6 +106,7 @@
95
106
  "src": "android"
96
107
  }
97
108
  },
109
+ "prettier": "@ebarooni/prettier-config",
98
110
  "publishConfig": {
99
111
  "access": "public"
100
112
  }