@napacitor/action-sheet 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 +38 -3
- package/dist/definitions.d.ts +44 -0
- package/dist/definitions.js +17 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +38 -0
- package/dist/web.d.ts +9 -0
- package/dist/web.js +9 -0
- package/maui/ActionSheetPlugin.cs +79 -0
- package/maui/Napacitor.ActionSheet.csproj +25 -0
- package/package.json +13 -6
package/README.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @napacitor/action-sheet
|
|
2
|
+
|
|
3
|
+
原生操作表插件(与 [@capacitor/action-sheet](https://github.com/ionic-team/capacitor-plugins/tree/main/action-sheet) 对应)。
|
|
4
|
+
|
|
5
|
+
## 用法
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { ActionSheet } from '@napacitor/action-sheet';
|
|
9
|
+
|
|
10
|
+
const { index, canceled } = await ActionSheet.showActions({
|
|
11
|
+
title: '选择操作',
|
|
12
|
+
options: [
|
|
13
|
+
{ title: '上传' },
|
|
14
|
+
{ title: '分享' },
|
|
15
|
+
{ title: '删除', style: ActionSheetButtonStyle.Destructive },
|
|
16
|
+
],
|
|
17
|
+
cancelable: true,
|
|
18
|
+
});
|
|
19
|
+
console.log(index, canceled); // 2 false / -1 true(取消)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 结构
|
|
23
|
+
|
|
24
|
+
- `src/` —— TypeScript 源码(index / definitions / web)
|
|
25
|
+
- `dist/` —— 构建产物(CJS + d.ts,已提交)
|
|
26
|
+
- `maui/` —— .NET MAUI C# 实现(程序集 `Napacitor.ActionSheet`,运行时反射自动发现)
|
|
27
|
+
|
|
28
|
+
原生实现映射:`Page.DisplayActionSheet`(Windows 上由 MAUI 落到 `ContentDialog` 风格的
|
|
29
|
+
选择弹层)。返回的下标按 `options` 数组顺序,被取消时为 `-1`。
|
|
30
|
+
|
|
31
|
+
## 与 Capacitor 的差异
|
|
32
|
+
|
|
33
|
+
- **style / message / icon**:仅 iOS / web 有语义,MAUI 的 DisplayActionSheet 无对应
|
|
34
|
+
参数,原生端当前忽略(破坏性按钮样式需平台代码);
|
|
35
|
+
- **cancelable**:为 true 时提供 'Cancel' 取消按钮,点击取消返回 `{index: -1, canceled: true}`;
|
|
36
|
+
- **web**:Capacitor 依赖 pwa-elements 渲染样式化操作表,Napacitor 0.1 暂无对应 UI
|
|
37
|
+
元素,调用时抛出不支持错误;
|
|
38
|
+
- 该插件需要 `Microsoft.Maui.Controls` 包引用(Page API 属于 Controls 层)。
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @napacitor/action-sheet 类型定义。
|
|
3
|
+
* 原生操作表(映射 MAUI Page.DisplayActionSheet)。
|
|
4
|
+
*/
|
|
5
|
+
/** 按钮风格(仅 iOS 生效;其余平台忽略)。 */
|
|
6
|
+
export declare enum ActionSheetButtonStyle {
|
|
7
|
+
/** 默认。 */
|
|
8
|
+
Default = "DEFAULT",
|
|
9
|
+
/** 破坏性操作(红色)。 */
|
|
10
|
+
Destructive = "DESTRUCTIVE",
|
|
11
|
+
/** 取消。 */
|
|
12
|
+
Cancel = "CANCEL"
|
|
13
|
+
}
|
|
14
|
+
/** 操作表按钮。 */
|
|
15
|
+
export interface ActionSheetButton {
|
|
16
|
+
/** 按钮文案。 */
|
|
17
|
+
title: string;
|
|
18
|
+
/** 按钮风格(仅 iOS 生效;其余平台忽略)。 */
|
|
19
|
+
style?: ActionSheetButtonStyle;
|
|
20
|
+
/** 按钮图标(仅 web 生效)。 */
|
|
21
|
+
icon?: string;
|
|
22
|
+
}
|
|
23
|
+
/** showActions() 参数。 */
|
|
24
|
+
export interface ShowActionsOptions {
|
|
25
|
+
/** 操作表标题。 */
|
|
26
|
+
title: string;
|
|
27
|
+
/** 标题下的消息(仅 iOS 生效)。 */
|
|
28
|
+
message?: string;
|
|
29
|
+
/** 可选项。 */
|
|
30
|
+
options: ActionSheetButton[];
|
|
31
|
+
/** 点击表外区域是否可取消(默认 false)。 */
|
|
32
|
+
cancelable?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** showActions() 返回值。 */
|
|
35
|
+
export interface ShowActionsResult {
|
|
36
|
+
/** 被点击选项的下标(从 0 起);被取消时为 -1。 */
|
|
37
|
+
index: number;
|
|
38
|
+
/** 是否被取消。 */
|
|
39
|
+
canceled: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface ActionSheetPlugin {
|
|
42
|
+
/** 显示操作表。 */
|
|
43
|
+
showActions(options: ShowActionsOptions): Promise<ShowActionsResult>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @napacitor/action-sheet 类型定义。
|
|
4
|
+
* 原生操作表(映射 MAUI Page.DisplayActionSheet)。
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ActionSheetButtonStyle = void 0;
|
|
8
|
+
/** 按钮风格(仅 iOS 生效;其余平台忽略)。 */
|
|
9
|
+
var ActionSheetButtonStyle;
|
|
10
|
+
(function (ActionSheetButtonStyle) {
|
|
11
|
+
/** 默认。 */
|
|
12
|
+
ActionSheetButtonStyle["Default"] = "DEFAULT";
|
|
13
|
+
/** 破坏性操作(红色)。 */
|
|
14
|
+
ActionSheetButtonStyle["Destructive"] = "DESTRUCTIVE";
|
|
15
|
+
/** 取消。 */
|
|
16
|
+
ActionSheetButtonStyle["Cancel"] = "CANCEL";
|
|
17
|
+
})(ActionSheetButtonStyle || (exports.ActionSheetButtonStyle = ActionSheetButtonStyle = {}));
|
package/dist/index.d.ts
ADDED
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.ActionSheet = void 0;
|
|
30
|
+
/**
|
|
31
|
+
* @napacitor/action-sheet 入口。
|
|
32
|
+
*/
|
|
33
|
+
const core_1 = require("@napacitor/core");
|
|
34
|
+
const ActionSheet = (0, core_1.registerPlugin)('ActionSheet', {
|
|
35
|
+
web: () => Promise.resolve().then(() => __importStar(require('./web'))).then((m) => new m.ActionSheetWeb()),
|
|
36
|
+
});
|
|
37
|
+
exports.ActionSheet = ActionSheet;
|
|
38
|
+
__exportStar(require("./definitions"), exports);
|
package/dist/web.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @napacitor/action-sheet 浏览器实现。
|
|
3
|
+
* Capacitor 依赖 pwa-elements 渲染样式化操作表;Napacitor 0.1 暂无对应
|
|
4
|
+
* UI 元素,调用时抛出不支持错误。
|
|
5
|
+
*/
|
|
6
|
+
import type { ShowActionsOptions, ShowActionsResult } from './definitions';
|
|
7
|
+
export declare class ActionSheetWeb {
|
|
8
|
+
showActions(_options: ShowActionsOptions): Promise<ShowActionsResult>;
|
|
9
|
+
}
|
package/dist/web.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionSheetWeb = void 0;
|
|
4
|
+
class ActionSheetWeb {
|
|
5
|
+
async showActions(_options) {
|
|
6
|
+
throw new Error('ActionSheet.showActions:web 平台需要 UI 元素支持(Napacitor 0.1 暂未提供)');
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.ActionSheetWeb = ActionSheetWeb;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
using Microsoft.Maui.ApplicationModel;
|
|
2
|
+
using Microsoft.Maui.Controls;
|
|
3
|
+
|
|
4
|
+
namespace Napacitor.Plugins.ActionSheet;
|
|
5
|
+
|
|
6
|
+
/* ─── 参数 / 返回 DTO ─────────────────────────────────────── */
|
|
7
|
+
|
|
8
|
+
/// <summary>操作表按钮。</summary>
|
|
9
|
+
public class ActionSheetButton
|
|
10
|
+
{
|
|
11
|
+
/// <summary>按钮文案。</summary>
|
|
12
|
+
public string? Title { get; set; }
|
|
13
|
+
|
|
14
|
+
/// <summary>按钮风格(DEFAULT/DESTRUCTIVE/CANCEL;仅 iOS 语义,当前忽略)。</summary>
|
|
15
|
+
public string? Style { get; set; }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/// <summary>showActions() 参数。</summary>
|
|
19
|
+
public class ShowActionsOptions
|
|
20
|
+
{
|
|
21
|
+
/// <summary>操作表标题。</summary>
|
|
22
|
+
public string? Title { get; set; }
|
|
23
|
+
|
|
24
|
+
/// <summary>标题下的消息(仅 iOS 语义,DisplayActionSheet 无对应参数)。</summary>
|
|
25
|
+
public string? Message { get; set; }
|
|
26
|
+
|
|
27
|
+
/// <summary>可选项。</summary>
|
|
28
|
+
public List<ActionSheetButton>? Options { get; set; }
|
|
29
|
+
|
|
30
|
+
/// <summary>点击表外区域是否可取消(默认 false)。</summary>
|
|
31
|
+
public bool? Cancelable { get; set; }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/// <summary>showActions() 返回值。</summary>
|
|
35
|
+
public class ShowActionsResult
|
|
36
|
+
{
|
|
37
|
+
/// <summary>被点击选项的下标(从 0 起);被取消时为 -1。</summary>
|
|
38
|
+
public int Index { get; set; } = -1;
|
|
39
|
+
|
|
40
|
+
/// <summary>是否被取消。</summary>
|
|
41
|
+
public bool Canceled { get; set; } = true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* ─── 插件主体 ─────────────────────────────────────────────── */
|
|
45
|
+
|
|
46
|
+
/// <summary>
|
|
47
|
+
/// ActionSheet 插件:原生操作表(映射 MAUI Page.DisplayActionSheet)。
|
|
48
|
+
/// </summary>
|
|
49
|
+
[NapacitorPlugin("ActionSheet")]
|
|
50
|
+
public class ActionSheetPlugin : NapacitorPluginBase
|
|
51
|
+
{
|
|
52
|
+
/// <summary>显示操作表;被取消时 index 为 -1、canceled 为 true。</summary>
|
|
53
|
+
[NapacitorMethod]
|
|
54
|
+
public async Task<ShowActionsResult> ShowActions(ShowActionsOptions options)
|
|
55
|
+
{
|
|
56
|
+
var buttons = options.Options?
|
|
57
|
+
.Where(o => !string.IsNullOrEmpty(o.Title))
|
|
58
|
+
.Select(o => o.Title!)
|
|
59
|
+
.ToArray() ?? Array.Empty<string>();
|
|
60
|
+
if (buttons.Length == 0)
|
|
61
|
+
{
|
|
62
|
+
throw new NapacitorException(
|
|
63
|
+
NapacitorException.InvalidArguments, "ActionSheet.showActions:options 不能为空");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
var app = Application.Current;
|
|
67
|
+
var page = (app?.Windows?.FirstOrDefault()?.Page ?? app?.MainPage)
|
|
68
|
+
?? throw new NapacitorException(
|
|
69
|
+
NapacitorException.Unavailable, "ActionSheet:当前无可用页面(宿主窗口尚未创建)");
|
|
70
|
+
|
|
71
|
+
// cancelable 时提供取消按钮(DisplayActionSheet 不传 cancel 则点外无法收起)
|
|
72
|
+
var cancel = options.Cancelable == true ? "Cancel" : null;
|
|
73
|
+
var choice = await MainThread.InvokeOnMainThreadAsync(
|
|
74
|
+
() => page.DisplayActionSheet(options.Title ?? string.Empty, cancel, null, buttons));
|
|
75
|
+
|
|
76
|
+
var index = choice is null ? -1 : Array.IndexOf(buttons, choice);
|
|
77
|
+
return new ShowActionsResult { Index = index, Canceled = index < 0 };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
|
2
|
+
|
|
3
|
+
<PropertyGroup>
|
|
4
|
+
<TargetFramework>net10.0</TargetFramework>
|
|
5
|
+
<RootNamespace>Napacitor.Plugins.ActionSheet</RootNamespace>
|
|
6
|
+
<AssemblyName>Napacitor.ActionSheet</AssemblyName>
|
|
7
|
+
<Nullable>enable</Nullable>
|
|
8
|
+
<ImplicitUsings>enable</ImplicitUsings>
|
|
9
|
+
<LangVersion>latest</LangVersion>
|
|
10
|
+
<Description>Napacitor ActionSheet 插件(.NET MAUI 实现)</Description>
|
|
11
|
+
<Version>0.1.0</Version>
|
|
12
|
+
</PropertyGroup>
|
|
13
|
+
|
|
14
|
+
<ItemGroup>
|
|
15
|
+
<!-- Page.DisplayActionSheet 需要 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/action-sheet",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@napacitor/action-sheet",
|
|
3
|
+
"version": "0.1.2-beta.3",
|
|
4
|
+
"description": "Napacitor ActionSheet 插件(原生操作表,映射 MAUI Page.DisplayActionSheet)",
|
|
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
|
+
}
|