@binblink/wasmnest-plugin-sdk-mobile 0.0.0-stage → 0.0.2

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 (122) hide show
  1. package/README.md +439 -2
  2. package/README_en.md +415 -0
  3. package/bin/build.js +271 -0
  4. package/bin/cli.js +96 -0
  5. package/bin/lib.js +349 -0
  6. package/bin/manifest-gen.js +327 -0
  7. package/bin/package.js +151 -0
  8. package/bin/scaffold.js +299 -0
  9. package/dev-shell/README.md +151 -0
  10. package/dev-shell/index.html +27 -0
  11. package/dev-shell/package.json +27 -0
  12. package/dev-shell/pnpm-workspace.yaml +9 -0
  13. package/dev-shell/postcss.config.js +6 -0
  14. package/dev-shell/src/App.vue +90 -0
  15. package/dev-shell/src/apps/mock-terminal/MockTerminalSlotCard.vue +43 -0
  16. package/dev-shell/src/apps/mock-terminal/MockTerminalView.vue +168 -0
  17. package/dev-shell/src/apps/mock-terminal/index.ts +50 -0
  18. package/dev-shell/src/components/DevToolbar.vue +100 -0
  19. package/dev-shell/src/components/DialogHost.vue +119 -0
  20. package/dev-shell/src/components/LogPanel.vue +80 -0
  21. package/dev-shell/src/i18n.ts +22 -0
  22. package/dev-shell/src/loader.ts +239 -0
  23. package/dev-shell/src/locale.ts +29 -0
  24. package/dev-shell/src/locales/en-shell.ts +332 -0
  25. package/dev-shell/src/locales/index.ts +70 -0
  26. package/dev-shell/src/locales/shell.ts +331 -0
  27. package/dev-shell/src/main.ts +58 -0
  28. package/dev-shell/src/mock/dialog-service.ts +58 -0
  29. package/dev-shell/src/mock/file-transfer.ts +390 -0
  30. package/dev-shell/src/mock/mobile-api.ts +369 -0
  31. package/dev-shell/src/mock/preset-tasks.ts +186 -0
  32. package/dev-shell/src/mock/session.ts +121 -0
  33. package/dev-shell/src/mock-context.ts +374 -0
  34. package/dev-shell/src/registry.ts +151 -0
  35. package/dev-shell/src/shared-runtime.ts +44 -0
  36. package/dev-shell/src/shell/ShellView.vue +52 -0
  37. package/dev-shell/src/shell/adapters/devAppSource.ts +144 -0
  38. package/dev-shell/src/shell/components/PluginContextHost.vue +40 -0
  39. package/dev-shell/src/shell/components/ShellAppCell.vue +75 -0
  40. package/dev-shell/src/shell/components/ShellAppIcon.vue +111 -0
  41. package/dev-shell/src/shell/components/ShellAppSurface.vue +46 -0
  42. package/dev-shell/src/shell/components/ShellBrandTile.vue +27 -0
  43. package/dev-shell/src/shell/components/ShellCapsuleMenu.vue +123 -0
  44. package/dev-shell/src/shell/components/ShellChip.vue +49 -0
  45. package/dev-shell/src/shell/components/ShellGroupCard.vue +17 -0
  46. package/dev-shell/src/shell/components/ShellHost.vue +75 -0
  47. package/dev-shell/src/shell/components/ShellNotificationShade.vue +501 -0
  48. package/dev-shell/src/shell/components/ShellPermissionPrompt.vue +127 -0
  49. package/dev-shell/src/shell/components/ShellPlaceholderSurface.vue +33 -0
  50. package/dev-shell/src/shell/components/ShellSection.vue +27 -0
  51. package/dev-shell/src/shell/components/ShellSheet.vue +74 -0
  52. package/dev-shell/src/shell/components/ShellStatusbar.vue +84 -0
  53. package/dev-shell/src/shell/components/screens/PluginRoutePage.vue +98 -0
  54. package/dev-shell/src/shell/components/screens/ShellAppDetailScreen.vue +359 -0
  55. package/dev-shell/src/shell/components/screens/ShellAppRunScreen.vue +90 -0
  56. package/dev-shell/src/shell/components/screens/ShellAppsScreen.vue +195 -0
  57. package/dev-shell/src/shell/components/screens/ShellHomeScreen.vue +357 -0
  58. package/dev-shell/src/shell/components/screens/ShellPermissionsScreen.vue +376 -0
  59. package/dev-shell/src/shell/components/screens/ShellSettingsScreen.vue +240 -0
  60. package/dev-shell/src/shell/components/screens/ShellSwitcherScreen.vue +559 -0
  61. package/dev-shell/src/shell/components/ui/ConfirmDialog.vue +137 -0
  62. package/dev-shell/src/shell/components/ui/Toggle.vue +53 -0
  63. package/dev-shell/src/shell/composables/useShellApps.ts +417 -0
  64. package/dev-shell/src/shell/composables/useShellNavigation.ts +197 -0
  65. package/dev-shell/src/shell/composables/useShellNotifications.ts +115 -0
  66. package/dev-shell/src/shell/composables/useShellOpen.ts +44 -0
  67. package/dev-shell/src/shell/composables/useShellOverlays.ts +101 -0
  68. package/dev-shell/src/shell/composables/useShellPreferences.ts +143 -0
  69. package/dev-shell/src/shell/composables/useShellRecent.ts +84 -0
  70. package/dev-shell/src/shell/composables/useSlotCarousel.ts +238 -0
  71. package/dev-shell/src/shell/composables/useToast.ts +33 -0
  72. package/dev-shell/src/shell/index.ts +88 -0
  73. package/dev-shell/src/shell/logger.ts +45 -0
  74. package/dev-shell/src/shell/permissions.ts +145 -0
  75. package/dev-shell/src/shell/registry.ts +220 -0
  76. package/dev-shell/src/shell/slotCards.ts +47 -0
  77. package/dev-shell/src/shell/styles/shell.css +1155 -0
  78. package/dev-shell/src/shell/surfaceIntent.ts +107 -0
  79. package/dev-shell/src/shell/types.ts +152 -0
  80. package/dev-shell/src/shell/utils.ts +54 -0
  81. package/dev-shell/src/styles/main.css +153 -0
  82. package/dev-shell/src/styles/mobile.css +981 -0
  83. package/dev-shell/src/styles/wallpaper.css +130 -0
  84. package/dev-shell/src/theme.ts +71 -0
  85. package/dev-shell/src/vite-env.d.ts +20 -0
  86. package/dev-shell/tailwind.config.js +101 -0
  87. package/dev-shell/tsconfig.json +16 -0
  88. package/dev-shell/vite.config.ts +130 -0
  89. package/dist/index.d.ts +124 -0
  90. package/dist/index.js +229 -0
  91. package/dist/types.d.ts +738 -0
  92. package/dist/types.js +0 -0
  93. package/dist/vite-plugin.d.ts +16 -0
  94. package/dist/vite-plugin.js +95 -0
  95. package/package.json +88 -3
  96. package/src/constants.ts +6 -0
  97. package/src/global-dialog.ts +168 -0
  98. package/src/index.ts +96 -0
  99. package/src/runtime.ts +44 -0
  100. package/src/types.ts +822 -0
  101. package/src/ui/AppUpdateSection.d.ts +44 -0
  102. package/src/ui/AppUpdateSection.vue +253 -0
  103. package/src/ui/PluginGlobalDialog.vue +388 -0
  104. package/src/ui/QuickCard.d.ts +33 -0
  105. package/src/ui/QuickCard.vue +167 -0
  106. package/src/ui/Select.d.ts +37 -0
  107. package/src/ui/Select.vue +307 -0
  108. package/src/ui/plugin-global-dialog.d.ts +11 -0
  109. package/src/ui/useSwipeTabs.d.ts +20 -0
  110. package/src/ui/useSwipeTabs.ts +53 -0
  111. package/src/update.ts +123 -0
  112. package/src/vite-plugin.ts +132 -0
  113. package/template/.gitignore +4 -0
  114. package/template/README.md +46 -0
  115. package/template/package.json +23 -0
  116. package/template/plugin.json +13 -0
  117. package/template/rust/Cargo.toml +19 -0
  118. package/template/rust/src/lib.rs +33 -0
  119. package/template/src/env.d.ts +24 -0
  120. package/template/src/index.ts +37 -0
  121. package/template/tsconfig.json +17 -0
  122. package/template/vite.config.ts +21 -0
