@ebarooni/capacitor-calendar 8.11.0 → 8.12.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 (82) hide show
  1. package/README.md +279 -103
  2. package/android/src/main/java/dev/barooni/capacitor/calendar/CapacitorCalendarPlugin.kt +37 -0
  3. package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CalendarChangeObserver.kt +181 -0
  4. package/android/src/main/java/dev/barooni/capacitor/calendar/implementation/CapacitorCalendar.kt +58 -8
  5. package/android/src/main/java/dev/barooni/capacitor/calendar/models/data/EventDeleteInfo.kt +6 -0
  6. package/android/src/main/java/dev/barooni/capacitor/calendar/models/inputs/StartListeningInput.kt +20 -0
  7. package/android/src/main/java/dev/barooni/capacitor/calendar/utils/ImplementationHelper.kt +88 -67
  8. package/dist/docs.json +1383 -976
  9. package/dist/esm/definitions.d.ts +2 -1
  10. package/dist/esm/definitions.js.map +1 -1
  11. package/dist/esm/index.d.ts +12 -2
  12. package/dist/esm/index.js +4 -1
  13. package/dist/esm/index.js.map +1 -1
  14. package/dist/esm/schemas/enums/capacitor-calendar-error-code.d.ts +2 -2
  15. package/dist/esm/schemas/enums/capacitor-calendar-error-code.js +2 -2
  16. package/dist/esm/schemas/enums/capacitor-calendar-error-code.js.map +1 -1
  17. package/dist/esm/schemas/interfaces/calendar-changed-event.d.ts +52 -0
  18. package/dist/esm/schemas/interfaces/calendar-changed-event.js +2 -0
  19. package/dist/esm/schemas/interfaces/calendar-changed-event.js.map +1 -0
  20. package/dist/esm/schemas/interfaces/calendar-links.d.ts +32 -0
  21. package/dist/esm/schemas/interfaces/calendar-links.js +2 -0
  22. package/dist/esm/schemas/interfaces/calendar-links.js.map +1 -0
  23. package/dist/esm/schemas/interfaces/create-event-options.d.ts +18 -0
  24. package/dist/esm/schemas/interfaces/create-event-options.js.map +1 -1
  25. package/dist/esm/schemas/interfaces/create-event-with-prompt-options.d.ts +9 -0
  26. package/dist/esm/schemas/interfaces/create-event-with-prompt-options.js.map +1 -1
  27. package/dist/esm/schemas/interfaces/create-ics-file-options.d.ts +20 -0
  28. package/dist/esm/schemas/interfaces/create-ics-file-options.js +2 -0
  29. package/dist/esm/schemas/interfaces/create-ics-file-options.js.map +1 -0
  30. package/dist/esm/schemas/interfaces/open-calendar-options.d.ts +9 -0
  31. package/dist/esm/schemas/interfaces/open-calendar-options.js.map +1 -1
  32. package/dist/esm/schemas/interfaces/share-ics-file-options.d.ts +17 -0
  33. package/dist/esm/schemas/interfaces/share-ics-file-options.js +2 -0
  34. package/dist/esm/schemas/interfaces/share-ics-file-options.js.map +1 -0
  35. package/dist/esm/schemas/interfaces/start-listening-options.d.ts +46 -0
  36. package/dist/esm/schemas/interfaces/start-listening-options.js +2 -0
  37. package/dist/esm/schemas/interfaces/start-listening-options.js.map +1 -0
  38. package/dist/esm/schemas/types/calendar-day-view-provider.d.ts +7 -0
  39. package/dist/esm/schemas/types/calendar-day-view-provider.js +2 -0
  40. package/dist/esm/schemas/types/calendar-day-view-provider.js.map +1 -0
  41. package/dist/esm/schemas/types/calendar-link-provider.d.ts +6 -0
  42. package/dist/esm/schemas/types/calendar-link-provider.js +2 -0
  43. package/dist/esm/schemas/types/calendar-link-provider.js.map +1 -0
  44. package/dist/esm/sub-definitions/calendar-listening.d.ts +49 -0
  45. package/dist/esm/sub-definitions/calendar-listening.js +2 -0
  46. package/dist/esm/sub-definitions/calendar-listening.js.map +1 -0
  47. package/dist/esm/sub-definitions/calendar-operations.d.ts +2 -1
  48. package/dist/esm/sub-definitions/calendar-operations.js.map +1 -1
  49. package/dist/esm/web/calendar-links.d.ts +26 -0
  50. package/dist/esm/web/calendar-links.js +114 -0
  51. package/dist/esm/web/calendar-links.js.map +1 -0
  52. package/dist/esm/web/create-ics-file.d.ts +21 -0
  53. package/dist/esm/web/create-ics-file.js +30 -0
  54. package/dist/esm/web/create-ics-file.js.map +1 -0
  55. package/dist/esm/web/ics.d.ts +11 -0
  56. package/dist/esm/web/ics.js +48 -32
  57. package/dist/esm/web/ics.js.map +1 -1
  58. package/dist/esm/web/share-ics-file.d.ts +21 -0
  59. package/dist/esm/web/share-ics-file.js +46 -0
  60. package/dist/esm/web/share-ics-file.js.map +1 -0
  61. package/dist/esm/web.d.ts +4 -1
  62. package/dist/esm/web.js +18 -4
  63. package/dist/esm/web.js.map +1 -1
  64. package/dist/plugin.cjs.js +292 -72
  65. package/dist/plugin.cjs.js.map +1 -1
  66. package/dist/plugin.js +292 -72
  67. package/dist/plugin.js.map +1 -1
  68. package/ios/Plugin/CapacitorCalendarPlugin.swift +19 -0
  69. package/ios/Plugin/Implementation/CalendarChangeObserver.swift +259 -0
  70. package/ios/Plugin/Implementation/CapacitorCalendar.swift +15 -1
  71. package/ios/Plugin/Models/Inputs/DeleteReminderInput.swift +1 -1
  72. package/ios/Plugin/Models/Inputs/DeleteReminderWithPromptInput.swift +1 -1
  73. package/ios/Plugin/Models/Inputs/DeleteRemindersListInput.swift +1 -1
  74. package/ios/Plugin/Models/Inputs/GetReminderByIdInput.swift +1 -1
  75. package/ios/Plugin/Models/Inputs/ModifyReminderInput.swift +1 -1
  76. package/ios/Plugin/Models/Inputs/StartListeningInput.swift +26 -0
  77. package/ios/Plugin/Models/Inputs/UpdateRemindersListInput.swift +1 -1
  78. package/ios/Plugin/PluginConfig.swift +2 -0
  79. package/ios/Plugin/PluginError.swift +25 -3
  80. package/ios/Plugin/Utils/ImplementationHelper.swift +16 -30
  81. package/ios/Plugin/Utils/PluginCallRejecter.swift +13 -0
  82. package/package.json +1 -1
