@ebarooni/capacitor-calendar 8.7.0 → 8.8.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 (79) hide show
  1. package/README.md +260 -167
  2. package/android/src/main/java/dev/barooni/capacitor/calendar/PluginError.kt +2 -0
  3. package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CapacitorCalendar.kt +54 -5
  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/ImplementationHelper.kt +80 -0
  8. package/dist/docs.json +463 -81
  9. package/dist/esm/index.d.ts +5 -1
  10. package/dist/esm/index.js.map +1 -1
  11. package/dist/esm/schemas/enums/calendar-permission-scope.d.ts +1 -1
  12. package/dist/esm/schemas/enums/calendar-permission-scope.js +1 -1
  13. package/dist/esm/schemas/enums/calendar-permission-scope.js.map +1 -1
  14. package/dist/esm/schemas/interfaces/calendar.d.ts +10 -2
  15. package/dist/esm/schemas/interfaces/calendar.js.map +1 -1
  16. package/dist/esm/schemas/interfaces/create-calendar-options.d.ts +6 -4
  17. package/dist/esm/schemas/interfaces/create-calendar-options.js.map +1 -1
  18. package/dist/esm/schemas/interfaces/create-event-options.d.ts +10 -1
  19. package/dist/esm/schemas/interfaces/create-event-options.js.map +1 -1
  20. package/dist/esm/schemas/interfaces/create-event-result.d.ts +0 -2
  21. package/dist/esm/schemas/interfaces/create-event-result.js.map +1 -1
  22. package/dist/esm/schemas/interfaces/create-event-with-prompt-options.d.ts +36 -10
  23. package/dist/esm/schemas/interfaces/create-event-with-prompt-options.js.map +1 -1
  24. package/dist/esm/schemas/interfaces/create-event-with-prompt-result.d.ts +10 -1
  25. package/dist/esm/schemas/interfaces/create-event-with-prompt-result.js.map +1 -1
  26. package/dist/esm/schemas/interfaces/create-reminder-options.d.ts +2 -0
  27. package/dist/esm/schemas/interfaces/create-reminder-options.js.map +1 -1
  28. package/dist/esm/schemas/interfaces/create-reminders-list-options.d.ts +12 -7
  29. package/dist/esm/schemas/interfaces/create-reminders-list-options.js.map +1 -1
  30. package/dist/esm/schemas/interfaces/delete-reminder-with-prompt-result.d.ts +12 -0
  31. package/dist/esm/schemas/interfaces/delete-reminder-with-prompt-result.js +2 -0
  32. package/dist/esm/schemas/interfaces/delete-reminder-with-prompt-result.js.map +1 -0
  33. package/dist/esm/schemas/interfaces/event-recurrence-rule.d.ts +9 -9
  34. package/dist/esm/schemas/interfaces/event-recurrence-rule.js.map +1 -1
  35. package/dist/esm/schemas/interfaces/get-default-reminders-list-result.d.ts +13 -0
  36. package/dist/esm/schemas/interfaces/get-default-reminders-list-result.js +2 -0
  37. package/dist/esm/schemas/interfaces/get-default-reminders-list-result.js.map +1 -0
  38. package/dist/esm/schemas/interfaces/get-reminders-lists-result.d.ts +13 -0
  39. package/dist/esm/schemas/interfaces/get-reminders-lists-result.js +2 -0
  40. package/dist/esm/schemas/interfaces/get-reminders-lists-result.js.map +1 -0
  41. package/dist/esm/schemas/interfaces/modify-calendar-options.d.ts +6 -2
  42. package/dist/esm/schemas/interfaces/modify-calendar-options.js.map +1 -1
  43. package/dist/esm/schemas/interfaces/modify-event-with-prompt-options.d.ts +77 -2
  44. package/dist/esm/schemas/interfaces/modify-event-with-prompt-options.js.map +1 -1
  45. package/dist/esm/schemas/interfaces/modify-reminder-options.d.ts +3 -0
  46. package/dist/esm/schemas/interfaces/modify-reminder-options.js.map +1 -1
  47. package/dist/esm/schemas/interfaces/reminder.d.ts +2 -0
  48. package/dist/esm/schemas/interfaces/reminder.js.map +1 -1
  49. package/dist/esm/schemas/interfaces/reminders-list.d.ts +6 -0
  50. package/dist/esm/schemas/interfaces/reminders-list.js.map +1 -1
  51. package/dist/esm/schemas/interfaces/update-reminders-list-options.d.ts +8 -5
  52. package/dist/esm/schemas/interfaces/update-reminders-list-options.js.map +1 -1
  53. package/dist/esm/schemas/types/system-color-name.d.ts +6 -0
  54. package/dist/esm/schemas/types/system-color-name.js +2 -0
  55. package/dist/esm/schemas/types/system-color-name.js.map +1 -0
  56. package/dist/esm/sub-definitions/event-operations.d.ts +7 -10
  57. package/dist/esm/sub-definitions/event-operations.js.map +1 -1
  58. package/dist/esm/sub-definitions/reminders-access.d.ts +1 -1
  59. package/dist/esm/sub-definitions/reminders-access.js.map +1 -1
  60. package/dist/esm/sub-definitions/reminders-operations.d.ts +41 -16
  61. package/dist/esm/sub-definitions/reminders-operations.js.map +1 -1
  62. package/dist/esm/web/ics.d.ts +8 -2
  63. package/dist/esm/web/ics.js +64 -22
  64. package/dist/esm/web/ics.js.map +1 -1
  65. package/dist/esm/web.d.ts +8 -15
  66. package/dist/esm/web.js +100 -5
  67. package/dist/esm/web.js.map +1 -1
  68. package/dist/plugin.cjs.js +165 -29
  69. package/dist/plugin.cjs.js.map +1 -1
  70. package/dist/plugin.js +165 -29
  71. package/dist/plugin.js.map +1 -1
  72. package/ios/Plugin/Models/Inputs/CreateCalendarInput.swift +5 -2
  73. package/ios/Plugin/Models/Inputs/CreateRemindersListInput.swift +4 -18
  74. package/ios/Plugin/Models/Inputs/ModifyCalendarInput.swift +2 -2
  75. package/ios/Plugin/Models/Inputs/UpdateRemindersListInput.swift +4 -18
  76. package/ios/Plugin/Models/Results/CreateEventWithPromptResult.swift +1 -0
  77. package/ios/Plugin/Utils/ImplementationHelper.swift +44 -0
  78. package/ios/Plugin/Utils/UIColorFromHexExtension.swift +5 -0
  79. package/package.json +2 -2
