@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.
- package/README.md +307 -2
- package/README_en.md +284 -0
- package/bin/cli.js +602 -0
- package/bin/manifest-gen.js +458 -0
- package/bin/manifest-validate.js +494 -0
- package/bin/permission-vocabulary.json +5 -0
- package/bin/plugin-watch.js +331 -0
- package/bin/wasm-hash.js +124 -0
- package/dev-shell/README.md +122 -0
- package/dev-shell/index.html +12 -0
- package/dev-shell/package.json +28 -0
- package/dev-shell/pnpm-workspace.yaml +9 -0
- package/dev-shell/postcss.config.js +6 -0
- package/dev-shell/src/App.vue +90 -0
- package/dev-shell/src/components/LogPanel.vue +90 -0
- package/dev-shell/src/loader.ts +104 -0
- package/dev-shell/src/locale.ts +29 -0
- package/dev-shell/src/locales.ts +50 -0
- package/dev-shell/src/main.ts +46 -0
- package/dev-shell/src/mock/app-env.ts +102 -0
- package/dev-shell/src/mock/commands.ts +54 -0
- package/dev-shell/src/mock/domain-context.ts +46 -0
- package/dev-shell/src/mock/events.ts +16 -0
- package/dev-shell/src/mock/file-transfer.ts +512 -0
- package/dev-shell/src/mock/tauri-ipc.ts +109 -0
- package/dev-shell/src/registry.ts +90 -0
- package/dev-shell/src/shell/components/AppMountSlot.vue +241 -0
- package/dev-shell/src/shell/components/ShellIcon.vue +141 -0
- package/dev-shell/src/shell/components/ShellStatusBar.vue +87 -0
- package/dev-shell/src/shell/components/ShellToolbar.vue +287 -0
- package/dev-shell/src/shell/mount/appSession.ts +45 -0
- package/dev-shell/src/shell/mount/devAppMount.ts +80 -0
- package/dev-shell/src/shell/types.ts +121 -0
- package/dev-shell/src/styles/dev.css +27 -0
- package/dev-shell/src/styles/shell.css +752 -0
- package/dev-shell/src/styles/style.css +1178 -0
- package/dev-shell/src/theme.ts +140 -0
- package/dev-shell/src/vite-env.d.ts +24 -0
- package/dev-shell/tailwind.config.js +98 -0
- package/dev-shell/vite.config.ts +174 -0
- package/dist/index.d.ts +150 -0
- package/dist/index.js +238 -0
- package/dist/types.d.ts +632 -0
- package/dist/types.js +0 -0
- package/dist/vite-plugin.d.ts +25 -0
- package/dist/vite-plugin.js +80 -0
- package/go/.gitignore +5 -0
- package/go/README.md +80 -0
- package/go/gen/wasmnest/api-call/host-api-call/empty.s +3 -0
- package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wasm.go +13 -0
- package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wit.go +34 -0
- package/go/gen/wasmnest/app/host-app/empty.s +3 -0
- package/go/gen/wasmnest/app/host-app/host-app.wasm.go +29 -0
- package/go/gen/wasmnest/app/host-app/host-app.wit.go +108 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/abi.go +14 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/empty.s +3 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wasm.go +49 -0
- package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wit.go +225 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/abi.go +14 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/empty.s +3 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wasm.go +17 -0
- package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wit.go +68 -0
- package/go/gen/wasmnest/connection-registry/host-connection-registry/empty.s +3 -0
- package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wasm.go +13 -0
- package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wit.go +50 -0
- package/go/gen/wasmnest/crypto/host-crypto/abi.go +18 -0
- package/go/gen/wasmnest/crypto/host-crypto/empty.s +3 -0
- package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wasm.go +37 -0
- package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wit.go +139 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/abi.go +14 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/empty.s +3 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wasm.go +21 -0
- package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wit.go +62 -0
- package/go/gen/wasmnest/http/host-http/abi.go +14 -0
- package/go/gen/wasmnest/http/host-http/empty.s +3 -0
- package/go/gen/wasmnest/http/host-http/host-http.wasm.go +13 -0
- package/go/gen/wasmnest/http/host-http/host-http.wit.go +40 -0
- package/go/gen/wasmnest/http-endpoint/host-http-endpoint/empty.s +3 -0
- package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wasm.go +17 -0
- package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wit.go +69 -0
- package/go/gen/wasmnest/mdns/host-mdns/empty.s +3 -0
- package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wasm.go +29 -0
- package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wit.go +101 -0
- package/go/gen/wasmnest/notify/host-notify/empty.s +3 -0
- package/go/gen/wasmnest/notify/host-notify/host-notify.wasm.go +13 -0
- package/go/gen/wasmnest/notify/host-notify/host-notify.wit.go +64 -0
- package/go/gen/wasmnest/peer/host-peer/abi.go +14 -0
- package/go/gen/wasmnest/peer/host-peer/empty.s +3 -0
- package/go/gen/wasmnest/peer/host-peer/host-peer.wasm.go +85 -0
- package/go/gen/wasmnest/peer/host-peer/host-peer.wit.go +357 -0
- package/go/gen/wasmnest/platform-desktop/host-platform-desktop/empty.s +3 -0
- package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wasm.go +21 -0
- package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wit.go +70 -0
- package/go/gen/wasmnest/plugin/abi-form/abi-form.exports.go +11 -0
- package/go/gen/wasmnest/plugin/abi-form/abi-form.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/abi-form/abi-form.wit.go +7 -0
- package/go/gen/wasmnest/plugin/abi-form/empty.s +3 -0
- package/go/gen/wasmnest/plugin/command/command.exports.go +11 -0
- package/go/gen/wasmnest/plugin/command/command.wasm.go +19 -0
- package/go/gen/wasmnest/plugin/command/command.wit.go +6 -0
- package/go/gen/wasmnest/plugin/command/empty.s +3 -0
- package/go/gen/wasmnest/plugin/events/empty.s +3 -0
- package/go/gen/wasmnest/plugin/events/events.exports.go +52 -0
- package/go/gen/wasmnest/plugin/events/events.wasm.go +74 -0
- package/go/gen/wasmnest/plugin/events/events.wit.go +195 -0
- package/go/gen/wasmnest/plugin/host-bus/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-bus/host-bus.wasm.go +29 -0
- package/go/gen/wasmnest/plugin/host-bus/host-bus.wit.go +94 -0
- package/go/gen/wasmnest/plugin/host-config/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-config/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-config/host-config.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/host-config/host-config.wit.go +21 -0
- package/go/gen/wasmnest/plugin/host-events/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-events/host-events.wasm.go +9 -0
- package/go/gen/wasmnest/plugin/host-events/host-events.wit.go +27 -0
- package/go/gen/wasmnest/plugin/host-fs/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-fs/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-fs/host-fs.wasm.go +33 -0
- package/go/gen/wasmnest/plugin/host-fs/host-fs.wit.go +86 -0
- package/go/gen/wasmnest/plugin/host-log/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-log/host-log.wasm.go +25 -0
- package/go/gen/wasmnest/plugin/host-log/host-log.wit.go +65 -0
- package/go/gen/wasmnest/plugin/host-metrics/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wit.go +34 -0
- package/go/gen/wasmnest/plugin/host-platform/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-platform/host-platform.wasm.go +21 -0
- package/go/gen/wasmnest/plugin/host-platform/host-platform.wit.go +85 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wasm.go +29 -0
- package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wit.go +70 -0
- package/go/gen/wasmnest/plugin/host-storage/abi.go +14 -0
- package/go/gen/wasmnest/plugin/host-storage/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-storage/host-storage.wasm.go +21 -0
- package/go/gen/wasmnest/plugin/host-storage/host-storage.wit.go +44 -0
- package/go/gen/wasmnest/plugin/host-worker/empty.s +3 -0
- package/go/gen/wasmnest/plugin/host-worker/host-worker.wasm.go +17 -0
- package/go/gen/wasmnest/plugin/host-worker/host-worker.wit.go +50 -0
- package/go/gen/wasmnest/plugin/lifecycle/empty.s +3 -0
- package/go/gen/wasmnest/plugin/lifecycle/lifecycle.exports.go +32 -0
- package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wasm.go +41 -0
- package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wit.go +9 -0
- package/go/gen/wasmnest/plugin/manifest/empty.s +3 -0
- package/go/gen/wasmnest/plugin/manifest/manifest.exports.go +11 -0
- package/go/gen/wasmnest/plugin/manifest/manifest.wasm.go +13 -0
- package/go/gen/wasmnest/plugin/manifest/manifest.wit.go +6 -0
- package/go/gen/wasmnest/plugin/plugin/plugin.wit.go +4 -0
- package/go/gen/wasmnest/process/host-process/empty.s +3 -0
- package/go/gen/wasmnest/process/host-process/host-process.wasm.go +21 -0
- package/go/gen/wasmnest/process/host-process/host-process.wit.go +56 -0
- package/go/gen/wasmnest/pty/host-pty/abi.go +14 -0
- package/go/gen/wasmnest/pty/host-pty/empty.s +3 -0
- package/go/gen/wasmnest/pty/host-pty/host-pty.wasm.go +33 -0
- package/go/gen/wasmnest/pty/host-pty/host-pty.wit.go +164 -0
- package/go/gen/wasmnest/task/host-task/abi.go +14 -0
- package/go/gen/wasmnest/task/host-task/empty.s +3 -0
- package/go/gen/wasmnest/task/host-task/host-task.wasm.go +29 -0
- package/go/gen/wasmnest/task/host-task/host-task.wit.go +110 -0
- package/go/gen/wasmnest/timer/host-timer/empty.s +3 -0
- package/go/gen/wasmnest/timer/host-timer/host-timer.wasm.go +13 -0
- package/go/gen/wasmnest/timer/host-timer/host-timer.wit.go +25 -0
- package/go/gen/wasmnest/ws/host-websocket/empty.s +3 -0
- package/go/gen/wasmnest/ws/host-websocket/host-websocket.wasm.go +29 -0
- package/go/gen/wasmnest/ws/host-websocket/host-websocket.wit.go +109 -0
- package/go/gen/wasmnest/ws-server/host-websocket-server/empty.s +3 -0
- package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wasm.go +49 -0
- package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wit.go +220 -0
- package/go/go.mod +14 -0
- package/go/go.sum +2 -0
- package/go/sdk/dispatch.go +49 -0
- package/go/sdk/dispatch_test.go +81 -0
- package/go/sdk/entry_native.go +13 -0
- package/go/sdk/entry_wasip2.go +188 -0
- package/go/sdk/host_http_wasip2.go +42 -0
- package/go/sdk/host_wasip2.go +251 -0
- package/go/sdk/plugin.go +103 -0
- package/go/testplugin/index.js +1 -0
- package/go/testplugin/main.go +67 -0
- package/go/testplugin/plugin.json +24 -0
- package/go/tools/assemble-wit.mjs +152 -0
- package/go/tools/gen-bindings.mjs +51 -0
- package/go/wit/core.wit +273 -0
- package/go/wit/deps/api-call/cap-api-call.wit +20 -0
- package/go/wit/deps/app/cap-app.wit +54 -0
- package/go/wit/deps/auth-center/cap-auth-center.wit +124 -0
- package/go/wit/deps/clipboard/clipboard.wit +48 -0
- package/go/wit/deps/clocks/monotonic-clock.wit +45 -0
- package/go/wit/deps/clocks/wall-clock.wit +42 -0
- package/go/wit/deps/clocks/world.wit +6 -0
- package/go/wit/deps/connection-registry/cap-connection-registry.wit +40 -0
- package/go/wit/deps/crypto/cap-crypto.wit +68 -0
- package/go/wit/deps/filesystem/preopens.wit +8 -0
- package/go/wit/deps/filesystem/types.wit +634 -0
- package/go/wit/deps/filesystem/world.wit +6 -0
- package/go/wit/deps/fs-desktop/cap-fs-desktop.wit +29 -0
- package/go/wit/deps/http/http.wit +28 -0
- package/go/wit/deps/http-endpoint/cap-http.wit +44 -0
- package/go/wit/deps/io/error.wit +34 -0
- package/go/wit/deps/io/poll.wit +41 -0
- package/go/wit/deps/io/streams.wit +262 -0
- package/go/wit/deps/io/world.wit +6 -0
- package/go/wit/deps/mdns/mdns.wit +45 -0
- package/go/wit/deps/notify/notify.wit +51 -0
- package/go/wit/deps/peer/peer.wit +126 -0
- package/go/wit/deps/platform-desktop/cap-platform-desktop.wit +38 -0
- package/go/wit/deps/process/cap-process.wit +25 -0
- package/go/wit/deps/pty/pty.wit +80 -0
- package/go/wit/deps/random/insecure-seed.wit +25 -0
- package/go/wit/deps/random/insecure.wit +22 -0
- package/go/wit/deps/random/random.wit +26 -0
- package/go/wit/deps/random/world.wit +7 -0
- package/go/wit/deps/sockets/instance-network.wit +9 -0
- package/go/wit/deps/sockets/ip-name-lookup.wit +51 -0
- package/go/wit/deps/sockets/network.wit +145 -0
- package/go/wit/deps/sockets/tcp-create-socket.wit +27 -0
- package/go/wit/deps/sockets/tcp.wit +353 -0
- package/go/wit/deps/sockets/udp-create-socket.wit +27 -0
- package/go/wit/deps/sockets/udp.wit +266 -0
- package/go/wit/deps/sockets/world.wit +11 -0
- package/go/wit/deps/task/cap-task.wit +56 -0
- package/go/wit/deps/timer/cap-timer.wit +14 -0
- package/go/wit/deps/wasi-cli/command.wit +7 -0
- package/go/wit/deps/wasi-cli/environment.wit +18 -0
- package/go/wit/deps/wasi-cli/exit.wit +4 -0
- package/go/wit/deps/wasi-cli/imports.wit +20 -0
- package/go/wit/deps/wasi-cli/run.wit +4 -0
- package/go/wit/deps/wasi-cli/stdio.wit +17 -0
- package/go/wit/deps/wasi-cli/terminal.wit +49 -0
- package/go/wit/deps/ws/ws.wit +50 -0
- package/go/wit/deps/ws-server/cap-ws.wit +99 -0
- package/go/wit/go-plugin.wit +28 -0
- package/go/wit/plugin-face.wit +355 -0
- package/go/wit/wasmnest.wit +25 -0
- package/package.json +100 -3
- package/src/config.ts +49 -0
- package/src/global-dialog.ts +169 -0
- package/src/index.ts +88 -0
- package/src/runtime.ts +54 -0
- package/src/types.ts +681 -0
- package/src/ui/AppUpdateSection.d.ts +44 -0
- package/src/ui/AppUpdateSection.vue +253 -0
- package/src/ui/MarkdownEditor.vue +520 -0
- package/src/ui/NumberField.d.ts +49 -0
- package/src/ui/NumberField.vue +390 -0
- package/src/ui/PluginGlobalDialog.vue +401 -0
- package/src/ui/Select.d.ts +36 -0
- package/src/ui/Select.vue +220 -0
- package/src/ui/TerminalInputRail.vue +184 -0
- package/src/ui/apply-select-position.ts +65 -0
- package/src/ui/markdown-editor-syntax.ts +234 -0
- package/src/ui/markdown-editor.d.ts +36 -0
- package/src/ui/plugin-global-dialog.d.ts +12 -0
- package/src/ui/select-position.ts +79 -0
- package/src/ui/terminal-input-rail.d.ts +30 -0
- package/src/ui/zoom-compensation.d.ts +9 -0
- package/src/ui/zoom-compensation.ts +52 -0
- package/src/update.ts +123 -0
- package/src/vite-plugin.ts +124 -0
- package/template/README.md +39 -0
- package/template/package.json +23 -0
- package/template/plugin.json +14 -0
- package/template/rust/Cargo.toml +21 -0
- package/template/rust/src/lib.rs +39 -0
- package/template/src/env.d.ts +24 -0
- package/template/src/index.ts +37 -0
- package/template/tsconfig.json +17 -0
- package/template/vite.config.ts +21 -0
- package/tools/componentize/Cargo.lock +299 -0
- package/tools/componentize/Cargo.toml +18 -0
- package/tools/componentize/src/main.rs +197 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* 终端输入导航条 — SDK 共享 UI 组件(桌面端终端右侧悬浮)
|
|
4
|
+
*
|
|
5
|
+
* 一根横线 = 一次用户输入,横线垂直位置映射该输入在终端 buffer 中的相对位置(
|
|
6
|
+
* 全量 buffer 压缩进条带内,非视口映射)。
|
|
7
|
+
* 状态:
|
|
8
|
+
* - 默认态:右侧竖直居中、固定高度(h-56)一列主题色横线,背景全透明(不遮挡终端内容)
|
|
9
|
+
* - 展开态:鼠标移入 → 背景卡片 + 输入列表(每条输入一行:截断文本 + 右侧横线,
|
|
10
|
+
* 文字与横线同一水平线;点击行/横线高亮选中并 emit navigate)
|
|
11
|
+
* - 无输入 / alternate buffer(TUI 全屏程序)时整体隐藏
|
|
12
|
+
* 点击横线/列表行 → emit navigate(line),父组件执行 terminal.scrollToLine。
|
|
13
|
+
*
|
|
14
|
+
* 用法:
|
|
15
|
+
* ```vue
|
|
16
|
+
* <TerminalInputRail
|
|
17
|
+
* :markers="visibleMarkers"
|
|
18
|
+
* :buffer-length="bufferLength"
|
|
19
|
+
* :is-alt-buffer="isAltBuffer"
|
|
20
|
+
* @navigate="(line) => terminal?.scrollToLine(line)"
|
|
21
|
+
* />
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
import { computed, ref, watch } from 'vue'
|
|
25
|
+
/** 一次用户输入的位置标记(宿主端由 useTerminalInputMarkers 等 composable 产出,结构相同) */
|
|
26
|
+
export interface InputMarker {
|
|
27
|
+
id: number
|
|
28
|
+
/** buffer 绝对行号(xterm 坐标,随 scrollback 淘汰自动校正,-1 = 已淘汰) */
|
|
29
|
+
line: number
|
|
30
|
+
/** 输入文本(不含提示符;多行粘贴取首行) */
|
|
31
|
+
text: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface Props {
|
|
35
|
+
/** 输入标记(已过滤 line >= 0,按时间正序,最多 maxMarkers 条) */
|
|
36
|
+
markers: InputMarker[]
|
|
37
|
+
/** 当前 buffer 总行数(横线位置百分比 = line / (bufferLength - 1)) */
|
|
38
|
+
bufferLength: number
|
|
39
|
+
/** alternate buffer(vim 等 TUI 全屏程序)时隐藏 */
|
|
40
|
+
isAltBuffer: boolean
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
44
|
+
bufferLength: 0,
|
|
45
|
+
isAltBuffer: false,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const emit = defineEmits<{
|
|
49
|
+
(e: 'navigate', line: number): void
|
|
50
|
+
}>()
|
|
51
|
+
|
|
52
|
+
const expanded = ref(false)
|
|
53
|
+
/** 当前选中(点击导航的)输入行 id,用于选中高亮态 */
|
|
54
|
+
const selectedId = ref<number | null>(null)
|
|
55
|
+
|
|
56
|
+
// 无输入时重置展开态与选中态,避免会话切换后残留展开卡片
|
|
57
|
+
watch(
|
|
58
|
+
() => props.markers.length,
|
|
59
|
+
(len) => {
|
|
60
|
+
if (len === 0) {
|
|
61
|
+
expanded.value = false
|
|
62
|
+
selectedId.value = null
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
/** 点击横线/列表行:记录选中 → 通知父组件滚动到该输入行 */
|
|
68
|
+
function navigate(m: PositionedMarker) {
|
|
69
|
+
selectedId.value = m.id
|
|
70
|
+
emit('navigate', m.line)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** 相邻横线最小间距(容器高度百分比,约 4px):间距过近时保留较新的那条,避免重叠 */
|
|
74
|
+
const MIN_GAP_PERCENT = 2
|
|
75
|
+
|
|
76
|
+
interface PositionedMarker extends InputMarker {
|
|
77
|
+
top: number
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 计算每个标记的垂直位置(0-100%)并过滤重叠项(保留较新) */
|
|
81
|
+
const positionedMarkers = computed<PositionedMarker[]>(() => {
|
|
82
|
+
const len = Math.max(props.bufferLength - 1, 1)
|
|
83
|
+
const items = props.markers.map((m) => ({ ...m, top: (m.line / len) * 100 }))
|
|
84
|
+
// 从最新往回遍历:与已保留的较新一项间距不足时丢弃(旧标记被新输出"挤"在一起)
|
|
85
|
+
const kept: PositionedMarker[] = []
|
|
86
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
87
|
+
const item = items[i]
|
|
88
|
+
const newer = kept[kept.length - 1]
|
|
89
|
+
if (newer && newer.top - item.top < MIN_GAP_PERCENT) continue
|
|
90
|
+
kept.push(item)
|
|
91
|
+
}
|
|
92
|
+
return kept.reverse()
|
|
93
|
+
})
|
|
94
|
+
</script>
|
|
95
|
+
|
|
96
|
+
<template>
|
|
97
|
+
<div
|
|
98
|
+
v-if="markers.length > 0 && !isAltBuffer"
|
|
99
|
+
:class="expanded ? 'w-[284px]' : 'w-[18px]'"
|
|
100
|
+
class="absolute right-0 top-1/2 -translate-y-1/2 z-20 h-56 max-h-full"
|
|
101
|
+
@mouseenter="expanded = true"
|
|
102
|
+
@mouseleave="expanded = false"
|
|
103
|
+
>
|
|
104
|
+
<!-- 横线轨道:仅默认态渲染(收起时的位置映射条带),展开后由行内横线替代 -->
|
|
105
|
+
<div v-if="!expanded" class="absolute inset-0">
|
|
106
|
+
<button
|
|
107
|
+
v-for="m in positionedMarkers"
|
|
108
|
+
:key="'line-' + m.id"
|
|
109
|
+
class="rail-line"
|
|
110
|
+
:style="{ top: `min(max(${m.top}%, 2px), calc(100% - 2px))` }"
|
|
111
|
+
:title="`$ ${m.text}`"
|
|
112
|
+
@click="navigate(m)"
|
|
113
|
+
/>
|
|
114
|
+
</div>
|
|
115
|
+
|
|
116
|
+
<Transition name="rail" mode="out-in">
|
|
117
|
+
<!-- 展开态:背景卡片 + 输入列表,每行 = 截断文本 + 右侧主题色横线(同一水平线) -->
|
|
118
|
+
<div
|
|
119
|
+
v-if="expanded"
|
|
120
|
+
class="absolute right-1 inset-y-0 w-[280px] max-w-[60%] bg-card border border-[var(--border)] rounded-card shadow-card p-2 overflow-y-auto"
|
|
121
|
+
>
|
|
122
|
+
<div
|
|
123
|
+
v-for="m in positionedMarkers"
|
|
124
|
+
:key="'row-' + m.id"
|
|
125
|
+
class="group flex items-center gap-2 px-2 py-1 rounded-btn text-xs cursor-pointer transition-colors duration-200 hover:bg-[var(--bg-hover)]"
|
|
126
|
+
:class="
|
|
127
|
+
selectedId === m.id
|
|
128
|
+
? 'bg-[color-mix(in_srgb,var(--color-primary)_15%,transparent)]'
|
|
129
|
+
: ''
|
|
130
|
+
"
|
|
131
|
+
:title="`$ ${m.text}`"
|
|
132
|
+
@click="navigate(m)"
|
|
133
|
+
>
|
|
134
|
+
<span
|
|
135
|
+
class="font-mono truncate min-w-0 flex-1 transition-colors duration-200"
|
|
136
|
+
:class="
|
|
137
|
+
selectedId === m.id ? 'text-[var(--text-primary)]' : 'text-[var(--text-secondary)]'
|
|
138
|
+
"
|
|
139
|
+
>$ {{ m.text }}</span
|
|
140
|
+
>
|
|
141
|
+
<span
|
|
142
|
+
class="w-[10px] h-[2px] rounded-full bg-[var(--color-primary)] flex-shrink-0 transition-opacity duration-200"
|
|
143
|
+
:class="selectedId === m.id ? 'opacity-100' : 'opacity-60 group-hover:opacity-100'"
|
|
144
|
+
/>
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
</Transition>
|
|
148
|
+
</div>
|
|
149
|
+
</template>
|
|
150
|
+
|
|
151
|
+
<style scoped>
|
|
152
|
+
/* 默认态横线:主题色,垂直位置映射 buffer 行,透明背景下仅此可见 */
|
|
153
|
+
.rail-line {
|
|
154
|
+
position: absolute;
|
|
155
|
+
right: 4px;
|
|
156
|
+
width: 10px;
|
|
157
|
+
height: 2px;
|
|
158
|
+
border: none;
|
|
159
|
+
border-radius: 9999px;
|
|
160
|
+
background: var(--color-primary);
|
|
161
|
+
opacity: 0.45;
|
|
162
|
+
cursor: pointer;
|
|
163
|
+
transform: translateY(-50%);
|
|
164
|
+
transition: opacity 0.2s ease;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.rail-line:hover {
|
|
168
|
+
opacity: 1;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/* 默认态 ↔ 展开态切换:fade + 轻微横向位移(GPU 合成属性) */
|
|
172
|
+
.rail-enter-active,
|
|
173
|
+
.rail-leave-active {
|
|
174
|
+
transition:
|
|
175
|
+
opacity 0.2s ease,
|
|
176
|
+
transform 0.2s ease;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.rail-enter-from,
|
|
180
|
+
.rail-leave-to {
|
|
181
|
+
opacity: 0;
|
|
182
|
+
transform: translateX(8px);
|
|
183
|
+
}
|
|
184
|
+
</style>
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Select 面板 DOM 定位封装(定位引擎的 DOM 接入层)
|
|
3
|
+
*
|
|
4
|
+
* 职责:把「视觉坐标测量 → 设计空间计算 → 设计 px 写回」三步收敛为一个入口,
|
|
5
|
+
* Select.vue 展开面板时调用 applySelectPanelPosition() 即可,不感知缩放细节。
|
|
6
|
+
* 翻转/收缩/夹持规则见 select-position.ts(纯函数,规则表驱动单测)。
|
|
7
|
+
*
|
|
8
|
+
* zoom 不变式(WebKitGTK 2.52.6 根 zoom 1.15 实测,F 自校准见 zoom-compensation.ts):
|
|
9
|
+
* - gBCR 读数 = 设计值 × F(视觉坐标)
|
|
10
|
+
* - DOM 写回 px 渲染 = 设计值 × F(与触发器同一坐标系)
|
|
11
|
+
* - 故:读数 ÷ F → 纯函数(设计空间)→ 写回计算结果。
|
|
12
|
+
* 无 zoom 环境 F=1,全部换算退化为恒等,与非 Linux 端行为逐位一致。
|
|
13
|
+
*
|
|
14
|
+
* 注:评估过 Floating UI 1.8.0,其内部在根 zoom 下混用 gBCR(视觉值)与
|
|
15
|
+
* offsetHeight(设计值)计算位置(实测 flip 上翻 y 偏差 36.6 视觉 px,输出
|
|
16
|
+
* 补偿无法修复),故保留本自校准实现。
|
|
17
|
+
*/
|
|
18
|
+
import { computeSelectPosition, SELECT_MAX_PANEL_HEIGHT } from './select-position'
|
|
19
|
+
import { getFixedZoomCompensation } from './zoom-compensation'
|
|
20
|
+
|
|
21
|
+
/** 参与定位的面板三要素 */
|
|
22
|
+
export interface SelectPanelElements {
|
|
23
|
+
/** 触发器(定位参照物) */
|
|
24
|
+
trigger: HTMLElement
|
|
25
|
+
/** 面板定位层(fixed;写入 top/left/width) */
|
|
26
|
+
panel: HTMLElement
|
|
27
|
+
/** 面板内选项列表(写入 maxHeight,并作为自然高测量目标) */
|
|
28
|
+
list: HTMLElement
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 面板设计高度上限(转发自纯函数模块,组件层不重复定义) */
|
|
32
|
+
export { SELECT_MAX_PANEL_HEIGHT }
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 测量并定位下拉面板(同步;调用时机 = 面板可见后的同一帧内)
|
|
36
|
+
*
|
|
37
|
+
* 写入均为设计 px:无 zoom 端与历史行为一致;Linux 端渲染时 ×F 恰好
|
|
38
|
+
* 落回触发器的视觉坐标系,面板与触发器严丝合缝。
|
|
39
|
+
*/
|
|
40
|
+
export function applySelectPanelPosition(elements: SelectPanelElements): void {
|
|
41
|
+
const { trigger, panel, list } = elements
|
|
42
|
+
const f = getFixedZoomCompensation()
|
|
43
|
+
|
|
44
|
+
// 先定宽再测高:面板宽度与触发器一致(视觉宽 ÷F),长选项标签的换行
|
|
45
|
+
// 高度才能在测量时生效,避免首开时按未定宽的自然宽误判面板高度
|
|
46
|
+
const rect = trigger.getBoundingClientRect()
|
|
47
|
+
panel.style.width = `${rect.width / f}px`
|
|
48
|
+
|
|
49
|
+
// 解除上次收缩残留的 maxHeight 再测自然高(同步块内完成,无中间渲染):
|
|
50
|
+
// 否则翻转判定与 maxHeight 会按上次收缩后的高度失真。
|
|
51
|
+
// 退回值必须在 ÷F 之后兜底(视觉 0 ÷F 仍为 0),否则 zoom 端会误得 240/F
|
|
52
|
+
list.style.maxHeight = ''
|
|
53
|
+
const measuredHeight = panel.getBoundingClientRect().height / f
|
|
54
|
+
const naturalHeight = measuredHeight || SELECT_MAX_PANEL_HEIGHT
|
|
55
|
+
|
|
56
|
+
const pos = computeSelectPosition(
|
|
57
|
+
{ top: rect.top / f, bottom: rect.bottom / f, left: rect.left / f, width: rect.width / f },
|
|
58
|
+
{ width: window.innerWidth / f, height: window.innerHeight / f },
|
|
59
|
+
naturalHeight,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
panel.style.top = `${pos.top}px`
|
|
63
|
+
panel.style.left = `${pos.left}px`
|
|
64
|
+
list.style.maxHeight = `${pos.maxHeight}px`
|
|
65
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MarkdownEditor 语法插入纯函数
|
|
3
|
+
*
|
|
4
|
+
* 工具栏各动作对 (text, selectionStart, selectionEnd) 的纯变换,返回新文本与新光标/选区。
|
|
5
|
+
* 不依赖 DOM / vue-i18n,便于单元测试与在任意编辑器环境复用。
|
|
6
|
+
*
|
|
7
|
+
* 动作语义(i18n 中立的刻意取舍:占位文本内置英文,组件 title 可经 labels props 覆盖):
|
|
8
|
+
* - inline 动作(bold / italic / codeInline / link):
|
|
9
|
+
* 无选区 → 插入带占位文本的模板并选中占位;有选区 → 包裹选区。
|
|
10
|
+
* - 行级动作(h1 / h2 / h3 / list / olist / quote):
|
|
11
|
+
* 作用于光标所在行,行首前缀 toggle(已有同族前缀则移除,否则插入;
|
|
12
|
+
* heading 族统一「先移除任意级别 # 前缀、再插目标级别」,支持逐级切换)。
|
|
13
|
+
* - codeBlock:无选区 → 用 ``` 围栏包裹光标所在行;有选区 → 包裹选区。
|
|
14
|
+
* - divider:在光标所在行之后插入独占一行的 --- 分隔线。
|
|
15
|
+
*/
|
|
16
|
+
export type MarkdownSyntaxAction =
|
|
17
|
+
| 'bold'
|
|
18
|
+
| 'italic'
|
|
19
|
+
| 'h1'
|
|
20
|
+
| 'h2'
|
|
21
|
+
| 'h3'
|
|
22
|
+
| 'list'
|
|
23
|
+
| 'olist'
|
|
24
|
+
| 'quote'
|
|
25
|
+
| 'codeBlock'
|
|
26
|
+
| 'codeInline'
|
|
27
|
+
| 'link'
|
|
28
|
+
| 'divider'
|
|
29
|
+
|
|
30
|
+
export interface SyntaxResult {
|
|
31
|
+
text: string
|
|
32
|
+
selectionStart: number
|
|
33
|
+
selectionEnd: number
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** inline 包裹动作模板:open + placeholder + close(占位内置英文,保持 SDK i18n 中立) */
|
|
37
|
+
const INLINE_ACTIONS: Record<'bold' | 'italic' | 'codeInline', { open: string; close: string; placeholder: string }> = {
|
|
38
|
+
bold: { open: '**', close: '**', placeholder: 'bold' },
|
|
39
|
+
italic: { open: '*', close: '*', placeholder: 'italic' },
|
|
40
|
+
codeInline: { open: '`', close: '`', placeholder: 'code' },
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const LINE_HEADING = /^(#{1,6})\s+/
|
|
44
|
+
const LINE_LIST = /^-\s+/
|
|
45
|
+
const LINE_OLIST = /^\d+\.\s+/
|
|
46
|
+
const LINE_QUOTE = /^>\s+/
|
|
47
|
+
|
|
48
|
+
/** 行级前缀 toggle:已有则移除(返回负 delta),否则插入 */
|
|
49
|
+
function togglePrefix(line: string, removeRe: RegExp, insert: string): { line: string; delta: number } {
|
|
50
|
+
const m = line.match(removeRe)
|
|
51
|
+
if (m) {
|
|
52
|
+
const removed = m[0].length
|
|
53
|
+
return { line: line.slice(removed), delta: -removed }
|
|
54
|
+
}
|
|
55
|
+
return { line: insert + line, delta: insert.length }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** heading:无前缀 → 插入目标级别;有同级别前缀 → 移除(toggle 回正文);有异级别前缀 → 替换为目标级别 */
|
|
59
|
+
function setHeading(line: string, level: 1 | 2 | 3): { line: string; delta: number } {
|
|
60
|
+
const prefix = '#'.repeat(level) + ' '
|
|
61
|
+
const m = line.match(LINE_HEADING)
|
|
62
|
+
if (!m) return { line: prefix + line, delta: prefix.length }
|
|
63
|
+
if (m[1].length === level) return { line: line.slice(m[0].length), delta: -m[0].length }
|
|
64
|
+
return { line: prefix + line.slice(m[0].length), delta: prefix.length - m[0].length }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** 光标所在行边界(选区存在时以光标所在行 = selectionStart 所在行为准) */
|
|
68
|
+
function lineBounds(text: string, position: number): { start: number; end: number } {
|
|
69
|
+
const start = text.lastIndexOf('\n', position - 1) + 1
|
|
70
|
+
let end = text.indexOf('\n', position)
|
|
71
|
+
if (end === -1) end = text.length
|
|
72
|
+
return { start, end }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** inline 包裹(无选区 → 模板+占位选中;有选区 → 包裹选区) */
|
|
76
|
+
function wrapInline(
|
|
77
|
+
text: string,
|
|
78
|
+
s: number,
|
|
79
|
+
e: number,
|
|
80
|
+
open: string,
|
|
81
|
+
close: string,
|
|
82
|
+
placeholder: string,
|
|
83
|
+
): SyntaxResult {
|
|
84
|
+
if (s === e) {
|
|
85
|
+
const insert = open + placeholder + close
|
|
86
|
+
return {
|
|
87
|
+
text: text.slice(0, s) + insert + text.slice(s),
|
|
88
|
+
selectionStart: s + open.length,
|
|
89
|
+
selectionEnd: s + open.length + placeholder.length,
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
text: text.slice(0, s) + open + text.slice(s, e) + close + text.slice(e),
|
|
94
|
+
selectionStart: s + open.length,
|
|
95
|
+
selectionEnd: e + open.length,
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** 行级前缀动作:作用于光标所在行,光标保持行内相对位置 */
|
|
100
|
+
function applyLinePrefix(
|
|
101
|
+
text: string,
|
|
102
|
+
s: number,
|
|
103
|
+
transform: (line: string) => { line: string; delta: number },
|
|
104
|
+
): SyntaxResult {
|
|
105
|
+
const { start, end } = lineBounds(text, s)
|
|
106
|
+
const line = text.slice(start, end)
|
|
107
|
+
const { line: newLine, delta } = transform(line)
|
|
108
|
+
const rel = Math.min(Math.max(s - start + delta, 0), newLine.length)
|
|
109
|
+
return {
|
|
110
|
+
text: text.slice(0, start) + newLine + text.slice(end),
|
|
111
|
+
selectionStart: start + rel,
|
|
112
|
+
selectionEnd: start + rel,
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** 代码块:无选区 → 围栏包裹光标所在行;有选区 → 包裹选区 */
|
|
117
|
+
function applyCodeBlock(text: string, s: number, e: number): SyntaxResult {
|
|
118
|
+
const fence = '```'
|
|
119
|
+
if (s === e) {
|
|
120
|
+
const { start, end } = lineBounds(text, s)
|
|
121
|
+
const insert = fence + '\n'
|
|
122
|
+
return {
|
|
123
|
+
text: text.slice(0, start) + insert + text.slice(start, end) + '\n' + fence + text.slice(end),
|
|
124
|
+
selectionStart: s + insert.length,
|
|
125
|
+
selectionEnd: s + insert.length,
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const insert = fence + '\n'
|
|
129
|
+
return {
|
|
130
|
+
text: text.slice(0, s) + insert + text.slice(s, e) + '\n' + fence + text.slice(e),
|
|
131
|
+
selectionStart: s + insert.length,
|
|
132
|
+
selectionEnd: e + insert.length,
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** 链接:无选区 → [link](https://) 选中 link;有选区 → [选区](https://) 选中 URL 待填 */
|
|
137
|
+
function applyLink(text: string, s: number, e: number): SyntaxResult {
|
|
138
|
+
const url = 'https://'
|
|
139
|
+
if (s === e) {
|
|
140
|
+
const placeholder = 'link'
|
|
141
|
+
const insert = `[${placeholder}](${url})`
|
|
142
|
+
return {
|
|
143
|
+
text: text.slice(0, s) + insert + text.slice(s),
|
|
144
|
+
selectionStart: s + 1,
|
|
145
|
+
selectionEnd: s + 1 + placeholder.length,
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const selected = text.slice(s, e)
|
|
149
|
+
const insert = `[${selected}](${url})`
|
|
150
|
+
const urlStart = s + selected.length + 3
|
|
151
|
+
return {
|
|
152
|
+
text: text.slice(0, s) + insert + text.slice(e),
|
|
153
|
+
selectionStart: urlStart,
|
|
154
|
+
selectionEnd: urlStart + url.length,
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* 分隔线:在光标行位置插入独占一行的 ---(保证 --- 前有空行,避免被解析为 setext 标题)
|
|
160
|
+
* - 非空行:行后插入「空行 + --- + 换行」
|
|
161
|
+
* - 空行:光标行变成 ---(保留前空行结构)
|
|
162
|
+
*/
|
|
163
|
+
function applyDivider(text: string, s: number): SyntaxResult {
|
|
164
|
+
const { start, end } = lineBounds(text, s)
|
|
165
|
+
const line = text.slice(start, end)
|
|
166
|
+
if (line.trim()) {
|
|
167
|
+
const hasNewline = end < text.length
|
|
168
|
+
const insertAt = hasNewline ? end + 1 : text.length
|
|
169
|
+
const insert = hasNewline ? '\n---\n' : '\n\n---\n'
|
|
170
|
+
const newText = text.slice(0, insertAt) + insert + text.slice(insertAt)
|
|
171
|
+
const newSel = insertAt + insert.length
|
|
172
|
+
return { text: newText, selectionStart: newSel, selectionEnd: newSel }
|
|
173
|
+
}
|
|
174
|
+
// 空行行:行前补空行再放 ---(后随原行尾换行),或末尾直接追加 ---\n
|
|
175
|
+
if (end < text.length) {
|
|
176
|
+
const newText = text.slice(0, start) + '\n---' + text.slice(end)
|
|
177
|
+
const newSel = start + 4
|
|
178
|
+
return { text: newText, selectionStart: newSel, selectionEnd: newSel }
|
|
179
|
+
}
|
|
180
|
+
// 末行空行:需保证 --- 与上一非空行之间有空行——否则 "hello\n---\n" 会被
|
|
181
|
+
// marked 解析为 setext H2 标题(实测 <h2>hello</h2>)。仅当上一行非空时补
|
|
182
|
+
// 前置空行;上一行已是空行(如 "a\n\n")则维持原结构不叠空行。
|
|
183
|
+
const prevBounds = start > 0 ? lineBounds(text, start - 1) : null
|
|
184
|
+
const prevLine = prevBounds ? text.slice(prevBounds.start, prevBounds.end).trim() : ''
|
|
185
|
+
const needGap = prevBounds !== null && prevLine !== ''
|
|
186
|
+
const insert = needGap ? '\n---\n' : '---\n'
|
|
187
|
+
const newText = text.slice(0, start) + insert + text.slice(end)
|
|
188
|
+
const newSel = start + insert.length
|
|
189
|
+
return { text: newText, selectionStart: newSel, selectionEnd: newSel }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* 对 (text, selectionStart, selectionEnd) 应用一次工具栏语法动作。
|
|
194
|
+
* 输入区间按 text 长度收敛;输出保证 selectionStart <= selectionEnd 且不越界。
|
|
195
|
+
*/
|
|
196
|
+
export function applyMarkdownSyntax(
|
|
197
|
+
action: MarkdownSyntaxAction,
|
|
198
|
+
text: string,
|
|
199
|
+
selectionStart: number,
|
|
200
|
+
selectionEnd: number,
|
|
201
|
+
): SyntaxResult {
|
|
202
|
+
// 各自收敛到文本边界后再归一化方向(逆序选区自动纠正)
|
|
203
|
+
const rawS = Math.min(Math.max(selectionStart, 0), text.length)
|
|
204
|
+
const rawE = Math.min(Math.max(selectionEnd, 0), text.length)
|
|
205
|
+
const s = Math.min(rawS, rawE)
|
|
206
|
+
const e = Math.max(rawS, rawE)
|
|
207
|
+
|
|
208
|
+
switch (action) {
|
|
209
|
+
case 'bold':
|
|
210
|
+
case 'italic':
|
|
211
|
+
case 'codeInline': {
|
|
212
|
+
const { open, close, placeholder } = INLINE_ACTIONS[action]
|
|
213
|
+
return wrapInline(text, s, e, open, close, placeholder)
|
|
214
|
+
}
|
|
215
|
+
case 'link':
|
|
216
|
+
return applyLink(text, s, e)
|
|
217
|
+
case 'codeBlock':
|
|
218
|
+
return applyCodeBlock(text, s, e)
|
|
219
|
+
case 'divider':
|
|
220
|
+
return applyDivider(text, s)
|
|
221
|
+
case 'h1':
|
|
222
|
+
return applyLinePrefix(text, s, (line) => setHeading(line, 1))
|
|
223
|
+
case 'h2':
|
|
224
|
+
return applyLinePrefix(text, s, (line) => setHeading(line, 2))
|
|
225
|
+
case 'h3':
|
|
226
|
+
return applyLinePrefix(text, s, (line) => setHeading(line, 3))
|
|
227
|
+
case 'list':
|
|
228
|
+
return applyLinePrefix(text, s, (line) => togglePrefix(line, LINE_LIST, '- '))
|
|
229
|
+
case 'olist':
|
|
230
|
+
return applyLinePrefix(text, s, (line) => togglePrefix(line, LINE_OLIST, '1. '))
|
|
231
|
+
case 'quote':
|
|
232
|
+
return applyLinePrefix(text, s, (line) => togglePrefix(line, LINE_QUOTE, '> '))
|
|
233
|
+
}
|
|
234
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { DefineComponent } from 'vue'
|
|
2
|
+
import type { MarkdownSyntaxAction } from './markdown-editor-syntax'
|
|
3
|
+
|
|
4
|
+
/** 工具栏 title / 预览切换文案 key(labels 覆盖,默认内置英文) */
|
|
5
|
+
export type MarkdownEditorLabelKey = MarkdownSyntaxAction | 'preview' | 'edit' | 'toolbar'
|
|
6
|
+
|
|
7
|
+
/** MarkdownEditor 组件 props */
|
|
8
|
+
export interface MarkdownEditorProps {
|
|
9
|
+
/** v-model 绑定值 */
|
|
10
|
+
modelValue: string
|
|
11
|
+
/** 空内容占位提示 */
|
|
12
|
+
placeholder?: string
|
|
13
|
+
/** 是否显示语法工具栏(默认 true) */
|
|
14
|
+
toolbar?: boolean
|
|
15
|
+
/** 是否显示预览切换按钮(默认 true) */
|
|
16
|
+
preview?: boolean
|
|
17
|
+
/** 禁用编辑与工具栏(保存中/预览锁定态) */
|
|
18
|
+
disabled?: boolean
|
|
19
|
+
/** 工具栏 title / 预览切换文案覆盖(不传用内置英文) */
|
|
20
|
+
labels?: Partial<Record<MarkdownEditorLabelKey, string>>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* SDK 公共轻量 markdown 编辑器(textarea 内核 + 语法工具栏 + 预览切换)
|
|
25
|
+
*
|
|
26
|
+
* 用法:
|
|
27
|
+
* ```vue
|
|
28
|
+
* <MarkdownEditor v-model="draft" placeholder="Write markdown..." />
|
|
29
|
+
* ```
|
|
30
|
+
* - 触发 `update:modelValue`(输入 / 工具栏语法插入)
|
|
31
|
+
* - 预览渲染用 marked(与移动端同库同版本,渲染行为一致)
|
|
32
|
+
* - 样式走宿主设计 token,暗色/亮色随主题自动跟随
|
|
33
|
+
*/
|
|
34
|
+
export declare const MarkdownEditor: DefineComponent<MarkdownEditorProps>
|
|
35
|
+
|
|
36
|
+
export default MarkdownEditor
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DefineComponent } from 'vue'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* PluginGlobalDialog — 宿主全局弹窗(通用能力)
|
|
5
|
+
*
|
|
6
|
+
* 仅在应用根挂载一次(宿主 DesktopLayout / dev-shell App);渲染完全由
|
|
7
|
+
* 全局弹窗控制器(global-dialog.ts)驱动,插件经 context.ui.showDialog 操控。
|
|
8
|
+
* 挂载方无 props 需传。
|
|
9
|
+
*/
|
|
10
|
+
export declare const PluginGlobalDialog: DefineComponent<Record<string, never>>
|
|
11
|
+
|
|
12
|
+
export default PluginGlobalDialog
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Select 下拉面板定位纯函数(无 DOM 依赖,规则表驱动单测)
|
|
3
|
+
*
|
|
4
|
+
* 翻转规则(面板固定宽 = 触发器宽):
|
|
5
|
+
* - 下方空间足够 → 向下展开(现状)
|
|
6
|
+
* - 下方不足但上方足够 → 向上展开
|
|
7
|
+
* - 两侧都不足 → 收缩 maxHeight 到可用空间较大的一侧,面板内滚动
|
|
8
|
+
* - 水平方向 clamp,保证面板不超出视口
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** 面板与触发器的固定间距(px) */
|
|
12
|
+
export const SELECT_GAP = 4
|
|
13
|
+
|
|
14
|
+
/** 面板设计高度上限(与面板内列表 max-height 一致,px) */
|
|
15
|
+
export const SELECT_MAX_PANEL_HEIGHT = 240
|
|
16
|
+
|
|
17
|
+
/** 触发器矩形(仅需要定位用到的字段) */
|
|
18
|
+
export interface TriggerRect {
|
|
19
|
+
top: number
|
|
20
|
+
bottom: number
|
|
21
|
+
left: number
|
|
22
|
+
width: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 视口尺寸 */
|
|
26
|
+
export interface ViewportSize {
|
|
27
|
+
width: number
|
|
28
|
+
height: number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 定位结果 */
|
|
32
|
+
export interface SelectPosition {
|
|
33
|
+
top: number
|
|
34
|
+
left: number
|
|
35
|
+
/** 面板可用的最大高度(px;面板内滚动) */
|
|
36
|
+
maxHeight: number
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function computeSelectPosition(
|
|
40
|
+
triggerRect: TriggerRect,
|
|
41
|
+
viewport: ViewportSize,
|
|
42
|
+
panelHeight: number,
|
|
43
|
+
): SelectPosition {
|
|
44
|
+
// 面板实际高度以设计上限截断(内容更长时交给面板内滚动)
|
|
45
|
+
const height = Math.min(Math.max(panelHeight, 0), SELECT_MAX_PANEL_HEIGHT)
|
|
46
|
+
|
|
47
|
+
const belowSpace = viewport.height - triggerRect.bottom - SELECT_GAP
|
|
48
|
+
const aboveSpace = triggerRect.top - SELECT_GAP
|
|
49
|
+
|
|
50
|
+
let top: number
|
|
51
|
+
let maxHeight: number
|
|
52
|
+
if (belowSpace >= height) {
|
|
53
|
+
// 下方足够:保持现状向下展开
|
|
54
|
+
top = triggerRect.bottom + SELECT_GAP
|
|
55
|
+
maxHeight = height
|
|
56
|
+
} else if (aboveSpace >= height) {
|
|
57
|
+
// 下方不足但上方足够:向上展开
|
|
58
|
+
top = triggerRect.top - SELECT_GAP - height
|
|
59
|
+
maxHeight = height
|
|
60
|
+
} else if (belowSpace >= aboveSpace) {
|
|
61
|
+
// 两侧都不足:贴下方展开并收缩高度(下方空间更大时);
|
|
62
|
+
// maxHeight 再让出一个间距,保证面板底边与视口底边保留 4px 留白
|
|
63
|
+
top = Math.max(triggerRect.bottom + SELECT_GAP, SELECT_GAP)
|
|
64
|
+
maxHeight = Math.max(belowSpace - SELECT_GAP, 0)
|
|
65
|
+
} else {
|
|
66
|
+
// 两侧都不足且上方空间更大:向上展开并收缩高度;
|
|
67
|
+
// maxHeight 让出触发器间距,面板底边不贴住触发器顶边
|
|
68
|
+
maxHeight = Math.max(aboveSpace - SELECT_GAP, 0)
|
|
69
|
+
top = Math.max(triggerRect.top - SELECT_GAP - maxHeight, SELECT_GAP)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 水平 clamp:面板与视口边缘保持至少 SELECT_GAP 间距
|
|
73
|
+
const left = Math.min(
|
|
74
|
+
Math.max(triggerRect.left, SELECT_GAP),
|
|
75
|
+
Math.max(viewport.width - triggerRect.width - SELECT_GAP, SELECT_GAP),
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
return { top, left, maxHeight }
|
|
79
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DefineComponent } from 'vue'
|
|
2
|
+
|
|
3
|
+
/** 一次用户输入的位置标记(宿主端由 useTerminalInputMarkers 等 composable 产出,结构相同) */
|
|
4
|
+
export interface InputMarker {
|
|
5
|
+
id: number
|
|
6
|
+
/** buffer 绝对行号(xterm 坐标,随 scrollback 淘汰自动校正,-1 = 已淘汰) */
|
|
7
|
+
line: number
|
|
8
|
+
/** 输入文本(不含提示符;多行粘贴取首行) */
|
|
9
|
+
text: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** TerminalInputRail 组件 props */
|
|
13
|
+
export interface TerminalInputRailProps {
|
|
14
|
+
/** 输入标记(已过滤 line >= 0,按时间正序,最多 maxMarkers 条) */
|
|
15
|
+
markers: InputMarker[]
|
|
16
|
+
/** 当前 buffer 总行数(横线位置百分比 = line / (bufferLength - 1)) */
|
|
17
|
+
bufferLength: number
|
|
18
|
+
/** alternate buffer(vim 等 TUI 全屏程序)时隐藏 */
|
|
19
|
+
isAltBuffer?: boolean
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 终端输入导航条(SDK 共享 UI)
|
|
24
|
+
*
|
|
25
|
+
* 一根横线 = 一次用户输入;默认态为右侧竖直居中、固定高度的透明横线条带,
|
|
26
|
+
* hover 展开为输入列表卡片,点击行/横线 emit `navigate(line)`。
|
|
27
|
+
*/
|
|
28
|
+
export declare const TerminalInputRail: DefineComponent<TerminalInputRailProps>
|
|
29
|
+
|
|
30
|
+
export default TerminalInputRail
|