@binblink/wasmnest-plugin-sdk-desktop 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +287 -2
- package/README_en.md +284 -0
- package/bin/cli.js +602 -0
- package/bin/manifest-gen.js +454 -0
- package/bin/manifest-validate.js +432 -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 +121 -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 +109 -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/agent-hub-commands.ts +1065 -0
- package/dev-shell/src/mock/agent-hub.ts +42 -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 +132 -0
- package/dev-shell/src/styles/dev.css +27 -0
- package/dev-shell/src/styles/shell.css +546 -0
- package/dev-shell/src/styles/style.css +1132 -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 +109 -0
- package/dist/index.js +170 -0
- package/dist/types.d.ts +585 -0
- package/dist/types.js +0 -0
- package/dist/vite-plugin.d.ts +25 -0
- package/dist/vite-plugin.js +80 -0
- package/package.json +89 -3
- package/src/config.ts +49 -0
- package/src/global-dialog.ts +169 -0
- package/src/index.ts +80 -0
- package/src/runtime.ts +54 -0
- package/src/types.ts +630 -0
- package/src/ui/MarkdownEditor.vue +520 -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/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 +270 -0
- package/tools/componentize/Cargo.toml +15 -0
- package/tools/componentize/src/main.rs +94 -0
package/package.json
CHANGED
|
@@ -1,6 +1,92 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@binblink/wasmnest-plugin-sdk-desktop",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"bin": {
|
|
12
|
+
"wasmnest-plugin-desktop": "./bin/cli.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src",
|
|
17
|
+
"bin",
|
|
18
|
+
"tools",
|
|
19
|
+
"template",
|
|
20
|
+
"README.md",
|
|
21
|
+
"README_en.md",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"dev-shell/src",
|
|
24
|
+
"dev-shell/index.html",
|
|
25
|
+
"dev-shell/package.json",
|
|
26
|
+
"dev-shell/vite.config.ts",
|
|
27
|
+
"dev-shell/tailwind.config.js",
|
|
28
|
+
"dev-shell/postcss.config.js",
|
|
29
|
+
"dev-shell/pnpm-workspace.yaml",
|
|
30
|
+
"dev-shell/README.md"
|
|
31
|
+
],
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./vite": {
|
|
38
|
+
"types": "./dist/vite-plugin.d.ts",
|
|
39
|
+
"import": "./dist/vite-plugin.js"
|
|
40
|
+
},
|
|
41
|
+
"./ui": {
|
|
42
|
+
"types": "./src/ui/Select.d.ts",
|
|
43
|
+
"import": "./src/ui/Select.vue"
|
|
44
|
+
},
|
|
45
|
+
"./ui/zoom-compensation": {
|
|
46
|
+
"types": "./src/ui/zoom-compensation.d.ts",
|
|
47
|
+
"import": "./src/ui/zoom-compensation.ts"
|
|
48
|
+
},
|
|
49
|
+
"./ui/terminal-input-rail": {
|
|
50
|
+
"types": "./src/ui/terminal-input-rail.d.ts",
|
|
51
|
+
"import": "./src/ui/TerminalInputRail.vue"
|
|
52
|
+
},
|
|
53
|
+
"./ui/plugin-global-dialog": {
|
|
54
|
+
"types": "./src/ui/plugin-global-dialog.d.ts",
|
|
55
|
+
"import": "./src/ui/PluginGlobalDialog.vue"
|
|
56
|
+
},
|
|
57
|
+
"./ui/markdown-editor": {
|
|
58
|
+
"types": "./src/ui/markdown-editor.d.ts",
|
|
59
|
+
"import": "./src/ui/MarkdownEditor.vue"
|
|
60
|
+
},
|
|
61
|
+
"./types": {
|
|
62
|
+
"types": "./dist/types.d.ts",
|
|
63
|
+
"import": "./dist/types.js"
|
|
64
|
+
},
|
|
65
|
+
"./bin/manifest-gen.js": "./bin/manifest-gen.js",
|
|
66
|
+
"./bin/wasm-hash.js": "./bin/wasm-hash.js",
|
|
67
|
+
"./bin/plugin-watch.js": "./bin/plugin-watch.js",
|
|
68
|
+
"./tools/componentize/Cargo.toml": "./tools/componentize/Cargo.toml",
|
|
69
|
+
"./package.json": "./package.json"
|
|
70
|
+
},
|
|
71
|
+
"dependencies": {
|
|
72
|
+
"magic-string": "^0.30.21",
|
|
73
|
+
"marked": "^18.0.11"
|
|
74
|
+
},
|
|
75
|
+
"peerDependencies": {
|
|
76
|
+
"vite": "^8.0.0",
|
|
77
|
+
"vue": "^3.4.0"
|
|
78
|
+
},
|
|
79
|
+
"devDependencies": {
|
|
80
|
+
"@vitejs/plugin-vue": "^6.0.0",
|
|
81
|
+
"@vue/test-utils": "^2.4.11",
|
|
82
|
+
"happy-dom": "^13.10.1",
|
|
83
|
+
"tsup": "^8.5.1",
|
|
84
|
+
"vitest": "^3.2.7"
|
|
85
|
+
},
|
|
86
|
+
"scripts": {
|
|
87
|
+
"build": "tsup src/index.ts src/vite-plugin.ts src/types.ts --format esm --dts --clean",
|
|
88
|
+
"gen:permissions": "cargo run --quiet --manifest-path rust/Cargo.toml --example gen_permission_vocabulary",
|
|
89
|
+
"test": "vitest",
|
|
90
|
+
"test:run": "vitest run"
|
|
91
|
+
}
|
|
6
92
|
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin Configuration Helpers
|
|
3
|
+
*
|
|
4
|
+
* SDK 侧配置约定:统一 storage key + 声明式配置助手。
|
|
5
|
+
* 插件运行时读写配置走 context.storage,与宿主配置页共享 key。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { PluginConfiguration, ConfigProperty } from './types'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 插件配置在 storage 中的统一键名
|
|
12
|
+
*
|
|
13
|
+
* 插件运行时:context.storage.get(PLUGIN_CONFIG_STORAGE_KEY)
|
|
14
|
+
* 宿主配置页:pluginStorageGet(pluginId, PLUGIN_CONFIG_STORAGE_KEY)
|
|
15
|
+
* 两者共享同一 key,保证数据一致
|
|
16
|
+
*/
|
|
17
|
+
export const PLUGIN_CONFIG_STORAGE_KEY = 'config'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 声明式构建插件配置(manifest contributes.configuration)
|
|
21
|
+
*
|
|
22
|
+
* 用途:插件开发者在代码中声明配置 schema,与 plugin.json 中保持一致。
|
|
23
|
+
* 实际 manifest 中的 configuration 以 plugin.json 为单一真源。
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const config = defineConfiguration('My Plugin Settings', {
|
|
28
|
+
* apiKey: { type: 'string', title: 'API Key', description: 'Your API key' },
|
|
29
|
+
* maxRetries: { type: 'number', title: 'Max Retries', default: 3 },
|
|
30
|
+
* debugMode: { type: 'boolean', title: 'Debug Mode', default: false },
|
|
31
|
+
* })
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function defineConfiguration(
|
|
35
|
+
title: string,
|
|
36
|
+
properties: Record<string, Omit<ConfigProperty, 'title'> & { title?: string }>,
|
|
37
|
+
): PluginConfiguration {
|
|
38
|
+
const props: Record<string, ConfigProperty> = {}
|
|
39
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
40
|
+
props[key] = {
|
|
41
|
+
type: value.type,
|
|
42
|
+
title: value.title ?? key,
|
|
43
|
+
description: value.description,
|
|
44
|
+
default: value.default,
|
|
45
|
+
enum: value.enum,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return { title, properties: props }
|
|
49
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 全局弹窗控制器(桌面宿主 + dev-shell 共用)
|
|
3
|
+
*
|
|
4
|
+
* 发布-订阅实现:不直接依赖 Vue reactivity,宿主 / dev-shell 的
|
|
5
|
+
* PluginGlobalDialog 组件经 subscribeGlobalDialog 订阅渲染,单元测试无需
|
|
6
|
+
* 初始化共享运行时即可驱动。
|
|
7
|
+
*
|
|
8
|
+
* 语义:
|
|
9
|
+
* - FIFO 队列:同一时刻至多一个弹窗,后到的排队;当前关闭后自动接替;
|
|
10
|
+
* - update() 生成新条目对象再广播(订阅方拿到新引用触发重渲染);
|
|
11
|
+
* - close() 幂等;排队中的条目也可关闭(从队列移除);
|
|
12
|
+
* - 定时自动关闭为**可选能力**:仅当提供 timeoutSec / deadlineAt 时生效,
|
|
13
|
+
* 计时从条目成为当前弹窗起计算(迟到打开/排队经过的时间不重复计入相对秒数)。
|
|
14
|
+
*/
|
|
15
|
+
import type { PluginDialogOptions } from './types'
|
|
16
|
+
|
|
17
|
+
/** 内部弹窗条目 = 公开选项 + 宿主注入字段 */
|
|
18
|
+
export interface GlobalDialogEntry extends PluginDialogOptions {
|
|
19
|
+
/** 内部唯一 ID(句柄路由用) */
|
|
20
|
+
_id: number
|
|
21
|
+
/** 内容组件宿主上下文(provide('pluginContext') 用;宿主 showDialog 注入) */
|
|
22
|
+
pluginContext?: unknown
|
|
23
|
+
/** 条目创建时刻(ms) */
|
|
24
|
+
createdAt: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 订阅输入(宿主注入 pluginContext 后交 openGlobalDialog) */
|
|
28
|
+
export type OpenGlobalDialogInput = PluginDialogOptions & { pluginContext?: unknown }
|
|
29
|
+
|
|
30
|
+
export type GlobalDialogListener = (entry: GlobalDialogEntry | null) => void
|
|
31
|
+
|
|
32
|
+
/** 打开/更新/关闭返回的句柄(供插件调用方使用) */
|
|
33
|
+
export interface GlobalDialogHandleOutput {
|
|
34
|
+
close(): void
|
|
35
|
+
update(options: Partial<PluginDialogOptions>): void
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let seq = 0
|
|
39
|
+
let current: GlobalDialogEntry | null = null
|
|
40
|
+
const queue: GlobalDialogEntry[] = []
|
|
41
|
+
const listeners = new Set<GlobalDialogListener>()
|
|
42
|
+
/** 条目 → 超时定时器(仅当条目指定 timeoutSec / deadlineAt) */
|
|
43
|
+
const timers = new Map<number, ReturnType<typeof setTimeout>>()
|
|
44
|
+
|
|
45
|
+
/** 当前弹窗(无则 null) */
|
|
46
|
+
export function getGlobalDialog(): GlobalDialogEntry | null {
|
|
47
|
+
return current
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 订阅弹窗变化;立即以当前值回调一次,返回退订函数 */
|
|
51
|
+
export function subscribeGlobalDialog(listener: GlobalDialogListener): () => void {
|
|
52
|
+
listeners.add(listener)
|
|
53
|
+
listener(current)
|
|
54
|
+
return () => {
|
|
55
|
+
listeners.delete(listener)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function emit(): void {
|
|
60
|
+
for (const fn of [...listeners]) fn(current)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function clearTimer(id: number): void {
|
|
64
|
+
const timer = timers.get(id)
|
|
65
|
+
if (timer) {
|
|
66
|
+
clearTimeout(timer)
|
|
67
|
+
timers.delete(id)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 解析条目的绝对截止时刻(deadlineAt 优先;缺省无定时关闭) */
|
|
72
|
+
export function resolveDialogDeadline(entry: GlobalDialogEntry): number | null {
|
|
73
|
+
if (entry.deadlineAt != null && entry.deadlineAt > 0) return entry.deadlineAt
|
|
74
|
+
if (entry.timeoutSec != null && entry.timeoutSec > 0) return entry.createdAt + entry.timeoutSec * 1000
|
|
75
|
+
return null
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 条目成为当前弹窗时的侧效:启动(或立即触发)超时计时 */
|
|
79
|
+
function startTimeout(entry: GlobalDialogEntry): void {
|
|
80
|
+
clearTimer(entry._id)
|
|
81
|
+
const deadline = resolveDialogDeadline(entry)
|
|
82
|
+
if (deadline == null) return
|
|
83
|
+
const delay = Math.max(0, deadline - Date.now())
|
|
84
|
+
timers.set(
|
|
85
|
+
entry._id,
|
|
86
|
+
setTimeout(() => {
|
|
87
|
+
// 超时:先回调 onTimeout(缺省仅关闭),再关闭(触发 onClose + 队列接替)
|
|
88
|
+
try {
|
|
89
|
+
entry.onTimeout?.()
|
|
90
|
+
} catch (e) {
|
|
91
|
+
console.error('[PluginDialog] onTimeout failed:', e)
|
|
92
|
+
}
|
|
93
|
+
closeGlobalDialog(entry._id)
|
|
94
|
+
}, delay),
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function fireOnClose(entry: GlobalDialogEntry): void {
|
|
99
|
+
try {
|
|
100
|
+
entry.onClose?.()
|
|
101
|
+
} catch (e) {
|
|
102
|
+
console.error('[PluginDialog] onClose failed:', e)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** 关闭指定弹窗:当前弹窗关闭后队列自动顶上;排队中直接移除(均幂等) */
|
|
107
|
+
export function closeGlobalDialog(id: number): void {
|
|
108
|
+
if (current && current._id === id) {
|
|
109
|
+
const closed = current
|
|
110
|
+
clearTimer(id)
|
|
111
|
+
current = null
|
|
112
|
+
const next = queue.shift() ?? null
|
|
113
|
+
current = next
|
|
114
|
+
emit()
|
|
115
|
+
fireOnClose(closed)
|
|
116
|
+
if (next) startTimeout(next)
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
const idx = queue.findIndex((e) => e._id === id)
|
|
120
|
+
if (idx >= 0) {
|
|
121
|
+
const [removed] = queue.splice(idx, 1)
|
|
122
|
+
fireOnClose(removed)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** 热更新指定弹窗(当前或排队中;新对象广播触发重渲染) */
|
|
127
|
+
export function updateGlobalDialog(id: number, options: Partial<PluginDialogOptions>): void {
|
|
128
|
+
if (current && current._id === id) {
|
|
129
|
+
current = { ...current, ...options }
|
|
130
|
+
emit()
|
|
131
|
+
startTimeout(current)
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
const idx = queue.findIndex((e) => e._id === id)
|
|
135
|
+
if (idx >= 0) {
|
|
136
|
+
queue[idx] = { ...queue[idx], ...options }
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 打开全局弹窗(宿主 ui.showDialog 调用)。
|
|
142
|
+
* 返回句柄:close() 幂等关闭(当前或排队项),update() 热更新选项。
|
|
143
|
+
*/
|
|
144
|
+
export function openGlobalDialog(input: OpenGlobalDialogInput): GlobalDialogHandleOutput {
|
|
145
|
+
const entry: GlobalDialogEntry = {
|
|
146
|
+
...input,
|
|
147
|
+
_id: ++seq,
|
|
148
|
+
createdAt: Date.now(),
|
|
149
|
+
}
|
|
150
|
+
if (current) {
|
|
151
|
+
queue.push(entry)
|
|
152
|
+
} else {
|
|
153
|
+
current = entry
|
|
154
|
+
emit()
|
|
155
|
+
startTimeout(entry)
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
close: () => closeGlobalDialog(entry._id),
|
|
159
|
+
update: (options) => updateGlobalDialog(entry._id, options),
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** 测试辅助:清空全部状态(队列/当前/监听器/定时器),用例间隔离 */
|
|
164
|
+
export function _resetGlobalDialogForTest(): void {
|
|
165
|
+
for (const id of [...timers.keys()]) clearTimer(id)
|
|
166
|
+
current = null
|
|
167
|
+
queue.length = 0
|
|
168
|
+
listeners.clear()
|
|
169
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @binblink/wasmnest-plugin-sdk-desktop
|
|
3
|
+
*
|
|
4
|
+
* WasmNest 插件开发工具包 — 类型定义 + 运行时代理 + 构建工具
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// 类型导出
|
|
8
|
+
export type {
|
|
9
|
+
Disposable,
|
|
10
|
+
PluginType,
|
|
11
|
+
PluginManifest,
|
|
12
|
+
PluginConfiguration,
|
|
13
|
+
ConfigProperty,
|
|
14
|
+
PluginContributes,
|
|
15
|
+
MonitorPanelContribution,
|
|
16
|
+
EndpointAuthTier,
|
|
17
|
+
HttpEndpointContribution,
|
|
18
|
+
WsEndpointContribution,
|
|
19
|
+
LifecycleContribution,
|
|
20
|
+
CommandContribution,
|
|
21
|
+
ViewContribution,
|
|
22
|
+
TerminalContribution,
|
|
23
|
+
ToolProviderContribution,
|
|
24
|
+
FileHandlerContribution,
|
|
25
|
+
SidebarPanelDescriptor,
|
|
26
|
+
ToolboxPageDescriptor,
|
|
27
|
+
StatusBarItemDescriptor,
|
|
28
|
+
InputExtensionDescriptor,
|
|
29
|
+
TerminalToolbarItemDescriptor,
|
|
30
|
+
TitleBarItemDescriptor,
|
|
31
|
+
PageToolbarItemDescriptor,
|
|
32
|
+
FileHandlerDescriptor,
|
|
33
|
+
PluginDialogAction,
|
|
34
|
+
PluginDialogOptions,
|
|
35
|
+
PluginDialogHandle,
|
|
36
|
+
RequestHandler,
|
|
37
|
+
CommandRegistry,
|
|
38
|
+
TerminalAPI,
|
|
39
|
+
SessionAPI,
|
|
40
|
+
UIRegistry,
|
|
41
|
+
EventAPI,
|
|
42
|
+
StorageAPI,
|
|
43
|
+
HttpAPI,
|
|
44
|
+
I18nAPI,
|
|
45
|
+
PluginContext,
|
|
46
|
+
PluginModule,
|
|
47
|
+
PluginDevMock,
|
|
48
|
+
PluginState,
|
|
49
|
+
PluginInfo,
|
|
50
|
+
} from './types'
|
|
51
|
+
|
|
52
|
+
// 运行时代理导出
|
|
53
|
+
export {
|
|
54
|
+
getSharedModule,
|
|
55
|
+
getI18n,
|
|
56
|
+
getVue,
|
|
57
|
+
getVueI18n,
|
|
58
|
+
getPinia,
|
|
59
|
+
getRouter,
|
|
60
|
+
getPluginContext,
|
|
61
|
+
} from './runtime'
|
|
62
|
+
|
|
63
|
+
// 全局弹窗控制器导出(宿主 / dev-shell 的 ui.showDialog 实现与渲染组件订阅)
|
|
64
|
+
export {
|
|
65
|
+
openGlobalDialog,
|
|
66
|
+
closeGlobalDialog,
|
|
67
|
+
updateGlobalDialog,
|
|
68
|
+
getGlobalDialog,
|
|
69
|
+
subscribeGlobalDialog,
|
|
70
|
+
resolveDialogDeadline,
|
|
71
|
+
} from './global-dialog'
|
|
72
|
+
export type {
|
|
73
|
+
GlobalDialogEntry,
|
|
74
|
+
GlobalDialogListener,
|
|
75
|
+
OpenGlobalDialogInput,
|
|
76
|
+
GlobalDialogHandleOutput,
|
|
77
|
+
} from './global-dialog'
|
|
78
|
+
|
|
79
|
+
// 配置约定导出
|
|
80
|
+
export { PLUGIN_CONFIG_STORAGE_KEY, defineConfiguration } from './config'
|
package/src/runtime.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @binblink/wasmnest-plugin-sdk-desktop 运行时代理
|
|
3
|
+
*
|
|
4
|
+
* 插件通过这些函数访问宿主共享模块,避免直接依赖 window 全局变量
|
|
5
|
+
*/
|
|
6
|
+
import type { PluginContext, I18nAPI } from './types'
|
|
7
|
+
|
|
8
|
+
/** 共享模块全局变量键名 */
|
|
9
|
+
const SHARED_KEY = '__WASMNEST_SHARED__'
|
|
10
|
+
|
|
11
|
+
/** 获取宿主共享模块 */
|
|
12
|
+
export function getSharedModule(name: string): any {
|
|
13
|
+
const shared = (window as any)[SHARED_KEY]
|
|
14
|
+
if (!shared) throw new Error('[PluginSDK] Shared runtime not initialized')
|
|
15
|
+
const mod = shared[name]
|
|
16
|
+
if (!mod) throw new Error(`[PluginSDK] Shared module "${name}" not found`)
|
|
17
|
+
return mod
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** 获取宿主 i18n 实例(模块级代码使用,组件内请用 useI18n()) */
|
|
21
|
+
export function getI18n(): any {
|
|
22
|
+
return getSharedModule('i18n')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 获取宿主 Vue 实例 */
|
|
26
|
+
export function getVue(): any {
|
|
27
|
+
return getSharedModule('vue')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 获取宿主 vue-i18n 模块 */
|
|
31
|
+
export function getVueI18n(): any {
|
|
32
|
+
return getSharedModule('vue-i18n')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 获取宿主 Pinia 模块 */
|
|
36
|
+
export function getPinia(): any {
|
|
37
|
+
return getSharedModule('pinia')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** 获取宿主 Router 实例 */
|
|
41
|
+
export function getRouter(): any {
|
|
42
|
+
return getSharedModule('router')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 从 Vue inject 获取 PluginContext(组件 setup 阶段调用) */
|
|
46
|
+
export function getPluginContext(): PluginContext {
|
|
47
|
+
const vue = getVue()
|
|
48
|
+
const context = vue.inject('pluginContext')
|
|
49
|
+
if (!context)
|
|
50
|
+
throw new Error(
|
|
51
|
+
'[PluginSDK] PluginContext not available — ensure component is rendered inside PluginViewHost',
|
|
52
|
+
)
|
|
53
|
+
return context
|
|
54
|
+
}
|