@napacitor/dialog 0.0.0-stage → 0.1.2-beta.3

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 CHANGED
@@ -1,3 +1,41 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # @napacitor/dialog
2
+
3
+ 原生对话框插件(与 [@capacitor/dialog](https://github.com/ionic-team/capacitor-plugins/tree/main/dialog) 对应)。
4
+
5
+ ## 用法
6
+
7
+ ```ts
8
+ import { Dialog } from '@napacitor/dialog';
9
+
10
+ await Dialog.alert({ title: '提示', message: 'Hello Napacitor', buttonTitle: '知道了' });
11
+
12
+ const { value } = await Dialog.confirm({ title: '确认', message: '继续吗?' });
13
+ console.log(value); // true / false
14
+
15
+ const { value: text, cancelled } = await Dialog.prompt({
16
+ title: '输入',
17
+ message: '你的名字?',
18
+ okButtonTitle: '确定',
19
+ cancelButtonTitle: '取消',
20
+ });
21
+ ```
22
+
23
+ ## 结构
24
+
25
+ - `src/` —— TypeScript 源码(index / definitions / web)
26
+ - `dist/` —— 构建产物(CJS + d.ts,已提交)
27
+ - `maui/` —— .NET MAUI C# 实现(程序集 `Napacitor.Dialog`,运行时反射自动发现)
28
+
29
+ 原生实现映射:`Page.DisplayAlert`(alert / confirm)、`Page.DisplayPromptAsync`(prompt);
30
+ Windows 上由 MAUI 落到 `ContentDialog`。对话框必须在 UI 线程弹出,插件内部经
31
+ `MainThread.InvokeOnMainThreadAsync` 切换。
32
+
33
+ ## 与 Capacitor 的差异
34
+
35
+ - **alert**:映射 DisplayAlert 的单按钮形态,`buttonTitle` 即按钮文案;
36
+ - **prompt**:`inputPlaceholder` 映射 DisplayPromptAsync 的 placeholder,MAUI 无
37
+ maxLength / keyboard 定制参数故未暴露;取消时 `value` 为空字符串;
38
+ - **web**:Capacitor 依赖 pwa-elements 渲染样式化弹层,此处用 `window.alert / confirm /
39
+ prompt` 兜底;
40
+ - 该插件是少数需要 `Microsoft.Maui.Controls` 包引用的插件(Page API 属于 Controls 层,
41
+ 运行时 Napacitor 程序集本身仍保持零 MAUI 依赖)。
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @napacitor/dialog 类型定义。
3
+ * 原生对话框:alert / prompt / confirm
4
+ * (映射 MAUI Page.DisplayAlert / DisplayPromptAsync;Windows 上由 MAUI 落到 ContentDialog)。
5
+ */
6
+ /** alert() 参数。 */
7
+ export interface AlertOptions {
8
+ /** 对话框标题。 */
9
+ title: string;
10
+ /** 对话框消息。 */
11
+ message: string;
12
+ /** 按钮文案(默认 'OK')。 */
13
+ buttonTitle?: string;
14
+ }
15
+ /** prompt() 参数。 */
16
+ export interface PromptOptions {
17
+ /** 对话框标题。 */
18
+ title: string;
19
+ /** 对话框消息。 */
20
+ message: string;
21
+ /** 确认按钮文案(默认 'OK')。 */
22
+ okButtonTitle?: string;
23
+ /** 取消按钮文案(默认 'Cancel')。 */
24
+ cancelButtonTitle?: string;
25
+ /** 输入框占位提示。 */
26
+ inputPlaceholder?: string;
27
+ /** 输入框预填文本。 */
28
+ inputText?: string;
29
+ }
30
+ /** prompt() 返回值。 */
31
+ export interface PromptResult {
32
+ /** 输入的文本(取消时为空字符串)。 */
33
+ value: string;
34
+ /** 是否被取消。 */
35
+ cancelled: boolean;
36
+ }
37
+ /** confirm() 参数。 */
38
+ export interface ConfirmOptions {
39
+ /** 对话框标题。 */
40
+ title: string;
41
+ /** 对话框消息。 */
42
+ message: string;
43
+ /** 确认按钮文案(默认 'OK')。 */
44
+ okButtonTitle?: string;
45
+ /** 取消按钮文案(默认 'Cancel')。 */
46
+ cancelButtonTitle?: string;
47
+ }
48
+ /** confirm() 返回值。 */
49
+ export interface ConfirmResult {
50
+ /** 点击确认按钮时为 true。 */
51
+ value: boolean;
52
+ }
53
+ export interface DialogPlugin {
54
+ /** 显示警告对话框。 */
55
+ alert(options: AlertOptions): Promise<void>;
56
+ /** 显示输入对话框。 */
57
+ prompt(options: PromptOptions): Promise<PromptResult>;
58
+ /** 显示确认对话框。 */
59
+ confirm(options: ConfirmOptions): Promise<ConfirmResult>;
60
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @napacitor/dialog 类型定义。
4
+ * 原生对话框:alert / prompt / confirm
5
+ * (映射 MAUI Page.DisplayAlert / DisplayPromptAsync;Windows 上由 MAUI 落到 ContentDialog)。
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import type { DialogPlugin } from './definitions';
2
+ declare const Dialog: DialogPlugin;
3
+ export * from './definitions';
4
+ export { Dialog };
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.Dialog = void 0;
30
+ /**
31
+ * @napacitor/dialog 入口。
32
+ */
33
+ const core_1 = require("@napacitor/core");
34
+ const Dialog = (0, core_1.registerPlugin)('Dialog', {
35
+ web: () => Promise.resolve().then(() => __importStar(require('./web'))).then((m) => new m.DialogWeb()),
36
+ });
37
+ exports.Dialog = Dialog;
38
+ __exportStar(require("./definitions"), exports);
package/dist/web.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @napacitor/dialog 浏览器实现(基于 window.alert / confirm / prompt,
3
+ * 与 @capacitor/dialog 的 web 实现对应;Capacitor 依赖 pwa-elements,
4
+ * 此处用原生对话框兜底)。
5
+ */
6
+ import type { AlertOptions, ConfirmOptions, ConfirmResult, PromptOptions, PromptResult } from './definitions';
7
+ export declare class DialogWeb {
8
+ alert(options: AlertOptions): Promise<void>;
9
+ confirm(options: ConfirmOptions): Promise<ConfirmResult>;
10
+ prompt(options: PromptOptions): Promise<PromptResult>;
11
+ }
package/dist/web.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DialogWeb = void 0;
4
+ class DialogWeb {
5
+ async alert(options) {
6
+ var _a, _b;
7
+ window.alert(`${(_a = options.title) !== null && _a !== void 0 ? _a : ''}\n${(_b = options.message) !== null && _b !== void 0 ? _b : ''}`.trim());
8
+ }
9
+ async confirm(options) {
10
+ var _a, _b;
11
+ const value = window.confirm(`${(_a = options.title) !== null && _a !== void 0 ? _a : ''}\n${(_b = options.message) !== null && _b !== void 0 ? _b : ''}`.trim());
12
+ return { value };
13
+ }
14
+ async prompt(options) {
15
+ var _a, _b, _c;
16
+ const value = window.prompt(`${(_a = options.title) !== null && _a !== void 0 ? _a : ''}\n${(_b = options.message) !== null && _b !== void 0 ? _b : ''}`.trim(), (_c = options.inputText) !== null && _c !== void 0 ? _c : '');
17
+ return { value: value !== null && value !== void 0 ? value : '', cancelled: value === null };
18
+ }
19
+ }
20
+ exports.DialogWeb = DialogWeb;
@@ -0,0 +1,118 @@
1
+ using Microsoft.Maui.ApplicationModel;
2
+ using Microsoft.Maui.Controls;
3
+
4
+ namespace Napacitor.Plugins.Dialog;
5
+
6
+ /* ─── 参数 / 返回 DTO ─────────────────────────────────────── */
7
+
8
+ /// <summary>alert() 参数。</summary>
9
+ public class DialogAlertOptions
10
+ {
11
+ /// <summary>对话框标题。</summary>
12
+ public string? Title { get; set; }
13
+
14
+ /// <summary>对话框消息。</summary>
15
+ public string? Message { get; set; }
16
+
17
+ /// <summary>按钮文案(默认 'OK')。</summary>
18
+ public string? ButtonTitle { get; set; }
19
+ }
20
+
21
+ /// <summary>prompt() 参数。</summary>
22
+ public class DialogPromptOptions
23
+ {
24
+ public string? Title { get; set; }
25
+ public string? Message { get; set; }
26
+ public string? OkButtonTitle { get; set; }
27
+ public string? CancelButtonTitle { get; set; }
28
+ public string? InputPlaceholder { get; set; }
29
+ public string? InputText { get; set; }
30
+ }
31
+
32
+ /// <summary>prompt() 返回值。</summary>
33
+ public class DialogPromptResult
34
+ {
35
+ public string Value { get; set; } = string.Empty;
36
+ public bool Cancelled { get; set; }
37
+ }
38
+
39
+ /// <summary>confirm() 参数。</summary>
40
+ public class DialogConfirmOptions
41
+ {
42
+ public string? Title { get; set; }
43
+ public string? Message { get; set; }
44
+ public string? OkButtonTitle { get; set; }
45
+ public string? CancelButtonTitle { get; set; }
46
+ }
47
+
48
+ /// <summary>confirm() 返回值。</summary>
49
+ public class DialogConfirmResult
50
+ {
51
+ public bool Value { get; set; }
52
+ }
53
+
54
+ /* ─── 插件主体 ─────────────────────────────────────────────── */
55
+
56
+ /// <summary>
57
+ /// Dialog 插件:原生对话框(映射 MAUI Page.DisplayAlert / DisplayPromptAsync;
58
+ /// Windows 上由 MAUI 落到 ContentDialog)。
59
+ /// </summary>
60
+ [NapacitorPlugin("Dialog")]
61
+ public class DialogPlugin : NapacitorPluginBase
62
+ {
63
+ /// <summary>显示警告对话框(单按钮)。</summary>
64
+ [NapacitorMethod]
65
+ public Task Alert(DialogAlertOptions options)
66
+ {
67
+ var page = CurrentPage();
68
+ return MainThread.InvokeOnMainThreadAsync(() => page.DisplayAlert(
69
+ options.Title ?? string.Empty,
70
+ options.Message ?? string.Empty,
71
+ OrDefault(options.ButtonTitle, "OK")));
72
+ }
73
+
74
+ /// <summary>显示输入对话框(取消时 value 为空串、cancelled 为 true)。</summary>
75
+ [NapacitorMethod]
76
+ public async Task<DialogPromptResult> Prompt(DialogPromptOptions options)
77
+ {
78
+ var page = CurrentPage();
79
+ var result = await MainThread.InvokeOnMainThreadAsync(() => page.DisplayPromptAsync(
80
+ options.Title ?? string.Empty,
81
+ options.Message ?? string.Empty,
82
+ OrDefault(options.OkButtonTitle, "OK"),
83
+ OrDefault(options.CancelButtonTitle, "Cancel"),
84
+ options.InputPlaceholder,
85
+ initialValue: options.InputText ?? string.Empty));
86
+ return new DialogPromptResult
87
+ {
88
+ Value = result ?? string.Empty,
89
+ Cancelled = result is null,
90
+ };
91
+ }
92
+
93
+ /// <summary>显示确认对话框。</summary>
94
+ [NapacitorMethod]
95
+ public async Task<DialogConfirmResult> Confirm(DialogConfirmOptions options)
96
+ {
97
+ var page = CurrentPage();
98
+ var ok = await MainThread.InvokeOnMainThreadAsync(() => page.DisplayAlert(
99
+ options.Title ?? string.Empty,
100
+ options.Message ?? string.Empty,
101
+ OrDefault(options.OkButtonTitle, "OK"),
102
+ OrDefault(options.CancelButtonTitle, "Cancel")));
103
+ return new DialogConfirmResult { Value = ok };
104
+ }
105
+
106
+ /* ── 页面定位(宿主窗口未创建 / 无页面时抛 UNAVAILABLE)── */
107
+
108
+ private static Page CurrentPage()
109
+ {
110
+ var app = Application.Current;
111
+ return (app?.Windows?.FirstOrDefault()?.Page ?? app?.MainPage)
112
+ ?? throw new NapacitorException(
113
+ NapacitorException.Unavailable, "Dialog:当前无可用页面(宿主窗口尚未创建)");
114
+ }
115
+
116
+ private static string OrDefault(string? value, string fallback) =>
117
+ string.IsNullOrEmpty(value) ? fallback : value;
118
+ }
@@ -0,0 +1,25 @@
1
+ <Project Sdk="Microsoft.NET.Sdk">
2
+
3
+ <PropertyGroup>
4
+ <TargetFramework>net10.0</TargetFramework>
5
+ <RootNamespace>Napacitor.Plugins.Dialog</RootNamespace>
6
+ <AssemblyName>Napacitor.Dialog</AssemblyName>
7
+ <Nullable>enable</Nullable>
8
+ <ImplicitUsings>enable</ImplicitUsings>
9
+ <LangVersion>latest</LangVersion>
10
+ <Description>Napacitor Dialog 插件(.NET MAUI 实现)</Description>
11
+ <Version>0.1.0</Version>
12
+ </PropertyGroup>
13
+
14
+ <ItemGroup>
15
+ <!-- Page.DisplayAlert / DisplayPromptAsync 需要 Controls 层 -->
16
+ <PackageReference Include="Microsoft.Maui.Essentials" Version="10.0.20" />
17
+ <PackageReference Include="Microsoft.Maui.Controls" Version="10.0.20" />
18
+ </ItemGroup>
19
+
20
+ <ItemGroup>
21
+ <ProjectReference Include="..\..\maui\src\Napacitor.csproj" Condition="Exists('..\..\maui\src\Napacitor.csproj')" />
22
+ <ProjectReference Include="..\..\..\maui\src\Napacitor.csproj" Condition="!Exists('..\..\maui\src\Napacitor.csproj')" />
23
+ </ItemGroup>
24
+
25
+ </Project>
package/package.json CHANGED
@@ -1,6 +1,13 @@
1
- {
2
- "name": "@napacitor/dialog",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@napacitor/dialog",
3
+ "version": "0.1.2-beta.3",
4
+ "description": "Napacitor Dialog 插件(原生对话框,映射 MAUI Page.DisplayAlert/DisplayPromptAsync)",
5
+ "homepage": "https://github.com/jevonsflash/napacitor",
6
+ "license": "MIT",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "files": ["dist/", "maui/", "!maui/bin/", "!maui/obj/"],
10
+ "scripts": { "build": "tsc", "type-check": "tsc --noEmit" },
11
+ "peerDependencies": { "@napacitor/core": "^0.1.0" },
12
+ "devDependencies": { "@napacitor/core": "^0.1.0", "typescript": "~5.4.5" }
13
+ }