@binblink/wasmnest-plugin-sdk-mobile 0.0.0-stage → 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 (114) hide show
  1. package/README.md +363 -2
  2. package/README_en.md +353 -0
  3. package/bin/build.js +269 -0
  4. package/bin/cli.js +96 -0
  5. package/bin/lib.js +349 -0
  6. package/bin/manifest-gen.js +324 -0
  7. package/bin/package.js +150 -0
  8. package/bin/scaffold.js +285 -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 +51 -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 +328 -0
  25. package/dev-shell/src/locales/index.ts +70 -0
  26. package/dev-shell/src/locales/shell.ts +328 -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 +351 -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 +155 -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 +496 -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 +378 -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 +316 -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 +415 -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 +35 -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/useToast.ts +33 -0
  71. package/dev-shell/src/shell/index.ts +88 -0
  72. package/dev-shell/src/shell/logger.ts +45 -0
  73. package/dev-shell/src/shell/permissions.ts +145 -0
  74. package/dev-shell/src/shell/registry.ts +220 -0
  75. package/dev-shell/src/shell/styles/shell.css +841 -0
  76. package/dev-shell/src/shell/types.ts +137 -0
  77. package/dev-shell/src/shell/utils.ts +54 -0
  78. package/dev-shell/src/styles/main.css +153 -0
  79. package/dev-shell/src/styles/mobile.css +884 -0
  80. package/dev-shell/src/styles/wallpaper.css +130 -0
  81. package/dev-shell/src/theme.ts +71 -0
  82. package/dev-shell/src/vite-env.d.ts +20 -0
  83. package/dev-shell/tailwind.config.js +101 -0
  84. package/dev-shell/tsconfig.json +16 -0
  85. package/dev-shell/vite.config.ts +130 -0
  86. package/dist/index.d.ts +84 -0
  87. package/dist/index.js +161 -0
  88. package/dist/types.d.ts +637 -0
  89. package/dist/types.js +0 -0
  90. package/dist/vite-plugin.d.ts +16 -0
  91. package/dist/vite-plugin.js +95 -0
  92. package/package.json +80 -3
  93. package/src/constants.ts +6 -0
  94. package/src/global-dialog.ts +168 -0
  95. package/src/index.ts +87 -0
  96. package/src/runtime.ts +44 -0
  97. package/src/types.ts +715 -0
  98. package/src/ui/PluginGlobalDialog.vue +388 -0
  99. package/src/ui/Select.d.ts +37 -0
  100. package/src/ui/Select.vue +307 -0
  101. package/src/ui/plugin-global-dialog.d.ts +11 -0
  102. package/src/ui/useSwipeTabs.d.ts +20 -0
  103. package/src/ui/useSwipeTabs.ts +53 -0
  104. package/src/vite-plugin.ts +132 -0
  105. package/template/.gitignore +4 -0
  106. package/template/README.md +46 -0
  107. package/template/package.json +23 -0
  108. package/template/plugin.json +13 -0
  109. package/template/rust/Cargo.toml +19 -0
  110. package/template/rust/src/lib.rs +33 -0
  111. package/template/src/env.d.ts +24 -0
  112. package/template/src/index.ts +37 -0
  113. package/template/tsconfig.json +17 -0
  114. package/template/vite.config.ts +21 -0