@@ -327,14 +327,14 @@ exports.CapacitorCalendarErrorCode = void 0;
327
327
  */
328
328
  CapacitorCalendarErrorCode["IoError"] = "EB-CLDR-0004";
329
329
  /**
330
- * The device cannot open the calendar UI, reminders UI, or target URL.
330
+ * The device cannot open the calendar UI, reminders UI, or target URL. Also used on iOS for a missing view controller and a calendar chooser that is already open.
331
331
  *
332
332
  * @since 8.10.0
333
333
  */
334
334
  CapacitorCalendarErrorCode["NotSupported"] = "EB-CLDR-0005";
335
335
  /**
336
336
  * Calendar access was denied.
337
- * On Android, calendar operations that fail with a permission error reject with this code. Permission check and request APIs still resolve `"denied"` on Android and iOS.
337
+ * On Android and iOS, calendar operations that fail with a permission error reject with this code. Permission check and request APIs still resolve `"denied"` on Android and iOS.
338
338
  *
339
339
  * @since 8.10.0
340
340
  */
@@ -449,43 +449,6 @@ exports.ReminderRecurrenceFrequency = void 0;
449
449
  ReminderRecurrenceFrequency[ReminderRecurrenceFrequency["YEARLY"] = 3] = "YEARLY";
450
450
  })(exports.ReminderRecurrenceFrequency || (exports.ReminderRecurrenceFrequency = {}));
451
451
 