@@ -17,6 +17,8 @@ sealed class PluginError(
17
17
  val details: String,
18
18
  ) : PluginError(details)
19
19
 
20
+ data object EventNotFound : PluginError("Event not found.")
21
+
20
22
  data object FailedToDelete : PluginError("Failed to delete.")
21
23
 
22
24
  data object FailedToModify : PluginError("Failed to modify.")
@@ -87,16 +87,24 @@ class CapacitorCalendar(
87
87
  fun createEvent(input: CreateEventInput): CreateEventResult {
88
88
  val cr = plugin.context.contentResolver
89
89
  val calendarId: Long = input.calendarId ?: ImplementationHelper.getDefaultCalendarId(cr)
90
+ val isAllDay = input.isAllDay == 1
91
+ val (startDate, endDate) =
92
+ if (isAllDay) {
93
+ ImplementationHelper.normalizeAllDayTimes(input.startDate, input.endDate)
94
+ } else {
95
+ Pair(input.startDate, input.endDate)
96
+ }
97
+ val timezoneId = if (isAllDay) "UTC" else input.timezoneId
90
98
 
91
99
  val values =
92
100
  ContentValues().apply {
93
101
  put(CalendarContract.Events.TITLE, input.title)
94
102
  put(CalendarContract.Events.CALENDAR_ID, calendarId)
95
- put(CalendarContract.Events.EVENT_TIMEZONE, input.timezoneId)
103
+ put(CalendarContract.Events.EVENT_TIMEZONE, timezoneId)
96
104
  input.isAllDay?.let { put(CalendarContract.Events.ALL_DAY, it) }
97
105
  input.location?.let { put(CalendarContract.Events.EVENT_LOCATION, it) }
98
- input.startDate?.let { put(CalendarContract.Events.DTSTART, it) }
99
- input.endDate?.let { put(CalendarContract.Events.DTEND, it) }
106
+ startDate?.let { put(CalendarContract.Events.DTSTART, it) }
107
+ endDate?.let { put(CalendarContract.Events.DTEND, it) }
100
108
  input.description?.let { put(CalendarContract.Events.DESCRIPTION, it) }
101
109
  input.availability?.let { put(CalendarContract.Events.AVAILABILITY, it) }
102
110
  input.organizer?.let { put(CalendarContract.Events.ORGANIZER, it) }
@@ -113,14 +121,55 @@ class CapacitorCalendar(
113
121
 
114
122
  fun modifyEvent(input: ModifyEvent) {
115
123
  val cr = plugin.context.contentResolver
124
+ val updatingDates = input.startDate != null || input.endDate != null
125
+ val settingAllDay = input.isAllDay == 1
126
+ // Normalize when setting all-day, or when editing dates on an existing all-day event
127
+ // without re-sending isAllDay. Reading ALL_DAY fails closed (EventNotFound) so a missed
128
+ // row cannot silently skip normalization and reintroduce the wrong-day bug.
129
+ val treatAsAllDay =
130
+ when {
131
+ input.isAllDay == 1 -> true
132
+ input.isAllDay == 0 -> false
133
+ updatingDates -> ImplementationHelper.isEventAllDay(cr, input.id)
134
+ else -> false
135
+ }
136
+ // Explicit isAllDay + startDate shares create's contract (inclusive local days; omitted
137
+ // endDate → one-day exclusive DTEND). Date-only patches on an existing all-day event
138
+ // normalize only the fields the caller sent, so a start-only update cannot truncate a
139
+ // multi-day span.
140
+ val (startDate, endDate) =
141
+ when {
142
+ !treatAsAllDay -> {
143
+ Pair(input.startDate, input.endDate)
144
+ }
145
+
146
+ settingAllDay && input.startDate != null -> {
147
+ ImplementationHelper.normalizeAllDayTimes(input.startDate, input.endDate)
148
+ }
149
+
150
+ else -> {
151
+ Pair(
152
+ input.startDate?.let { ImplementationHelper.utcMidnightForLocalDay(it) },
153
+ input.endDate?.let { ImplementationHelper.exclusiveUtcEndForInclusiveLocalDay(it) },
154
+ )
155
+ }
156
+ }
157
+ val writeDefaultAllDayEnd = settingAllDay && input.startDate != null && input.endDate == null
116
158
  val values =
117
159
  ContentValues().apply {
118
160
  input.title?.let { put(CalendarContract.Events.TITLE, it) }
119
161
  input.calendarId?.let { put(CalendarContract.Events.CALENDAR_ID, it) }
120
162
  input.location?.let { put(CalendarContract.Events.EVENT_LOCATION, it) }
121
- input.startDate?.let { put(CalendarContract.Events.DTSTART, it) }
122
- input.endDate?.let { put(CalendarContract.Events.DTEND, it) }
163
+ if (input.startDate != null) {
164
+ startDate?.let { put(CalendarContract.Events.DTSTART, it) }
165
+ }
166
+ if (input.endDate != null || writeDefaultAllDayEnd) {
167
+ endDate?.let { put(CalendarContract.Events.DTEND, it) }
168
+ }
123
169
  input.isAllDay?.let { put(CalendarContract.Events.ALL_DAY, it) }
170
+ if (treatAsAllDay) {
171
+ put(CalendarContract.Events.EVENT_TIMEZONE, "UTC")
172
+ }
124
173
  input.description?.let { put(CalendarContract.Events.DESCRIPTION, it) }
125
174
  input.availability?.let { put(CalendarContract.Events.AVAILABILITY, it) }
126
175
  input.organizer?.let { put(CalendarContract.Events.ORGANIZER, it) }
@@ -6,6 +6,7 @@ import dev.barooni.capacitor.calendar.models.templates.JSResult
6
6
  class CreateEventWithPromptResult : JSResult {
7
7
  override fun toJSON(): JSObject {
8
8
  val result = JSObject()
9
+ result.put("ics", null)
9
10
  result.put("id", null)
10
11
  return result
11
12
  }
@@ -17,6 +17,7 @@ data class GetDefaultCalendarResult(
17
17
  put("title", cal.title)
18
18
  put("internalTitle", cal.internalName)
19
19
  put("color", cal.color)
20
+ put("colorName", null)
20
21
  put("isImmutable", null)
21
22
  put("allowsContentModifications", null)
22
23
  put("type", null)
@@ -22,6 +22,7 @@ data class ListCalendarsResult(
22
22
  obj.put("title", calendar.title)
23
23
  obj.put("internalTitle", calendar.internalName)
24
24
  obj.put("color", calendar.color)
25
+ obj.put("colorName", null)
25
26
  obj.put("isImmutable", null)
26
27
  obj.put("allowsContentModifications", null)
27
28
  obj.put("type", null)
@@ -26,6 +26,86 @@ class ImplementationHelper {
26
26
  timeInMillis = timestamp ?: System.currentTimeMillis()
27
27
  }
28
28
 
29
+ /**
30
+ * Maps a timestamp to UTC midnight of its local calendar day.
31
+ * Required for [CalendarContract.Events] all-day rows (`EVENT_TIMEZONE` = UTC).
32
+ */
33
+ fun utcMidnightForLocalDay(timestamp: Long): Long {
34
+ val local = Calendar.getInstance().apply { timeInMillis = timestamp }
35
+ return Calendar
36
+ .getInstance(TimeZone.getTimeZone("UTC"))
37
+ .apply {
38
+ clear()
39
+ set(
40
+ local.get(Calendar.YEAR),
41
+ local.get(Calendar.MONTH),
42
+ local.get(Calendar.DAY_OF_MONTH),
43
+ )
44
+ }.timeInMillis
45
+ }
46
+
47
+ /**
48
+ * Inclusive local-day end → exclusive UTC midnight `DTEND` for all-day rows.
49
+ */
50
+ fun exclusiveUtcEndForInclusiveLocalDay(timestamp: Long): Long =
51
+ Calendar
52
+ .getInstance(TimeZone.getTimeZone("UTC"))
53
+ .apply {
54
+ timeInMillis = utcMidnightForLocalDay(timestamp)
55
+ add(Calendar.DAY_OF_MONTH, 1)
56
+ }.timeInMillis
57
+
58
+ /**
59
+ * Plugin all-day dates use local calendar days with an inclusive end (same as iOS).
60
+ * [CalendarContract] needs UTC midnight boundaries and an exclusive `DTEND`.
61
+ * When [endDate] is omitted, uses a one-day span from [startDate].
62
+ */
63
+ fun normalizeAllDayTimes(
64
+ startDate: Long?,
65
+ endDate: Long?,
66
+ ): Pair<Long?, Long?> {
67
+ val start = startDate?.let { utcMidnightForLocalDay(it) }
68
+ val exclusiveEnd =
69
+ when {
70
+ endDate != null -> {
71
+ exclusiveUtcEndForInclusiveLocalDay(endDate)
72
+ }
73
+
74
+ start != null -> {
75
+ Calendar
76
+ .getInstance(TimeZone.getTimeZone("UTC"))
77
+ .apply {
78
+ timeInMillis = start
79
+ add(Calendar.DAY_OF_MONTH, 1)
80
+ }.timeInMillis
81
+ }
82
+
83
+ else -> {
84
+ null
85
+ }
86
+ }
87
+ return Pair(start, exclusiveEnd)
88
+ }
89
+
90
+ /**
91
+ * Reads [CalendarContract.Events.ALL_DAY] for an existing event.
92
+ * Throws [PluginError.EventNotFound] when the row is missing or unreadable,
93
+ * so callers that need the flag cannot silently skip all-day normalization.
94
+ */
95
+ fun isEventAllDay(
96
+ cr: ContentResolver,
97
+ eventId: Long,
98
+ ): Boolean {
99
+ val uri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventId)
100
+ val projection = arrayOf(CalendarContract.Events.ALL_DAY)
101
+ cr.query(uri, projection, null, null, null)?.use { cursor ->
102
+ if (cursor.moveToFirst()) {
103
+ return cursor.getInt(0) == 1
104
+ }
105
+ }
106
+ throw PluginError.EventNotFound
107
+ }
108
+
29
109
  fun jsArrayToComaSeparatedString(array: JSArray?): String? {
30
110
  val list = array?.toList<Any>() ?: return null
31
111