@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,90 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Dev Shell 舞台
4
+ *
5
+ * 外框(深色工作台 + 工具条)+ 手机骨架(宿主壳)。frame 开启时以 390×844 手机框
6
+ * 呈现(与真机尺寸一致),关闭时全宽渲染便于 DevTools 模拟。
7
+ *
8
+ * 内容区按「当前是不是插件动态路由页」二选一:
9
+ * · 常规(/)→ 宿主壳 `ShellView`(屏幕栈 + 底栏 + 胶囊)
10
+ * · 插件路由(/plugin/:pluginId/*)→ `RouterView`(插件声明的整页跳转,与宿主同构:
11
+ * 走 vue-router 而不是塞进壳的屏幕栈)
12
+ * 两者共用同一个手机视口容器,保证插件路由页的宽度/安全区表现与运行面一致。
13
+ */
14
+ import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
15
+ import { useRoute } from 'vue-router'
16
+ import DevToolbar from './components/DevToolbar.vue'
17
+ import DialogHost from './components/DialogHost.vue'
18
+ import PluginGlobalDialog from '../../src/ui/PluginGlobalDialog.vue'
19
+ import LogPanel from './components/LogPanel.vue'
20
+ import ShellView from './shell/ShellView.vue'
21
+ import './shell/styles/shell.css'
22
+ import { deactivateAll } from './loader'
23
+
24
+ const frame = ref(true)
25
+ const logOpen = ref(false)
26
+
27
+ const route = useRoute()
28
+ /** 是否处于插件动态路由页(meta.pluginRoute 由 mock-context 的 registerRoute 写入) */
29
+ const isPluginRoute = computed(() => Boolean(route.meta.pluginRoute))
30
+
31
+ // 插件在停用/停机时注册的事件监听必须回收;浏览器关页面前没有可靠钩子,
32
+ // 因此在组件卸载与页面隐藏两处各撤一次(幂等)
33
+ onMounted(() => {
34
+ window.addEventListener('beforeunload', onBeforeUnload)
35
+ document.addEventListener('visibilitychange', onVisibilityChange)
36
+ })
37
+
38
+ onBeforeUnmount(() => {
39
+ window.removeEventListener('beforeunload', onBeforeUnload)
40
+ document.removeEventListener('visibilitychange', onVisibilityChange)
41
+ })
42
+
43
+ function onBeforeUnload(): void {
44
+ void deactivateAll()
45
+ }
46
+
47
+ function onVisibilityChange(): void {
48
+ if (document.visibilityState === 'hidden') void deactivateAll()
49
+ }
50
+ </script>
51
+
52
+ <template>
53
+ <div class="h-screen w-screen bg-[#14141a] flex flex-col overflow-hidden dev-stage">
54
+ <DevToolbar v-model:log-open="logOpen" :frame="frame" @toggle-frame="frame = !frame" />
55
+ <div class="flex-1 min-h-0 w-full flex overflow-auto p-3">
56
+ <div
57
+ v-if="frame"
58
+ class="phone-frame m-auto flex-shrink-0 rounded-[42px] border-[10px] border-[#2a2a33] shadow-2xl overflow-hidden"
59
+ :style="{ height: 'var(--dev-shell-frame-h)' }"
60
+ >
61
+ <div class="phone-screen h-full w-[390px] mobile-app mobile-ui">
62
+ <RouterView v-if="isPluginRoute" />
63
+ <ShellView v-else />
64
+ </div>
65
+ </div>
66
+ <div v-else class="dev-shell-app h-full w-full max-w-2xl m-auto mobile-app mobile-ui">
67
+ <RouterView v-if="isPluginRoute" />
68
+ <ShellView v-else />
69
+ </div>
70
+ </div>
71
+ </div>
72
+
73
+ <!-- 全局浮层(Teleport to body) -->
74
+ <DialogHost />
75
+ <PluginGlobalDialog />
76
+ <LogPanel v-model:log-open="logOpen" />
77
+ </template>
78
+
79
+ <style scoped>
80
+ .dev-stage {
81
+ user-select: none;
82
+ }
83
+
84
+ /* 手机框内 / 全宽模式:压过宿主 mobile-app 的 min-height:100dvh,否则显式高度被撑破,
85
+ 底部(导航栏)超出舞台被裁切 */
86
+ .phone-screen,
87
+ .dev-shell-app {
88
+ min-height: 0 !important;
89
+ }
90
+ </style>
@@ -0,0 +1,43 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * 会话状态磁贴(内置应用贡献给平台首页的快捷卡片)
4
+ *
5
+ * 用来在预览环境里真实跑通 `registerSlot` 这条路径:壳的首页会渲染应用注册的卡片
6
+ * 组件,插件开发者在这里能确认自己的 slot 组件在壳的布局里表现如何(而不是自己
7
+ * 搭一个假首页去验)。
8
+ *
9
+ * 外观用 SDK 公共 QuickCard(`src/ui/QuickCard.vue`;dev-shell 不装自己的 npm 包,
10
+ * 故以内联源码路径引用)。点击与跳转归宿主壳——整张卡由壳包成按钮并打开本应用,
11
+ * 卡片内不再放按钮 / 交互。
12
+ */
13
+ import { computed, onMounted, onUnmounted, ref } from 'vue'
14
+ import QuickCard from '../../../../src/ui/QuickCard.vue'
15
+ import { sessions } from '../../mock/session'
16
+
17
+ /** 壳透传的应用上下文(本卡不消费,留着是为了与 slot 契约一致) */
18
+ defineProps<{ app?: { id: string; name: string } }>()
19
+
20
+ const ICON = ['M4 5h16v14H4z', 'M8 10l3 2.5-3 2.5', 'M13.5 15H16']
21
+
22
+ const running = ref(0)
23
+
24
+ function refresh(): void {
25
+ running.value = sessions.value.filter((s) => s.status === 'running').length
26
+ }
27
+
28
+ const timer = setInterval(refresh, 1000)
29
+ onMounted(refresh)
30
+ onUnmounted(() => clearInterval(timer))
31
+
32
+ const hint = computed(() => `mock · ${running.value} running`)
33
+ </script>
34
+
35
+ <template>
36
+ <QuickCard
37
+ label="mock-terminal"
38
+ :value="running"
39
+ :hint="hint"
40
+ :tone="running > 0 ? 'success' : 'neutral'"
41
+ :icon-path="ICON"
42
+ />
43
+ </template>
@@ -0,0 +1,168 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * 模拟终端(内置应用运行面)
4
+ *
5
+ * dev-shell 的模拟终端:输入发送(记录到会话输入行)、模拟输出(触发 terminal:output
6
+ * 事件供 openTerminalStream mock 消费)、会话创建/停止、连接/断开、认证成功
7
+ * (触发对应 lifecycle 钩子)。底部展示 mobileApi 任务队列 mock。
8
+ *
9
+ * 归属变更:原先它是壳的一个调试页签(`views/MockTerminalView.vue` + 底部导航一项),
10
+ * 现在降为**内置应用**——自持运行面、经壳的 registerSurface 挂载、与被调试插件走
11
+ * 同一条加载与渲染路径。理由:应用自持界面是新宿主壳的核心形态,预览环境里必须
12
+ * 有一个真实应用在场,否则「壳怎么渲染别人的界面」这件事在 dev-shell 里无法验证。
13
+ *
14
+ * 与真机的差异见 README「Mock 边界」:WASM 后端不在浏览器运行,这里驱动的是
15
+ * mock/session.ts 的模拟会话。
16
+ */
17
+ import { computed, ref } from 'vue'
18
+ import { useI18n } from 'vue-i18n'
19
+ import {
20
+ activeSessionId,
21
+ authSuccess,
22
+ connected,
23
+ createSession,
24
+ inputs,
25
+ outputs,
26
+ sendInputToSession,
27
+ sendOutput,
28
+ sessions,
29
+ setConnected,
30
+ stopSession,
31
+ } from '../../mock/session'
32
+ import { queueTasks } from '../../mock/mobile-api'
33
+
34
+ const { t } = useI18n()
35
+
36
+ const inputText = ref('')
37
+ const simulateText = ref('ls -la')
38
+ const activeOutputs = computed(() => outputs[activeSessionId.value] || [])
39
+ const activeInputs = computed(() => inputs[activeSessionId.value] || [])
40
+ const activeSession = computed(() => sessions.value.find((s) => s.id === activeSessionId.value))
41
+
42
+ function send() {
43
+ const text = inputText.value
44
+ if (!text.trim()) return
45
+ sendInputToSession(activeSessionId.value, text)
46
+ inputText.value = ''
47
+ }
48
+
49
+ function simulate() {
50
+ sendOutput(activeSessionId.value, simulateText.value || 'mock output')
51
+ }
52
+
53
+ function resetQueue() {
54
+ queueTasks.value = []
55
+ }
56
+ </script>
57
+
58
+ <template>
59
+ <div class="h-full flex flex-col min-h-0 mobile-ui mobile-app">
60
+
61
+ <div class="flex-1 min-h-0 flex flex-col md:flex-row">
62
+ <!-- 会话列表 -->
63
+ <div class="md:w-44 flex-shrink-0 border-b md:border-b-0 md:border-r border-[var(--mobile-border)] p-2 flex md:flex-col gap-1.5 overflow-x-auto md:overflow-y-auto">
64
+ <button
65
+ v-for="s in sessions"
66
+ :key="s.id"
67
+ class="flex items-center gap-2 px-3 py-2 rounded-lg text-xs text-left min-w-[120px] transition-colors duration-200"
68
+ :class="
69
+ activeSessionId === s.id
70
+ ? 'bg-[var(--mobile-accent-muted)] text-[var(--mobile-accent)]'
71
+ : 'text-[var(--mobile-text-secondary)] hover:bg-[var(--mobile-bg-tertiary)]'
72
+ "
73
+ @click="activeSessionId = s.id"
74
+ >
75
+ <span
76
+ class="w-2 h-2 rounded-full flex-shrink-0"
77
+ :class="s.status === 'running' ? 'bg-[var(--mobile-success)]' : 'bg-[var(--mobile-text-disabled)]'"
78
+ />
79
+ <span class="truncate min-w-0">{{ s.id }}</span>
80
+ </button>
81
+ </div>
82
+
83
+ <!-- 输出 + 控制 -->
84
+ <div class="flex-1 min-h-0 flex flex-col">
85
+ <div class="flex-1 min-h-0 overflow-y-auto p-3 font-mono text-xs leading-relaxed text-[var(--mobile-text-secondary)]">
86
+ <p v-for="(line, i) in activeOutputs" :key="'o' + i" class="terminal-output">{{ line }}</p>
87
+ <p v-for="(line, i) in activeInputs" :key="'i' + i" class="terminal-output text-[var(--mobile-accent)]">
88
+ $ {{ line }}
89
+ </p>
90
+ </div>
91
+
92
+ <!-- 连接状态 + 生命周期按钮 -->
93
+ <div class="flex-shrink-0 flex flex-wrap items-center gap-1.5 px-3 py-2 border-t border-[var(--mobile-border)]">
94
+ <span
95
+ class="text-[11px] px-2 py-0.5 rounded-full"
96
+ :class="
97
+ connected
98
+ ? 'bg-[var(--mobile-success-muted)] text-[var(--mobile-success)]'
99
+ : 'bg-[var(--mobile-error-muted)] text-[var(--mobile-error)]'
100
+ "
101
+ >
102
+ {{ connected ? t('devshell.terminal.connected') : t('devshell.terminal.disconnected') }}
103
+ </span>
104
+ <button class="chip" @click="createSession()">{{ t('devshell.terminal.createSession') }}</button>
105
+ <button class="chip" :disabled="!activeSession" @click="stopSession(activeSessionId)">{{ t('devshell.terminal.stopSession') }}</button>
106
+ <button class="chip" @click="setConnected(!connected)">{{ connected ? t('devshell.terminal.disconnect') : t('devshell.terminal.connect') }}</button>
107
+ <button class="chip" @click="authSuccess()">{{ t('devshell.terminal.authSuccess') }}</button>
108
+ </div>
109
+
110
+ <!-- 输入行 -->
111
+ <div class="flex-shrink-0 flex items-center gap-2 px-3 py-2 border-t border-[var(--mobile-border)]">
112
+ <input
113
+ v-model="inputText"
114
+ class="flex-1 min-w-0 bg-[var(--mobile-input-bg)] border border-[var(--mobile-input-border)] rounded-lg px-3 py-2 text-xs text-[var(--mobile-text-primary)] placeholder:text-[var(--mobile-input-placeholder)] focus:border-[var(--mobile-input-focus)] outline-none transition-colors duration-200"
115
+ :placeholder="t('devshell.terminal.inputPlaceholder')"
116
+ @keydown.enter="send()"
117
+ />
118
+ <button class="px-3 py-2 rounded-lg bg-[var(--mobile-accent)] text-[var(--mobile-text-on-accent)] text-xs font-medium" @click="send()">
119
+ {{ t('devshell.terminal.send') }}
120
+ </button>
121
+ </div>
122
+
123
+ <!-- 模拟输出行 -->
124
+ <div class="flex-shrink-0 flex items-center gap-2 px-3 py-2 border-t border-[var(--mobile-border)]">
125
+ <input
126
+ v-model="simulateText"
127
+ class="flex-1 min-w-0 bg-[var(--mobile-input-bg)] border border-[var(--mobile-input-border)] rounded-lg px-3 py-2 text-xs text-[var(--mobile-text-primary)] placeholder:text-[var(--mobile-input-placeholder)] focus:border-[var(--mobile-input-focus)] outline-none transition-colors duration-200"
128
+ placeholder="output"
129
+ @keydown.enter="simulate()"
130
+ />
131
+ <button class="chip" @click="simulate()">{{ t('devshell.terminal.simulateOutput') }}</button>
132
+ </div>
133
+ </div>
134
+ </div>
135
+
136
+ <!-- 任务队列 mock(mobileApi) -->
137
+ <div class="flex-shrink-0 border-t border-[var(--mobile-border)] px-4 py-2 flex items-center gap-2 text-xs">
138
+ <span class="text-[var(--mobile-text-muted)]">{{ t('devshell.terminal.queueMock') }}</span>
139
+ <span class="text-[var(--mobile-text-secondary)] truncate min-w-0">
140
+ {{ queueTasks.length ? queueTasks.map((task) => task.prompt).join(' / ') : t('devshell.terminal.queueEmpty') }}
141
+ </span>
142
+ <button class="ml-auto flex-shrink-0 text-[var(--mobile-text-muted)] hover:text-[var(--mobile-error)] transition-colors duration-200" @click="resetQueue()">
143
+ {{ t('devshell.terminal.queueClear') }}
144
+ </button>
145
+ </div>
146
+ </div>
147
+ </template>
148
+
149
+ <style scoped>
150
+ .chip {
151
+ flex-shrink: 0;
152
+ padding: 4px 10px;
153
+ border-radius: 8px;
154
+ font-size: 11px;
155
+ color: var(--mobile-text-secondary);
156
+ background: var(--mobile-bg-tertiary);
157
+ border: 1px solid var(--mobile-border);
158
+ transition: color 0.2s, border-color 0.2s;
159
+ }
160
+ .chip:hover:not(:disabled) {
161
+ color: var(--mobile-text-primary);
162
+ border-color: var(--mobile-border-hover);
163
+ }
164
+ .chip:disabled {
165
+ opacity: 0.4;
166
+ cursor: not-allowed;
167
+ }
168
+ </style>
@@ -0,0 +1,50 @@
1
+ /**
2
+ * 内置应用「模拟终端」
3
+ * -----------------------------------------------------------------------------
4
+ * 身份:一个**内置应用**,与被调试插件同构——同样有 id / manifest / activate /
5
+ * deactivate,同样经 `context.ui.registerSurface` 把运行面交给壳。
6
+ *
7
+ * 为什么这么绕(不直接当壳的一页):
8
+ * 宿主壳的核心形态是「应用自持运行面,壳只挂载」。预览环境里若没有真实应用在场,
9
+ * 插件开发者就无法在 dev-shell 里验证「壳怎么渲染别人的界面」——这条路径只存在于
10
+ * 与真机相同的加载链路里才有效。把模拟终端做成内置应用,等于让预览环境自带一个
11
+ * 正确形态的样本,同时顺带跑通 registerSurface / registerSlot 两条贡献路径。
12
+ *
13
+ * activate 契约与插件入口一致(收 context、注册贡献、返回 Disposable 由外层收集),
14
+ * 因此「内置应用」与「被调试插件」在壳眼里没有区别。
15
+ */
16
+
17
+ import type { Disposable, PluginContext } from '../../../../src/types'
18
+ import MockTerminalSlotCard from './MockTerminalSlotCard.vue'
19
+ import MockTerminalView from './MockTerminalView.vue'
20
+
21
+ /** 内置应用标识(与插件 id 同命名空间,避免与被调试插件撞名) */
22
+ export const MOCK_TERMINAL_ID = 'dev.mock-terminal'
23
+
24
+ /** 内置应用元信息(结构对齐 plugin.json 的可读字段,供数据源投影) */
25
+ export const MOCK_TERMINAL_MANIFEST = {
26
+ id: MOCK_TERMINAL_ID,
27
+ name: 'Mock Terminal',
28
+ version: '1.0.0',
29
+ description: 'dev-shell 内置应用:驱动模拟会话 / 生命周期事件,供插件调试前端逻辑',
30
+ author: 'WasmNest Dev Shell',
31
+ permissions: ['storage', 'bus', 'session:read'],
32
+ }
33
+
34
+ export function activate(context: PluginContext): Disposable[] {
35
+ const disposables: Disposable[] = []
36
+
37
+ // 运行面:壳的应用运行屏渲染它,壳不加任何 chrome(应用自持全部界面)
38
+ disposables.push(context.ui.registerSurface({ component: MockTerminalView }))
39
+
40
+ // 首页快捷卡片:让 registerSlot 这条路径在预览环境里也有真实消费方
41
+ disposables.push(
42
+ context.ui.registerSlot({ id: 'sessions', component: MockTerminalSlotCard, order: 10 }),
43
+ )
44
+
45
+ return disposables
46
+ }
47
+
48
+ export function deactivate(): void {
49
+ // 贡献项由 mock context 的 _disposables 统一回收(与被调试插件同一条路径)
50
+ }
@@ -0,0 +1,100 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Dev Toolbar — 工作台工具条:被调试插件、主题切换(深色/浅色/跟随系统)、
4
+ * 手机框开关、日志面板开关
5
+ */
6
+ import { computed } from 'vue'
7
+ import { useI18n } from 'vue-i18n'
8
+ import { logs, plugins } from '../registry'
9
+ import { useDevTheme, type ThemeMode } from '../theme'
10
+ import { saveLocale, type DevLocale } from '../locale'
11
+
12
+ defineProps<{ frame: boolean }>()
13
+ defineEmits<{ 'toggle-frame': [] }>()
14
+
15
+ const { t, locale } = useI18n()
16
+ const logOpen = defineModel<boolean>('logOpen', { default: false })
17
+ const { theme, setTheme } = useDevTheme()
18
+
19
+ const themeOptions = computed(() => [
20
+ { value: 'dark' as ThemeMode, label: t('devshell.theme.dark') },
21
+ { value: 'light' as ThemeMode, label: t('devshell.theme.light') },
22
+ { value: 'system' as ThemeMode, label: t('devshell.theme.system') },
23
+ ])
24
+
25
+ // 语言切换选项(语言名用自身文字展示,无需翻译)
26
+ const localeOptions: { value: DevLocale; label: string }[] = [
27
+ { value: 'zh-CN', label: '中' },
28
+ { value: 'en', label: 'EN' },
29
+ ]
30
+
31
+ function setLocale(next: DevLocale) {
32
+ locale.value = next
33
+ saveLocale(next)
34
+ }
35
+
36
+ const summary = computed(() => {
37
+ const isEn = locale.value === 'en'
38
+ const parts = plugins.value.map((p) => `${p.name}${isEn ? ` (${p.state})` : `(${p.state})`}`)
39
+ return parts.join(isEn ? ', ' : ',') || t('devshell.toolbar.noPlugins')
40
+ })
41
+ const errorCount = computed(() => logs.value.filter((l) => l.level === 'error').length)
42
+ </script>
43
+
44
+ <template>
45
+ <div
46
+ class="flex items-center gap-2 px-4 h-12 flex-shrink-0 border-b border-white/10 bg-[#1b1b22] text-[13px] text-[#9ca3af]"
47
+ >
48
+ <span class="font-semibold text-[#e5e7eb] whitespace-nowrap">WasmNest Dev Shell</span>
49
+ <span class="truncate min-w-0 text-[#6b7280]">{{ summary }}</span>
50
+ <span class="flex-1" />
51
+
52
+ <!-- 语言切换(中 / EN 分段按钮) -->
53
+ <div class="flex items-center rounded-md bg-white/5 p-0.5">
54
+ <button
55
+ v-for="opt in localeOptions"
56
+ :key="opt.value"
57
+ class="px-2 py-0.5 rounded text-[12px] transition-colors duration-200"
58
+ :class="
59
+ locale === opt.value
60
+ ? 'bg-[#ECE8DC]/20 text-[#ECE8DC]'
61
+ : 'text-[#9ca3af] hover:text-[#d1d5db]'
62
+ "
63
+ @click="setLocale(opt.value)"
64
+ >
65
+ {{ opt.label }}
66
+ </button>
67
+ </div>
68
+
69
+ <!-- 主题切换(与宿主设置页同款三选项分段按钮) -->
70
+ <div class="flex items-center rounded-md bg-white/5 p-0.5">
71
+ <button
72
+ v-for="opt in themeOptions"
73
+ :key="opt.value"
74
+ class="px-2 py-0.5 rounded text-[12px] transition-colors duration-200"
75
+ :class="
76
+ theme === opt.value
77
+ ? 'bg-[#ECE8DC]/20 text-[#ECE8DC]'
78
+ : 'text-[#9ca3af] hover:text-[#d1d5db]'
79
+ "
80
+ @click="setTheme(opt.value)"
81
+ >
82
+ {{ opt.label }}
83
+ </button>
84
+ </div>
85
+
86
+ <button
87
+ class="px-2.5 py-1 rounded-md bg-white/5 text-[#d1d5db] hover:bg-white/10 transition-colors duration-200"
88
+ @click="$emit('toggle-frame')"
89
+ >
90
+ {{ frame ? t('devshell.frame.on') : t('devshell.frame.off') }}
91
+ </button>
92
+ <button
93
+ class="px-2.5 py-1 rounded-md bg-white/5 hover:bg-white/10 transition-colors duration-200 flex items-center gap-1"
94
+ @click="logOpen = !logOpen"
95
+ >
96
+ <span>{{ t('devshell.logs.title') }}</span>
97
+ <span v-if="errorCount" class="px-1 rounded bg-red-500/20 text-red-400 text-[11px]">{{ errorCount }}</span>
98
+ </button>
99
+ </div>
100
+ </template>
@@ -0,0 +1,119 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * DialogHost — 渲染 dialogService 队列(dialog / confirm / prompt)+ toasts
4
+ *
5
+ * 与宿主 PluginDialogHost 同形状:模块级队列 + resolveTop 完成 Promise。
6
+ * 移动端样式(--mobile-* token)+ Teleport to body(safe-stack z-50)。
7
+ */
8
+ import { ref, watch } from 'vue'
9
+ import { dialogService, resolveTop } from '../mock/dialog-service'
10
+
11
+ const promptValue = ref('')
12
+ const showPromptError = ref(false)
13
+
14
+ // 队列顶部条目变化时预填 inputValue(与宿主 showPrompt 默认值语义一致)
15
+ watch(
16
+ () => dialogService.queue.value[0]?.options.inputValue,
17
+ (v) => {
18
+ if (v !== undefined) promptValue.value = v
19
+ showPromptError.value = false
20
+ },
21
+ )
22
+
23
+ function confirmTop(action: 'confirm' | 'cancel') {
24
+ const top = dialogService.queue.value[0]
25
+ if (!top) return
26
+ if (top.kind === 'prompt' && action === 'confirm' && !promptValue.value) {
27
+ showPromptError.value = true
28
+ return
29
+ }
30
+ showPromptError.value = false
31
+ resolveTop(action, top.kind === 'prompt' ? promptValue.value : undefined)
32
+ promptValue.value = ''
33
+ }
34
+ </script>
35
+
36
+ <template>
37
+ <Teleport to="body">
38
+ <!-- 对话框队列(mobile-ui:Teleport 到 body 后仍需继承 --mobile-* token 的浅色作用域) -->
39
+ <div
40
+ v-if="dialogService.queue.value.length"
41
+ class="mobile-ui fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-[var(--mobile-overlay)] backdrop-blur-sm p-4"
42
+ @click.self="dialogService.queue.value[0]?.options.dismissible && confirmTop('cancel')"
43
+ >
44
+ <div
45
+ class="w-full max-w-sm rounded-2xl bg-[var(--mobile-bg-elevated)] border border-[var(--mobile-border)] shadow-2xl p-5"
46
+ >
47
+ <h3
48
+ class="text-base font-semibold mb-1"
49
+ :class="dialogService.queue.value[0]?.options.variant === 'danger' ? 'text-[var(--mobile-error)]' : 'text-[var(--mobile-text-primary)]'"
50
+ >
51
+ {{ dialogService.queue.value[0]?.options.title || '' }}
52
+ </h3>
53
+ <p v-if="dialogService.queue.value[0]?.options.message" class="text-sm text-[var(--mobile-text-secondary)] mb-4 leading-relaxed whitespace-pre-line">
54
+ {{ dialogService.queue.value[0]?.options.message }}
55
+ </p>
56
+
57
+ <input
58
+ v-if="dialogService.queue.value[0]?.kind === 'prompt'"
59
+ v-model="promptValue"
60
+ class="w-full bg-[var(--mobile-input-bg)] border rounded-lg px-3 py-2.5 text-sm text-[var(--mobile-text-primary)] placeholder:text-[var(--mobile-input-placeholder)] outline-none mb-1 transition-colors duration-200"
61
+ :class="showPromptError ? 'border-[var(--mobile-error)]' : 'border-[var(--mobile-input-border)] focus:border-[var(--mobile-input-focus)]'"
62
+ :placeholder="dialogService.queue.value[0]?.options.inputPlaceholder"
63
+ @keydown.enter="confirmTop('confirm')"
64
+ />
65
+ <p v-if="showPromptError" class="text-[11px] text-[var(--mobile-error)] mb-2">请输入内容</p>
66
+
67
+ <div class="flex justify-end gap-2 mt-4">
68
+ <button
69
+ v-if="dialogService.queue.value[0]?.options.cancelText !== undefined || dialogService.queue.value[0]?.kind !== 'dialog'"
70
+ class="px-4 py-2 rounded-lg text-sm text-[var(--mobile-text-secondary)] hover:text-[var(--mobile-text-primary)] transition-colors duration-200"
71
+ @click="confirmTop('cancel')"
72
+ >
73
+ {{ dialogService.queue.value[0]?.options.cancelText || '取消' }}
74
+ </button>
75
+ <button
76
+ class="px-4 py-2 rounded-lg text-sm font-medium transition-colors duration-200"
77
+ :class="dialogService.queue.value[0]?.options.variant === 'danger'
78
+ ? 'bg-[var(--mobile-error)] text-[var(--mobile-text-on-accent)]'
79
+ : 'bg-[var(--mobile-accent)] text-[var(--mobile-text-on-accent)]'"
80
+ @click="confirmTop('confirm')"
81
+ >
82
+ {{ dialogService.queue.value[0]?.options.confirmText || '确定' }}
83
+ </button>
84
+ </div>
85
+ </div>
86
+ </div>
87
+
88
+ <!-- Toasts(mobile-ui:Teleport 到 body 后仍需继承 --mobile-* token 的浅色作用域) -->
89
+ <div class="mobile-ui fixed top-14 left-0 right-0 z-50 flex flex-col items-center gap-2 pointer-events-none px-4">
90
+ <TransitionGroup name="toast">
91
+ <div
92
+ v-for="toast in dialogService.toasts.value"
93
+ :key="toast.id"
94
+ class="px-4 py-2 rounded-xl text-sm shadow-lg backdrop-blur-xl pointer-events-auto max-w-sm"
95
+ :class="{
96
+ info: 'bg-[var(--mobile-bg-elevated)]/95 text-[var(--mobile-text-primary)] border border-[var(--mobile-border)]',
97
+ success: 'bg-[var(--mobile-success-muted)]/95 text-[var(--mobile-success)] border border-[var(--mobile-success)]/30',
98
+ warning: 'bg-[var(--mobile-warning-muted)]/95 text-[var(--mobile-warning)] border border-[var(--mobile-warning)]/30',
99
+ error: 'bg-[var(--mobile-error-muted)]/95 text-[var(--mobile-error)] border border-[var(--mobile-error)]/30',
100
+ }[toast.type]"
101
+ >
102
+ {{ toast.message }}
103
+ </div>
104
+ </TransitionGroup>
105
+ </div>
106
+ </Teleport>
107
+ </template>
108
+
109
+ <style scoped>
110
+ .toast-enter-active,
111
+ .toast-leave-active {
112
+ transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
113
+ }
114
+ .toast-enter-from,
115
+ .toast-leave-to {
116
+ opacity: 0;
117
+ transform: translateY(-8px);
118
+ }
119
+ </style>
@@ -0,0 +1,80 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * LogPanel — 插件日志面板(context.logger / 生命周期 / 加载错误)
4
+ *
5
+ * 常驻右下角(工作台层,非手机框内),Teleport to body。
6
+ */
7
+ import { computed, ref } from 'vue'
8
+ import { useI18n } from 'vue-i18n'
9
+ import { clearLogs, logs } from '../registry'
10
+
11
+ const open = defineModel<boolean>('logOpen', { default: false })
12
+ const filter = ref<'all' | 'warn' | 'error'>('all')
13
+
14
+ const { t } = useI18n()
15
+
16
+ const visibleLogs = computed(() => {
17
+ if (filter.value === 'all') return logs.value
18
+ return logs.value.filter((l) => l.level === filter.value || (filter.value === 'warn' && l.level === 'warn') || l.level === 'error')
19
+ })
20
+
21
+ const levelColor: Record<string, string> = {
22
+ debug: 'text-[var(--mobile-text-muted)]',
23
+ info: 'text-[var(--mobile-text-secondary)]',
24
+ warn: 'text-[var(--mobile-warning)]',
25
+ error: 'text-[var(--mobile-error)]',
26
+ }
27
+ </script>
28
+
29
+ <template>
30
+ <Teleport to="body">
31
+ <Transition name="log-panel">
32
+ <div
33
+ v-if="open"
34
+ class="mobile-ui fixed right-3 bottom-3 z-50 w-[380px] max-w-[calc(100vw-24px)] h-[280px] rounded-xl border border-[var(--mobile-border)] bg-[var(--mobile-bg-elevated)]/95 backdrop-blur-xl shadow-2xl flex flex-col overflow-hidden"
35
+ >
36
+ <div class="flex items-center gap-2 px-3 h-9 flex-shrink-0 border-b border-[var(--mobile-border)]">
37
+ <span class="text-xs font-semibold text-[var(--mobile-text-primary)]">{{ t('devshell.logs.title') }}</span>
38
+ <div class="flex items-center gap-1 ml-2">
39
+ <button
40
+ v-for="f in (['all', 'warn', 'error'] as const)"
41
+ :key="f"
42
+ class="px-2 py-0.5 rounded text-[11px] transition-colors duration-200"
43
+ :class="filter === f ? 'bg-[var(--mobile-accent-muted)] text-[var(--mobile-accent)]' : 'text-[var(--mobile-text-muted)] hover:text-[var(--mobile-text-secondary)]'"
44
+ @click="filter = f"
45
+ >
46
+ {{ f }}
47
+ </button>
48
+ </div>
49
+ <span class="flex-1" />
50
+ <button class="text-[11px] text-[var(--mobile-text-muted)] hover:text-[var(--mobile-text-secondary)] transition-colors duration-200" @click="clearLogs()">
51
+ {{ t('devshell.logs.clear') }}
52
+ </button>
53
+ <button class="w-6 h-6 flex items-center justify-center text-[var(--mobile-text-muted)] hover:text-[var(--mobile-text-primary)] transition-colors duration-200" @click="open = false">
54
+ ×
55
+ </button>
56
+ </div>
57
+ <div class="flex-1 min-h-0 overflow-y-auto p-2 font-mono text-[11px] leading-relaxed">
58
+ <p v-if="visibleLogs.length === 0" class="text-[var(--mobile-text-muted)] px-2">{{ t('devshell.logs.empty') }}</p>
59
+ <p v-for="log in visibleLogs" :key="log.id" class="px-2 py-0.5 break-all">
60
+ <span class="text-[var(--mobile-text-muted)]">{{ log.ts }}</span>
61
+ <span class="text-[var(--mobile-accent)]"> [{{ log.pluginId }}]</span>
62
+ <span :class="levelColor[log.level]"> {{ log.message }}</span>
63
+ </p>
64
+ </div>
65
+ </div>
66
+ </Transition>
67
+ </Teleport>
68
+ </template>
69
+
70
+ <style scoped>
71
+ .log-panel-enter-active,
72
+ .log-panel-leave-active {
73
+ transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
74
+ }
75
+ .log-panel-enter-from,
76
+ .log-panel-leave-to {
77
+ opacity: 0;
78
+ transform: translateY(8px) scale(0.98);
79
+ }
80
+ </style>
@@ -0,0 +1,22 @@
1
+ /**
2
+ * dev-shell 的 i18n 单例
3
+ * -----------------------------------------------------------------------------
4
+ * 与宿主 `@/locales` 同位置同职责:main.ts 与模块级代码(通知文案 / 相对时间等)
5
+ * 共用同一个实例,避免「组件内 useI18n 拿 A 实例、模块里读 B 实例」导致切换语言
6
+ * 后通知栏文案不跟着变。
7
+ *
8
+ * main.ts 只负责装配(app.use(i18n) + 交给共享运行时),实例本身在这里。
9
+ */
10
+
11
+ import { createI18n } from 'vue-i18n'
12
+ import { zhCN, en } from './locales'
13
+ import { readSavedLocale } from './locale'
14
+
15
+ export const i18n = createI18n({
16
+ legacy: false,
17
+ locale: readSavedLocale(),
18
+ fallbackLocale: 'en',
19
+ messages: { 'zh-CN': zhCN, en },
20
+ missingWarn: false,
21
+ fallbackWarn: false,
22
+ })