452
- /**
453
- * Triggers a browser download for an `.ics` `File`.
454
- * Resolves after the object URL is revoked.
455
- *
456
- * @throws If `document` or `URL` is not available.
457
- *
458
- * @example
459
- * const { ics } = await CapacitorCalendar.createEvent({
460
- * title: 'Team standup',
461
- * icsFileName: 'team-standup.ics',
462
- * });
463
- * if (ics) {
464
- * await downloadIcsFile(ics);
465
- * }
466
- *
467
- * @since 8.5.0
468
- */
469
- async function downloadIcsFile(file) {
470
- if (typeof document === 'undefined' || typeof URL === 'undefined') {
471
- throw new Error('downloadIcsFile requires a browser document environment.');
472
- }
473
- const url = URL.createObjectURL(file);
474
- const link = document.createElement('a');
475
- link.href = url;
476
- link.download = file.name.length > 0 ? file.name : 'event.ics';
477
- document.body.appendChild(link);
478
- link.click();
479
- link.remove();
480
- // Delay revoke so the browser can start the download
481
- await new Promise((resolve) => setTimeout(resolve, 1000));
482
- URL.revokeObjectURL(url);
483
- }
484
-
485
- const CapacitorCalendar = core.registerPlugin('CapacitorCalendar', {
486
- web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorCalendarWeb()),
487
- });
488
-
489
452
  const HOUR_MS = 60 * 60 * 1000;
490
453
  const DAY_MS$1 = 24 * HOUR_MS;
491
454
  const CRLF = '\r\n';
@@ -495,18 +458,34 @@ const CRLF = '\r\n';
495
458
  * All-day ends that fall on the start's local day bump to the next day (exclusive `DTEND`).
496
459
  */
497
460
  function buildEventIcs(options) {
498
- var _a;
499
- const startDate = (_a = options.startDate) !== null && _a !== void 0 ? _a : Date.now();
500
- const isAllDay = options.isAllDay === true;
501
- const endDate = resolveEndDate(startDate, options.endDate, options.duration, isAllDay);
461
+ return buildCalendarIcs([options]);
462
+ }
463
+ /**
464
+ * Builds one `VCALENDAR` document with one `VEVENT` for each item in `events`.
465
+ * With method `CANCEL`, each event gets `STATUS:CANCELLED` and a `SEQUENCE` of at least 1.
466
+ */
467
+ function buildCalendarIcs(events, method = 'PUBLISH') {
502
468
  const lines = [
503
469
  'BEGIN:VCALENDAR',
504
470
  'VERSION:2.0',
505
471
  'PRODID:-//ebarooni/capacitor-calendar//EN',
506
472
  'CALSCALE:GREGORIAN',
507
- 'METHOD:PUBLISH',
473
+ `METHOD:${method}`,
474
+ ];
475
+ for (const event of events) {
476
+ lines.push(...buildEventLines(event, method));
477
+ }
478
+ lines.push('END:VCALENDAR');
479
+ return lines.map(foldLine).join(CRLF) + CRLF;
480
+ }
481
+ function buildEventLines(options, method) {
482
+ var _a, _b;
483
+ const startDate = (_a = options.startDate) !== null && _a !== void 0 ? _a : Date.now();
484
+ const isAllDay = options.isAllDay === true;
485
+ const endDate = resolveEndDate(startDate, options.endDate, options.duration, isAllDay);
486
+ const lines = [
508
487
  'BEGIN:VEVENT',
509
- `UID:${generateUid()}`,
488
+ `UID:${options.uid != null && options.uid.length > 0 ? escapeText(options.uid) : generateUid()}`,
510
489
  `DTSTAMP:${formatDateTimeUtc(Date.now())}`,
511
490
  ];
512
491
  if (isAllDay) {
@@ -551,8 +530,15 @@ function buildEventIcs(options) {
551
530
  lines.push(...buildAlarm(minutes));
552
531
  }
553
532
  }
554
- lines.push('END:VEVENT', 'END:VCALENDAR');
555
- return lines.map(foldLine).join(CRLF) + CRLF;
533
+ if (method === 'CANCEL') {
534
+ lines.push('STATUS:CANCELLED');
535
+ }
536
+ const sequence = method === 'CANCEL' ? Math.max(1, (_b = options.sequence) !== null && _b !== void 0 ? _b : 1) : options.sequence;
537
+ if (sequence != null && sequence > 0) {
538
+ lines.push(`SEQUENCE:${Math.floor(sequence)}`);
539
+ }
540
+ lines.push('END:VEVENT');
541
+ return lines;
556
542
  }
