Skip to content

本页由脚本自动生成,请勿手动编辑。如需补充说明,请使用 ::: tip 块。

Defined in: types/base-plugin.d.ts:3

Extended by

Implements

Constructors

Constructor

ts
new BasePlugin(host): BasePlugin;

Defined in: types/base-plugin.d.ts:8

Parameters

ParameterType
hostEditorHost

Returns

BasePlugin

Properties

name

ts
abstract name: string;

Defined in: types/base-plugin.d.ts:4

Implementation of

IEditorPlugin.name


version

ts
abstract version: string;

Defined in: types/base-plugin.d.ts:5

Implementation of

IEditorPlugin.version

Methods

install()

ts
install(): void;

Defined in: types/base-plugin.d.ts:9

Returns

void

Implementation of

IEditorPlugin.install


uninstall()

ts
uninstall(): void;

Defined in: types/base-plugin.d.ts:10

Returns

void

Implementation of

IEditorPlugin.uninstall


activate()

ts
activate(): void;

Defined in: types/base-plugin.d.ts:11

Returns

void

Implementation of

IEditorPlugin.activate


deactivate()

ts
deactivate(): void;

Defined in: types/base-plugin.d.ts:12

Returns

void

Implementation of

IEditorPlugin.deactivate


自定义插件示例

typescript
import { BasePlugin, AddElementCommand } from 'vkedit'

class StampPlugin extends BasePlugin {
  name = 'stamp-plugin'

  onInstall() {
    // 注册工具栏按钮
    this.host.getPlugin('toolbar')?.addButton({
      id: 'stamp',
      label: '印章',
      icon: 'stamp-icon',
      onClick: () => this.addStamp(),
    })
  }

  onUninstall() {
    // 清理资源
    this.host.getPlugin('toolbar')?.removeButton('stamp')
  }

  private addStamp() {
    this.host.executeCommand(
      new AddElementCommand({
        type: 'rect',
        x: 50, y: 50,
        width: 40, height: 40,
        fill: '#EF4444',
        cornerRadius: 20,
      })
    )
  }
}

插件命名规范

插件 name 属性使用 kebab-case(如 'stamp-plugin'),与内置插件保持一致。

onUninstall 必须实现

onUninstall 中必须清理 onInstall 中注册的所有资源(工具栏按钮、事件监听、定时器等),否则卸载后会有残留。

基于 MIT 许可发布