@capawesome/capacitor-mail-composer 0.0.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/CapawesomeCapacitorMailComposer.podspec +17 -0
  2. package/LICENSE +21 -0
  3. package/Package.swift +28 -0
  4. package/README.md +208 -0
  5. package/android/build.gradle +58 -0
  6. package/android/src/main/AndroidManifest.xml +8 -0
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mailcomposer/MailComposer.java +120 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mailcomposer/MailComposerPlugin.java +101 -0
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mailcomposer/classes/CustomException.java +20 -0
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mailcomposer/classes/CustomExceptions.java +9 -0
  11. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mailcomposer/classes/options/ComposeMailOptions.java +86 -0
  12. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mailcomposer/classes/results/CanComposeMailResult.java +22 -0
  13. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mailcomposer/classes/results/ComposeMailResult.java +23 -0
  14. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mailcomposer/interfaces/Callback.java +5 -0
  15. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mailcomposer/interfaces/NonEmptyResultCallback.java +7 -0
  16. package/android/src/main/java/io/capawesome/capacitorjs/plugins/mailcomposer/interfaces/Result.java +7 -0
  17. package/android/src/main/res/.gitkeep +0 -0
  18. package/dist/docs.json +261 -0
  19. package/dist/esm/definitions.d.ts +133 -0
  20. package/dist/esm/definitions.js +19 -0
  21. package/dist/esm/definitions.js.map +1 -0
  22. package/dist/esm/index.d.ts +4 -0
  23. package/dist/esm/index.js +7 -0
  24. package/dist/esm/index.js.map +1 -0
  25. package/dist/esm/web.d.ts +8 -0
  26. package/dist/esm/web.js +35 -0
  27. package/dist/esm/web.js.map +1 -0
  28. package/dist/plugin.cjs.js +68 -0
  29. package/dist/plugin.cjs.js.map +1 -0
  30. package/dist/plugin.js +71 -0
  31. package/dist/plugin.js.map +1 -0
  32. package/ios/Plugin/Classes/Options/ComposeMailOptions.swift +22 -0
  33. package/ios/Plugin/Classes/Results/CanComposeMailResult.swift +16 -0
  34. package/ios/Plugin/Classes/Results/ComposeMailResult.swift +16 -0
  35. package/ios/Plugin/Enums/CustomError.swift +31 -0
  36. package/ios/Plugin/Info.plist +24 -0
  37. package/ios/Plugin/MailComposer.swift +88 -0
  38. package/ios/Plugin/MailComposerPlugin.swift +62 -0
  39. package/ios/Plugin/Protocols/Result.swift +5 -0
  40. package/package.json +91 -0