@@ -0,0 +1,95 @@
1
+ // src/vite-plugin.ts
2
+ import MagicString from "magic-string";
3
+ var SHARED_MODULES = {
4
+ "vue": 'window.__WASMNEST_SHARED__["vue"]',
5
+ "vue-i18n": 'window.__WASMNEST_SHARED__["vue-i18n"]',
6
+ "pinia": 'window.__WASMNEST_SHARED__["pinia"]'
7
+ };
8
+ function wasmnestPlugin() {
9
+ return [sharedModulesPlugin(), inlinePluginCss()];
10
+ }
11
+ function sharedModulesPlugin() {
12
+ const externalModules = Object.keys(SHARED_MODULES);
13
+ return {
14
+ name: "wasmnest-shared-modules",
15
+ enforce: "pre",
16
+ config(config) {
17
+ const existingExternal = config.build?.rollupOptions?.external;
18
+ const externalArray = Array.isArray(existingExternal) ? existingExternal : typeof existingExternal === "string" ? [existingExternal] : [];
19
+ return {
20
+ build: {
21
+ rollupOptions: {
22
+ external: [...externalArray, ...externalModules]
23
+ }
24
+ }
25
+ };
26
+ },
27
+ renderChunk(code, chunk) {
28
+ let modified = false;
29
+ const s = new MagicString(code);
30
+ for (const [modName, globalExpr] of Object.entries(SHARED_MODULES)) {
31
+ const escapedName = modName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
32
+ const defaultRe = new RegExp(
33
+ `import\\s+(\\w+)\\s+from\\s+['"]${escapedName}['"]`,
34
+ "gm"
35
+ );
36
+ let match;
37
+ while ((match = defaultRe.exec(code)) !== null) {
38
+ const varName = match[1];
39
+ s.overwrite(match.index, match.index + match[0].length, `const ${varName} = ${globalExpr}`);
40
+ modified = true;
41
+ }
42
+ const namedRe = new RegExp(
43
+ `import\\s*\\{([^}]+)\\}\\s*from\\s+['"]${escapedName}['"]`,
44
+ "gm"
45
+ );
46
+ while ((match = namedRe.exec(code)) !== null) {
47
+ const imports = match[1];
48
+ s.overwrite(match.index, match.index + match[0].length, `const { ${imports} } = ${globalExpr}`);
49
+ modified = true;
50
+ }
51
+ const namespaceRe = new RegExp(
52
+ `import\\s+\\*\\s+as\\s+(\\w+)\\s+from\\s+['"]${escapedName}['"]`,
53
+ "gm"
54
+ );
55
+ while ((match = namespaceRe.exec(code)) !== null) {
56
+ const varName = match[1];
57
+ s.overwrite(match.index, match.index + match[0].length, `const ${varName} = ${globalExpr}`);
58
+ modified = true;
59
+ }
60
+ }
61
+ if (!modified) return null;
62
+ return {
63
+ code: s.toString(),
64
+ map: s.generateMap({ hires: true })
65
+ };
66
+ }
67
+ };
68
+ }
69
+ function inlinePluginCss() {
70
+ return {
71
+ name: "wasmnest-inline-plugin-css",
72
+ apply: "build",
73
+ enforce: "post",
74
+ generateBundle(_options, bundle) {
75
+ const entry = Object.values(bundle).find((f) => f.type === "chunk" && f.isEntry);
76
+ if (!entry || entry.type !== "chunk") return;
77
+ const cssParts = [];
78
+ for (const fileName of Object.keys(bundle)) {
79
+ if (!fileName.endsWith(".css")) continue;
80
+ const css = bundle[fileName];
81
+ if (css.type !== "asset") continue;
82
+ cssParts.push(
83
+ typeof css.source === "string" ? css.source : new TextDecoder().decode(css.source)
84
+ );
85
+ delete bundle[fileName];
86
+ }
87
+ if (cssParts.length === 0) return;
88
+ const injected = `;(function(){var s=document.createElement('style');s.setAttribute('data-wasmnest-plugin-css','');s.textContent=${JSON.stringify(cssParts.join("\n"))};document.head.appendChild(s)})();`;
89
+ entry.code = injected + "\n" + entry.code;
90
+ }
91
+ };
92
+ }
93
+ export {
94
+ wasmnestPlugin
95
+ };
package/package.json CHANGED
@@ -1,6 +1,83 @@
1
1
  {
2
2
  "name": "@binblink/wasmnest-plugin-sdk-mobile",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.1",
4
+ "license": "MIT",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "bin": {
12
+ "wasmnest-plugin": "./bin/cli.js"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "src",
17
+ "bin",
18
+ "template",
19
+ "README.md",
20
+ "README_en.md",
21
+ "LICENSE",
22
+ "dev-shell/src",
23
+ "dev-shell/index.html",
24
+ "dev-shell/package.json",
25
+ "dev-shell/vite.config.ts",
26
+ "dev-shell/tailwind.config.js",
27
+ "dev-shell/postcss.config.js",
28
+ "dev-shell/tsconfig.json",
29
+ "dev-shell/pnpm-workspace.yaml",
30
+ "dev-shell/README.md"
31
+ ],
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "import": "./dist/index.js"
36
+ },
37
+ "./vite": {
38
+ "types": "./dist/vite-plugin.d.ts",
39
+ "import": "./dist/vite-plugin.js"
40
+ },
41
+ "./ui": {
42
+ "types": "./src/ui/Select.d.ts",
43
+ "import": "./src/ui/Select.vue"
44
+ },
45
+ "./ui/plugin-global-dialog": {
46
+ "types": "./src/ui/plugin-global-dialog.d.ts",
47
+ "import": "./src/ui/PluginGlobalDialog.vue"
48
+ },
49
+ "./ui/swipe-tabs": {
50
+ "types": "./src/ui/useSwipeTabs.d.ts",
51
+ "import": "./src/ui/useSwipeTabs.ts"
52
+ },
53
+ "./global-dialog": {
54
+ "types": "./src/global-dialog.ts",
55
+ "import": "./src/global-dialog.ts"
56
+ },
57
+ "./types": {
58
+ "types": "./dist/types.d.ts",
59
+ "import": "./dist/types.js"
60
+ },
61
+ "./package.json": "./package.json"
62
+ },
63
+ "dependencies": {
64
+ "magic-string": "^0.30.21"
65
+ },
66
+ "peerDependencies": {
67
+ "vite": "^8.0.0",
68
+ "vue": "^3.4.0"
69
+ },
70
+ "devDependencies": {
71
+ "@vitejs/plugin-vue": "^6.0.0",
72
+ "autoprefixer": "^10.4.20",
73
+ "tailwindcss": "^3.4.1",
74
+ "tsup": "^8.5.1",
75
+ "typescript": "^5.9.3",
76
+ "vitest": "^3.2.7"
77
+ },
78
+ "scripts": {
79
+ "build": "tsup src/index.ts src/vite-plugin.ts src/types.ts --format esm --dts --clean",
80
+ "test": "vitest",
81
+ "test:run": "vitest run --passWithNoTests"
82
+ }
6
83
  }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * SDK 常量(宿主与插件共用单一事实源)
