@binblink/wasmnest-plugin-sdk-desktop 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 (271) hide show
  1. package/README.md +307 -2
  2. package/README_en.md +284 -0
  3. package/bin/cli.js +602 -0
  4. package/bin/manifest-gen.js +458 -0
  5. package/bin/manifest-validate.js +494 -0
  6. package/bin/permission-vocabulary.json +5 -0
  7. package/bin/plugin-watch.js +331 -0
  8. package/bin/wasm-hash.js +124 -0
  9. package/dev-shell/README.md +122 -0
  10. package/dev-shell/index.html +12 -0
  11. package/dev-shell/package.json +28 -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/components/LogPanel.vue +90 -0
  16. package/dev-shell/src/loader.ts +104 -0
  17. package/dev-shell/src/locale.ts +29 -0
  18. package/dev-shell/src/locales.ts +50 -0
  19. package/dev-shell/src/main.ts +46 -0
  20. package/dev-shell/src/mock/app-env.ts +102 -0
  21. package/dev-shell/src/mock/commands.ts +54 -0
  22. package/dev-shell/src/mock/domain-context.ts +46 -0
  23. package/dev-shell/src/mock/events.ts +16 -0
  24. package/dev-shell/src/mock/file-transfer.ts +512 -0
  25. package/dev-shell/src/mock/tauri-ipc.ts +109 -0
  26. package/dev-shell/src/registry.ts +90 -0
  27. package/dev-shell/src/shell/components/AppMountSlot.vue +241 -0
  28. package/dev-shell/src/shell/components/ShellIcon.vue +141 -0
  29. package/dev-shell/src/shell/components/ShellStatusBar.vue +87 -0
  30. package/dev-shell/src/shell/components/ShellToolbar.vue +287 -0
  31. package/dev-shell/src/shell/mount/appSession.ts +45 -0
  32. package/dev-shell/src/shell/mount/devAppMount.ts +80 -0
  33. package/dev-shell/src/shell/types.ts +121 -0
  34. package/dev-shell/src/styles/dev.css +27 -0
  35. package/dev-shell/src/styles/shell.css +752 -0
  36. package/dev-shell/src/styles/style.css +1178 -0
  37. package/dev-shell/src/theme.ts +140 -0
  38. package/dev-shell/src/vite-env.d.ts +24 -0
  39. package/dev-shell/tailwind.config.js +98 -0
  40. package/dev-shell/vite.config.ts +174 -0
  41. package/dist/index.d.ts +150 -0
  42. package/dist/index.js +238 -0
  43. package/dist/types.d.ts +632 -0
  44. package/dist/types.js +0 -0
  45. package/dist/vite-plugin.d.ts +25 -0
  46. package/dist/vite-plugin.js +80 -0
  47. package/go/.gitignore +5 -0
  48. package/go/README.md +80 -0
  49. package/go/gen/wasmnest/api-call/host-api-call/empty.s +3 -0
  50. package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wasm.go +13 -0
  51. package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wit.go +34 -0
  52. package/go/gen/wasmnest/app/host-app/empty.s +3 -0
  53. package/go/gen/wasmnest/app/host-app/host-app.wasm.go +29 -0
  54. package/go/gen/wasmnest/app/host-app/host-app.wit.go +108 -0
  55. package/go/gen/wasmnest/auth-center/host-auth-center/abi.go +14 -0
  56. package/go/gen/wasmnest/auth-center/host-auth-center/empty.s +3 -0
  57. package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wasm.go +49 -0
  58. package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wit.go +225 -0
  59. package/go/gen/wasmnest/clipboard/host-clipboard/abi.go +14 -0
  60. package/go/gen/wasmnest/clipboard/host-clipboard/empty.s +3 -0
  61. package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wasm.go +17 -0
  62. package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wit.go +68 -0
  63. package/go/gen/wasmnest/connection-registry/host-connection-registry/empty.s +3 -0
  64. package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wasm.go +13 -0
  65. package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wit.go +50 -0
  66. package/go/gen/wasmnest/crypto/host-crypto/abi.go +18 -0
  67. package/go/gen/wasmnest/crypto/host-crypto/empty.s +3 -0
  68. package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wasm.go +37 -0
  69. package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wit.go +139 -0
  70. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/abi.go +14 -0
  71. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/empty.s +3 -0
  72. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wasm.go +21 -0
  73. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wit.go +62 -0
  74. package/go/gen/wasmnest/http/host-http/abi.go +14 -0
  75. package/go/gen/wasmnest/http/host-http/empty.s +3 -0
  76. package/go/gen/wasmnest/http/host-http/host-http.wasm.go +13 -0
  77. package/go/gen/wasmnest/http/host-http/host-http.wit.go +40 -0
  78. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/empty.s +3 -0
  79. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wasm.go +17 -0
  80. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wit.go +69 -0
  81. package/go/gen/wasmnest/mdns/host-mdns/empty.s +3 -0
  82. package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wasm.go +29 -0
  83. package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wit.go +101 -0
  84. package/go/gen/wasmnest/notify/host-notify/empty.s +3 -0
  85. package/go/gen/wasmnest/notify/host-notify/host-notify.wasm.go +13 -0
  86. package/go/gen/wasmnest/notify/host-notify/host-notify.wit.go +64 -0
  87. package/go/gen/wasmnest/peer/host-peer/abi.go +14 -0
  88. package/go/gen/wasmnest/peer/host-peer/empty.s +3 -0
  89. package/go/gen/wasmnest/peer/host-peer/host-peer.wasm.go +85 -0
  90. package/go/gen/wasmnest/peer/host-peer/host-peer.wit.go +357 -0
  91. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/empty.s +3 -0
  92. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wasm.go +21 -0
  93. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wit.go +70 -0
  94. package/go/gen/wasmnest/plugin/abi-form/abi-form.exports.go +11 -0
  95. package/go/gen/wasmnest/plugin/abi-form/abi-form.wasm.go +13 -0
  96. package/go/gen/wasmnest/plugin/abi-form/abi-form.wit.go +7 -0
  97. package/go/gen/wasmnest/plugin/abi-form/empty.s +3 -0
  98. package/go/gen/wasmnest/plugin/command/command.exports.go +11 -0
  99. package/go/gen/wasmnest/plugin/command/command.wasm.go +19 -0
  100. package/go/gen/wasmnest/plugin/command/command.wit.go +6 -0
  101. package/go/gen/wasmnest/plugin/command/empty.s +3 -0
  102. package/go/gen/wasmnest/plugin/events/empty.s +3 -0
  103. package/go/gen/wasmnest/plugin/events/events.exports.go +52 -0
  104. package/go/gen/wasmnest/plugin/events/events.wasm.go +74 -0
  105. package/go/gen/wasmnest/plugin/events/events.wit.go +195 -0
  106. package/go/gen/wasmnest/plugin/host-bus/empty.s +3 -0
  107. package/go/gen/wasmnest/plugin/host-bus/host-bus.wasm.go +29 -0
  108. package/go/gen/wasmnest/plugin/host-bus/host-bus.wit.go +94 -0
  109. package/go/gen/wasmnest/plugin/host-config/abi.go +14 -0
  110. package/go/gen/wasmnest/plugin/host-config/empty.s +3 -0
  111. package/go/gen/wasmnest/plugin/host-config/host-config.wasm.go +13 -0
  112. package/go/gen/wasmnest/plugin/host-config/host-config.wit.go +21 -0
  113. package/go/gen/wasmnest/plugin/host-events/empty.s +3 -0
  114. package/go/gen/wasmnest/plugin/host-events/host-events.wasm.go +9 -0
  115. package/go/gen/wasmnest/plugin/host-events/host-events.wit.go +27 -0
  116. package/go/gen/wasmnest/plugin/host-fs/abi.go +14 -0
  117. package/go/gen/wasmnest/plugin/host-fs/empty.s +3 -0
  118. package/go/gen/wasmnest/plugin/host-fs/host-fs.wasm.go +33 -0
  119. package/go/gen/wasmnest/plugin/host-fs/host-fs.wit.go +86 -0
  120. package/go/gen/wasmnest/plugin/host-log/empty.s +3 -0
  121. package/go/gen/wasmnest/plugin/host-log/host-log.wasm.go +25 -0
  122. package/go/gen/wasmnest/plugin/host-log/host-log.wit.go +65 -0
  123. package/go/gen/wasmnest/plugin/host-metrics/empty.s +3 -0
  124. package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wasm.go +13 -0
  125. package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wit.go +34 -0
  126. package/go/gen/wasmnest/plugin/host-platform/empty.s +3 -0
  127. package/go/gen/wasmnest/plugin/host-platform/host-platform.wasm.go +21 -0
  128. package/go/gen/wasmnest/plugin/host-platform/host-platform.wit.go +85 -0
  129. package/go/gen/wasmnest/plugin/host-plugin-database/abi.go +14 -0
  130. package/go/gen/wasmnest/plugin/host-plugin-database/empty.s +3 -0
  131. package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wasm.go +29 -0
  132. package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wit.go +70 -0
  133. package/go/gen/wasmnest/plugin/host-storage/abi.go +14 -0
  134. package/go/gen/wasmnest/plugin/host-storage/empty.s +3 -0
  135. package/go/gen/wasmnest/plugin/host-storage/host-storage.wasm.go +21 -0
  136. package/go/gen/wasmnest/plugin/host-storage/host-storage.wit.go +44 -0
  137. package/go/gen/wasmnest/plugin/host-worker/empty.s +3 -0
  138. package/go/gen/wasmnest/plugin/host-worker/host-worker.wasm.go +17 -0
  139. package/go/gen/wasmnest/plugin/host-worker/host-worker.wit.go +50 -0
  140. package/go/gen/wasmnest/plugin/lifecycle/empty.s +3 -0
  141. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.exports.go +32 -0
  142. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wasm.go +41 -0
  143. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wit.go +9 -0
  144. package/go/gen/wasmnest/plugin/manifest/empty.s +3 -0
  145. package/go/gen/wasmnest/plugin/manifest/manifest.exports.go +11 -0
  146. package/go/gen/wasmnest/plugin/manifest/manifest.wasm.go +13 -0
  147. package/go/gen/wasmnest/plugin/manifest/manifest.wit.go +6 -0
  148. package/go/gen/wasmnest/plugin/plugin/plugin.wit.go +4 -0
  149. package/go/gen/wasmnest/process/host-process/empty.s +3 -0
  150. package/go/gen/wasmnest/process/host-process/host-process.wasm.go +21 -0
  151. package/go/gen/wasmnest/process/host-process/host-process.wit.go +56 -0
  152. package/go/gen/wasmnest/pty/host-pty/abi.go +14 -0
  153. package/go/gen/wasmnest/pty/host-pty/empty.s +3 -0
  154. package/go/gen/wasmnest/pty/host-pty/host-pty.wasm.go +33 -0
  155. package/go/gen/wasmnest/pty/host-pty/host-pty.wit.go +164 -0
  156. package/go/gen/wasmnest/task/host-task/abi.go +14 -0
  157. package/go/gen/wasmnest/task/host-task/empty.s +3 -0
  158. package/go/gen/wasmnest/task/host-task/host-task.wasm.go +29 -0
  159. package/go/gen/wasmnest/task/host-task/host-task.wit.go +110 -0
  160. package/go/gen/wasmnest/timer/host-timer/empty.s +3 -0
  161. package/go/gen/wasmnest/timer/host-timer/host-timer.wasm.go +13 -0
  162. package/go/gen/wasmnest/timer/host-timer/host-timer.wit.go +25 -0
  163. package/go/gen/wasmnest/ws/host-websocket/empty.s +3 -0
  164. package/go/gen/wasmnest/ws/host-websocket/host-websocket.wasm.go +29 -0
  165. package/go/gen/wasmnest/ws/host-websocket/host-websocket.wit.go +109 -0
  166. package/go/gen/wasmnest/ws-server/host-websocket-server/empty.s +3 -0
  167. package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wasm.go +49 -0
  168. package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wit.go +220 -0
  169. package/go/go.mod +14 -0
  170. package/go/go.sum +2 -0
  171. package/go/sdk/dispatch.go +49 -0
  172. package/go/sdk/dispatch_test.go +81 -0
  173. package/go/sdk/entry_native.go +13 -0
  174. package/go/sdk/entry_wasip2.go +188 -0
  175. package/go/sdk/host_http_wasip2.go +42 -0
  176. package/go/sdk/host_wasip2.go +251 -0
  177. package/go/sdk/plugin.go +103 -0
  178. package/go/testplugin/index.js +1 -0
  179. package/go/testplugin/main.go +67 -0
  180. package/go/testplugin/plugin.json +24 -0
  181. package/go/tools/assemble-wit.mjs +152 -0
  182. package/go/tools/gen-bindings.mjs +51 -0
  183. package/go/wit/core.wit +273 -0
  184. package/go/wit/deps/api-call/cap-api-call.wit +20 -0
  185. package/go/wit/deps/app/cap-app.wit +54 -0
  186. package/go/wit/deps/auth-center/cap-auth-center.wit +124 -0
  187. package/go/wit/deps/clipboard/clipboard.wit +48 -0
  188. package/go/wit/deps/clocks/monotonic-clock.wit +45 -0
  189. package/go/wit/deps/clocks/wall-clock.wit +42 -0
  190. package/go/wit/deps/clocks/world.wit +6 -0
  191. package/go/wit/deps/connection-registry/cap-connection-registry.wit +40 -0
  192. package/go/wit/deps/crypto/cap-crypto.wit +68 -0
  193. package/go/wit/deps/filesystem/preopens.wit +8 -0
  194. package/go/wit/deps/filesystem/types.wit +634 -0
  195. package/go/wit/deps/filesystem/world.wit +6 -0
  196. package/go/wit/deps/fs-desktop/cap-fs-desktop.wit +29 -0
  197. package/go/wit/deps/http/http.wit +28 -0
  198. package/go/wit/deps/http-endpoint/cap-http.wit +44 -0
  199. package/go/wit/deps/io/error.wit +34 -0
  200. package/go/wit/deps/io/poll.wit +41 -0
  201. package/go/wit/deps/io/streams.wit +262 -0
  202. package/go/wit/deps/io/world.wit +6 -0
  203. package/go/wit/deps/mdns/mdns.wit +45 -0
  204. package/go/wit/deps/notify/notify.wit +51 -0
  205. package/go/wit/deps/peer/peer.wit +126 -0
  206. package/go/wit/deps/platform-desktop/cap-platform-desktop.wit +38 -0
  207. package/go/wit/deps/process/cap-process.wit +25 -0
  208. package/go/wit/deps/pty/pty.wit +80 -0
  209. package/go/wit/deps/random/insecure-seed.wit +25 -0
  210. package/go/wit/deps/random/insecure.wit +22 -0
  211. package/go/wit/deps/random/random.wit +26 -0
  212. package/go/wit/deps/random/world.wit +7 -0
  213. package/go/wit/deps/sockets/instance-network.wit +9 -0
  214. package/go/wit/deps/sockets/ip-name-lookup.wit +51 -0
  215. package/go/wit/deps/sockets/network.wit +145 -0
  216. package/go/wit/deps/sockets/tcp-create-socket.wit +27 -0
  217. package/go/wit/deps/sockets/tcp.wit +353 -0
  218. package/go/wit/deps/sockets/udp-create-socket.wit +27 -0
  219. package/go/wit/deps/sockets/udp.wit +266 -0
  220. package/go/wit/deps/sockets/world.wit +11 -0
  221. package/go/wit/deps/task/cap-task.wit +56 -0
  222. package/go/wit/deps/timer/cap-timer.wit +14 -0
  223. package/go/wit/deps/wasi-cli/command.wit +7 -0
  224. package/go/wit/deps/wasi-cli/environment.wit +18 -0
  225. package/go/wit/deps/wasi-cli/exit.wit +4 -0
  226. package/go/wit/deps/wasi-cli/imports.wit +20 -0
  227. package/go/wit/deps/wasi-cli/run.wit +4 -0
  228. package/go/wit/deps/wasi-cli/stdio.wit +17 -0
  229. package/go/wit/deps/wasi-cli/terminal.wit +49 -0
  230. package/go/wit/deps/ws/ws.wit +50 -0
  231. package/go/wit/deps/ws-server/cap-ws.wit +99 -0
  232. package/go/wit/go-plugin.wit +28 -0
  233. package/go/wit/plugin-face.wit +355 -0
  234. package/go/wit/wasmnest.wit +25 -0
  235. package/package.json +100 -3
  236. package/src/config.ts +49 -0
  237. package/src/global-dialog.ts +169 -0
  238. package/src/index.ts +88 -0
  239. package/src/runtime.ts +54 -0
  240. package/src/types.ts +681 -0
  241. package/src/ui/AppUpdateSection.d.ts +44 -0
  242. package/src/ui/AppUpdateSection.vue +253 -0
  243. package/src/ui/MarkdownEditor.vue +520 -0
  244. package/src/ui/NumberField.d.ts +49 -0
  245. package/src/ui/NumberField.vue +390 -0
  246. package/src/ui/PluginGlobalDialog.vue +401 -0
  247. package/src/ui/Select.d.ts +36 -0
  248. package/src/ui/Select.vue +220 -0
  249. package/src/ui/TerminalInputRail.vue +184 -0
  250. package/src/ui/apply-select-position.ts +65 -0
  251. package/src/ui/markdown-editor-syntax.ts +234 -0
  252. package/src/ui/markdown-editor.d.ts +36 -0
  253. package/src/ui/plugin-global-dialog.d.ts +12 -0
  254. package/src/ui/select-position.ts +79 -0
  255. package/src/ui/terminal-input-rail.d.ts +30 -0
  256. package/src/ui/zoom-compensation.d.ts +9 -0
  257. package/src/ui/zoom-compensation.ts +52 -0
  258. package/src/update.ts +123 -0
  259. package/src/vite-plugin.ts +124 -0
  260. package/template/README.md +39 -0
  261. package/template/package.json +23 -0
  262. package/template/plugin.json +14 -0
  263. package/template/rust/Cargo.toml +21 -0
  264. package/template/rust/src/lib.rs +39 -0
  265. package/template/src/env.d.ts +24 -0
  266. package/template/src/index.ts +37 -0
  267. package/template/tsconfig.json +17 -0
  268. package/template/vite.config.ts +21 -0
  269. package/tools/componentize/Cargo.lock +299 -0
  270. package/tools/componentize/Cargo.toml +18 -0
  271. package/tools/componentize/src/main.rs +197 -0
