@capawesome/capacitor-dialog 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 (45) hide show
  1. package/CapawesomeCapacitorDialog.podspec +17 -0
  2. package/LICENSE +21 -0
  3. package/Package.swift +28 -0
  4. package/README.md +232 -0
  5. package/android/build.gradle +58 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/Dialog.java +75 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/DialogPlugin.java +121 -0
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/classes/CustomException.java +20 -0
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/classes/CustomExceptions.java +6 -0
  11. package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/classes/options/AlertOptions.java +43 -0
  12. package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/classes/options/ConfirmOptions.java +52 -0
  13. package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/classes/options/PromptOptions.java +70 -0
  14. package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/classes/results/ConfirmResult.java +22 -0
  15. package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/classes/results/PromptResult.java +27 -0
  16. package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/interfaces/Callback.java +5 -0
  17. package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/interfaces/EmptyCallback.java +5 -0
  18. package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/interfaces/NonEmptyResultCallback.java +7 -0
  19. package/android/src/main/java/io/capawesome/capacitorjs/plugins/dialog/interfaces/Result.java +7 -0
  20. package/android/src/main/res/.gitkeep +0 -0
  21. package/dist/docs.json +433 -0
  22. package/dist/esm/definitions.d.ts +180 -0
  23. package/dist/esm/definitions.js +2 -0
  24. package/dist/esm/definitions.js.map +1 -0
  25. package/dist/esm/index.d.ts +4 -0
  26. package/dist/esm/index.js +7 -0
  27. package/dist/esm/index.js.map +1 -0
  28. package/dist/esm/web.d.ts +8 -0
  29. package/dist/esm/web.js +29 -0
  30. package/dist/esm/web.js.map +1 -0
  31. package/dist/plugin.cjs.js +43 -0
  32. package/dist/plugin.cjs.js.map +1 -0
  33. package/dist/plugin.js +46 -0
  34. package/dist/plugin.js.map +1 -0
  35. package/ios/Plugin/Classes/Options/AlertOptions.swift +17 -0
  36. package/ios/Plugin/Classes/Options/ConfirmOptions.swift +19 -0
  37. package/ios/Plugin/Classes/Options/PromptOptions.swift +23 -0
  38. package/ios/Plugin/Classes/Results/ConfirmResult.swift +16 -0
  39. package/ios/Plugin/Classes/Results/PromptResult.swift +19 -0
  40. package/ios/Plugin/Dialog.swift +57 -0
  41. package/ios/Plugin/DialogPlugin.swift +83 -0
  42. package/ios/Plugin/Enums/CustomError.swift +21 -0
  43. package/ios/Plugin/Info.plist +24 -0
  44. package/ios/Plugin/Protocols/Result.swift +5 -0
  45. package/package.json +95 -0
