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