557
543
  /**
558
544
  * Resolves the `.ics` download filename.
@@ -744,42 +730,261 @@ function formatParamValue(value) {
744
730
  }
745
731
  /**
746
732
  * Folds a content line so each physical line is at most 75 octets (RFC 5545 §3.1).
733
+ * A continuation line starts with one space, so it holds at most 74 octets of content.
747
734
  */
748
735
  function foldLine(line) {
749
736
  const max = 75;
750
737
  if (byteLength(line) <= max) {
751
738
  return line;
752
739
  }
753
- const chars = [...line];
754
- let result = '';
740
+ const parts = [];
755
741
  let current = '';
756
- for (const ch of chars) {
757
- const next = current + ch;
758
- if (byteLength(next) > max) {
759
- result += result.length === 0 ? current : `${CRLF} ${current}`;
760
- current = ch;
761
- // Continuations are limited to 74 octets of content + leading space = 75
762
- while (byteLength(current) > max - 1) {
763
- // Extremely rare for a single code point; split by taking first unit as-is
764
- result += `${CRLF} ${current}`;
765
- current = '';
766
- break;
767
- }
742
+ let currentBytes = 0;
743
+ for (const ch of line) {
744
+ const chBytes = byteLength(ch);
745
+ const limit = parts.length === 0 ? max : max - 1;
746
+ if (currentBytes + chBytes > limit && current.length > 0) {
747
+ parts.push(current);
748
+ current = '';
749
+ currentBytes = 0;
768
750
  }
769
- else {
770
- current = next;
771
- }
772
- }
773
- if (current.length > 0) {
774
- result += result.length === 0 ? current : `${CRLF} ${current}`;
751
+ current += ch;
752
+ currentBytes += chBytes;
775
753
  }
776
- return result;
754
+ parts.push(current);
755
+ return parts.join(`${CRLF} `);
777
756
  }
778
757
  function byteLength(s) {
779
758
  return new TextEncoder().encode(s).length;
780
759
  }
781
760
 
761
+ /**
762
+ * Builds links that open a web calendar with the event already filled in.
763
+ * The user must confirm in the web calendar. Nothing is saved without that step.
764
+ *
765
+ * Supported fields: `title`, `startDate`, `endDate`, `duration`, `isAllDay`, `description`, `location`.
766
+ * Google Calendar also gets `recurrence` and `attendees`. Alerts and `availability` are not part of any link.
767
+ * Outlook and Yahoo links ignore `recurrence`.
768
+ *
769
+ * @example
770
+ * const { google, outlook } = getCalendarLinks({ title: 'Team standup', startDate: Date.now() });
771
+ * window.open(google, '_blank', 'noopener');
772
+ *
773
+ * @since 8.12.0
774
+ */
775
+ function getCalendarLinks(options) {
776
+ var _a;
777
+ const startDate = (_a = options.startDate) !== null && _a !== void 0 ? _a : Date.now();
778
+ const isAllDay = options.isAllDay === true;
779
+ const endDate = resolveEndDate(startDate, options.endDate, options.duration, isAllDay);
780
+ return {
781
+ google: buildGoogleLink(options, startDate, endDate, isAllDay),
782
+ outlook: buildOutlookLink('https://outlook.live.com', options, startDate, endDate, isAllDay),
783
+ office365: buildOutlookLink('https://outlook.office.com', options, startDate, endDate, isAllDay),
784
+ yahoo: buildYahooLink(options, startDate, endDate, isAllDay),
785
+ };
786
+ }
787
+ /**
788
+ * Builds the link that opens the day view of a web calendar.
789
+ *
790
+ * @throws If `provider` is not `google`, `outlook`, or `office365`.
791
+ *
792
+ * @since 8.12.0
793
+ */
794
+ function getCalendarDayLink(provider, date) {
795
+ const day = new Date(date);
796
+ const datePath = `${day.getFullYear()}/${day.getMonth() + 1}/${day.getDate()}`;
797
+ switch (provider) {
798
+ case 'google':
799
+ return `https://calendar.google.com/calendar/r/day/${datePath}`;
800
+ case 'outlook':
801
+ return `https://outlook.live.com/calendar/0/view/day/${datePath}`;
802
+ case 'office365':
803
+ return `https://outlook.office.com/calendar/0/view/day/${datePath}`;
804
+ default:
805
+ throw new Error(`Unsupported calendar provider: ${String(provider)}. Use google, outlook, or office365.`);
806
+ }
807
+ }
808
+ function buildGoogleLink(options, startDate, endDate, isAllDay) {
809
+ var _a;
810
+ const params = new URLSearchParams();
811
+ params.set('action', 'TEMPLATE');
812
+ params.set('text', options.title);
813
+ params.set('dates', `${formatCompactDate(startDate, isAllDay)}/${formatCompactDate(endDate, isAllDay)}`);
814
+ setIfPresent(params, 'details', options.description);
815
+ setIfPresent(params, 'location', options.location);
816
+ if (options.recurrence != null) {
817
+ params.set('recur', `RRULE:${toRRule(options.recurrence, isAllDay)}`);
818
+ }
819
+ const emails = ((_a = options.attendees) !== null && _a !== void 0 ? _a : []).map((guest) => guest.email).filter((email) => email.length > 0);
820
+ if (emails.length > 0) {
821
+ params.set('add', emails.join(','));
822
+ }
823
+ return `https://calendar.google.com/calendar/render?${toQuery(params)}`;
824
+ }
825
+ function buildOutlookLink(host, options, startDate, endDate, isAllDay) {
826
+ const params = new URLSearchParams();
827
+ params.set('path', '/calendar/action/compose');
828
+ params.set('rru', 'addevent');
829
+ params.set('subject', options.title);
830
+ params.set('startdt', isAllDay ? formatIsoDate(startDate) : new Date(startDate).toISOString());
831
+ params.set('enddt', isAllDay ? formatIsoDate(endDate) : new Date(endDate).toISOString());
832
+ if (isAllDay) {
833
+ params.set('allday', 'true');
834
+ }
835
+ setIfPresent(params, 'body', options.description);
836
+ setIfPresent(params, 'location', options.location);
837
+ return `${host}/calendar/0/deeplink/compose?${toQuery(params)}`;
838
+ }
839
+ function buildYahooLink(options, startDate, endDate, isAllDay) {
840
+ const params = new URLSearchParams();
841
+ params.set('v', '60');
842
+ params.set('title', options.title);
843
+ params.set('st', formatCompactDate(startDate, isAllDay));
844
+ if (isAllDay) {
845
+ params.set('dur', 'allday');
846
+ }
847
+ else {
848
+ params.set('et', formatCompactDate(endDate, false));
849
+ }
850
+ setIfPresent(params, 'desc', options.description);
851
+ setIfPresent(params, 'in_loc', options.location);
852
+ return `https://calendar.yahoo.com/?${toQuery(params)}`;
853
+ }
854
+ /**
855
+ * Encodes spaces as `%20`, not `+`.
856
+ * Outlook shows a literal `+` when the link goes through its sign-in redirect.
857
+ */
858
+ function toQuery(params) {
859
+ return [...params].map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join('&');
860
+ }
861
+ function setIfPresent(params, key, value) {
862
+ if (value != null && value.length > 0) {
863
+ params.set(key, value);
864
+ }
865
+ }
866
+ function formatCompactDate(ms, isAllDay) {
867
+ return isAllDay ? formatDateOnlyLocal(ms) : formatDateTimeUtc(ms);
868
+ }
869
+ function formatIsoDate(ms) {
870
+ const compact = formatDateOnlyLocal(ms);
871
+ return `${compact.slice(0, 4)}-${compact.slice(4, 6)}-${compact.slice(6, 8)}`;
872
+ }
873
+
874
+ /**
875
+ * Builds an `.ics` `File` with one `VEVENT` for each event.
876
+ * Use it to export many events in one file, or to cancel events you exported before.
877
+ *
878
+ * @throws If `events` is empty.
879
+ *
880
+ * @example
881
+ * const file = createIcsFile([
882
+ * { title: 'Kickoff', startDate: Date.now(), uid: 'kickoff-1' },
883
+ * { title: 'Review', startDate: Date.now() + 86400000, uid: 'review-1' },
884
+ * ], { fileName: 'project.ics' });
885
+ *
886
+ * @example
887
+ * // Ask calendar apps to remove an event that was imported before
888
+ * const file = createIcsFile({ title: 'Kickoff', uid: 'kickoff-1', sequence: 1 }, { method: 'CANCEL' });
889
+ *
890
+ * @since 8.12.0
891
+ */
892
+ function createIcsFile(events, options = {}) {
893
+ var _a, _b;
894
+ const list = Array.isArray(events) ? events : [events];
895
+ if (list.length === 0) {
896
+ throw new Error('createIcsFile requires at least one event.');
897
+ }
898
+ const content = buildCalendarIcs(list, (_a = options.method) !== null && _a !== void 0 ? _a : 'PUBLISH');
899
+ const name = resolveIcsFileName({ icsFileName: (_b = options.fileName) !== null && _b !== void 0 ? _b : list[0].icsFileName, title: list[0].title });
900
+ return new File([content], name, { type: 'text/calendar;charset=utf-8' });
901
+ }
902
+
903
+ /**
904
+ * Triggers a browser download for an `.ics` `File`.
905
+ * Resolves after the object URL is revoked.
906
+ *
907
+ * @throws If `document` or `URL` is not available.
908
+ *
909
+ * @example
910
+ * const { ics } = await CapacitorCalendar.createEvent({
911
+ * title: 'Team standup',
912
+ * icsFileName: 'team-standup.ics',
913
+ * });
914
+ * if (ics) {
915
+ * await downloadIcsFile(ics);
916
+ * }
917
+ *
918
+ * @since 8.5.0
919
+ */
920
+ async function downloadIcsFile(file) {
921
+ if (typeof document === 'undefined' || typeof URL === 'undefined') {
922
+ throw new Error('downloadIcsFile requires a browser document environment.');
923
+ }
924
+ const url = URL.createObjectURL(file);
925
+ const link = document.createElement('a');
926
+ link.href = url;
927
+ link.download = file.name.length > 0 ? file.name : 'event.ics';
928
+ document.body.appendChild(link);
929
+ link.click();
930
+ link.remove();
931
+ // Delay revoke so the browser can start the download
932
+ await new Promise((resolve) => setTimeout(resolve, 1000));
933
+ URL.revokeObjectURL(url);
934
+ }
935
+
936
+ /**
937
+ * Opens the share sheet of the device for an `.ics` `File`.
938
+ * When the browser cannot share files, the file downloads instead.
939
+ * Call it from a user action, such as a click. Browsers reject the share sheet otherwise.
940
+ * Build the file synchronously (for example with `createIcsFile`) so the click still counts when the sheet opens.
941
+ * Some browsers, such as Chrome, do not share `.ics` files and download them instead.
942
+ * Chrome can report that it shares the file and then reject with `NotAllowedError`, so that error also falls back to a download.
943
+ *
944
+ * Resolves `'shared'` after the user picks a target, `'cancelled'` when the user closes the sheet,
945
+ * and `'downloaded'` when the browser fell back to a download.
946
+ *
947
+ * @example
948
+ * button.addEventListener('click', async () => {
949
+ * const file = createIcsFile({ title: 'Team standup', startDate: Date.now() });
950
+ * await shareIcsFile(file, { title: 'Team standup' });
951
+ * });
952
+ *
953
+ * @since 8.12.0
954
+ */
955
+ async function shareIcsFile(file, options = {}) {
956
+ const shareData = { files: [file], title: options.title, text: options.text };
957
+ if (typeof navigator === 'undefined' ||
958
+ typeof navigator.share !== 'function' ||
959
+ typeof navigator.canShare !== 'function' ||
960
+ !navigator.canShare(shareData)) {
961
+ await downloadIcsFile(file);
962
+ return 'downloaded';
963
+ }
964
+ try {
965
+ await navigator.share(shareData);
966
+ return 'shared';
967
+ }
968
+ catch (error) {
969
+ if (error instanceof DOMException && error.name === 'AbortError') {
970
+ return 'cancelled';
971
+ }
972
+ // Chrome: canShare() accepts the file, but share() rejects the file type with "Permission denied"
973
+ if (error instanceof DOMException && error.name === 'NotAllowedError') {
974
+ await downloadIcsFile(file);
975
+ return 'downloaded';
976
+ }
977
+ throw error;
978
+ }
979
+ }
980
+
981
+ const CapacitorCalendar = core.registerPlugin('CapacitorCalendar', {
982
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorCalendarWeb()),
983
+ });
984
+
782
985
  const DAY_MS = 24 * 60 * 60 * 1000;
986
+ const WEB_HINT = 'The web has no calendar store. Use createEvent or createIcsFile for an .ics file, ' +
987
+ 'getCalendarLinks for web calendar links, and shareIcsFile or downloadIcsFile to hand the file to the user.';
783
988
  class CapacitorCalendarWeb extends core.WebPlugin {
784
989
  checkPermission(_options) {
785
990
  return this.throwUnimplemented(this.checkPermission.name);
@@ -813,7 +1018,7 @@ class CapacitorCalendarWeb extends core.WebPlugin {
813
1018
  }
814
1019
  async createEventWithPrompt(options = {}) {
815
1020
  try {
816
- const confirmed = window.confirm(buildCreateEventConfirmMessage(options));
1021
+ const confirmed = options.skipPrompt === true || window.confirm(buildCreateEventConfirmMessage(options));
817
1022
  if (!confirmed) {
818
1023
  return { id: null, ics: null };
819
1024
  }
@@ -863,6 +1068,12 @@ class CapacitorCalendarWeb extends core.WebPlugin {
863
1068
  fetchAllCalendarSources() {
864
1069
  return this.throwUnimplemented(this.fetchAllCalendarSources.name);
865
1070
  }
1071
+ startListening(_options) {
1072
+ return this.throwUnimplemented(this.startListening.name);
1073
+ }
1074
+ stopListening() {
1075
+ return this.throwUnimplemented(this.stopListening.name);
1076
+ }
866
1077
  listCalendars() {
867
1078
  return this.throwUnimplemented(this.listCalendars.name);
868
1079
  }
@@ -881,8 +1092,13 @@ class CapacitorCalendarWeb extends core.WebPlugin {
881
1092
  getRemindersLists() {
882
1093
  return this.throwUnimplemented(this.getRemindersLists.name);
883
1094
  }
884
- openCalendar(_options) {
885
- return this.throwUnimplemented(this.openCalendar.name);
1095
+ async openCalendar(options) {
1096
+ var _a;
1097
+ if ((options === null || options === void 0 ? void 0 : options.provider) == null) {
1098
+ return this.throwUnimplemented(this.openCalendar.name);
1099
+ }
1100
+ const url = getCalendarDayLink(options.provider, (_a = options.date) !== null && _a !== void 0 ? _a : Date.now());
1101
+ window.open(url, '_blank', 'noopener');
886
1102
  }
887
1103
  createCalendar(_options) {
888
1104
  return this.throwUnimplemented(this.createCalendar.name);
@@ -933,7 +1149,7 @@ class CapacitorCalendarWeb extends core.WebPlugin {
933
1149
  return this.throwUnimplemented(this.updateRemindersList.name);
934
1150
  }
935
1151
  throwUnimplemented(methodName) {
936
- return Promise.reject(this.unimplemented(`${methodName} is not implemented on the web.`));
1152
+ return Promise.reject(this.unimplemented(`${methodName} is not implemented on the web. ${WEB_HINT}`));
937
1153
  }
938
1154
  }
939
1155
  function mapPromptOptionsToCreateEvent(options) {
@@ -1015,5 +1231,9 @@ var web = /*#__PURE__*/Object.freeze({
1015
1231
  });
1016
1232
 
1017
1233
  exports.CapacitorCalendar = CapacitorCalendar;
1234
+ exports.createIcsFile = createIcsFile;
1018
1235
  exports.downloadIcsFile = downloadIcsFile;
1236
+ exports.getCalendarDayLink = getCalendarDayLink;
1237
+ exports.getCalendarLinks = getCalendarLinks;
1238
+ exports.shareIcsFile = shareIcsFile;
1019
1239
  //# sourceMappingURL=plugin.cjs.js.map