3
+ */
4
+
5
+ /** DEV mock 会话 id:宿主 useMockTerminal / 终端插件 UI 共用;生产构建无意义 */
6
+ export const MOCK_SESSION_ID = '__mock_terminal__'
@@ -0,0 +1,168 @@
1
+ /**
2
+ * 全局弹窗控制器(移动端宿主 + dev-shell 共用)
3
+ *
4
+ * 与桌面端 packages/plugin-sdk-desktop/src/global-dialog.ts 同构:
5
+ * 发布-订阅实现,不直接依赖 Vue reactivity,宿主 / dev-shell 的
6
+ * PluginGlobalDialog 组件经 subscribeGlobalDialog 订阅渲染。
7
+ *
8
+ * 语义:
9
+ * - FIFO 队列:同一时刻至多一个弹窗,后到的排队;当前关闭后自动接替;
10
+ * - update() 生成新条目对象再广播(订阅方拿到新引用触发重渲染);
11
+ * - close() 幂等;排队中的条目也可关闭(从队列移除);
12
+ * - 定时自动关闭为**可选能力**:仅当提供 timeoutSec / deadlineAt 时生效,
13
+ * 计时从条目成为当前弹窗起计算。
14
+ */
15
+ import type { PluginDialogOptions } from './types'
16
+
17
+ /** 内部弹窗条目 = 公开选项 + 宿主注入字段 */
18
+ export interface GlobalDialogEntry extends PluginDialogOptions {
19
+ /** 内部唯一 ID(句柄路由用) */
20
+ _id: number
21
+ /** 内容组件宿主上下文(provide('pluginContext') 用;宿主 showDialog 注入) */
22
+ pluginContext?: unknown
23
+ /** 条目创建时刻(ms) */
24
+ createdAt: number
25
+ }
26
+
27
+ /** 订阅输入(宿主注入 pluginContext 后交 openGlobalDialog) */
28
+ export type OpenGlobalDialogInput = PluginDialogOptions & { pluginContext?: unknown }
29
+
30
+ export type GlobalDialogListener = (entry: GlobalDialogEntry | null) => void
31
+
32
+ /** 打开/更新/关闭返回的句柄(供插件调用方使用) */
33
+ export interface GlobalDialogHandleOutput {
34
+ close(): void
35
+ update(options: Partial<PluginDialogOptions>): void
36
+ }
37
+
38
+ let seq = 0
39
+ let current: GlobalDialogEntry | null = null
40
+ const queue: GlobalDialogEntry[] = []
41
+ const listeners = new Set<GlobalDialogListener>()
42
+ /** 条目 → 超时定时器(仅当条目指定 timeoutSec / deadlineAt) */
43
+ const timers = new Map<number, ReturnType<typeof setTimeout>>()
44
+
45
+ /** 当前弹窗(无则 null) */
46
+ export function getGlobalDialog(): GlobalDialogEntry | null {
47
+ return current
48
+ }
49
+
50
+ /** 订阅弹窗变化;立即以当前值回调一次,返回退订函数 */
51
+ export function subscribeGlobalDialog(listener: GlobalDialogListener): () => void {
52
+ listeners.add(listener)
53
+ listener(current)
54
+ return () => {
55
+ listeners.delete(listener)
56
+ }
57
+ }
58
+
59
+ function emit(): void {
60
+ for (const fn of [...listeners]) fn(current)
61
+ }
62
+
63
+ function clearTimer(id: number): void {
64
+ const timer = timers.get(id)
65
+ if (timer) {
66
+ clearTimeout(timer)
67
+ timers.delete(id)
68
+ }
69
+ }
70
+
71
+ /** 解析条目的绝对截止时刻(deadlineAt 优先;缺省无定时关闭) */
72
+ export function resolveDialogDeadline(entry: GlobalDialogEntry): number | null {
73
+ if (entry.deadlineAt != null && entry.deadlineAt > 0) return entry.deadlineAt
74
+ if (entry.timeoutSec != null && entry.timeoutSec > 0) return entry.createdAt + entry.timeoutSec * 1000
75
+ return null
76
+ }
77
+
78
+ /** 条目成为当前弹窗时的侧效:启动(或立即触发)超时计时 */
79
+ function startTimeout(entry: GlobalDialogEntry): void {
80
+ clearTimer(entry._id)
81
+ const deadline = resolveDialogDeadline(entry)
82
+ if (deadline == null) return
83
+ const delay = Math.max(0, deadline - Date.now())
84
+ timers.set(
85
+ entry._id,
86
+ setTimeout(() => {
87
+ try {
88
+ entry.onTimeout?.()
89
+ } catch (e) {
90
+ console.error('[PluginDialog] onTimeout failed:', e)
91
+ }
92
+ closeGlobalDialog(entry._id)
93
+ }, delay),
94
+ )
95
+ }
96
+
97
+ function fireOnClose(entry: GlobalDialogEntry): void {
98
+ try {
99
+ entry.onClose?.()
100
+ } catch (e) {
101
+ console.error('[PluginDialog] onClose failed:', e)
102
+ }
103
+ }
104
+
105
+ /** 关闭指定弹窗:当前弹窗关闭后队列自动顶上;排队中直接移除(均幂等) */
106
+ export function closeGlobalDialog(id: number): void {
107
+ if (current && current._id === id) {
108
+ const closed = current
109
+ clearTimer(id)
110
+ current = null
111
+ const next = queue.shift() ?? null
112
+ current = next
113
+ emit()
114
+ fireOnClose(closed)
115
+ if (next) startTimeout(next)
116
+ return
117
+ }
118
+ const idx = queue.findIndex((e) => e._id === id)
119
+ if (idx >= 0) {
120
+ const [removed] = queue.splice(idx, 1)
121
+ fireOnClose(removed)
122
+ }
123
+ }
124
+
125
+ /** 热更新指定弹窗(当前或排队中;新对象广播触发重渲染) */
126
+ export function updateGlobalDialog(id: number, options: Partial<PluginDialogOptions>): void {
127
+ if (current && current._id === id) {
128
+ current = { ...current, ...options }
129
+ emit()
130
+ startTimeout(current)
131
+ return
132
+ }
133
+ const idx = queue.findIndex((e) => e._id === id)
134
+ if (idx >= 0) {
135
+ queue[idx] = { ...queue[idx], ...options }
136
+ }
137
+ }
138
+
139
+ /**
140
+ * 打开全局弹窗(宿主 ui.showDialog 调用)。
141
+ * 返回句柄:close() 幂等关闭(当前或排队项),update() 热更新选项。
142
+ */
143
+ export function openGlobalDialog(input: OpenGlobalDialogInput): GlobalDialogHandleOutput {
144
+ const entry: GlobalDialogEntry = {
145
+ ...input,
146
+ _id: ++seq,
147
+ createdAt: Date.now(),
148
+ }
149
+ if (current) {
150
+ queue.push(entry)
151
+ } else {
152
+ current = entry
153
+ emit()
154
+ startTimeout(entry)
155
+ }
156
+ return {
157
+ close: () => closeGlobalDialog(entry._id),
158
+ update: (options) => updateGlobalDialog(entry._id, options),
159
+ }
160
+ }
161
+
162
+ /** 测试辅助:清空全部状态(队列/当前/监听器/定时器),用例间隔离 */
163
+ export function _resetGlobalDialogForTest(): void {
164
+ for (const id of [...timers.keys()]) clearTimer(id)
165
+ current = null
166
+ queue.length = 0
167
+ listeners.clear()
168
+ }
package/src/index.ts ADDED
@@ -0,0 +1,87 @@
1
+ /**
2
+ * @binblink/wasmnest-plugin-sdk-mobile
3
+ *
4
+ * WasmNest 移动端插件开发工具包
5
+ */
6
+
7
+ export type {
8
+ Disposable,
9
+ PluginType,
10
+ PluginState,
11
+ PluginManifest,
12
+ PluginConfiguration,
13
+ ConfigProperty,
14
+ MobilePluginContributes,
15
+ LifecycleContribution,
16
+ CommandContribution,
17
+ ViewContribution,
18
+ NavTabContribution,
19
+ SettingsContribution,
20
+ RouteContribution,
21
+ TerminalContribution,
22
+ TerminalToolbarItemContribution,
23
+ TerminalStreamHandle,
24
+ MobileHostSessionEvent,
25
+ PluginRouteDescriptor,
26
+ ShellSurfaceContribution,
27
+ ShellSlotContribution,
28
+ ShellCapsuleItem,
29
+ PluginDialogAction,
30
+ PluginDialogOptions,
31
+ PluginDialogHandle,
32
+ CommandRegistry,
33
+ SessionAPI,
34
+ UIRegistry,
35
+ EventAPI,
36
+ StorageAPI,
37
+ I18nAPI,
38
+ LifecycleAPI,
39
+ LoggerAPI,
40
+ DialogOptions,
41
+ DialogResult,
42
+ DialogAPI,
43
+ NotificationAPI,
44
+ StatusAPI,
45
+ SystemAPI,
46
+ PluginDevMock,
47
+ PluginContext,
48
+ PluginModule,
49
+ MobileHttpResult,
50
+ MobileHttpRequestOptions,
51
+ MobileHostApi,
52
+ MonitorPanelContribution,
53
+ MonitorPanelEnv,
54
+ MonitorPanelHandle,
55
+ MountMonitorPanel,
56
+ } from './types'
57
+
58
+ export {
59
+ getSharedModule,
60
+ getI18n,
61
+ getVue,
62
+ getVueI18n,
63
+ getPinia,
64
+ getRouter,
65
+ getPluginContext,
66
+ getPresetTasks,
67
+ getMobileApi,
68
+ } from './runtime'
69
+
70
+ // SDK 常量(宿主与插件共用单一事实源)
71
+ export { MOCK_SESSION_ID } from './constants'
72
+
73
+ // 全局弹窗控制器(宿主 / dev-shell 共用,插件经 context.ui.showDialog 操控)
74
+ export {
75
+ openGlobalDialog,
76
+ closeGlobalDialog,
77
+ updateGlobalDialog,
78
+ getGlobalDialog,
79
+ subscribeGlobalDialog,
80
+ resolveDialogDeadline,
81
+ } from './global-dialog'
82
+ export type {
83
+ GlobalDialogEntry,
84
+ GlobalDialogListener,
85
+ OpenGlobalDialogInput,
86
+ GlobalDialogHandleOutput,
87
+ } from './global-dialog'
package/src/runtime.ts ADDED
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @binblink/wasmnest-plugin-sdk-mobile 运行时代理
3
+ */
4
+ import type { MobileHostApi, PluginContext } from './types'
5
+
6
+ const SHARED_KEY = '__WASMNEST_SHARED__'
7
+
8
+ /** 获取宿主共享模块 */
9
+ export function getSharedModule(name: string): any {
10
+ const shared = (window as any)[SHARED_KEY]
11
+ if (!shared) throw new Error('[PluginSDK] Shared runtime not initialized')
12
+ const mod = shared[name]
13
+ if (!mod) throw new Error(`[PluginSDK] Shared module "${name}" not found`)
14
+ return mod
15
+ }
16
+
17
+ /** 获取宿主 i18n 实例 */
18
+ export function getI18n(): any { return getSharedModule('i18n') }
19
+
20
+ /** 获取宿主 Vue 实例 */
21
+ export function getVue(): any { return getSharedModule('vue') }
22
+
23
+ /** 获取宿主 vue-i18n 模块 */
24
+ export function getVueI18n(): any { return getSharedModule('vue-i18n') }
25
+
26
+ /** 获取宿主 Pinia 模块 */
27
+ export function getPinia(): any { return getSharedModule('pinia') }
28
+
29
+ /** 获取宿主 Router 实例 */
30
+ export function getRouter(): any { return getSharedModule('router') }
31
+
32
+ /** 获取宿主预设任务 composable */
33
+ export function getPresetTasks(): any { return getSharedModule('presetTasks') }
34
+
35
+ /** 获取宿主移动端连接/HTTP 能力(MobileHostApi,通用连接 + httpRequest 通道) */
36
+ export function getMobileApi(): MobileHostApi { return getSharedModule('mobileApi') }
37
+
38
+ /** 从 Vue inject 获取 PluginContext */
39
+ export function getPluginContext(): PluginContext {
40
+ const vue = getVue()
41
+ const context = vue.inject('pluginContext')
42
+ if (!context) throw new Error('[PluginSDK] PluginContext not available')
43
+ return context
44
+ }