Skip to content

Commit cb53290

Browse files
committed
enhance: add panel api demo
1 parent 7c155f1 commit cb53290

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import cssText from './style.css?inline';
1515

1616
import type { PluginInterface, PluginInterfaceCtx } from '../types/any-menu';
1717

18+
let cache_ctx: PluginInterfaceCtx | undefined
19+
1820
export default class ExamplePluginSimple implements PluginInterface {
1921
metadata = {
2022
id: 'example-plugin-simple',
@@ -32,12 +34,23 @@ export default class ExamplePluginSimple implements PluginInterface {
3234
}
3335

3436
onUnload(): void {
37+
if (cache_ctx) cache_ctx.api.unregisterSubPanel('example-plugin-simple-panel')
3538
console.log('[ExamplePluginSimple] Plugin unloaded');
3639
}
3740

3841
async run(ctx: PluginInterfaceCtx): Promise<void> {
39-
const selected = ctx.env.selectedText;
42+
// 注册面板示例
43+
if (!cache_ctx) {
44+
cache_ctx = ctx
45+
const newPanel = document.createElement('div'); newPanel.innerText = 'New Panel Content';
46+
ctx.api.registerSubPanel({
47+
id: 'example-plugin-simple-panel',
48+
el: newPanel
49+
})
50+
}
4051

52+
// 文本输出示例
53+
const selected = ctx.env.selectedText;
4154
if (selected) {
4255
// 如果有选中文本,在其后追加问候
4356
ctx.api.sendText(`${selected} — Hello World!`);

0 commit comments

Comments
 (0)