@binblink/wasmnest-plugin-sdk-desktop 0.0.1 → 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 (219) hide show
  1. package/README.md +24 -4
  2. package/README_en.md +1 -1
  3. package/bin/cli.js +5 -5
  4. package/bin/manifest-gen.js +4 -0
  5. package/bin/manifest-validate.js +68 -6
  6. package/bin/permission-vocabulary.json +2 -2
  7. package/dev-shell/README.md +6 -5
  8. package/dev-shell/src/loader.ts +0 -5
  9. package/dev-shell/src/mock/commands.ts +1 -1
  10. package/dev-shell/src/mock/domain-context.ts +1 -1
  11. package/dev-shell/src/shell/types.ts +21 -32
  12. package/dev-shell/src/styles/shell.css +208 -2
  13. package/dev-shell/src/styles/style.css +72 -26
  14. package/dist/index.d.ts +44 -3
  15. package/dist/index.js +69 -1
  16. package/dist/types.d.ts +52 -5
  17. package/go/.gitignore +5 -0
  18. package/go/README.md +80 -0
  19. package/go/gen/wasmnest/api-call/host-api-call/empty.s +3 -0
  20. package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wasm.go +13 -0
  21. package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wit.go +34 -0
  22. package/go/gen/wasmnest/app/host-app/empty.s +3 -0
  23. package/go/gen/wasmnest/app/host-app/host-app.wasm.go +29 -0
  24. package/go/gen/wasmnest/app/host-app/host-app.wit.go +108 -0
  25. package/go/gen/wasmnest/auth-center/host-auth-center/abi.go +14 -0
  26. package/go/gen/wasmnest/auth-center/host-auth-center/empty.s +3 -0
  27. package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wasm.go +49 -0
  28. package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wit.go +225 -0
  29. package/go/gen/wasmnest/clipboard/host-clipboard/abi.go +14 -0
  30. package/go/gen/wasmnest/clipboard/host-clipboard/empty.s +3 -0
  31. package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wasm.go +17 -0
  32. package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wit.go +68 -0
  33. package/go/gen/wasmnest/connection-registry/host-connection-registry/empty.s +3 -0
  34. package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wasm.go +13 -0
  35. package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wit.go +50 -0
  36. package/go/gen/wasmnest/crypto/host-crypto/abi.go +18 -0
  37. package/go/gen/wasmnest/crypto/host-crypto/empty.s +3 -0
  38. package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wasm.go +37 -0
  39. package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wit.go +139 -0
  40. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/abi.go +14 -0
  41. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/empty.s +3 -0
  42. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wasm.go +21 -0
  43. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wit.go +62 -0
  44. package/go/gen/wasmnest/http/host-http/abi.go +14 -0
  45. package/go/gen/wasmnest/http/host-http/empty.s +3 -0
  46. package/go/gen/wasmnest/http/host-http/host-http.wasm.go +13 -0
  47. package/go/gen/wasmnest/http/host-http/host-http.wit.go +40 -0
  48. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/empty.s +3 -0
  49. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wasm.go +17 -0
  50. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wit.go +69 -0
  51. package/go/gen/wasmnest/mdns/host-mdns/empty.s +3 -0
  52. package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wasm.go +29 -0
  53. package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wit.go +101 -0
  54. package/go/gen/wasmnest/notify/host-notify/empty.s +3 -0
  55. package/go/gen/wasmnest/notify/host-notify/host-notify.wasm.go +13 -0
  56. package/go/gen/wasmnest/notify/host-notify/host-notify.wit.go +64 -0
  57. package/go/gen/wasmnest/peer/host-peer/abi.go +14 -0
  58. package/go/gen/wasmnest/peer/host-peer/empty.s +3 -0
  59. package/go/gen/wasmnest/peer/host-peer/host-peer.wasm.go +85 -0
  60. package/go/gen/wasmnest/peer/host-peer/host-peer.wit.go +357 -0
  61. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/empty.s +3 -0
  62. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wasm.go +21 -0
  63. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wit.go +70 -0
  64. package/go/gen/wasmnest/plugin/abi-form/abi-form.exports.go +11 -0
  65. package/go/gen/wasmnest/plugin/abi-form/abi-form.wasm.go +13 -0
  66. package/go/gen/wasmnest/plugin/abi-form/abi-form.wit.go +7 -0
  67. package/go/gen/wasmnest/plugin/abi-form/empty.s +3 -0
  68. package/go/gen/wasmnest/plugin/command/command.exports.go +11 -0
  69. package/go/gen/wasmnest/plugin/command/command.wasm.go +19 -0
  70. package/go/gen/wasmnest/plugin/command/command.wit.go +6 -0
  71. package/go/gen/wasmnest/plugin/command/empty.s +3 -0
  72. package/go/gen/wasmnest/plugin/events/empty.s +3 -0
  73. package/go/gen/wasmnest/plugin/events/events.exports.go +52 -0
  74. package/go/gen/wasmnest/plugin/events/events.wasm.go +74 -0
  75. package/go/gen/wasmnest/plugin/events/events.wit.go +195 -0
  76. package/go/gen/wasmnest/plugin/host-bus/empty.s +3 -0
  77. package/go/gen/wasmnest/plugin/host-bus/host-bus.wasm.go +29 -0
  78. package/go/gen/wasmnest/plugin/host-bus/host-bus.wit.go +94 -0
  79. package/go/gen/wasmnest/plugin/host-config/abi.go +14 -0
  80. package/go/gen/wasmnest/plugin/host-config/empty.s +3 -0
  81. package/go/gen/wasmnest/plugin/host-config/host-config.wasm.go +13 -0
  82. package/go/gen/wasmnest/plugin/host-config/host-config.wit.go +21 -0
  83. package/go/gen/wasmnest/plugin/host-events/empty.s +3 -0
  84. package/go/gen/wasmnest/plugin/host-events/host-events.wasm.go +9 -0
  85. package/go/gen/wasmnest/plugin/host-events/host-events.wit.go +27 -0
  86. package/go/gen/wasmnest/plugin/host-fs/abi.go +14 -0
  87. package/go/gen/wasmnest/plugin/host-fs/empty.s +3 -0
  88. package/go/gen/wasmnest/plugin/host-fs/host-fs.wasm.go +33 -0
  89. package/go/gen/wasmnest/plugin/host-fs/host-fs.wit.go +86 -0
  90. package/go/gen/wasmnest/plugin/host-log/empty.s +3 -0
  91. package/go/gen/wasmnest/plugin/host-log/host-log.wasm.go +25 -0
  92. package/go/gen/wasmnest/plugin/host-log/host-log.wit.go +65 -0
  93. package/go/gen/wasmnest/plugin/host-metrics/empty.s +3 -0
  94. package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wasm.go +13 -0
  95. package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wit.go +34 -0
  96. package/go/gen/wasmnest/plugin/host-platform/empty.s +3 -0
  97. package/go/gen/wasmnest/plugin/host-platform/host-platform.wasm.go +21 -0
  98. package/go/gen/wasmnest/plugin/host-platform/host-platform.wit.go +85 -0
  99. package/go/gen/wasmnest/plugin/host-plugin-database/abi.go +14 -0
  100. package/go/gen/wasmnest/plugin/host-plugin-database/empty.s +3 -0
  101. package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wasm.go +29 -0
  102. package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wit.go +70 -0
  103. package/go/gen/wasmnest/plugin/host-storage/abi.go +14 -0
  104. package/go/gen/wasmnest/plugin/host-storage/empty.s +3 -0
  105. package/go/gen/wasmnest/plugin/host-storage/host-storage.wasm.go +21 -0
  106. package/go/gen/wasmnest/plugin/host-storage/host-storage.wit.go +44 -0
  107. package/go/gen/wasmnest/plugin/host-worker/empty.s +3 -0
  108. package/go/gen/wasmnest/plugin/host-worker/host-worker.wasm.go +17 -0
  109. package/go/gen/wasmnest/plugin/host-worker/host-worker.wit.go +50 -0
  110. package/go/gen/wasmnest/plugin/lifecycle/empty.s +3 -0
  111. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.exports.go +32 -0
  112. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wasm.go +41 -0
  113. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wit.go +9 -0
  114. package/go/gen/wasmnest/plugin/manifest/empty.s +3 -0
  115. package/go/gen/wasmnest/plugin/manifest/manifest.exports.go +11 -0
  116. package/go/gen/wasmnest/plugin/manifest/manifest.wasm.go +13 -0
  117. package/go/gen/wasmnest/plugin/manifest/manifest.wit.go +6 -0
  118. package/go/gen/wasmnest/plugin/plugin/plugin.wit.go +4 -0
  119. package/go/gen/wasmnest/process/host-process/empty.s +3 -0
  120. package/go/gen/wasmnest/process/host-process/host-process.wasm.go +21 -0
  121. package/go/gen/wasmnest/process/host-process/host-process.wit.go +56 -0
  122. package/go/gen/wasmnest/pty/host-pty/abi.go +14 -0
  123. package/go/gen/wasmnest/pty/host-pty/empty.s +3 -0
  124. package/go/gen/wasmnest/pty/host-pty/host-pty.wasm.go +33 -0
  125. package/go/gen/wasmnest/pty/host-pty/host-pty.wit.go +164 -0
  126. package/go/gen/wasmnest/task/host-task/abi.go +14 -0
  127. package/go/gen/wasmnest/task/host-task/empty.s +3 -0
  128. package/go/gen/wasmnest/task/host-task/host-task.wasm.go +29 -0
  129. package/go/gen/wasmnest/task/host-task/host-task.wit.go +110 -0
  130. package/go/gen/wasmnest/timer/host-timer/empty.s +3 -0
  131. package/go/gen/wasmnest/timer/host-timer/host-timer.wasm.go +13 -0
  132. package/go/gen/wasmnest/timer/host-timer/host-timer.wit.go +25 -0
  133. package/go/gen/wasmnest/ws/host-websocket/empty.s +3 -0
  134. package/go/gen/wasmnest/ws/host-websocket/host-websocket.wasm.go +29 -0
  135. package/go/gen/wasmnest/ws/host-websocket/host-websocket.wit.go +109 -0
  136. package/go/gen/wasmnest/ws-server/host-websocket-server/empty.s +3 -0
  137. package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wasm.go +49 -0
  138. package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wit.go +220 -0
  139. package/go/go.mod +14 -0
  140. package/go/go.sum +2 -0
  141. package/go/sdk/dispatch.go +49 -0
  142. package/go/sdk/dispatch_test.go +81 -0
  143. package/go/sdk/entry_native.go +13 -0
  144. package/go/sdk/entry_wasip2.go +188 -0
  145. package/go/sdk/host_http_wasip2.go +42 -0
  146. package/go/sdk/host_wasip2.go +251 -0
  147. package/go/sdk/plugin.go +103 -0
  148. package/go/testplugin/index.js +1 -0
  149. package/go/testplugin/main.go +67 -0
  150. package/go/testplugin/plugin.json +24 -0
  151. package/go/tools/assemble-wit.mjs +152 -0
  152. package/go/tools/gen-bindings.mjs +51 -0
  153. package/go/wit/core.wit +273 -0
  154. package/go/wit/deps/api-call/cap-api-call.wit +20 -0
  155. package/go/wit/deps/app/cap-app.wit +54 -0
  156. package/go/wit/deps/auth-center/cap-auth-center.wit +124 -0
  157. package/go/wit/deps/clipboard/clipboard.wit +48 -0
  158. package/go/wit/deps/clocks/monotonic-clock.wit +45 -0
  159. package/go/wit/deps/clocks/wall-clock.wit +42 -0
  160. package/go/wit/deps/clocks/world.wit +6 -0
  161. package/go/wit/deps/connection-registry/cap-connection-registry.wit +40 -0
  162. package/go/wit/deps/crypto/cap-crypto.wit +68 -0
  163. package/go/wit/deps/filesystem/preopens.wit +8 -0
  164. package/go/wit/deps/filesystem/types.wit +634 -0
  165. package/go/wit/deps/filesystem/world.wit +6 -0
  166. package/go/wit/deps/fs-desktop/cap-fs-desktop.wit +29 -0
  167. package/go/wit/deps/http/http.wit +28 -0
  168. package/go/wit/deps/http-endpoint/cap-http.wit +44 -0
  169. package/go/wit/deps/io/error.wit +34 -0
  170. package/go/wit/deps/io/poll.wit +41 -0
  171. package/go/wit/deps/io/streams.wit +262 -0
  172. package/go/wit/deps/io/world.wit +6 -0
  173. package/go/wit/deps/mdns/mdns.wit +45 -0
  174. package/go/wit/deps/notify/notify.wit +51 -0
  175. package/go/wit/deps/peer/peer.wit +126 -0
  176. package/go/wit/deps/platform-desktop/cap-platform-desktop.wit +38 -0
  177. package/go/wit/deps/process/cap-process.wit +25 -0
  178. package/go/wit/deps/pty/pty.wit +80 -0
  179. package/go/wit/deps/random/insecure-seed.wit +25 -0
  180. package/go/wit/deps/random/insecure.wit +22 -0
  181. package/go/wit/deps/random/random.wit +26 -0
  182. package/go/wit/deps/random/world.wit +7 -0
  183. package/go/wit/deps/sockets/instance-network.wit +9 -0
  184. package/go/wit/deps/sockets/ip-name-lookup.wit +51 -0
  185. package/go/wit/deps/sockets/network.wit +145 -0
  186. package/go/wit/deps/sockets/tcp-create-socket.wit +27 -0
  187. package/go/wit/deps/sockets/tcp.wit +353 -0
  188. package/go/wit/deps/sockets/udp-create-socket.wit +27 -0
  189. package/go/wit/deps/sockets/udp.wit +266 -0
  190. package/go/wit/deps/sockets/world.wit +11 -0
  191. package/go/wit/deps/task/cap-task.wit +56 -0
  192. package/go/wit/deps/timer/cap-timer.wit +14 -0
  193. package/go/wit/deps/wasi-cli/command.wit +7 -0
  194. package/go/wit/deps/wasi-cli/environment.wit +18 -0
  195. package/go/wit/deps/wasi-cli/exit.wit +4 -0
  196. package/go/wit/deps/wasi-cli/imports.wit +20 -0
  197. package/go/wit/deps/wasi-cli/run.wit +4 -0
  198. package/go/wit/deps/wasi-cli/stdio.wit +17 -0
  199. package/go/wit/deps/wasi-cli/terminal.wit +49 -0
  200. package/go/wit/deps/ws/ws.wit +50 -0
  201. package/go/wit/deps/ws-server/cap-ws.wit +99 -0
  202. package/go/wit/go-plugin.wit +28 -0
  203. package/go/wit/plugin-face.wit +355 -0
  204. package/go/wit/wasmnest.wit +25 -0
  205. package/package.json +12 -1
  206. package/src/index.ts +8 -0
  207. package/src/types.ts +681 -630
  208. package/src/ui/AppUpdateSection.d.ts +44 -0
  209. package/src/ui/AppUpdateSection.vue +253 -0
  210. package/src/ui/NumberField.d.ts +49 -0
  211. package/src/ui/NumberField.vue +390 -0
  212. package/src/ui/Select.vue +4 -4
  213. package/src/update.ts +123 -0
  214. package/template/README.md +39 -39
  215. package/tools/componentize/Cargo.lock +30 -1
  216. package/tools/componentize/Cargo.toml +3 -0
  217. package/tools/componentize/src/main.rs +197 -94
  218. package/dev-shell/src/mock/agent-hub-commands.ts +0 -1065
  219. package/dev-shell/src/mock/agent-hub.ts +0 -42