@@ -0,0 +1,22 @@
1
+ package io.capawesome.capacitorjs.plugins.mailcomposer.classes.results;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.mailcomposer.interfaces.Result;
6
+
7
+ public class CanComposeMailResult implements Result {
8
+
9
+ private final boolean canCompose;
10
+
11
+ public CanComposeMailResult(boolean canCompose) {
12
+ this.canCompose = canCompose;
13
+ }
14
+
15
+ @Override
16
+ @NonNull
17
+ public JSObject toJSObject() {
18
+ JSObject result = new JSObject();
19
+ result.put("canCompose", canCompose);
20
+ return result;
21
+ }
22
+ }
@@ -0,0 +1,23 @@
1
+ package io.capawesome.capacitorjs.plugins.mailcomposer.classes.results;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.mailcomposer.interfaces.Result;
6
+
7
+ public class ComposeMailResult implements Result {
8
+
9
+ @NonNull
10
+ private final String status;
11
+
12
+ public ComposeMailResult(@NonNull String status) {
13
+ this.status = status;
14
+ }
15
+
16
+ @Override
17
+ @NonNull
18
+ public JSObject toJSObject() {
19
+ JSObject result = new JSObject();
20
+ result.put("status", status);
21
+ return result;
22
+ }
23
+ }
@@ -0,0 +1,5 @@
1
+ package io.capawesome.capacitorjs.plugins.mailcomposer.interfaces;
2
+
3
+ public interface Callback {
4
+ void error(Exception exception);
5
+ }
@@ -0,0 +1,7 @@
1
+ package io.capawesome.capacitorjs.plugins.mailcomposer.interfaces;
2
+
3
+ import androidx.annotation.NonNull;
4
+
5
+ public interface NonEmptyResultCallback<T extends Result> extends Callback {
6
+ void success(@NonNull T result);
7
+ }
@@ -0,0 +1,7 @@
1
+ package io.capawesome.capacitorjs.plugins.mailcomposer.interfaces;
2
+
3
+ import com.getcapacitor.JSObject;
4
+
5
+ public interface Result {
6
+ JSObject toJSObject();
7
+ }
File without changes
package/dist/docs.json ADDED
@@ -0,0 +1,261 @@
1
+ {
2
+ "api": {
3
+ "name": "MailComposerPlugin",
4
+ "slug": "mailcomposerplugin",
5
+ "docs": "",
6
+ "tags": [],
7
+ "methods": [
8
+ {
9
+ "name": "canComposeMail",
10
+ "signature": "() => Promise<CanComposeMailResult>",
11
+ "parameters": [],
12
+ "returns": "Promise<CanComposeMailResult>",
13
+ "tags": [
14
+ {
15
+ "name": "since",
16
+ "text": "0.1.0"
17
+ }
18
+ ],
19
+ "docs": "Check whether the device is able to compose and send emails.\n\nOn iOS, this returns `true` only if a mail account is configured. On\nAndroid, this returns `true` if a mail app is installed. On the web, this\nalways returns `true` (best effort, not verifiable).",
20
+ "complexTypes": [
21
+ "CanComposeMailResult"
22
+ ],
23
+ "slug": "cancomposemail"
24
+ },
25
+ {
26
+ "name": "composeMail",
27
+ "signature": "(options: ComposeMailOptions) => Promise<ComposeMailResult>",
28
+ "parameters": [
29
+ {
30
+ "name": "options",
31
+ "docs": "",
32
+ "type": "ComposeMailOptions"
33
+ }
34
+ ],
35
+ "returns": "Promise<ComposeMailResult>",
36
+ "tags": [
37
+ {
38
+ "name": "since",
39
+ "text": "0.1.0"
40
+ }
41
+ ],
42
+ "docs": "Open the native email composer prefilled with the provided data.\n\nThe user reviews the email and decides whether to send it. The plugin\nnever sends the email itself.",
43
+ "complexTypes": [
44
+ "ComposeMailResult",
45
+ "ComposeMailOptions"
46
+ ],
47
+ "slug": "composemail"
48
+ }
49
+ ],
50
+ "properties": []
51
+ },
52
+ "interfaces": [
53
+ {
54
+ "name": "CanComposeMailResult",
55
+ "slug": "cancomposemailresult",
56
+ "docs": "",
57
+ "tags": [
58
+ {
59
+ "text": "0.1.0",
60
+ "name": "since"
61
+ }
62
+ ],
63
+ "methods": [],
64
+ "properties": [
65
+ {
66
+ "name": "canCompose",
67
+ "tags": [
68
+ {
69
+ "text": "0.1.0",
70
+ "name": "since"
71
+ }
72
+ ],
73
+ "docs": "Whether the device is able to compose and send emails.",
74
+ "complexTypes": [],
75
+ "type": "boolean"
76
+ }
77
+ ]
78
+ },
79
+ {
80
+ "name": "ComposeMailResult",
81
+ "slug": "composemailresult",
82
+ "docs": "",
83
+ "tags": [
84
+ {
85
+ "text": "0.1.0",
86
+ "name": "since"
87
+ }
88
+ ],
89
+ "methods": [],
90
+ "properties": [
91
+ {
92
+ "name": "status",
93
+ "tags": [
94
+ {
95
+ "text": "0.1.0",
96
+ "name": "since"
97
+ }
98
+ ],
99
+ "docs": "The status of the email compose operation.\n\n**Note**: On Android, the status is always `unknown` because the mail\nintent does not return a reliable result.",
100
+ "complexTypes": [
101
+ "MailComposeStatus"
102
+ ],
103
+ "type": "MailComposeStatus"
104
+ }
105
+ ]
106
+ },
107
+ {
108
+ "name": "ComposeMailOptions",
109
+ "slug": "composemailoptions",
110
+ "docs": "",
111
+ "tags": [
112
+ {
113
+ "text": "0.1.0",
114
+ "name": "since"
115
+ }
116
+ ],
117
+ "methods": [],
118
+ "properties": [
119
+ {
120
+ "name": "attachments",
121
+ "tags": [
122
+ {
123
+ "text": "['/path/to/file.pdf']",
124
+ "name": "example"
125
+ },
126
+ {
127
+ "text": "0.1.0",
128
+ "name": "since"
129
+ }
130
+ ],
131
+ "docs": "The absolute file paths or `file://` URIs of the files to attach.\n\nAttachments are not supported on the web.",
132
+ "complexTypes": [],
133
+ "type": "string[] | undefined"
134
+ },
135
+ {
136
+ "name": "bcc",
137
+ "tags": [
138
+ {
139
+ "text": "['secret@example.com']",
140
+ "name": "example"
141
+ },
142
+ {
143
+ "text": "0.1.0",
144
+ "name": "since"
145
+ }
146
+ ],
147
+ "docs": "The email addresses of the blind carbon copy (BCC) recipients.",
148
+ "complexTypes": [],
149
+ "type": "string[] | undefined"
150
+ },
151
+ {
152
+ "name": "body",
153
+ "tags": [
154
+ {
155
+ "text": "'This is the body of the email.'",
156
+ "name": "example"
157
+ },
158
+ {
159
+ "text": "0.1.0",
160
+ "name": "since"
161
+ }
162
+ ],
163
+ "docs": "The body of the email.",
164
+ "complexTypes": [],
165
+ "type": "string | undefined"
166
+ },
167
+ {
168
+ "name": "cc",
169
+ "tags": [
170
+ {
171
+ "text": "['john@example.com']",
172
+ "name": "example"
173
+ },
174
+ {
175
+ "text": "0.1.0",
176
+ "name": "since"
177
+ }
178
+ ],
179
+ "docs": "The email addresses of the carbon copy (CC) recipients.",
180
+ "complexTypes": [],
181
+ "type": "string[] | undefined"
182
+ },
183
+ {
184
+ "name": "isHtml",
185
+ "tags": [
186
+ {
187
+ "text": "false",
188
+ "name": "default"
189
+ },
190
+ {
191
+ "text": "0.1.0",
192
+ "name": "since"
193
+ }
194
+ ],
195
+ "docs": "Whether the body should be interpreted as HTML.\n\n**Note**: On Android, HTML is best-effort as many mail apps ignore it. On\nthe web, HTML is not supported and the body is always sent as plain text.",
196
+ "complexTypes": [],
197
+ "type": "boolean | undefined"
198
+ },
199
+ {
200
+ "name": "subject",
201
+ "tags": [
202
+ {
203
+ "text": "'Hello World'",
204
+ "name": "example"
205
+ },
206
+ {
207
+ "text": "0.1.0",
208
+ "name": "since"
209
+ }
210
+ ],
211
+ "docs": "The subject of the email.",
212
+ "complexTypes": [],
213
+ "type": "string | undefined"
214
+ },
215
+ {
216
+ "name": "to",
217
+ "tags": [
218
+ {
219
+ "text": "['jane@example.com']",
220
+ "name": "example"
221
+ },
222
+ {
223
+ "text": "0.1.0",
224
+ "name": "since"
225
+ }
226
+ ],
227
+ "docs": "The email addresses of the primary recipients.",
228
+ "complexTypes": [],
229
+ "type": "string[] | undefined"
230
+ }
231
+ ]
232
+ }
233
+ ],
234
+ "enums": [],
235
+ "typeAliases": [
236
+ {
237
+ "name": "MailComposeStatus",
238
+ "slug": "mailcomposestatus",
239
+ "docs": "The status of an email compose operation.\n\n- `sent`: The email was sent.\n- `saved`: The email was saved as a draft.\n- `canceled`: The user canceled the operation.\n- `unknown`: The status is unknown.",
240
+ "types": [
241
+ {
242
+ "text": "'sent'",
243
+ "complexTypes": []
244
+ },
245
+ {
246
+ "text": "'saved'",
247
+ "complexTypes": []
248
+ },
249
+ {
250
+ "text": "'canceled'",
251
+ "complexTypes": []
252
+ },
253
+ {
254
+ "text": "'unknown'",
255
+ "complexTypes": []
256
+ }
257
+ ]
258
+ }
259
+ ],
260
+ "pluginConfigs": []
261
+ }
@@ -0,0 +1,133 @@
1
+ export interface MailComposerPlugin {
2
+ /**
3
+ * Check whether the device is able to compose and send emails.
4
+ *
5
+ * On iOS, this returns `true` only if a mail account is configured. On
6
+ * Android, this returns `true` if a mail app is installed. On the web, this
7
+ * always returns `true` (best effort, not verifiable).
8
+ *
9
+ * @since 0.1.0
10
+ */
11
+ canComposeMail(): Promise<CanComposeMailResult>;
12
+ /**
13
+ * Open the native email composer prefilled with the provided data.
14
+ *
15
+ * The user reviews the email and decides whether to send it. The plugin
16
+ * never sends the email itself.
17
+ *
18
+ * @since 0.1.0
19
+ */
20
+ composeMail(options: ComposeMailOptions): Promise<ComposeMailResult>;
21
+ }
22
+ /**
23
+ * @since 0.1.0
24
+ */
25
+ export interface CanComposeMailResult {
26
+ /**
27
+ * Whether the device is able to compose and send emails.
28
+ *
29
+ * @since 0.1.0
30
+ */
31
+ canCompose: boolean;
32
+ }
33
+ /**
34
+ * @since 0.1.0
35
+ */
36
+ export interface ComposeMailOptions {
37
+ /**
38
+ * The absolute file paths or `file://` URIs of the files to attach.
39
+ *
40
+ * Attachments are not supported on the web.
41
+ *
42
+ * @example ['/path/to/file.pdf']
43
+ * @since 0.1.0
44
+ */
45
+ attachments?: string[];
46
+ /**
47
+ * The email addresses of the blind carbon copy (BCC) recipients.
48
+ *
49
+ * @example ['secret@example.com']
50
+ * @since 0.1.0
51
+ */
52
+ bcc?: string[];
53
+ /**
54
+ * The body of the email.
55
+ *
56
+ * @example 'This is the body of the email.'
57
+ * @since 0.1.0
58
+ */
59
+ body?: string;
60
+ /**
61
+ * The email addresses of the carbon copy (CC) recipients.
62
+ *
63
+ * @example ['john@example.com']
64
+ * @since 0.1.0
65
+ */
66
+ cc?: string[];
67
+ /**
68
+ * Whether the body should be interpreted as HTML.
69
+ *
70
+ * **Note**: On Android, HTML is best-effort as many mail apps ignore it. On
71
+ * the web, HTML is not supported and the body is always sent as plain text.
72
+ *
73
+ * @default false
74
+ * @since 0.1.0
75
+ */
76
+ isHtml?: boolean;
77
+ /**
78
+ * The subject of the email.
79
+ *
80
+ * @example 'Hello World'
81
+ * @since 0.1.0
82
+ */
83
+ subject?: string;
84
+ /**
85
+ * The email addresses of the primary recipients.
86
+ *
87
+ * @example ['jane@example.com']
88
+ * @since 0.1.0
89
+ */
90
+ to?: string[];
91
+ }
92
+ /**
93
+ * @since 0.1.0
94
+ */
95
+ export interface ComposeMailResult {
96
+ /**
97
+ * The status of the email compose operation.
98
+ *
99
+ * **Note**: On Android, the status is always `unknown` because the mail
100
+ * intent does not return a reliable result.
101
+ *
102
+ * @since 0.1.0
103
+ */
104
+ status: MailComposeStatus;
105
+ }
106
+ /**
107
+ * The status of an email compose operation.
108
+ *
109
+ * - `sent`: The email was sent.
110
+ * - `saved`: The email was saved as a draft.
111
+ * - `canceled`: The user canceled the operation.
112
+ * - `unknown`: The status is unknown.
113
+ *
114
+ * @since 0.1.0
115
+ */
116
+ export type MailComposeStatus = 'sent' | 'saved' | 'canceled' | 'unknown';
117
+ /**
118
+ * @since 0.1.0
119
+ */
120
+ export declare enum ErrorCode {
121
+ /**
122
+ * An attachment could not be found at the provided path.
123
+ *
124
+ * @since 0.1.0
125
+ */
126
+ AttachmentNotFound = "ATTACHMENT_NOT_FOUND",
127
+ /**
128
+ * The email could not be composed.
129
+ *
130
+ * @since 0.1.0
131
+ */
132
+ ComposeFailed = "COMPOSE_FAILED"
133
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @since 0.1.0
3
+ */
4
+ export var ErrorCode;
5
+ (function (ErrorCode) {
6
+ /**
7
+ * An attachment could not be found at the provided path.
8
+ *
9
+ * @since 0.1.0
10
+ */
11
+ ErrorCode["AttachmentNotFound"] = "ATTACHMENT_NOT_FOUND";
12
+ /**
13
+ * The email could not be composed.
14
+ *
15
+ * @since 0.1.0
16
+ */
17
+ ErrorCode["ComposeFailed"] = "COMPOSE_FAILED";
18
+ })(ErrorCode || (ErrorCode = {}));
19
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAyHA;;GAEG;AACH,MAAM,CAAN,IAAY,SAaX;AAbD,WAAY,SAAS;IACnB;;;;OAIG;IACH,wDAA2C,CAAA;IAC3C;;;;OAIG;IACH,6CAAgC,CAAA;AAClC,CAAC,EAbW,SAAS,KAAT,SAAS,QAapB","sourcesContent":["export interface MailComposerPlugin {\n /**\n * Check whether the device is able to compose and send emails.\n *\n * On iOS, this returns `true` only if a mail account is configured. On\n * Android, this returns `true` if a mail app is installed. On the web, this\n * always returns `true` (best effort, not verifiable).\n *\n * @since 0.1.0\n */\n canComposeMail(): Promise<CanComposeMailResult>;\n /**\n * Open the native email composer prefilled with the provided data.\n *\n * The user reviews the email and decides whether to send it. The plugin\n * never sends the email itself.\n *\n * @since 0.1.0\n */\n composeMail(options: ComposeMailOptions): Promise<ComposeMailResult>;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface CanComposeMailResult {\n /**\n * Whether the device is able to compose and send emails.\n *\n * @since 0.1.0\n */\n canCompose: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface ComposeMailOptions {\n /**\n * The absolute file paths or `file://` URIs of the files to attach.\n *\n * Attachments are not supported on the web.\n *\n * @example ['/path/to/file.pdf']\n * @since 0.1.0\n */\n attachments?: string[];\n /**\n * The email addresses of the blind carbon copy (BCC) recipients.\n *\n * @example ['secret@example.com']\n * @since 0.1.0\n */\n bcc?: string[];\n /**\n * The body of the email.\n *\n * @example 'This is the body of the email.'\n * @since 0.1.0\n */\n body?: string;\n /**\n * The email addresses of the carbon copy (CC) recipients.\n *\n * @example ['john@example.com']\n * @since 0.1.0\n */\n cc?: string[];\n /**\n * Whether the body should be interpreted as HTML.\n *\n * **Note**: On Android, HTML is best-effort as many mail apps ignore it. On\n * the web, HTML is not supported and the body is always sent as plain text.\n *\n * @default false\n * @since 0.1.0\n */\n isHtml?: boolean;\n /**\n * The subject of the email.\n *\n * @example 'Hello World'\n * @since 0.1.0\n */\n subject?: string;\n /**\n * The email addresses of the primary recipients.\n *\n * @example ['jane@example.com']\n * @since 0.1.0\n */\n to?: string[];\n}\n\n/**\n * @since 0.1.0\n */\nexport interface ComposeMailResult {\n /**\n * The status of the email compose operation.\n *\n * **Note**: On Android, the status is always `unknown` because the mail\n * intent does not return a reliable result.\n *\n * @since 0.1.0\n */\n status: MailComposeStatus;\n}\n\n/**\n * The status of an email compose operation.\n *\n * - `sent`: The email was sent.\n * - `saved`: The email was saved as a draft.\n * - `canceled`: The user canceled the operation.\n * - `unknown`: The status is unknown.\n *\n * @since 0.1.0\n */\nexport type MailComposeStatus = 'sent' | 'saved' | 'canceled' | 'unknown';\n\n/**\n * @since 0.1.0\n */\nexport enum ErrorCode {\n /**\n * An attachment could not be found at the provided path.\n *\n * @since 0.1.0\n */\n AttachmentNotFound = 'ATTACHMENT_NOT_FOUND',\n /**\n * The email could not be composed.\n *\n * @since 0.1.0\n */\n ComposeFailed = 'COMPOSE_FAILED',\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { MailComposerPlugin } from './definitions';
2
+ declare const MailComposer: MailComposerPlugin;
3
+ export * from './definitions';
4
+ export { MailComposer };
@@ -0,0 +1,7 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const MailComposer = registerPlugin('MailComposer', {
3
+ web: () => import('./web').then(m => new m.MailComposerWeb()),
4
+ });
5
+ export * from './definitions';
6
+ export { MailComposer };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,YAAY,GAAG,cAAc,CAAqB,cAAc,EAAE;IACtE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;CAC9D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { MailComposerPlugin } from './definitions';\n\nconst MailComposer = registerPlugin<MailComposerPlugin>('MailComposer', {\n web: () => import('./web').then(m => new m.MailComposerWeb()),\n});\n\nexport * from './definitions';\nexport { MailComposer };\n"]}
@@ -0,0 +1,8 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { CanComposeMailResult, ComposeMailOptions, ComposeMailResult, MailComposerPlugin } from './definitions';
3
+ export declare class MailComposerWeb extends WebPlugin implements MailComposerPlugin {
4
+ private static readonly errorAttachmentsNotSupported;
5
+ canComposeMail(): Promise<CanComposeMailResult>;
6
+ composeMail(options: ComposeMailOptions): Promise<ComposeMailResult>;
7
+ private createMailtoUrl;
8
+ }
@@ -0,0 +1,35 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class MailComposerWeb extends WebPlugin {
3
+ async canComposeMail() {
4
+ return { canCompose: true };
5
+ }
6
+ async composeMail(options) {
7
+ if (options.attachments && options.attachments.length > 0) {
8
+ throw new Error(MailComposerWeb.errorAttachmentsNotSupported);
9
+ }
10
+ const url = this.createMailtoUrl(options);
11
+ window.open(url, '_self');
12
+ return { status: 'unknown' };
13
+ }
14
+ createMailtoUrl(options) {
15
+ var _a;
16
+ const to = ((_a = options.to) !== null && _a !== void 0 ? _a : []).join(',');
17
+ const params = new URLSearchParams();
18
+ if (options.cc && options.cc.length > 0) {
19
+ params.set('cc', options.cc.join(','));
20
+ }
21
+ if (options.bcc && options.bcc.length > 0) {
22
+ params.set('bcc', options.bcc.join(','));
23
+ }
24
+ if (options.subject) {
25
+ params.set('subject', options.subject);
26
+ }
27
+ if (options.body) {
28
+ params.set('body', options.body);
29
+ }
30
+ const query = params.toString();
31
+ return `mailto:${encodeURIComponent(to)}${query ? `?${query}` : ''}`;
32
+ }
33
+ }
34
+ MailComposerWeb.errorAttachmentsNotSupported = 'Attachments are not supported on the web.';
35
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAI5C,KAAK,CAAC,cAAc;QAClB,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAA2B;QAC3C,IAAI,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1D,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,4BAA4B,CAAC,CAAC;QAChE,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC1C,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CA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ult,\n MailComposerPlugin,\n} from './definitions';\n\nexport class MailComposerWeb extends WebPlugin implements MailComposerPlugin {\n private static readonly errorAttachmentsNotSupported =\n 'Attachments are not supported on the web.';\n\n async canComposeMail(): Promise<CanComposeMailResult> {\n return { canCompose: true };\n }\n\n async composeMail(options: ComposeMailOptions): Promise<ComposeMailResult> {\n if (options.attachments && options.attachments.length > 0) {\n throw new Error(MailComposerWeb.errorAttachmentsNotSupported);\n }\n const url = this.createMailtoUrl(options);\n window.open(url, '_self');\n return { status: 'unknown' };\n }\n\n private createMailtoUrl(options: ComposeMailOptions): string {\n const to = (options.to ?? []).join(',');\n const params = new URLSearchParams();\n if (options.cc && options.cc.length > 0) {\n params.set('cc', options.cc.join(','));\n }\n if (options.bcc && options.bcc.length > 0) {\n params.set('bcc', options.bcc.join(','));\n }\n if (options.subject) {\n params.set('subject', options.subject);\n }\n if (options.body) {\n params.set('body', options.body);\n }\n const query = params.toString();\n return `mailto:${encodeURIComponent(to)}${query ? `?${query}` : ''}`;\n }\n}\n"]}
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ /**
6
+ * @since 0.1.0
7
+ */
8
+ exports.ErrorCode = void 0;
9
+ (function (ErrorCode) {
10
+ /**
11
+ * An attachment could not be found at the provided path.
12
+ *
13
+ * @since 0.1.0
14
+ */
15
+ ErrorCode["AttachmentNotFound"] = "ATTACHMENT_NOT_FOUND";
16
+ /**
17
+ * The email could not be composed.
18
+ *
19
+ * @since 0.1.0
20
+ */
21
+ ErrorCode["ComposeFailed"] = "COMPOSE_FAILED";
22
+ })(exports.ErrorCode || (exports.ErrorCode = {}));
23
+
24
+ const MailComposer = core.registerPlugin('MailComposer', {
25
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.MailComposerWeb()),
26
+ });
27
+
28
+ class MailComposerWeb extends core.WebPlugin {
29
+ async canComposeMail() {
30
+ return { canCompose: true };
31
+ }
32
+ async composeMail(options) {
33
+ if (options.attachments && options.attachments.length > 0) {
34
+ throw new Error(MailComposerWeb.errorAttachmentsNotSupported);
35
+ }
36
+ const url = this.createMailtoUrl(options);
37
+ window.open(url, '_self');
38
+ return { status: 'unknown' };
39
+ }
40
+ createMailtoUrl(options) {
41
+ var _a;
42
+ const to = ((_a = options.to) !== null && _a !== void 0 ? _a : []).join(',');
43
+ const params = new URLSearchParams();
44
+ if (options.cc && options.cc.length > 0) {
45
+ params.set('cc', options.cc.join(','));
46
+ }
47
+ if (options.bcc && options.bcc.length > 0) {
48
+ params.set('bcc', options.bcc.join(','));
49
+ }
50
+ if (options.subject) {
51
+ params.set('subject', options.subject);
52
+ }
53
+ if (options.body) {
54
+ params.set('body', options.body);
55
+ }
56
+ const query = params.toString();
57
+ return `mailto:${encodeURIComponent(to)}${query ? `?${query}` : ''}`;
58
+ }
59
+ }
60
+ MailComposerWeb.errorAttachmentsNotSupported = 'Attachments are not supported on the web.';
61
+
62
+ var web = /*#__PURE__*/Object.freeze({
63
+ __proto__: null,
64
+ MailComposerWeb: MailComposerWeb
65
+ });
66
+
67
+ exports.MailComposer = MailComposer;
68
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * @since 0.1.0\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * An attachment could not be found at the provided path.\n *\n * @since 0.1.0\n */\n ErrorCode[\"AttachmentNotFound\"] = \"ATTACHMENT_NOT_FOUND\";\n /**\n * The email could not be composed.\n *\n * @since 0.1.0\n */\n ErrorCode[\"ComposeFailed\"] = \"COMPOSE_FAILED\";\n})(ErrorCode || (ErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst MailComposer = registerPlugin('MailComposer', {\n web: () => import('./web').then(m => new m.MailComposerWeb()),\n});\nexport * from './definitions';\nexport { MailComposer };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class MailComposerWeb extends WebPlugin {\n async canComposeMail() {\n return { canCompose: true };\n }\n async composeMail(options) {\n if (options.attachments && options.attachments.length > 0) {\n throw new Error(MailComposerWeb.errorAttachmentsNotSupported);\n }\n const url = this.createMailtoUrl(options);\n window.open(url, '_self');\n return { status: 'unknown' };\n }\n createMailtoUrl(options) {\n var _a;\n const to = ((_a = options.to) !== null && _a !== void 0 ? _a : []).join(',');\n const params = new URLSearchParams();\n if (options.cc && options.cc.length > 0) {\n params.set('cc', options.cc.join(','));\n }\n if (options.bcc && options.bcc.length > 0) {\n params.set('bcc', options.bcc.join(','));\n }\n if (options.subject) {\n params.set('subject', options.subject);\n }\n if (options.body) {\n params.set('body', options.body);\n }\n const query = params.toString();\n return `mailto:${encodeURIComponent(to)}${query ? `?${query}` : ''}`;\n }\n}\nMailComposerWeb.errorAttachmentsNotSupported = 'Attachments are not supported on the web.';\n//# sourceMappingURL=web.js.map"],"names":["ErrorCode","registerPlugin","WebPlugin"],"mappings":";;;;AAAA;AACA;AACA;AACWA;AACX,CAAC,UAAU,SAAS,EAAE;AACtB;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,oBAAoB,CAAC,GAAG,sBAAsB;AAC5D;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,eAAe,CAAC,GAAG,gBAAgB;AACjD,CAAC,EAAEA,iBAAS,KAAKA,iBAAS,GAAG,EAAE,CAAC,CAAC;;AChB5B,MAAC,YAAY,GAAGC,mBAAc,CAAC,cAAc,EAAE;AACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;AACjE,CAAC;;ACFM,MAAM,eAAe,SAASC,cAAS,CAAC;AAC/C,IAAI,MAAM,cAAc,GAAG;AAC3B,QAAQ,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE;AACnC,IAAI;AACJ,IAAI,MAAM,WA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