@@ -0,0 +1,331 @@
1
+ /**
2
+ * Dev Shell 宿主壳文案 —— 简体中文
3
+ * -----------------------------------------------------------------------------
4
+ * 与宿主 `wasmnest-mobile/src/locales/zh-CN/shell.ts` 同键同义(措辞沿用宿主,
5
+ * 避免预览与真机两套说法)。宿主新增 key 时按 `dev-shell/__tests__/visualParity.test.ts`
6
+ * 之外的这份副本同步(本文件是 dev-shell 自有命名空间,不做逐字比对)。
7
+ *
8
+ * dev-shell 独有的 key 保留在既有段内并注明理由(主题档位 / 调试数据等浏览器环境专有面)。
9
+ *
10
+ * 新增 / 修改 key 必须同步 en/shell.ts(i18n 双语纪律)。
11
+ */
12
+ export const zhCNShell = {
13
+ shell: {
14
+ common: {
15
+ loading: '加载中…',
16
+ retry: '重试',
17
+ na: '—',
18
+ running: '运行中',
19
+ stopped: '未启动',
20
+ disabled: '已停用',
21
+ approval: '待审批',
22
+ error: '启动失败',
23
+ cancel: '取消',
24
+ active: '当前',
25
+ back: '返回'
26
+ },
27
+ home: {
28
+ localDevice: '本机',
29
+ appCount: '{count} 个应用',
30
+ runningTitle: '正在运行',
31
+ switchTo: '切换到 {name}',
32
+ stopInstance: '停止',
33
+ slotsTitle: '快捷卡片',
34
+ slotOpen: '打开 {name}',
35
+ slotPause: '暂停轮播',
36
+ slotPlay: '开始轮播',
37
+ appsTitle: '我的 WASM 应用',
38
+ appsNote: '{count} 个已安装',
39
+ manageApps: '应用管理',
40
+ appAria: '{name},{state}',
41
+ emptyApps: '尚未安装 WASM 应用',
42
+ emptyAppsHint: '在「应用管理」里安装或启用后,入口会出现在这里',
43
+ sysTitle: '系统',
44
+ sysApps: '应用管理',
45
+ sysPermissions: '权限管理',
46
+ sysSettings: '设置'
47
+ },
48
+ apps: {
49
+ title: 'WASM 应用',
50
+ subtitle: '{installed} 个已安装 · {running} 个运行中',
51
+ statInstalled: '已安装',
52
+ statRunning: '运行中',
53
+ statSize: '总占用',
54
+ installedTitle: '已安装应用',
55
+ addTitle: '添加应用',
56
+ installLocal: '安装本地包(.wasm)',
57
+ installLocalHint: '需审批',
58
+ empty: '暂无应用',
59
+ permissionCount: '{count} 项权限',
60
+ installSuccess: '安装完成,可在列表中批准并启动',
61
+ installFailed: '安装失败:{error}',
62
+ uninstallConfirm: '确定卸载「{name}」并删除其数据吗?此操作不可恢复。',
63
+ uninstallSuccess: '已卸载 {name}',
64
+ uninstallFailed: '卸载失败:{error}'
65
+ },
66
+ detail: {
67
+ title: '应用详情',
68
+ back: '返回',
69
+ official: '官方',
70
+ approvalDesc: '该应用申请 {count} 项权限,批准后才能启动;批准会同时钉扎当前文件哈希。',
71
+ approveStart: '批准并启动',
72
+ state: '运行状态',
73
+ permissions: '权限',
74
+ permissionsNote: '{granted} 项已授予 · {locked} 项默认',
75
+ permissionsReadonly: '权限随应用包声明,宿主整单裁决;此处只读,不可逐项变更。',
76
+ permissionLocked: '默认授予 · 不可变更',
77
+ permissionUnsupported: '当前后端不支持逐项开关权限',
78
+ storage: '存储',
79
+ appData: '应用数据',
80
+ grants: '授权记录',
81
+ grantsNote: '近 7 天',
82
+ grantsEmpty: '暂无授权记录',
83
+ disable: '停用应用',
84
+ uninstall: '卸载并删除数据',
85
+ version: 'v{version}'
86
+ },
87
+ run: {
88
+ menu: '应用菜单',
89
+ recents: '多任务',
90
+ home: '回主屏',
91
+ noSurface: '应用暂无可用界面',
92
+ noSurfaceHint: '该应用尚未提供运行界面',
93
+ notFound: '应用不存在或已卸载'
94
+ },
95
+ switcher: {
96
+ title: '多任务',
97
+ back: '返回',
98
+ countUnit: '个',
99
+ closeAll: '全部关闭',
100
+ closeCard: '关闭 {name} 的卡片',
101
+ dormant: '未运行',
102
+ enterApp: '进入 {name}',
103
+ launchApp: '启动 {name}',
104
+ goHome: '回到主屏',
105
+ empty: '没有可切换的应用',
106
+ emptyHint: '回到主屏打开一个应用,它会出现在这里'
107
+ },
108
+ notify: {
109
+ title: '通知栏',
110
+ count: '{count} 条',
111
+ open: '打开通知栏({count} 条)',
112
+ close: '收起通知栏',
113
+ pending: '待处理',
114
+ pendingNote: '需要你决定',
115
+ pendingBody: '{count} 项权限待批准',
116
+ pendingAction: '去审批',
117
+ list: '通知',
118
+ listNote: '{count} 条',
119
+ empty: '暂无通知',
120
+ emptyHint: '应用启动、连接状态与待审批事项会出现在这里',
121
+ clearAll: '清除全部',
122
+ dismissOne: '关闭通知:{title}',
123
+ openByTap: '点击打开 {title}',
124
+ justNow: '刚刚',
125
+ minutesAgo: '{count} 分钟前',
126
+ hoursAgo: '{count} 小时前',
127
+ daysAgo: '{count} 天前',
128
+ source: {
129
+ shell: '平台',
130
+ host: '连接'
131
+ },
132
+ connected: {
133
+ title: '已连接到桌面端',
134
+ body: '连接已建立并通过认证'
135
+ },
136
+ reconnected: {
137
+ title: '连接已恢复',
138
+ body: '断线后自动重连成功'
139
+ },
140
+ disconnected: {
141
+ title: '连接已断开',
142
+ body: '与桌面端的连接中断'
143
+ },
144
+ reauthRejected: {
145
+ title: '需要重新配对',
146
+ body: '凭据被拒绝,重新配对后才能连接'
147
+ },
148
+ app: {
149
+ started: {
150
+ title: '{name} 已启动',
151
+ body: '应用正在后台运行'
152
+ },
153
+ stopped: {
154
+ title: '{name} 已停止',
155
+ body: '应用已停止,数据保留'
156
+ },
157
+ approved: {
158
+ title: '{name} 已批准',
159
+ body: '权限申请已批准并完成内容钉扎'
160
+ },
161
+ installed: {
162
+ title: '{name} 已安装',
163
+ body: '批准后即可启动'
164
+ },
165
+ uninstalled: {
166
+ title: '{name} 已卸载',
167
+ body: '应用与其数据已删除'
168
+ },
169
+ failed: {
170
+ title: '{name} 启动失败',
171
+ body: '请查看应用详情后重试'
172
+ }
173
+ }
174
+ },
175
+ settings: {
176
+ title: '设置',
177
+ platform: '平台',
178
+ appearance: '外观',
179
+ appearanceHint: '主题与色板',
180
+ permissions: '权限总览',
181
+ permissionsHint: '按权限看应用',
182
+ about: '关于 WasmApp',
183
+ runtime: 'WasmApp Mobile {version}',
184
+ devShellHint: '浏览器调试环境 · WASM 后端不在此运行',
185
+ language: '语言',
186
+ debugObjects: '调试对象',
187
+ debugObjectsHint: '{count} 个对象 · {running} 个运行中',
188
+ devData: '调试数据',
189
+ clearDevData: '清除调试数据',
190
+ clearDevDataHint: '清空本机 localStorage 里的调试键(插件 storage、最近使用、语言),页面会重新加载。此操作不可恢复。',
191
+ clearDevDataDone: '已清除 {count} 项调试数据,正在重新加载…'
192
+ },
193
+ permissions: {
194
+ pending: '待审批',
195
+ pendingNote: '需要你决定',
196
+ pendingBody: '{count} 项权限待批准',
197
+ approveStart: '批准并启动',
198
+ approveFailed: '批准失败,请查看应用详情',
199
+ viewSwitch: '权限总览视图',
200
+ viewApps: '按应用',
201
+ viewGroups: '按权限',
202
+ appSection: '应用权限',
203
+ appSummary: '{granted} 项已授予',
204
+ appSummaryLocked: '{granted} 项已授予 · {locked} 项默认',
205
+ appNone: '未申请权限',
206
+ granted: '已授予',
207
+ locked: '默认授予',
208
+ ungranted: '未授予'
209
+ },
210
+ capsule: {
211
+ title: '应用',
212
+ permissions: '权限设置',
213
+ about: '关于此应用',
214
+ disable: '停用此应用'
215
+ },
216
+ permissionPrompt: {
217
+ title: '{name} 申请权限',
218
+ purpose: '用途:{reason}',
219
+ purposeUnknown: '用途:应用未说明',
220
+ deny: '拒绝',
221
+ allow: '允许',
222
+ fineprint: '拒绝后应用的相关功能将不可用;可随时在「应用 → {name} → 权限」中变更。'
223
+ },
224
+ permission: {
225
+ group: {
226
+ terminal: '终端与会话',
227
+ data: '文件与网络',
228
+ device: '设备与链路',
229
+ system: '系统与监控',
230
+ interface: '界面与消息',
231
+ other: '其他'
232
+ },
233
+ perm: {
234
+ storage: {
235
+ title: '本地存储'
236
+ },
237
+ terminalOutput: {
238
+ title: '终端输出流'
239
+ },
240
+ sessionRead: {
241
+ title: '会话读取'
242
+ },
243
+ sessionWrite: {
244
+ title: '会话写入'
245
+ },
246
+ uiToolbox: {
247
+ title: '工具箱 UI'
248
+ },
249
+ uiNavtab: {
250
+ title: '导航标签'
251
+ },
252
+ uiSettings: {
253
+ title: '设置区域'
254
+ },
255
+ uiInput: {
256
+ title: '输入辅助'
257
+ },
258
+ networkHttp: {
259
+ title: '网络请求'
260
+ },
261
+ fsRead: {
262
+ title: '文件读取'
263
+ },
264
+ fsWrite: {
265
+ title: '文件写入'
266
+ },
267
+ fsPick: {
268
+ title: '文件选择'
269
+ },
270
+ fileservice: {
271
+ title: '文件服务'
272
+ },
273
+ transfer: {
274
+ title: '文件传输'
275
+ },
276
+ systemOpen: {
277
+ title: '系统打开'
278
+ },
279
+ bus: {
280
+ title: '消息总线'
281
+ },
282
+ broadcast: {
283
+ title: '广播消息'
284
+ },
285
+ mdns: {
286
+ title: '局域网发现'
287
+ },
288
+ peer: {
289
+ title: '对端连接'
290
+ },
291
+ wsClient: {
292
+ title: 'WebSocket 客户端'
293
+ },
294
+ auth: {
295
+ title: '认证'
296
+ },
297
+ notify: {
298
+ title: '通知'
299
+ },
300
+ uiRoute: {
301
+ title: '页面路由'
302
+ },
303
+ uiDialog: {
304
+ title: '弹窗'
305
+ },
306
+ uiBack: {
307
+ title: '返回键接管'
308
+ },
309
+ metricsRead: {
310
+ title: '运行指标读取',
311
+ desc: '只读查看所有已加载插件的运行指标(计数与资源用量);一次授权全局可见,可推断其他应用活跃度(侧信道)。'
312
+ }
313
+ }
314
+ },
315
+ mobile: {
316
+ plugin: {
317
+ noPermissions: '无权限请求'
318
+ }
319
+ }
320
+ }
321
+ };
322
+
323
+
324
+ /** dev-shell 专有文案(工具条 / 日志面板 / 内置应用 / 插件路由页) */
325
+ export const zhCNDevShell = {
326
+ 'devshell.plugin.loadFailed': '插件组件未注册',
327
+ 'devshell.plugin.routeLoading': '加载中',
328
+ 'devshell.terminal.queueMock': '队列(mock):',
329
+ 'devshell.terminal.queueEmpty': '空',
330
+ 'devshell.terminal.queueClear': '清空',
331
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Dev Shell 入口
3
+ *
4
+ * 初始化顺序与宿主一致:pinia → router → i18n → 共享运行时(必须在导入插件前)→
5
+ * 加载调试对象(async)→ 挂载应用。mount 前先渲染 loading 骨架,对象就绪后展示真实内容。
6
+ *
7
+ * router 的职责收敛为一件事:承载**插件动态路由**(`/plugin/{pluginId}/{routeId}`,
8
+ * 由 mock-context 的 registerRoute 动态 addRoute)。宿主壳自己不走路由——它是一层
9
+ * 屏幕栈平台,路由只负责「进插件声明的整页跳转」,与宿主同构。
10
+ */
11
+ import { createApp } from 'vue'
12
+ import { createPinia } from 'pinia'
13
+ import { createRouter, createWebHashHistory } from 'vue-router'
14
+ import App from './App.vue'
15
+ import { initSharedRuntime } from './shared-runtime'
16
+ import { loadPlugins } from './loader'
17
+ import { initTheme } from './theme'
18
+ import { presetTasksApi } from './mock/preset-tasks'
19
+ import { mobileApi } from './mock/mobile-api'
20
+ import { dialogService } from './mock/dialog-service'
21
+ // i18n 单例:main.ts 装配 + 模块级代码(通知文案 / 相对时间)共用
22
+ import { i18n } from './i18n'
23
+ import './styles/main.css'
24
+ // token 走单一真源:monorepo 内指向宿主 src/styles/mobile.css(见 vite.config.ts),
25
+ // npm 包内回落到 dev-shell 自带副本
26
+ import '@wasmnest/mobile-styles/mobile.css'
27
+ // 主屏壁纸样式(宿主 wall-* 真源的副本 / 别名接线,见 vite.config.ts)
28
+ import '@wasmnest/mobile-styles/wallpaper.css'
29
+
30
+ const app = createApp(App)
31
+ const pinia = createPinia()
32
+
33
+ const router = createRouter({
34
+ history: createWebHashHistory(),
35
+ routes: [{ path: '/', component: { template: '<span />' } }],
36
+ })
37
+
38
+ app.use(pinia)
39
+ app.use(router)
40
+ app.use(i18n)
41
+
42
+ // 主题初始化(index.html 内联脚本已消除首帧闪烁,这里建立监听/持久化)
43
+ initTheme()
44
+
45
+ // 共享运行时必须在插件模块导入之前就位(插件模块顶层可能调用 getVue() 等)
46
+ await initSharedRuntime({
47
+ pinia,
48
+ router,
49
+ i18n,
50
+ presetTasks: presetTasksApi,
51
+ dialogs: dialogService,
52
+ mobileApi,
53
+ })
54
+
55
+ // 调试对象就绪后挂载(壳的应用清单依赖注册结果)
56
+ await loadPlugins()
57
+
58
+ app.mount('#app')
@@ -0,0 +1,58 @@
1
+ /**
2
+ * 对话框服务 mock(宿主 dialog-host.ts 的浏览器实现)
3
+ *
4
+ * 队列式 Promise 关联:DialogHost.vue 渲染 queue 中的条目,
5
+ * 用户操作后 resolveTop 完成对应 Promise。toasts 由 ToastHost 渲染。
6
+ */
7
+ import { ref } from 'vue'
8
+ import type { DialogOptions, DialogResult } from '../../../src/types'
9
+
10
+ export interface DialogItem {
11
+ id: number
12
+ kind: 'dialog' | 'confirm' | 'prompt'
13
+ options: DialogOptions
14
+ resolve: (result: DialogResult) => void
15
+ }
16
+
17
+ export interface ToastItem {
18
+ id: number
19
+ message: string
20
+ type: 'info' | 'success' | 'warning' | 'error'
21
+ }
22
+
23
+ const queue = ref<DialogItem[]>([])
24
+ const toasts = ref<ToastItem[]>([])
25
+ let nextId = 0
26
+
27
+ function push(kind: DialogItem['kind'], options: DialogOptions): Promise<DialogResult> {
28
+ return new Promise<DialogResult>((resolve) => {
29
+ const id = ++nextId
30
+ queue.value.push({ id, kind, options, resolve })
31
+ })
32
+ }
33
+
34
+ /** 解析队列顶部条目 */
35
+ export function resolveTop(action: DialogResult['action'], value?: string): void {
36
+ const item = queue.value.shift()
37
+ if (item) item.resolve({ action, value })
38
+ }
39
+
40
+ /** 暴露到 window.__WASMNEST_SHARED__.dialogs(与宿主 pluginDialogHost 同形状) */
41
+ export const dialogService = {
42
+ queue,
43
+ toasts,
44
+ showDialog: (options: DialogOptions) => push('dialog', options),
45
+ showConfirm: (options: DialogOptions) =>
46
+ push('confirm', options).then((r) => r.action === 'confirm'),
47
+ showPrompt: (options: DialogOptions) =>
48
+ push('prompt', options).then((r) => (r.action === 'confirm' ? (r.value ?? '') : null)),
49
+ showToast: (message: string, type: ToastItem['type'] = 'info') => {
50
+ const id = ++nextId
51
+ toasts.value.push({ id, message, type })
52
+ setTimeout(() => {
53
+ const idx = toasts.value.findIndex((t) => t.id === id)
54
+ if (idx !== -1) toasts.value.splice(idx, 1)
55
+ }, type === 'error' ? 5000 : type === 'warning' ? 4000 : 3000)
56
+ },
57
+ resolveTop,
58
+ }