@@ -0,0 +1,390 @@
1
+ <template>
2
+ <!--
3
+ 数字步进输入(token 皮肤 + reka-ui Primitive 原语)
4
+ 右侧竖排两个大按钮取代浏览器原生 spinner(原生上下箭头只有 6px 左右,点不中也不吃 token)。
5
+ -->
6
+ <div
7
+ class="wb-nf"
8
+ :class="[sizeCls, { 'wb-nf-disabled': disabled, 'wb-nf-readonly': readonly }]"
9
+ :style="width ? { width } : undefined"
10
+ >
11
+ <Primitive
12
+ as="input"
13
+ :id="inputId"
14
+ class="wb-nf-input"
15
+ :class="[{ 'wb-nf-input-right': align === 'right' }, mono && 'wb-mono']"
16
+ type="text"
17
+ role="spinbutton"
18
+ inputmode="numeric"
19
+ autocomplete="off"
20
+ spellcheck="false"
21
+ :value="text"
22
+ :disabled="disabled"
23
+ :readonly="readonly"
24
+ :aria-label="ariaLabel"
25
+ :aria-valuenow="modelValue ?? undefined"
26
+ :aria-valuemin="min"
27
+ :aria-valuemax="max"
28
+ :aria-valuetext="text || undefined"
29
+ :data-testid="testid"
30
+ @input="onInput"
31
+ @keydown="onKeydown"
32
+ @blur="onBlur"
33
+ />
34
+ <span class="wb-nf-steppers">
35
+ <button
36
+ type="button"
37
+ class="wb-nf-btn"
38
+ tabindex="-1"
39
+ :aria-label="labelIncrease"
40
+ :disabled="disabled || readonly || atMax"
41
+ @click="stepBy(1)"
42
+ >
43
+ <svg viewBox="0 0 12 12" aria-hidden="true" fill="none" stroke="currentColor">
44
+ <path
45
+ stroke-linecap="round"
46
+ stroke-linejoin="round"
47
+ stroke-width="2"
48
+ d="M3 7.5 6 4.5l3 3"
49
+ />
50
+ </svg>
51
+ </button>
52
+ <button
53
+ type="button"
54
+ class="wb-nf-btn"
55
+ tabindex="-1"
56
+ :aria-label="labelDecrease"
57
+ :disabled="disabled || readonly || atMin"
58
+ @click="stepBy(-1)"
59
+ >
60
+ <svg viewBox="0 0 12 12" aria-hidden="true" fill="none" stroke="currentColor">
61
+ <path
62
+ stroke-linecap="round"
63
+ stroke-linejoin="round"
64
+ stroke-width="2"
65
+ d="M3 4.5 6 7.5l3-3"
66
+ />
67
+ </svg>
68
+ </button>
69
+ </span>
70
+ </div>
71
+ </template>
72
+
73
+ <script setup lang="ts">
74
+ /**
75
+ * NumberField — 数字输入(含步进按钮)共享组件
76
+ *
77
+ * 为什么取代原生 `<input type="number">`:原生 spinner 由浏览器绘制,箭头只有 6px 左右、
78
+ * 不吃 token 也不吃 `--ui-scale`,在设置页里既点不中也难看(「原生 UI 禁令」同口径)。
79
+ *
80
+ * 实现路线:reka-ui 的 `Primitive` 原语(开源 headless,Radix UI 的 Vue 版,也是
81
+ * shadcn-vue 的底层)+ 本组件的受控状态。**没有**直接用 reka-ui 的 `NumberField` 成套
82
+ * 组件,原因是它把输入框渲染成受控 `value`,用户键入后内部 `inputValue` 与 `textValue`
83
+ * 不同步,失焦时会把已输入的合法值回退成旧值(实测键入 600、失焦后框里变回 300)。
84
+ * 这里只借原语的元素下发与属性转发,值、解析、钳制、提交时机全部在本组件内闭合。
85
+ *
86
+ * 取值口径:
87
+ * - 手动输入不做「吸附到步进网格」(端口 8765、超时 45 这类值不该被悄悄改掉),
88
+ * 只按 `min`/`max` 硬钳制,并按整数取整。
89
+ * - `update:modelValue`:合法键入即时上抛(受控:调用方回写即生效)。
90
+ * - `commit`:失焦 / 回车时上抛**钳制后**的最终值——落盘用它,不要在 `@blur` 里读事件值。
91
+ * - 清空输入不提交(调用方保留原值),避免「清空即写 0」。
92
+ */
93
+ import { Primitive } from 'reka-ui'
94
+ import { computed, ref, watch } from 'vue'
95
+
96
+ interface Props {
97
+ /** 当前值;清空后以 null 回抛 */
98
+ modelValue: number | null
99
+ min?: number
100
+ /** 不传 = 不设上限 */
101
+ max?: number
102
+ /** 每次点击 / 方向键的变化量,默认 1 */
103
+ step?: number
104
+ /** 框体尺寸:sm = 插件紧凑行(32px / 12px),md = 宿主表单默认(--input-height) */
105
+ size?: 'sm' | 'md'
106
+ /** 文本对齐:设置页右侧控件用 right,表单字段用 left */
107
+ align?: 'left' | 'right'
108
+ /** 宽度(CSS 长度);不传则铺满父容器 */
109
+ width?: string
110
+ /** 等宽字体(端口 / 秒数这类纯数字更整齐),默认 true */
111
+ mono?: boolean
112
+ disabled?: boolean
113
+ readonly?: boolean
114
+ /** 无障碍名称(没有外置 label 时必须给) */
115
+ ariaLabel?: string
116
+ /** 输入框 id;与外部 `<label for>` 配对时必传(否则标签点不到输入框) */
117
+ inputId?: string
118
+ /** 增/减按钮的无障碍名称,默认 "增加"/"减少" */
119
+ labelIncrease?: string
120
+ labelDecrease?: string
121
+ testid?: string
122
+ }
123
+
124
+ const props = withDefaults(defineProps<Props>(), {
125
+ min: undefined,
126
+ max: undefined,
127
+ step: 1,
128
+ size: 'sm',
129
+ align: 'right',
130
+ width: undefined,
131
+ mono: true,
132
+ disabled: false,
133
+ readonly: false,
134
+ ariaLabel: undefined,
135
+ inputId: undefined,
136
+ labelIncrease: '增加',
137
+ labelDecrease: '减少',
138
+ testid: undefined,
139
+ })
140
+
141
+ const emit = defineEmits<{
142
+ /** 合法键入 / 步进后的值;清空为 null */
143
+ (e: 'update:modelValue', value: number | null): void
144
+ /** 输入结束,携带钳制后的最终值——落盘时机 */
145
+ (e: 'commit', value: number): void
146
+ }>()
147
+
148
+ /** 尺寸类:模板 `:class` 直接引用;**必须**有定义,缺了它框体只剩内容高度
149
+ * (12.5px 字 + 行高 ≈ 17px),步进箭头跟着被压成一条,设置页里就是「输入框和
150
+ * 上下箭头都小得不成比例」(2026-11-06 修复:此前 sizeCls 悬空,sm/md 两档样式从未生效)。 */
151
+ const sizeCls = computed(() => `wb-nf-${props.size}`)
152
+
153
+ /** 用户正在编辑的原始文本;非编辑态跟随 modelValue 格式化回显 */
154
+ const draft = ref<string>(props.modelValue === null ? '' : String(props.modelValue))
155
+ const editing = ref(false)
156
+
157
+ watch(
158
+ () => props.modelValue,
159
+ (next) => {
160
+ // 编辑中不打断用户键入(受控回写由文本本身体现);非编辑态同步外部改动
161
+ if (editing.value) return
162
+ draft.value = next === null ? '' : String(next)
163
+ },
164
+ )
165
+
166
+ const text = computed(() => draft.value)
167
+
168
+ /** 收敛到 [min, max] 并取整 */
169
+ function clampValue(value: number): number {
170
+ let next = Math.round(value)
171
+ if (props.min !== undefined) next = Math.max(props.min, next)
172
+ if (props.max !== undefined) next = Math.min(props.max, next)
173
+ return next
174
+ }
175
+
176
+ /** 解析文本框内容:空 / 非数字返回 null */
177
+ function parseDraft(): number | null {
178
+ const raw = draft.value.trim()
179
+ if (raw === '') return null
180
+ // 只接受可选负号 + 数字,避免 "12abc" / "1e5" 这类被 Number 宽松接受
181
+ if (!/^-?\d+$/.test(raw)) return null
182
+ const parsed = Number(raw)
183
+ return Number.isFinite(parsed) ? parsed : null
184
+ }
185
+
186
+ const atMin = computed(() => props.min !== undefined && (props.modelValue ?? 0) <= props.min)
187
+ const atMax = computed(() => props.max !== undefined && (props.modelValue ?? 0) >= props.max)
188
+
189
+ function onInput(e: Event) {
190
+ const el = e.target as HTMLInputElement
191
+ editing.value = true
192
+ // 过滤掉数字与负号以外的键入,光标位置不受影响(只挡非法字符,不改合法输入)
193
+ const cleaned = el.value.replace(/[^\d-]/g, '')
194
+ if (cleaned !== el.value) el.value = cleaned
195
+ draft.value = cleaned
196
+ const parsed = parseDraft()
197
+ emit('update:modelValue', parsed)
198
+ }
199
+
200
+ /** 按 step 增减:以当前生效值(文本框解析值优先)为基准 */
201
+ function stepBy(direction: 1 | -1) {
202
+ if (props.disabled || props.readonly) return
203
+ const base = parseDraft() ?? props.modelValue ?? props.min ?? 0
204
+ const next = clampValue(base + direction * props.step)
205
+ editing.value = false
206
+ draft.value = String(next)
207
+ emit('update:modelValue', next)
208
+ emit('commit', next)
209
+ }
210
+
211
+ function onKeydown(e: KeyboardEvent) {
212
+ if (e.isComposing) return
213
+ // 方向键单步;PageUp/PageDown 十倍步进(与原生 number 一致)
214
+ const multiplier = e.key === 'PageUp' || e.key === 'PageDown' ? 10 : 1
215
+ if (e.key === 'ArrowUp' || e.key === 'PageUp') {
216
+ e.preventDefault()
217
+ stepTimes(multiplier)
218
+ } else if (e.key === 'ArrowDown' || e.key === 'PageDown') {
219
+ e.preventDefault()
220
+ stepTimes(-multiplier)
221
+ } else if (e.key === 'Home' && props.min !== undefined) {
222
+ e.preventDefault()
223
+ setValue(props.min)
224
+ } else if (e.key === 'End' && props.max !== undefined) {
225
+ e.preventDefault()
226
+ setValue(props.max)
227
+ } else if (e.key === 'Enter') {
228
+ // 回车:与失焦同口径(原生 number 输入也是回车即提交)
229
+ e.preventDefault()
230
+ commitInput()
231
+ ;(e.target as HTMLInputElement).blur()
232
+ }
233
+ }
234
+
235
+ function stepTimes(multiplier: number) {
236
+ if (props.disabled || props.readonly) return
237
+ const base = parseDraft() ?? props.modelValue ?? props.min ?? 0
238
+ const next = clampValue(base + Math.sign(multiplier) * props.step * Math.abs(multiplier))
239
+ editing.value = false
240
+ draft.value = String(next)
241
+ emit('update:modelValue', next)
242
+ emit('commit', next)
243
+ }
244
+
245
+ function setValue(value: number) {
246
+ editing.value = false
247
+ draft.value = String(value)
248
+ emit('update:modelValue', value)
249
+ emit('commit', value)
250
+ }
251
+
252
+ /**
253
+ * 失焦:把键入值收敛后落盘,并把框内文本改成收敛结果。
254
+ * 收敛在本组件里算,不依赖任何三方库的回写时序。
255
+ */
256
+ function commitInput() {
257
+ const parsed = parseDraft()
258
+ editing.value = false
259
+ if (parsed === null) {
260
+ // 非法 / 清空:回到当前受控值,不提交
261
+ draft.value = props.modelValue === null ? '' : String(props.modelValue)
262
+ return
263
+ }
264
+ const next = clampValue(parsed)
265
+ draft.value = String(next)
266
+ if (next !== props.modelValue) emit('update:modelValue', next)
267
+ emit('commit', next)
268
+ }
269
+
270
+ function onBlur() {
271
+ commitInput()
272
+ }
273
+ </script>
274
+
275
+ <style>
276
+ /**
277
+ * 样式刻意不加 scoped:Tailwind 由宿主 / 各插件 app 自编译,SDK 组件的 class 也要在
278
+ * 全局样式表里生效;副作用面由 `wb-nf` 前缀收敛。颜色全部绑定 token,随主题与
279
+ * `--ui-scale` 一起变。
280
+ */
281
+ .wb-nf {
282
+ display: inline-flex;
283
+ align-items: stretch;
284
+ box-sizing: border-box;
285
+ overflow: hidden;
286
+ border: 1px solid var(--border-input);
287
+ border-radius: var(--radius-input, 8px);
288
+ background: var(--bg-input);
289
+ transition:
290
+ border-color 0.15s ease,
291
+ box-shadow 0.15s ease;
292
+ }
293
+
294
+ /* 焦点环挂在容器上(真正聚焦的是里面的 input) */
295
+ .wb-nf:focus-within {
296
+ border-color: var(--color-primary);
297
+ box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-primary) 18%, transparent);
298
+ }
299
+
300
+ .wb-nf-disabled,
301
+ .wb-nf-readonly {
302
+ opacity: 0.5;
303
+ }
304
+
305
+ /* 尺寸:sm = 插件设置页紧凑行(与既有 h-8 / 12.5px 控件同高) */
306
+ .wb-nf-sm {
307
+ height: 32px;
308
+ }
309
+
310
+ /* md = 宿主表单默认高度,字号与 Select(md) 对齐 */
311
+ .wb-nf-md {
312
+ height: var(--input-height, 36px);
313
+ }
314
+
315
+ .wb-nf-md .wb-nf-input {
316
+ padding: 0 12px;
317
+ font-size: 14px;
318
+ }
319
+
320
+ .wb-nf-md .wb-nf-steppers {
321
+ width: 28px;
322
+ }
323
+
324
+ .wb-nf-md .wb-nf-btn svg {
325
+ width: 13px;
326
+ height: 13px;
327
+ }
328
+
329
+ .wb-nf-input {
330
+ flex: 1 1 auto;
331
+ min-width: 0;
332
+ padding: 0 10px;
333
+ border: 0;
334
+ outline: none;
335
+ background: transparent;
336
+ color: var(--text-primary);
337
+ font-size: 12.5px;
338
+ line-height: 1.2;
339
+ }
340
+
341
+ .wb-nf-input-right {
342
+ text-align: right;
343
+ }
344
+
345
+ /* 右侧竖排步进按钮:各占半高,可点区域远大于原生 spinner 的 6px 小箭头
346
+ (24px 列宽是下限:20px 时 12px 字形只剩 4px 内边距,箭头看起来像装饰而不是控件) */
347
+ .wb-nf-steppers {
348
+ display: flex;
349
+ flex: 0 0 auto;
350
+ flex-direction: column;
351
+ width: 24px;
352
+ border-left: 1px solid var(--border-input);
353
+ }
354
+
355
+ .wb-nf-btn {
356
+ display: flex;
357
+ flex: 1 1 0;
358
+ align-items: center;
359
+ justify-content: center;
360
+ border: 0;
361
+ padding: 0;
362
+ background: transparent;
363
+ /* 用 secondary 而不是 tertiary:12px 字形下 tertiary 太淡,看不清是可点的箭头 */
364
+ color: var(--text-secondary);
365
+ cursor: pointer;
366
+ transition:
367
+ background-color 0.12s ease,
368
+ color 0.12s ease;
369
+ }
370
+
371
+ .wb-nf-btn svg {
372
+ width: 12px;
373
+ height: 12px;
374
+ }
375
+
376
+ .wb-nf-btn:hover:not(:disabled) {
377
+ background: var(--color-primary-light);
378
+ color: var(--color-primary);
379
+ }
380
+
381
+ .wb-nf-btn:disabled {
382
+ cursor: not-allowed;
383
+ opacity: 0.3;
384
+ }
385
+
386
+ /* 上下两格之间的细分隔线,视觉上分成两个可点区域 */
387
+ .wb-nf-btn + .wb-nf-btn {
388
+ border-top: 1px solid var(--border-input);
389
+ }
390
+ </style>
package/src/ui/Select.vue CHANGED
@@ -6,7 +6,7 @@
6
6
  class="block text-xs font-medium mb-1.5 text-[var(--text-secondary)]"