@@ -0,0 +1,180 @@
1
+ export interface DialogPlugin {
2
+ /**
3
+ * Display an alert dialog with a single button.
4
+ *
5
+ * @since 0.1.0
6
+ */
7
+ alert(options: AlertOptions): Promise<void>;
8
+ /**
9
+ * Display a confirmation dialog with two buttons.
10
+ *
11
+ * @since 0.1.0
12
+ */
13
+ confirm(options: ConfirmOptions): Promise<ConfirmResult>;
14
+ /**
15
+ * Display a prompt dialog with a text input, a confirm and a cancel button.
16
+ *
17
+ * @since 0.1.0
18
+ */
19
+ prompt(options: PromptOptions): Promise<PromptResult>;
20
+ }
21
+ /**
22
+ * @since 0.1.0
23
+ */
24
+ export interface AlertOptions {
25
+ /**
26
+ * The title of the button that confirms the dialog.
27
+ *
28
+ * On the web, the button title cannot be customized and is ignored.
29
+ *
30
+ * @since 0.1.0
31
+ * @default 'OK'
32
+ * @example 'Got it'
33
+ */
34
+ buttonTitle?: string;
35
+ /**
36
+ * The message to display in the dialog.
37
+ *
38
+ * @since 0.1.0
39
+ * @example 'Your changes have been saved.'
40
+ */
41
+ message: string;
42
+ /**
43
+ * The title of the dialog.
44
+ *
45
+ * On the web, the title cannot be customized and is ignored.
46
+ *
47
+ * @since 0.1.0
48
+ * @example 'Success'
49
+ */
50
+ title?: string;
51
+ }
52
+ /**
53
+ * @since 0.1.0
54
+ */
55
+ export interface ConfirmOptions {
56
+ /**
57
+ * The title of the button that cancels the dialog.
58
+ *
59
+ * On the web, the button title cannot be customized and is ignored.
60
+ *
61
+ * @since 0.1.0
62
+ * @default 'Cancel'
63
+ * @example 'No'
64
+ */
65
+ cancelButtonTitle?: string;
66
+ /**
67
+ * The message to display in the dialog.
68
+ *
69
+ * @since 0.1.0
70
+ * @example 'Do you want to delete this item?'
71
+ */
72
+ message: string;
73
+ /**
74
+ * The title of the button that confirms the dialog.
75
+ *
76
+ * On the web, the button title cannot be customized and is ignored.
77
+ *
78
+ * @since 0.1.0
79
+ * @default 'OK'
80
+ * @example 'Yes'
81
+ */
82
+ okButtonTitle?: string;
83
+ /**
84
+ * The title of the dialog.
85
+ *
86
+ * On the web, the title cannot be customized and is ignored.
87
+ *
88
+ * @since 0.1.0
89
+ * @example 'Confirm'
90
+ */
91
+ title?: string;
92
+ }
93
+ /**
94
+ * @since 0.1.0
95
+ */
96
+ export interface ConfirmResult {
97
+ /**
98
+ * Whether the user confirmed the dialog.
99
+ *
100
+ * @since 0.1.0
101
+ * @example true
102
+ */
103
+ value: boolean;
104
+ }
105
+ /**
106
+ * @since 0.1.0
107
+ */
108
+ export interface PromptOptions {
109
+ /**
110
+ * The title of the button that cancels the dialog.
111
+ *
112
+ * On the web, the button title cannot be customized and is ignored.
113
+ *
114
+ * @since 0.1.0
115
+ * @default 'Cancel'
116
+ * @example 'No'
117
+ */
118
+ cancelButtonTitle?: string;
119
+ /**
120
+ * The placeholder of the text input.
121
+ *
122
+ * On the web, the placeholder cannot be customized and is ignored.
123
+ *
124
+ * @since 0.1.0
125
+ * @example 'Enter your name'
126
+ */
127
+ inputPlaceholder?: string;
128
+ /**
129
+ * The initial value of the text input.
130
+ *
131
+ * @since 0.1.0
132
+ * @example 'John Doe'
133
+ */
134
+ inputText?: string;
135
+ /**
136
+ * The message to display in the dialog.
137
+ *
138
+ * @since 0.1.0
139
+ * @example 'What is your name?'
140
+ */
141
+ message: string;
142
+ /**
143
+ * The title of the button that confirms the dialog.
144
+ *
145
+ * On the web, the button title cannot be customized and is ignored.
146
+ *
147
+ * @since 0.1.0
148
+ * @default 'OK'
149
+ * @example 'Submit'
150
+ */
151
+ okButtonTitle?: string;
152
+ /**
153
+ * The title of the dialog.
154
+ *
155
+ * On the web, the title cannot be customized and is ignored.
156
+ *
157
+ * @since 0.1.0
158
+ * @example 'Name'
159
+ */
160
+ title?: string;
161
+ }
162
+ /**
163
+ * @since 0.1.0
164
+ */
165
+ export interface PromptResult {
166
+ /**
167
+ * Whether the user canceled the dialog.
168
+ *
169
+ * @since 0.1.0
170
+ * @example false
171
+ */
172
+ canceled: boolean;
173
+ /**
174
+ * The value of the text input.
175
+ *
176
+ * @since 0.1.0
177
+ * @example 'John Doe'
178
+ */
179
+ value: string;
180
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface DialogPlugin {\n /**\n * Display an alert dialog with a single button.\n *\n * @since 0.1.0\n */\n alert(options: AlertOptions): Promise<void>;\n /**\n * Display a confirmation dialog with two buttons.\n *\n * @since 0.1.0\n */\n confirm(options: ConfirmOptions): Promise<ConfirmResult>;\n /**\n * Display a prompt dialog with a text input, a confirm and a cancel button.\n *\n * @since 0.1.0\n */\n prompt(options: PromptOptions): Promise<PromptResult>;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface AlertOptions {\n /**\n * The title of the button that confirms the dialog.\n *\n * On the web, the button title cannot be customized and is ignored.\n *\n * @since 0.1.0\n * @default 'OK'\n * @example 'Got it'\n */\n buttonTitle?: string;\n /**\n * The message to display in the dialog.\n *\n * @since 0.1.0\n * @example 'Your changes have been saved.'\n */\n message: string;\n /**\n * The title of the dialog.\n *\n * On the web, the title cannot be customized and is ignored.\n *\n * @since 0.1.0\n * @example 'Success'\n */\n title?: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface ConfirmOptions {\n /**\n * The title of the button that cancels the dialog.\n *\n * On the web, the button title cannot be customized and is ignored.\n *\n * @since 0.1.0\n * @default 'Cancel'\n * @example 'No'\n */\n cancelButtonTitle?: string;\n /**\n * The message to display in the dialog.\n *\n * @since 0.1.0\n * @example 'Do you want to delete this item?'\n */\n message: string;\n /**\n * The title of the button that confirms the dialog.\n *\n * On the web, the button title cannot be customized and is ignored.\n *\n * @since 0.1.0\n * @default 'OK'\n * @example 'Yes'\n */\n okButtonTitle?: string;\n /**\n * The title of the dialog.\n *\n * On the web, the title cannot be customized and is ignored.\n *\n * @since 0.1.0\n * @example 'Confirm'\n */\n title?: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface ConfirmResult {\n /**\n * Whether the user confirmed the dialog.\n *\n * @since 0.1.0\n * @example true\n */\n value: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface PromptOptions {\n /**\n * The title of the button that cancels the dialog.\n *\n * On the web, the button title cannot be customized and is ignored.\n *\n * @since 0.1.0\n * @default 'Cancel'\n * @example 'No'\n */\n cancelButtonTitle?: string;\n /**\n * The placeholder of the text input.\n *\n * On the web, the placeholder cannot be customized and is ignored.\n *\n * @since 0.1.0\n * @example 'Enter your name'\n */\n inputPlaceholder?: string;\n /**\n * The initial value of the text input.\n *\n * @since 0.1.0\n * @example 'John Doe'\n */\n inputText?: string;\n /**\n * The message to display in the dialog.\n *\n * @since 0.1.0\n * @example 'What is your name?'\n */\n message: string;\n /**\n * The title of the button that confirms the dialog.\n *\n * On the web, the button title cannot be customized and is ignored.\n *\n * @since 0.1.0\n * @default 'OK'\n * @example 'Submit'\n */\n okButtonTitle?: string;\n /**\n * The title of the dialog.\n *\n * On the web, the title cannot be customized and is ignored.\n *\n * @since 0.1.0\n * @example 'Name'\n */\n title?: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface PromptResult {\n /**\n * Whether the user canceled the dialog.\n *\n * @since 0.1.0\n * @example false\n */\n canceled: boolean;\n /**\n * The value of the text input.\n *\n * @since 0.1.0\n * @example 'John Doe'\n */\n value: string;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { DialogPlugin } from './definitions';
2
+ declare const Dialog: DialogPlugin;
3
+ export * from './definitions';
4
+ export { Dialog };
@@ -0,0 +1,7 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const Dialog = registerPlugin('Dialog', {
3
+ web: () => import('./web').then(m => new m.DialogWeb()),
4
+ });
5
+ export * from './definitions';
6
+ export { Dialog };
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,MAAM,GAAG,cAAc,CAAe,QAAQ,EAAE;IACpD,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;CACxD,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { DialogPlugin } from './definitions';\n\nconst Dialog = registerPlugin<DialogPlugin>('Dialog', {\n web: () => import('./web').then(m => new m.DialogWeb()),\n});\n\nexport * from './definitions';\nexport { Dialog };\n"]}
@@ -0,0 +1,8 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { AlertOptions, ConfirmOptions, ConfirmResult, DialogPlugin, PromptOptions, PromptResult } from './definitions';
3
+ export declare class DialogWeb extends WebPlugin implements DialogPlugin {
4
+ private static readonly errorMessageMissing;
5
+ alert(options: AlertOptions): Promise<void>;
6
+ confirm(options: ConfirmOptions): Promise<ConfirmResult>;
7
+ prompt(options: PromptOptions): Promise<PromptResult>;
8
+ }
@@ -0,0 +1,29 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class DialogWeb extends WebPlugin {
3
+ async alert(options) {
4
+ if (!options.message) {
5
+ throw new Error(DialogWeb.errorMessageMissing);
6
+ }
7
+ window.alert(options.message);
8
+ }
9
+ async confirm(options) {
10
+ if (!options.message) {
11
+ throw new Error(DialogWeb.errorMessageMissing);
12
+ }
13
+ const value = window.confirm(options.message);
14
+ return { value };
15
+ }
16
+ async prompt(options) {
17
+ var _a;
18
+ if (!options.message) {
19
+ throw new Error(DialogWeb.errorMessageMissing);
20
+ }
21
+ const value = window.prompt(options.message, (_a = options.inputText) !== null && _a !== void 0 ? _a : '');
22
+ if (value === null) {
23
+ return { canceled: true, value: '' };
24
+ }
25
+ return { canceled: false, value };
26
+ }
27
+ }
28
+ DialogWeb.errorMessageMissing = 'message must be provided.';
29
+ //# 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;AAW5C,MAAM,OAAO,SAAU,SAAQ,SAAS;IAGtC,KAAK,CAAC,KAAK,CAAC,OAAqB;QAC/B,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;QACjD,CAAC;QACD,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAuB;QACnC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;QACjD,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9C,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAsB;;QACjC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;QACjD,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,MAAA,OAAO,CAAC,SAAS,mCAAI,EAAE,CAAC,CAAC;QACtE,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;QACvC,CAAC;QACD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IACpC,CAAC;;AA1BuB,6BAAmB,GAAG,2BAA2B,CAAC","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n AlertOptions,\n ConfirmOptions,\n ConfirmResult,\n DialogPlugin,\n PromptOptions,\n PromptResult,\n} from './definitions';\n\nexport class DialogWeb extends WebPlugin implements DialogPlugin {\n private static readonly errorMessageMissing = 'message must be provided.';\n\n async alert(options: AlertOptions): Promise<void> {\n if (!options.message) {\n throw new Error(DialogWeb.errorMessageMissing);\n }\n window.alert(options.message);\n }\n\n async confirm(options: ConfirmOptions): Promise<ConfirmResult> {\n if (!options.message) {\n throw new Error(DialogWeb.errorMessageMissing);\n }\n const value = window.confirm(options.message);\n return { value };\n }\n\n async prompt(options: PromptOptions): Promise<PromptResult> {\n if (!options.message) {\n throw new Error(DialogWeb.errorMessageMissing);\n }\n const value = window.prompt(options.message, options.inputText ?? '');\n if (value === null) {\n return { canceled: true, value: '' };\n }\n return { canceled: false, value };\n }\n}\n"]}
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const Dialog = core.registerPlugin('Dialog', {
6
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.DialogWeb()),
7
+ });
8
+
9
+ class DialogWeb extends core.WebPlugin {
10
+ async alert(options) {
11
+ if (!options.message) {
12
+ throw new Error(DialogWeb.errorMessageMissing);
13
+ }
14
+ window.alert(options.message);
15
+ }
16
+ async confirm(options) {
17
+ if (!options.message) {
18
+ throw new Error(DialogWeb.errorMessageMissing);
19
+ }
20
+ const value = window.confirm(options.message);
21
+ return { value };
22
+ }
23
+ async prompt(options) {
24
+ var _a;
25
+ if (!options.message) {
26
+ throw new Error(DialogWeb.errorMessageMissing);
27
+ }
28
+ const value = window.prompt(options.message, (_a = options.inputText) !== null && _a !== void 0 ? _a : '');
29
+ if (value === null) {
30
+ return { canceled: true, value: '' };
31
+ }
32
+ return { canceled: false, value };
33
+ }
34
+ }
35
+ DialogWeb.errorMessageMissing = 'message must be provided.';
36
+
37
+ var web = /*#__PURE__*/Object.freeze({
38
+ __proto__: null,
39
+ DialogWeb: DialogWeb
40
+ });
41
+
42
+ exports.Dialog = Dialog;
43
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Dialog = registerPlugin('Dialog', {\n web: () => import('./web').then(m => new m.DialogWeb()),\n});\nexport * from './definitions';\nexport { Dialog };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class DialogWeb extends WebPlugin {\n async alert(options) {\n if (!options.message) {\n throw new Error(DialogWeb.errorMessageMissing);\n }\n window.alert(options.message);\n }\n async confirm(options) {\n if (!options.message) {\n throw new Error(DialogWeb.errorMessageMissing);\n }\n const value = window.confirm(options.message);\n return { value };\n }\n async prompt(options) {\n var _a;\n if (!options.message) {\n throw new Error(DialogWeb.errorMessageMissing);\n }\n const value = window.prompt(options.message, (_a = options.inputText) !== null && _a !== void 0 ? _a : '');\n if (value === null) {\n return { canceled: true, value: '' };\n }\n return { canceled: false, value };\n }\n}\nDialogWeb.errorMessageMissing = 'message must be provided.';\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,MAAM,GAAGA,mBAAc,CAAC,QAAQ,EAAE;AACxC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;AAC3D,CAAC;;ACFM,MAAM,SAAS,SAASC,cAAS,CAAC;AACzC,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;AACzB,QAAQ,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;AAC9B,YAAY,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC;AAC1D,QAAQ;AACR,QAAQ,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;AACrC,IAAI;AACJ,IAAI,MAAM,OAAO,CAAC,OAAO,EAAE;AAC3B,QAAQ,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;AAC9B,YAAY,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC;AAC1D,QAAQ;AACR,QAAQ,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;AACrD,QAAQ,OAAO,EAAE,KAAK,EAAE;AACxB,IAAI;AACJ,IAAI,MAAM,MAAM,CAAC,OAAO,EAAE;AAC1B,QAAQ,IAAI,EAAE;AACd,QAAQ,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;AAC9B,YAAY,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC;AAC1D,QAAQ;AACR,QAAQ,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,SAAS,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,EAAE,GAAG,EAAE,CAAC;AAClH,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE;AAC5B,YAAY,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE;AAChD,QAAQ;AACR,QAAQ,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE;AACzC,IAAI;AACJ;AACA,SAAS,CAAC,mBAAmB,GAAG,2BAA2B;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,46 @@
1
+ var capacitorDialog = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ const Dialog = core.registerPlugin('Dialog', {
5
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.DialogWeb()),
6
+ });
7
+
8
+ class DialogWeb extends core.WebPlugin {
9
+ async alert(options) {
10
+ if (!options.message) {
11
+ throw new Error(DialogWeb.errorMessageMissing);
12
+ }
13
+ window.alert(options.message);
14
+ }
15
+ async confirm(options) {
16
+ if (!options.message) {
17
+ throw new Error(DialogWeb.errorMessageMissing);
18
+ }
19
+ const value = window.confirm(options.message);
20
+ return { value };
21
+ }
22
+ async prompt(options) {
23
+ var _a;
24
+ if (!options.message) {
25
+ throw new Error(DialogWeb.errorMessageMissing);
26
+ }
27
+ const value = window.prompt(options.message, (_a = options.inputText) !== null && _a !== void 0 ? _a : '');
28
+ if (value === null) {
29
+ return { canceled: true, value: '' };
30
+ }
31
+ return { canceled: false, value };
32
+ }
33
+ }
34
+ DialogWeb.errorMessageMissing = 'message must be provided.';
35
+
36
+ var web = /*#__PURE__*/Object.freeze({
37
+ __proto__: null,
38
+ DialogWeb: DialogWeb
39
+ });
40
+
41
+ exports.Dialog = Dialog;
42
+
43
+ return exports;
44
+
45
+ })({}, capacitorExports);
46
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Dialog = registerPlugin('Dialog', {\n web: () => import('./web').then(m => new m.DialogWeb()),\n});\nexport * from './definitions';\nexport { Dialog };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class DialogWeb extends WebPlugin {\n async alert(options) {\n if (!options.message) {\n throw new Error(DialogWeb.errorMessageMissing);\n }\n window.alert(options.message);\n }\n async confirm(options) {\n if (!options.message) {\n throw new Error(DialogWeb.errorMessageMissing);\n }\n const value = window.confirm(options.message);\n return { value };\n }\n async prompt(options) {\n var _a;\n if (!options.message) {\n throw new Error(DialogWeb.errorMessageMissing);\n }\n const value = window.prompt(options.message, (_a = options.inputText) !== null && _a !== void 0 ? _a : '');\n if (value === null) {\n return { canceled: true, value: '' };\n }\n return { canceled: false, value };\n }\n}\nDialogWeb.errorMessageMissing = 'message must be provided.';\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,MAAM,GAAGA,mBAAc,CAAC,QAAQ,EAAE;IACxC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;IAC3D,CAAC;;ICFM,MAAM,SAAS,SAASC,cAAS,CAAC;IACzC,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;IACzB,QAAQ,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;IAC9B,YAAY,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC;IAC1D,QAAQ;IACR,QAAQ,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;IACrC,IAAI;IACJ,IAAI,MAAM,OAAO,CAAC,OAAO,EAAE;IAC3B,QAAQ,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;IAC9B,YAAY,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC;IAC1D,QAAQ;IACR,QAAQ,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;IACrD,QAAQ,OAAO,EAAE,KAAK,EAAE;IACxB,IAAI;IACJ,IAAI,MAAM,MAAM,CAAC,OAAO,EAAE;IAC1B,QAAQ,IAAI,EAAE;IACd,QAAQ,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;IAC9B,YAAY,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC;IAC1D,QAAQ;IACR,QAAQ,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,SAAS,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,EAAE,GAAG,EAAE,CAAC;IAClH,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE;IAC5B,YAAY,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE;IAChD,QAAQ;IACR,QAAQ,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE;IACzC,IAAI;IACJ;IACA,SAAS,CAAC,mBAAmB,GAAG,2BAA2B;;;;;;;;;;;;;;;"}
@@ -0,0 +1,17 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ @objc public class AlertOptions: NSObject {
5
+ let buttonTitle: String
6
+ let message: String
7
+ let title: String?
8
+
9
+ init(_ call: CAPPluginCall) throws {
10
+ guard let message = call.getString("message") else {
11
+ throw CustomError.messageMissing
12
+ }
13
+ self.message = message
14
+ self.buttonTitle = call.getString("buttonTitle", "OK")
15
+ self.title = call.getString("title")
16
+ }
17
+ }
@@ -0,0 +1,19 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ @objc public class ConfirmOptions: NSObject {
5
+ let cancelButtonTitle: String
6
+ let message: String
7
+ let okButtonTitle: String
8
+ let title: String?
9
+
10
+ init(_ call: CAPPluginCall) throws {
11
+ guard let message = call.getString("message") else {
12
+ throw CustomError.messageMissing
13
+ }
14
+ self.message = message
15
+ self.cancelButtonTitle = call.getString("cancelButtonTitle", "Cancel")
16
+ self.okButtonTitle = call.getString("okButtonTitle", "OK")
17
+ self.title = call.getString("title")
18
+ }
19
+ }
@@ -0,0 +1,23 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ @objc public class PromptOptions: NSObject {
5
+ let cancelButtonTitle: String
6
+ let inputPlaceholder: String?
7
+ let inputText: String?
8
+ let message: String
9
+ let okButtonTitle: String
10
+ let title: String?
11
+
12
+ init(_ call: CAPPluginCall) throws {
13
+ guard let message = call.getString("message") else {
14
+ throw CustomError.messageMissing
15
+ }
16
+ self.message = message
17
+ self.cancelButtonTitle = call.getString("cancelButtonTitle", "Cancel")
18
+ self.inputPlaceholder = call.getString("inputPlaceholder")
19
+ self.inputText = call.getString("inputText")
20
+ self.okButtonTitle = call.getString("okButtonTitle", "OK")
21
+ self.title = call.getString("title")
22
+ }
23
+ }
@@ -0,0 +1,16 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ @objc public class ConfirmResult: NSObject, Result {
5
+ let value: Bool
6
+
7
+ init(value: Bool) {
8
+ self.value = value
9
+ }
10
+
11
+ @objc public func toJSObject() -> AnyObject {
12
+ var result = JSObject()
13
+ result["value"] = value
14
+ return result as AnyObject
15
+ }
16
+ }
@@ -0,0 +1,19 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ @objc public class PromptResult: NSObject, Result {
5
+ let canceled: Bool
6
+ let value: String
7
+
8
+ init(value: String, canceled: Bool) {
9
+ self.value = value
10
+ self.canceled = canceled
11
+ }
12
+
13
+ @objc public func toJSObject() -> AnyObject {
14
+ var result = JSObject()
15
+ result["canceled"] = canceled
16
+ result["value"] = value
17
+ return result as AnyObject
18
+ }
19
+ }
@@ -0,0 +1,57 @@
1
+ import Foundation
2
+ import Capacitor
3
+ import UIKit
4
+
5
+ @objc public class Dialog: NSObject {
6
+ private let plugin: DialogPlugin
7
+
8
+ init(plugin: DialogPlugin) {
9
+ self.plugin = plugin
10
+ }
11
+
12
+ @objc public func alert(_ options: AlertOptions, completion: @escaping (Error?) -> Void) {
13
+ DispatchQueue.main.async {
14
+ let alertController = UIAlertController(title: options.title, message: options.message, preferredStyle: .alert)
15
+ alertController.addAction(UIAlertAction(title: options.buttonTitle, style: .default) { _ in
16
+ completion(nil)
17
+ })
18
+ self.present(alertController)
19
+ }
20
+ }
21
+
22
+ @objc public func confirm(_ options: ConfirmOptions, completion: @escaping (ConfirmResult?, Error?) -> Void) {
23
+ DispatchQueue.main.async {
24
+ let alertController = UIAlertController(title: options.title, message: options.message, preferredStyle: .alert)
25
+ alertController.addAction(UIAlertAction(title: options.cancelButtonTitle, style: .cancel) { _ in
26
+ completion(ConfirmResult(value: false), nil)
27
+ })
28
+ alertController.addAction(UIAlertAction(title: options.okButtonTitle, style: .default) { _ in
29
+ completion(ConfirmResult(value: true), nil)
30
+ })
31
+ self.present(alertController)
32
+ }
33
+ }
34
+
35
+ @objc public func prompt(_ options: PromptOptions, completion: @escaping (PromptResult?, Error?) -> Void) {
36
+ DispatchQueue.main.async {
37
+ let alertController = UIAlertController(title: options.title, message: options.message, preferredStyle: .alert)
38
+ alertController.addTextField { textField in
39
+ textField.placeholder = options.inputPlaceholder
40
+ textField.text = options.inputText
41
+ }
42
+ alertController.addAction(UIAlertAction(title: options.cancelButtonTitle, style: .cancel) { _ in
43
+ let value = alertController.textFields?.first?.text ?? ""
44
+ completion(PromptResult(value: value, canceled: true), nil)
45
+ })
46
+ alertController.addAction(UIAlertAction(title: options.okButtonTitle, style: .default) { _ in
47
+ let value = alertController.textFields?.first?.text ?? ""
48
+ completion(PromptResult(value: value, canceled: false), nil)
49
+ })
50
+ self.present(alertController)
51
+ }
52
+ }
53
+
54
+ private func present(_ alertController: UIAlertController) {
55
+ plugin.bridge?.viewController?.present(alertController, animated: true)
56
+ }
57
+ }
@@ -0,0 +1,83 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ @objc(DialogPlugin)
5
+ public class DialogPlugin: CAPPlugin, CAPBridgedPlugin {
6
+ public let identifier = "DialogPlugin"
7
+ public let jsName = "Dialog"
8
+ public let pluginMethods: [CAPPluginMethod] = [
9
+ CAPPluginMethod(name: "alert", returnType: CAPPluginReturnPromise),
10
+ CAPPluginMethod(name: "confirm", returnType: CAPPluginReturnPromise),
11
+ CAPPluginMethod(name: "prompt", returnType: CAPPluginReturnPromise)
12
+ ]
13
+ public static let tag = "DialogPlugin"
14
+
15
+ private var implementation: Dialog?
16
+
17
+ override public func load() {
18
+ self.implementation = Dialog(plugin: self)
19
+ }
20
+
21
+ @objc func alert(_ call: CAPPluginCall) {
22
+ do {
23
+ let options = try AlertOptions(call)
24
+ implementation?.alert(options) { error in
25
+ if let error = error {
26
+ self.rejectCall(call, error)
27
+ return
28
+ }
29
+ self.resolveCall(call)
30
+ }
31
+ } catch {
32
+ rejectCall(call, error)
33
+ }
34
+ }
35
+
36
+ @objc func confirm(_ call: CAPPluginCall) {
37
+ do {
38
+ let options = try ConfirmOptions(call)
39
+ implementation?.confirm(options) { result, error in
40
+ if let error = error {
41
+ self.rejectCall(call, error)
42
+ return
43
+ }
44
+ self.resolveCall(call, result)
45
+ }
46
+ } catch {
47
+ rejectCall(call, error)
48
+ }
49
+ }
50
+
51
+ @objc func prompt(_ call: CAPPluginCall) {
52
+ do {
53
+ let options = try PromptOptions(call)
54
+ implementation?.prompt(options) { result, error in
55
+ if let error = error {
56
+ self.rejectCall(call, error)
57
+ return
58
+ }
59
+ self.resolveCall(call, result)
60
+ }
61
+ } catch {
62
+ rejectCall(call, error)
63
+ }
64
+ }
65
+
66
+ private func rejectCall(_ call: CAPPluginCall, _ error: Error) {
67
+ CAPLog.print("[", DialogPlugin.tag, "] ", error)
68
+ let code = (error as? CustomError)?.code
69
+ call.reject(error.localizedDescription, code)
70
+ }
71
+
72
+ private func resolveCall(_ call: CAPPluginCall) {
73
+ call.resolve()
74
+ }
75
+
76
+ private func resolveCall(_ call: CAPPluginCall, _ result: Result?) {
77
+ if let result = result?.toJSObject() as? JSObject {
78
+ call.resolve(result)
79
+ } else {
80
+ call.resolve()
81
+ }
82
+ }
83
+ }
@@ -0,0 +1,21 @@
1
+ import Foundation
2
+
3
+ enum CustomError: Error {
4
+ case messageMissing
5
+
6
+ var code: String? {
7
+ switch self {
8
+ case .messageMissing:
9
+ return nil
10
+ }
11
+ }
12
+ }
13
+
14
+ extension CustomError: LocalizedError {
15
+ public var errorDescription: String? {
16
+ switch self {
17
+ case .messageMissing:
18
+ return NSLocalizedString("message must be provided.", comment: "messageMissing")
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>$(DEVELOPMENT_LANGUAGE)</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string>$(EXECUTABLE_NAME)</string>
9
+ <key>CFBundleIdentifier</key>
10
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11
+ <key>CFBundleInfoDictionaryVersion</key>
12
+ <string>6.0</string>
13
+ <key>CFBundleName</key>
14
+ <string>$(PRODUCT_NAME)</string>
15
+ <key>CFBundlePackageType</key>
16
+ <string>FMWK</string>
17
+ <key>CFBundleShortVersionString</key>
18
+ <string>1.0</string>
19
+ <key>CFBundleVersion</key>
20
+ <string>$(CURRENT_PROJECT_VERSION)</string>
21
+ <key>NSPrincipalClass</key>
22
+ <string></string>
23
+ </dict>
24
+ </plist>
@@ -0,0 +1,5 @@
1
+ import Capacitor
2
+
3
+ @objc public protocol Result {
4
+ @objc func toJSObject() -> AnyObject
5
+ }