@@ -0,0 +1,520 @@
1
+ <template>
2
+ <div class="mde">
3
+ <!-- 语法工具栏:mousedown.prevent 保证点击不抢 textarea 焦点,光标位置得以保留 -->
4
+ <div v-if="toolbar" class="mde-toolbar" role="toolbar" :aria-label="t('toolbar')">
5
+ <button
6
+ v-for="action in toolbarActions"
7
+ :key="action"
8
+ type="button"
9
+ class="mde-tb-btn"
10
+ :disabled="disabled"
11
+ :title="t(action)"
12
+ :aria-label="t(action)"
13
+ @mousedown.prevent
14
+ @click="runAction(action)"
15
+ >
16
+ <span v-if="action === 'bold'" class="mde-tb-glyph mde-tb-bold">B</span>
17
+ <span v-else-if="action === 'italic'" class="mde-tb-glyph mde-tb-italic">I</span>
18
+ <span v-else-if="action === 'h1'" class="mde-tb-glyph">H1</span>
19
+ <span v-else-if="action === 'h2'" class="mde-tb-glyph">H2</span>
20
+ <span v-else-if="action === 'h3'" class="mde-tb-glyph">H3</span>
21
+ <span v-else-if="action === 'olist'" class="mde-tb-glyph mde-tb-mono">1.</span>
22
+ <span v-else-if="action === 'quote'" class="mde-tb-glyph mde-tb-mono">&quot;</span>
23
+ <span v-else-if="action === 'codeInline'" class="mde-tb-glyph mde-tb-mono">`</span>
24
+ <svg
25
+ v-else
26
+ class="mde-tb-icon"
27
+ fill="none"
28
+ stroke="currentColor"
29
+ stroke-width="2"
30
+ stroke-linecap="round"
31
+ stroke-linejoin="round"
32
+ viewBox="0 0 24 24"
33
+ >
34
+ <template v-if="action === 'list'">
35
+ <line x1="8" y1="6" x2="21" y2="6" />
36
+ <line x1="8" y1="12" x2="21" y2="12" />
37
+ <line x1="8" y1="18" x2="21" y2="18" />
38
+ <line x1="3" y1="6" x2="3.01" y2="6" />
39
+ <line x1="3" y1="12" x2="3.01" y2="12" />
40
+ <line x1="3" y1="18" x2="3.01" y2="18" />
41
+ </template>
42
+ <template v-else-if="action === 'codeBlock'">
43
+ <polyline points="16 18 22 12 16 6" />
44
+ <polyline points="8 6 2 12 8 18" />
45
+ </template>
46
+ <template v-else-if="action === 'link'">
47
+ <path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" />
48
+ <path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" />
49
+ </template>
50
+ <template v-else-if="action === 'divider'">
51
+ <line x1="3" y1="12" x2="21" y2="12" />
52
+ </template>
53
+ </svg>
54
+ </button>
55
+
56
+ <span class="mde-tb-sep"></span>
57
+
58
+ <button
59
+ v-if="preview"
60
+ type="button"
61
+ class="mde-tb-btn"
62
+ :disabled="disabled"
63
+ :title="mode === 'preview' ? t('edit') : t('preview')"
64
+ :aria-label="mode === 'preview' ? t('edit') : t('preview')"
65
+ @mousedown.prevent
66
+ @click="toggleMode"
67
+ >
68
+ <svg
69
+ v-if="mode === 'edit'"
70
+ class="mde-tb-icon"
71
+ fill="none"
72
+ stroke="currentColor"
73
+ stroke-width="2"
74
+ stroke-linecap="round"
75
+ stroke-linejoin="round"
76
+ viewBox="0 0 24 24"
77
+ >
78
+ <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" />
79
+ <circle cx="12" cy="12" r="3" />
80
+ </svg>
81
+ <svg
82
+ v-else
83
+ class="mde-tb-icon"
84
+ fill="none"
85
+ stroke="currentColor"
86
+ stroke-width="2"
87
+ stroke-linecap="round"
88
+ stroke-linejoin="round"
89
+ viewBox="0 0 24 24"
90
+ >
91
+ <path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z" />
92
+ </svg>
93
+ </button>
94
+ </div>
95
+
96
+ <!-- 编辑 / 预览主体(flex:1,随容器高度自适应) -->
97
+ <div class="mde-body">
98
+ <textarea
99
+ v-show="mode === 'edit'"
100
+ ref="textareaRef"
101
+ class="mde-textarea"
102
+ :value="draft"
103
+ :placeholder="placeholder"
104
+ :disabled="disabled"
105
+ spellcheck="false"
106
+ data-testid="markdown-textarea"
107
+ @input="onInput"
108
+ ></textarea>
109
+ <div v-show="mode === 'preview'" class="mde-preview" data-testid="markdown-preview" v-html="previewHtml"></div>
110
+ </div>
111
+ </div>
112
+ </template>
113
+
114
+ <script setup lang="ts">
115
+ /**
116
+ * MarkdownEditor - SDK 公共轻量 markdown 编辑器(textarea 内核 + 语法工具栏 + 预览切换)
117
+ *
118
+ * - 编辑内核:原生 <textarea>,v-model 契约(modelValue / update:modelValue)
119
+ * - 语法插入:applyMarkdownSyntax 纯函数作用于光标/选区(src/ui/markdown-editor-syntax.ts)
120
+ * - 预览渲染:marked(与移动端 FileViewerModal 同库同版本 18.0.11,渲染行为一致)
121
+ * - 样式:宿主设计 token(--text-* / --bg-input / --border-input / --radius-input 等),
122
+ * 暗色/亮色随 token 自动跟随;不硬编码色值
123
+ * - i18n 中立:按钮 title 内置英文,可经 labels props 覆盖;不依赖 vue-i18n
124
+ *
125
+ * 安全取舍(有意记录):预览不引入 DOMPurify(保持轻量,与移动端一致);
126
+ * 安全边界在 marked 渲染层收紧:
127
+ * - 链接协议白名单(javascript: 等降级为纯文本);
128
+ * - **raw HTML 整体转义为文本**(marked 18 无 `html:false` 选项,关闭点是
129
+ * `renderer.html`):预览内容可能是 GitHub/本地导入的**不可信 skill**,
130
+ * v-html 透传 raw HTML 即任意 XSS(`<img src=x onerror=...>` 等)。
131
+ */
132
+ import { computed, ref, watch } from 'vue'
133
+ import { nextTick } from 'vue'
134
+ import { Marked } from 'marked'
135
+ import { applyMarkdownSyntax, type MarkdownSyntaxAction } from './markdown-editor-syntax'
136
+
137
+ export type MarkdownEditorLabelKey = MarkdownSyntaxAction | 'preview' | 'edit' | 'toolbar'
138
+
139
+ export interface MarkdownEditorProps {
140
+ /** v-model 绑定值 */
141
+ modelValue: string
142
+ /** 空内容占位提示 */
143
+ placeholder?: string
144
+ /** 是否显示语法工具栏(默认 true) */
145
+ toolbar?: boolean
146
+ /** 是否显示预览切换按钮(默认 true) */
147
+ preview?: boolean
148
+ /** 禁用编辑与工具栏(保存中/预览锁定态) */
149
+ disabled?: boolean
150
+ /** 工具栏 title / 预览切换文案覆盖(不传用内置英文) */
151
+ labels?: Partial<Record<MarkdownEditorLabelKey, string>>
152
+ }
153
+
154
+ const props = withDefaults(defineProps<MarkdownEditorProps>(), {
155
+ placeholder: '',
156
+ toolbar: true,
157
+ preview: true,
158
+ disabled: false,
159
+ labels: () => ({}),
160
+ })
161
+
162
+ const emit = defineEmits<{ 'update:modelValue': [value: string] }>()
163
+
164
+ // ==================== i18n 中立的默认文案 ====================
165
+ const DEFAULT_LABELS: Record<MarkdownEditorLabelKey, string> = {
166
+ bold: 'Bold',
167
+ italic: 'Italic',
168
+ h1: 'Heading 1',
169
+ h2: 'Heading 2',
170
+ h3: 'Heading 3',
171
+ list: 'Bulleted list',
172
+ olist: 'Numbered list',
173
+ quote: 'Blockquote',
174
+ codeBlock: 'Code block',
175
+ codeInline: 'Inline code',
176
+ link: 'Link',
177
+ divider: 'Divider',
178
+ preview: 'Preview',
179
+ edit: 'Edit',
180
+ toolbar: 'Markdown formatting',
181
+ }
182
+
183
+ function t(key: MarkdownEditorLabelKey): string {
184
+ return props.labels?.[key] ?? DEFAULT_LABELS[key]
185
+ }
186
+
187
+ const toolbarActions: MarkdownSyntaxAction[] = [
188
+ 'bold',
189
+ 'italic',
190
+ 'h1',
191
+ 'h2',
192
+ 'h3',
193
+ 'list',
194
+ 'olist',
195
+ 'quote',
196
+ 'codeBlock',
197
+ 'codeInline',
198
+ 'link',
199
+ 'divider',
200
+ ]
201
+
202
+ // ==================== 编辑状态 ====================
203
+ /** 草稿(组件内部持有;编辑/预览切换不丢内容) */
204
+ const draft = ref(props.modelValue)
205
+ const textareaRef = ref<HTMLTextAreaElement | null>(null)
206
+ const mode = ref<'edit' | 'preview'>('edit')
207
+
208
+ /** 外部 modelValue 变化时同步草稿(v-model 受控方向) */
209
+ watch(
210
+ () => props.modelValue,
211
+ (value) => {
212
+ if (value !== draft.value) draft.value = value
213
+ },
214
+ )
215
+
216
+ function onInput(event: Event) {
217
+ draft.value = (event.target as HTMLTextAreaElement).value
218
+ emit('update:modelValue', draft.value)
219
+ }
220
+
221
+ /** 工具栏动作:纯函数变换文本与光标/选区,恢复焦点与选区位置 */
222
+ function runAction(action: MarkdownSyntaxAction) {
223
+ const ta = textareaRef.value
224
+ if (!ta) return
225
+ const result = applyMarkdownSyntax(action, draft.value, ta.selectionStart, ta.selectionEnd)
226
+ draft.value = result.text
227
+ emit('update:modelValue', result.text)
228
+ void nextTick(() => {
229
+ ta.focus()
230
+ ta.setSelectionRange(result.selectionStart, result.selectionEnd)
231
+ })
232
+ }
233
+
234
+ function toggleMode() {
235
+ mode.value = mode.value === 'edit' ? 'preview' : 'edit'
236
+ }
237
+
238
+ // ==================== 预览渲染(marked) ====================
239
+
240
+ /** 链接协议白名单:只允许 http/https/mailto/锚点/相对路径,未知协议降级为纯文本 */
241
+ function isSafeUrl(href: string): boolean {
242
+ if (!href) return false
243
+ if (/^(https?:|mailto:|#)/i.test(href)) return true
244
+ // 相对路径(不以协议形式开头)
245
+ return !/^[a-z][a-z0-9+.-]*:/i.test(href)
246
+ }
247
+
248
+ function escapeAttr(value: string): string {
249
+ return value.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#39;')
250
+ }
251
+
252
+ /** HTML 实体转义:raw HTML 降级为可见文本,不生成可执行节点 */
253
+ function escapeHtml(value: string): string {
254
+ return value
255
+ .replace(/&/g, '&amp;')
256
+ .replace(/</g, '&lt;')
257
+ .replace(/>/g, '&gt;')
258
+ .replace(/"/g, '&quot;')
259
+ .replace(/'/g, '&#39;')
260
+ }
261
+
262
+ // 组件私有 Marked 实例(模块级构建一次,多实例组件共享同一渲染策略):
263
+ // 不用全局 `marked` 单例的 use() 副作用——vitest/多副本解析下全局注册可能落在
264
+ // 另一份 marked 实例上(实测组件渲染与注册策略分家),私有实例保证
265
+ // 「注册的安全策略 = 实际渲染路径」恒一致。
266
+ const md = new Marked()
267
+ md.use({
268
+ renderer: {
269
+ link({ href, title, tokens }) {
270
+ const text = this.parser.parseInline(tokens)
271
+ if (!isSafeUrl(href)) return text
272
+ const attrs = [`href="${escapeAttr(href)}"`, 'target="_blank"', 'rel="noopener noreferrer"']
273
+ if (title) attrs.push(`title="${escapeAttr(title)}"`)
274
+ return `<a ${attrs.join(' ')}>${text}</a>`
275
+ },
276
+ // 块级与内联 raw HTML 统一转义为文本:marked 默认透传 raw HTML,
277
+ // 预览内容含不可信来源时等于任意 XSS(实测 <img onerror> 原样进 v-html)。
278
+ // marked 18 已无 `html:false` 选项,安全关闭点即本 renderer。
279
+ html({ text }) {
280
+ return escapeHtml(text)
281
+ },
282
+ },
283
+ })
284
+
285
+ const previewHtml = computed(() => md.parse(draft.value) as string)
286
+ </script>
287
+
288
+ <style scoped>
289
+ /* ==================== 容器 ==================== */
290
+ .mde {
291
+ display: flex;
292
+ flex-direction: column;
293
+ height: 100%;
294
+ min-height: 0;
295
+ box-sizing: border-box;
296
+ }
297
+
298
+ /* ==================== 工具栏 ==================== */
299
+ .mde-toolbar {
300
+ display: flex;
301
+ align-items: center;
302
+ gap: 2px;
303
+ padding: 6px 8px;
304
+ border: 1px solid var(--border-input);
305
+ border-bottom: none;
306
+ border-radius: var(--radius-input) var(--radius-input) 0 0;
307
+ background: var(--bg-input);
308
+ flex-shrink: 0;
309
+ }
310
+
311
+ .mde-tb-btn {
312
+ display: inline-flex;
313
+ align-items: center;
314
+ justify-content: center;
315
+ width: 28px;
316
+ height: 28px;
317
+ padding: 0;
318
+ border: none;
319
+ border-radius: 6px;
320
+ background: transparent;
321
+ color: var(--text-secondary);
322
+ cursor: pointer;
323
+ transition:
324
+ background-color 0.15s,
325
+ color 0.15s;
326
+ }
327
+
328
+ .mde-tb-btn:hover {
329
+ background: var(--color-primary-light);
330
+ color: var(--text-primary);
331
+ }
332
+
333
+ .mde-tb-btn:disabled {
334
+ opacity: 0.45;
335
+ cursor: not-allowed;
336
+ }
337
+
338
+ .mde-tb-btn:disabled:hover {
339
+ background: transparent;
340
+ color: var(--text-secondary);
341
+ }
342
+
343
+ .mde-tb-btn:focus-visible {
344
+ outline: 2px solid var(--color-primary);
345
+ outline-offset: -2px;
346
+ }
347
+
348
+ .mde-tb-icon {
349
+ width: 15px;
350
+ height: 15px;
351
+ flex-shrink: 0;
352
+ }
353
+
354
+ .mde-tb-glyph {
355
+ font-size: 13px;
356
+ line-height: 1;
357
+ font-family: inherit;
358
+ }
359
+
360
+ .mde-tb-bold {
361
+ font-weight: 700;
362
+ }
363
+
364
+ .mde-tb-italic {
365
+ font-style: italic;
366
+ }
367
+
368
+ .mde-tb-mono {
369
+ font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
370
+ }
371
+
372
+ .mde-tb-sep {
373
+ width: 1px;
374
+ height: 16px;
375
+ margin: 0 4px;
376
+ background: var(--border-input);
377
+ flex-shrink: 0;
378
+ }
379
+
380
+ /* ==================== 编辑 / 预览主体 ==================== */
381
+ .mde-body {
382
+ flex: 1;
383
+ min-height: 0;
384
+ display: flex;
385
+ flex-direction: column;
386
+ border: 1px solid var(--border-input);
387
+ border-top: none;
388
+ border-radius: 0 0 var(--radius-input) var(--radius-input);
389
+ background: var(--bg-input);
390
+ }
391
+
392
+ .mde-textarea {
393
+ flex: 1;
394
+ min-height: 0;
395
+ width: 100%;
396
+ height: 100%;
397
+ padding: 10px 12px;
398
+ box-sizing: border-box;
399
+ border: none;
400
+ outline: none;
401
+ resize: none;
402
+ background: transparent;
403
+ color: var(--text-primary);
404
+ font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
405
+ font-size: var(--font-size-base);
406
+ line-height: 1.6;
407
+ }
408
+
409
+ .mde-textarea::placeholder {
410
+ color: var(--text-tertiary);
411
+ }
412
+
413
+ .mde-textarea:disabled {
414
+ cursor: not-allowed;
415
+ }
416
+
417
+ /* 预览区:基础 markdown 排版,色值全部走宿主 token */
418
+ .mde-preview {
419
+ flex: 1;
420
+ min-height: 0;
421
+ overflow-y: auto;
422
+ padding: 10px 12px;
423
+ color: var(--text-primary);
424
+ font-size: var(--font-size-base);
425
+ line-height: 1.6;
426
+ word-break: break-word;
427
+ }
428
+
429
+ .mde-preview :deep(h1),
430
+ .mde-preview :deep(h2),
431
+ .mde-preview :deep(h3),
432
+ .mde-preview :deep(h4),
433
+ .mde-preview :deep(h5),
434
+ .mde-preview :deep(h6) {
435
+ margin: 0.6em 0 0.4em;
436
+ line-height: 1.3;
437
+ font-weight: 600;
438
+ color: var(--text-primary);
439
+ }
440
+
441
+ .mde-preview :deep(h1) {
442
+ font-size: 1.5em;
443
+ }
444
+
445
+ .mde-preview :deep(h2) {
446
+ font-size: 1.3em;
447
+ }
448
+
449
+ .mde-preview :deep(h3) {
450
+ font-size: 1.15em;
451
+ }
452
+
453
+ .mde-preview :deep(p) {
454
+ margin: 0.4em 0;
455
+ }
456
+
457
+ .mde-preview :deep(ul),
458
+ .mde-preview :deep(ol) {
459
+ margin: 0.4em 0;
460
+ padding-left: 1.6em;
461
+ }
462
+
463
+ .mde-preview :deep(li) {
464
+ margin: 0.15em 0;
465
+ }
466
+
467
+ .mde-preview :deep(blockquote) {
468
+ margin: 0.5em 0;
469
+ padding: 0.2em 0.9em;
470
+ border-left: 3px solid var(--border-strong);
471
+ color: var(--text-secondary);
472
+ }
473
+
474
+ .mde-preview :deep(code) {
475
+ padding: 0.15em 0.35em;
476
+ border-radius: 4px;
477
+ background: var(--bg-hover);
478
+ font-family: ui-monospace, 'Cascadia Code', Consolas, monospace;
479
+ font-size: 0.9em;
480
+ }
481
+
482
+ .mde-preview :deep(pre) {
483
+ margin: 0.5em 0;
484
+ padding: 0.7em 0.9em;
485
+ overflow-x: auto;
486
+ border-radius: var(--radius-input);
487
+ background: var(--bg-hover);
488
+ }
489
+
490
+ .mde-preview :deep(pre code) {
491
+ padding: 0;
492
+ background: transparent;
493
+ }
494
+
495
+ .mde-preview :deep(a) {
496
+ color: var(--color-primary);
497
+ text-decoration: underline;
498
+ }
499
+
500
+ .mde-preview :deep(hr) {
501
+ margin: 0.8em 0;
502
+ border: none;
503
+ border-top: 1px solid var(--border-strong);
504
+ }
505
+
506
+ .mde-preview :deep(table) {
507
+ margin: 0.5em 0;
508
+ border-collapse: collapse;
509
+ }
510
+
511
+ .mde-preview :deep(th),
512
+ .mde-preview :deep(td) {
513
+ padding: 0.3em 0.7em;
514
+ border: 1px solid var(--border-input);
515
+ }
516
+
517
+ .mde-preview :deep(img) {
518
+ max-width: 100%;
519
+ }
520
+ </style>
@@ -0,0 +1,49 @@
1
+ import type { DefineComponent } from 'vue'
2
+
3
+ /** NumberField 组件 props */
4
+ export interface NumberFieldProps {
5
+ /** 当前值;清空后以 null 回抛 */
6
+ modelValue: number | null
7
+ /** 下限(含) */
8
+ min?: number
9
+ /** 上限(含);不传 = 不设上限 */
10
+ max?: number
11
+ /** 每次点击 / 方向键的变化量,默认 1 */
12
+ step?: number
13
+ /** sm:插件紧凑行(32px 高 / 12.5px 字 / 24px 步进列);md:宿主表单默认(--input-height 36px / 28px 步进列) */
14
+ size?: 'sm' | 'md'
15
+ /** 文本对齐;设置页右侧控件用 right(默认),表单字段用 left */
16
+ align?: 'left' | 'right'
17
+ /** 宽度(CSS 长度);不传则铺满父容器 */
18
+ width?: string
19
+ /** 等宽字体,默认 true(端口 / 秒数这类纯数字更整齐) */
20
+ mono?: boolean
21
+ disabled?: boolean
22
+ readonly?: boolean
23
+ /** 无障碍名称(没有外置 label 时必须给) */
24
+ ariaLabel?: string
25
+ /** 增 / 减按钮的无障碍名称,默认「增加」/「减少」 */
26
+ labelIncrease?: string
27
+ labelDecrease?: string
28
+ testid?: string
29
+ }
30
+
31
+ /**
32
+ * 数字输入(含右侧竖排步进按钮)共享组件
33
+ *
34
+ * 取代原生 `<input type="number">`:原生 spinner 的上下箭头只有 6px 左右,点不中、
35
+ * 也不吃 token。本组件用 reka-ui 的 `Primitive` 原语下发元素(开源 headless),
36
+ * 值、解析、钳制、提交时机全部在本组件内闭环,视觉绑定宿主 token。
37
+ *
38
+ * 用法:
39
+ * ```vue
40
+ * <NumberField v-model="ttl" :min="60" :max="3600" @commit="save" />
41
+ * ```
42
+ * - `update:modelValue`:合法键入 / 步进即时抛;清空为 null。
43
+ * - `commit`:失焦或回车时抛,携带**已按 min/max 钳制**的最终值——落盘用它,
44
+ * 不要在 `@blur` 里读事件值。
45
+ * - 键位:↑/↓ 单步、PageUp/PageDown 十步、Home/End 到边界、Enter 提交。
46
+ */
47
+ export declare const NumberField: DefineComponent<NumberFieldProps>
48
+
49
+ export default NumberField