7
7
  >
8
8
  {{ label }}
9
- <span v-if="required" class="text-red-500">*</span>
9
+ <span v-if="required" class="text-[var(--color-danger-ink)] field-required">*</span>
10
10
  </label>
11
11
 
12
12
  <div ref="triggerRef" class="relative">
@@ -15,10 +15,10 @@
15
15
  :id="id"
16
16
  type="button"
17
17
  :disabled="disabled"
18
- class="w-full border text-left transition-all duration-200 outline-none cursor-pointer bg-[var(--bg-input)] text-[var(--text-primary)] focus:border-brand focus:shadow-input-focus shadow-xs dark:shadow-none flex items-center justify-between gap-2"
18
+ class="w-full border text-left transition-[border-color,box-shadow,background-color,color] duration-150 outline-none cursor-pointer bg-[var(--bg-input)] text-[var(--text-primary)] focus:border-brand focus:shadow-input-focus shadow-xs dark:shadow-none flex items-center justify-between gap-2"
19
19
  :class="[
20
20
  triggerSizeCls,
21
- error ? 'border-red-500' : 'border-[var(--border-input)]',
21
+ error ? 'border-[var(--color-danger)]' : 'border-[var(--border-input)]',
22
22
  { 'opacity-50 cursor-not-allowed': disabled },
23
23
  ]"
24
24
  @click="toggle"
@@ -86,7 +86,7 @@
86
86
  </div>
87
87
 
88
88
  <!-- Error Message -->
89
- <p v-if="error" class="mt-1 text-xs text-red-500">{{ error }}</p>
89
+ <p v-if="error" class="mt-1 text-xs text-[var(--color-danger-ink)] field-error">{{ error }}</p>
90
90
  </div>
91
91
  </template>
92
92
 
package/src/update.ts ADDED
@@ -0,0 +1,123 @@
1
+ /**
2
+ * 应用更新检查(SDK 默认实现;宿主统一提供 GitHub Release 判定)
3
+ *
4
+ * 数据面由宿主给出(`PluginContext.appUpdate.check`):宿主负责查 Release、校验
5
+ * 身份 / 完整性、做平台兼容裁决;本模块只做状态机与展示口径,供应用设置页复用。
6
+ *
7
+ * 应用可以选择:
8
+ * - **默认实现**:`useAppUpdate()` / `<AppUpdateSection />`(宿主能力 + 本模块状态);
9
+ * - **自实现**:自己查更新 / 自己画界面,不消费本模块。
10
+ *
11
+ * 失败口径:检查是被动动作,不向用户抛技术错误——状态落 `error`,技术详情由宿主
12
+ * 日志承载(应用可自行决定是否提示)。
13
+ */
14
+ import { computed, getCurrentInstance, inject, ref, type ComputedRef, type Ref } from 'vue'
15
+ import type { AppUpdateAPI, AppUpdateCheckResult, AppUpdateReason, PluginContext } from './types'
16
+
17
+ /** 状态机的展示态(与宿主返回的 status 子集一致) */
18
+ export type AppUpdateStatus =
19
+ 'idle' | 'checking' | 'up-to-date' | 'available' | 'incompatible' | 'error'
20
+
21
+ export interface UseAppUpdateOptions {
22
+ /**
23
+ * 自定义检查器(缺省 = 宿主 `PluginContext.appUpdate.check`)
24
+ *
25
+ * 应用自实现更新检查时传入;返回形状与宿主默认实现一致,SDK 默认卡片即可复用。
26
+ */
27
+ check?: () => Promise<AppUpdateCheckResult>
28
+ }
29
+
30
+ export interface UseAppUpdate {
31
+ status: Ref<AppUpdateStatus>
32
+ latestVersion: Ref<string | undefined>
33
+ currentVersion: Ref<string | undefined>
34
+ reason: Ref<AppUpdateReason | undefined>
35
+ checking: ComputedRef<boolean>
36
+ /** 当前平台是否提供更新检查能力(旧宿主 / dev-shell 可能没有) */
37
+ supported: ComputedRef<boolean>
38
+ /** 执行一次检查;并发调用复用同一在途请求 */
39
+ check: () => Promise<void>
40
+ }
41
+
42
+ /**
43
+ * 取宿主注入的更新能力(composable 必须在 setup 期间调用;inject 只在 setup 有上下文)
44
+ *
45
+ * 不经 SDK `getPluginContext()`:桌面挂载包没有 `__WASMNEST_SHARED__`,移动端虽有
46
+ * 共享运行时但取 context 的路径也不同;`inject('pluginContext')` 是双端应用都已
47
+ * 提供的唯一入口(桌面 appContext / 移动 PluginViewHost 同键)。
48
+ */
49
+ function resolveHostApi(): AppUpdateAPI | undefined {
50
+ if (!getCurrentInstance()) return undefined
51
+ return inject<PluginContext | undefined>('pluginContext', undefined)?.appUpdate
52
+ }
53
+
54
+ /**
55
+ * 应用更新状态机(模块内无全局单例:每个设置页实例各自持状态,避免跨应用串状态)
56
+ */
57
+ export function useAppUpdate(options: UseAppUpdateOptions = {}): UseAppUpdate {
58
+ const hostApi = options.check ? undefined : resolveHostApi()
59
+ const checker =
60
+ options.check ??
61
+ (() => {
62
+ if (!hostApi) {
63
+ return Promise.reject(
64
+ new Error('[PluginSDK] app update capability is not provided by this host'),
65
+ )
66
+ }
67
+ return hostApi.check()
68
+ })
69
+ const status = ref<AppUpdateStatus>('idle')
70
+ const latestVersion = ref<string | undefined>()
71
+ const currentVersion = ref<string | undefined>()
72
+ const reason = ref<AppUpdateReason | undefined>()
73
+ let inFlight: Promise<void> | null = null
74
+
75
+ const supported = computed(() => Boolean(options.check || hostApi))
76
+
77
+ async function run(): Promise<void> {
78
+ status.value = 'checking'
79
+ reason.value = undefined
80
+ try {
81
+ const result = await checker()
82
+ currentVersion.value = result.currentVersion
83
+ latestVersion.value = result.latestVersion
84
+ reason.value = result.reason
85
+ switch (result.status) {
86
+ case 'up-to-date':
87
+ case 'available':
88
+ case 'incompatible':
89
+ status.value = result.status
90
+ break
91
+ case 'idle':
92
+ case 'checking':
93
+ // 宿主返回中间态没有意义(调用已返回)→ 按失败处理,不把界面钉在「检查中」
94
+ status.value = 'error'
95
+ break
96
+ default:
97
+ status.value = 'error'
98
+ }
99
+ } catch {
100
+ status.value = 'error'
101
+ }
102
+ }
103
+
104
+ function check(): Promise<void> {
105
+ if (!inFlight) {
106
+ const pending = run().finally(() => {
107
+ if (inFlight === pending) inFlight = null
108
+ })
109
+ inFlight = pending
110
+ }
111
+ return inFlight
112
+ }
113
+
114
+ return {
115
+ status,
116
+ latestVersion,
117
+ currentVersion,
118
+ reason,
119
+ checking: computed(() => status.value === 'checking'),
120
+ supported,
121
+ check,
122
+ }
123
+ }
@@ -1,39 +1,39 @@
1
- # {{NAME}}
2
-
3
- {{NAME}} wasm 应用 — WasmNest Desktop wasm 应用工程(由 `wasmnest-plugin-desktop create` 生成)。
4
-
5
- > 术语:本仓把「插件」称为 wasm 应用;`plugin.json` / CLI 命令 / SDK 包名仍用 `plugin` 原词。
6
-
7
- ## 快速开始
8
-
9
- ```bash
10
- pnpm install # 安装依赖(含 SDK、vite、vue)
11
- pnpm run dev # 浏览器开发环境(Dev Shell:空壳宿主 + 桌面端骨架,HMR)
12
- pnpm run build # 构建:vite(前端)+ cargo(WASM,仅 rust-ts 插件)
13
- pnpm run manifest # 按源码自动填充 plugin.json 的 contributes/permissions
14
- ```
15
-
16
- ## 目录结构
17
-
18
- ```
19
- ├── plugin.json # 应用清单(id/name/权限/扩展点声明)
20
- ├── package.json # 工程脚本:dev / build / manifest
21
- ├── vite.config.ts # 前端构建配置(产物 dist/index.js,vue 等外部化到宿主)
22
- ├── tsconfig.json
23
- ├── src/
24
- │ ├── index.ts # 前端入口:activate(context) / deactivate()
25
- │ └── env.d.ts # 环境类型声明
26
- └── rust/ # WASM 后端(--rust 创建;ts-only 应用无此目录)
27
- ├── Cargo.toml
28
- └── src/lib.rs # WasmPlugin 实现(含 manifest 声明)
29
- ```
30
-
31
- ## 安装到 WasmNest Desktop
32
-
33
- `pnpm run build -- --resources-dir <宿主资源父目录>` 把产物复制到
34
- `<父目录>/{id}/`(内置应用随安装包分发);用户安装走宿主应用管理。
35
-
36
- > 权限提醒:桌面端**无默认授予**——`storage` 等权限均需写入 `plugin.json` 的 `permissions`,
37
- > 未声明即被拒(内置应用均显式声明了 `storage`)。
38
-
39
- 完整开发指南见仓库文档 `../../../docs/wasm-app-dev-desktop.md`。
1
+ # {{NAME}}
2
+
3
+ {{NAME}} wasm 应用 — WasmNest Desktop wasm 应用工程(由 `wasmnest-plugin-desktop create` 生成)。
4
+
5
+ > 术语:本仓把「插件」称为 wasm 应用;`plugin.json` / CLI 命令 / SDK 包名仍用 `plugin` 原词。
6
+
7
+ ## 快速开始
8
+
9
+ ```bash
10
+ pnpm install # 安装依赖(含 SDK、vite、vue)
11
+ pnpm run dev # 浏览器开发环境(Dev Shell:空壳宿主 + 桌面端骨架,HMR)
12
+ pnpm run build # 构建:vite(前端)+ cargo(WASM,仅 full 形态插件)
13
+ pnpm run manifest # 按源码自动填充 plugin.json 的 contributes/permissions
14
+ ```
15
+
16
+ ## 目录结构
17
+
18
+ ```
19
+ ├── plugin.json # 应用清单(id/name/权限/扩展点声明)
20
+ ├── package.json # 工程脚本:dev / build / manifest
21
+ ├── vite.config.ts # 前端构建配置(产物 dist/index.js,vue 等外部化到宿主)
22
+ ├── tsconfig.json
23
+ ├── src/
24
+ │ ├── index.ts # 前端入口:activate(context) / deactivate()
25
+ │ └── env.d.ts # 环境类型声明
26
+ └── rust/ # WASM 后端(--rust 创建;纯前端应用无此目录)
27
+ ├── Cargo.toml
28
+ └── src/lib.rs # WasmPlugin 实现(含 manifest 声明)
29
+ ```
30
+
31
+ ## 安装到 WasmNest Desktop
32
+
33
+ `pnpm run build -- --resources-dir <宿主资源父目录>` 把产物复制到
34
+ `<父目录>/{id}/`(内置应用随安装包分发);用户安装走宿主应用管理。
35
+
36
+ > 权限提醒:桌面端**无默认授予**——`storage` 等权限均需写入 `plugin.json` 的 `permissions`,
37
+ > 未声明即被拒(内置应用均显式声明了 `storage`)。
38
+
39
+ 完整开发指南见仓库文档 `../../../docs/wasm-app-dev-desktop.md`。
@@ -187,6 +187,7 @@ name = "wasmnest-componentize"
187
187
  version = "0.0.1"
188
188
  dependencies = [
189
189
  "wit-component",
190
+ "wit-parser",
190
191
  ]
191
192
 
192
193
  [[package]]
@@ -247,10 +248,30 @@ checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
247
248
 
248
249
  [[patch.unused]]
249
250
  name = "wasmnest-plugin-api"
250
- version = "0.0.1"
251
+ version = "0.0.2"
251
252
 
252
253
  [[patch.unused]]
253
254
  name = "wasmnest-plugin-api-macros"
255
+ version = "0.0.2"
256
+
257
+ [[patch.unused]]
258
+ name = "wasmnest-crypto-engine"
259
+ version = "0.0.1"
260
+
261
+ [[patch.unused]]
262
+ name = "wasmnest-discovery-engine"
263
+ version = "0.0.1"
264
+
265
+ [[patch.unused]]
266
+ name = "wasmnest-host-kit"
267
+ version = "0.0.1"
268
+
269
+ [[patch.unused]]
270
+ name = "wasmnest-link-crypto"
271
+ version = "0.0.1"
272
+
273
+ [[patch.unused]]
274
+ name = "wasmnest-pty-engine"
254
275
  version = "0.0.1"
255
276
 
256
277
  [[patch.unused]]
@@ -265,6 +286,14 @@ version = "0.0.1"
265
286
  name = "wasmnest-server-http"
266
287
  version = "0.0.1"
267
288
 
289
+ [[patch.unused]]
290
+ name = "wasmnest-server-peer-net"
291
+ version = "0.0.1"
292
+
268
293
  [[patch.unused]]
269
294
  name = "wasmnest-server-websocket"
270
295
  version = "0.0.1"
296
+
297
+ [[patch.unused]]
298
+ name = "wasmnest-wasm-core"
299
+ version = "0.0.1"
@@ -13,3 +13,6 @@ path = "src/main.rs"
13
13
  # 与宿主 src-tauri dev-dep 同版本(spike 实证 0.256 编码产物 00 61 73 6d 0d 00 01 00),
14
14
  # 保证编码行为一致;与 wit-bindgen 版本无锁(独立演进,见迁移 spec §4 S2)
15
15
  wit-component = "=0.256.0"
16
+ # `--list-packages` 需要遍历 decoded resolve 的 world 成员类型(WorldKey / WorldItem);
17
+ # 必须与 wit-component 同一 wit-parser 版本,否则类型不是同一个 crate(编译期即红)
18
+ wit-parser = "=0.256.0"