本页由脚本自动生成,请勿手动编辑。如需补充说明,请使用
::: tip块。
Defined in: core/editor-host.d.ts:4
Constructors
Constructor
new EditorHost(): EditorHost;Returns
EditorHost
Properties
contentLayer
contentLayer: any;Defined in: core/editor-host.d.ts:9
contentGroup
contentGroup: any;Defined in: core/editor-host.d.ts:10
stage
stage: any;Defined in: core/editor-host.d.ts:11
stageState
stageState: object;Defined in: core/editor-host.d.ts:13
viewportWidth
viewportWidth: number;viewportHeight
viewportHeight: number;wrapperEl
wrapperEl: HTMLElement | null;currentCursorMode
currentCursorMode: CursorMode;mouseStageX
mouseStageX: number;mouseStageY
mouseStageY: number;spacePressed
spacePressed: boolean;isPanning
isPanning: boolean;offsetX
offsetX: number;offsetY
offsetY: number;Accessors
status
Get Signature
get status(): IEditorState;Defined in: core/editor-host.d.ts:37
Returns
Methods
emit()
emit<K>(event, payload): void;Defined in: core/editor-host.d.ts:25
Type Parameters
| Type Parameter |
|---|
K extends keyof EventMap |
Parameters
| Parameter | Type |
|---|---|
event | K |
payload | Parameters<EventMap[K]>[0] |
Returns
void
on()
on<K>(event, handler): void;Defined in: core/editor-host.d.ts:26
Type Parameters
| Type Parameter |
|---|
K extends keyof EventMap |
Parameters
| Parameter | Type |
|---|---|
event | K |
handler | EventMap[K] |
Returns
void
off()
off<K>(event, handler): void;Defined in: core/editor-host.d.ts:27
Type Parameters
| Type Parameter |
|---|
K extends keyof EventMap |
Parameters
| Parameter | Type |
|---|---|
event | K |
handler | EventMap[K] |
Returns
void
installPlugin()
Call Signature
installPlugin<K>(name, pluginClass): EditorHost;Defined in: core/editor-host.d.ts:28
Type Parameters
| Type Parameter |
|---|
K extends keyof PluginMap |
Parameters
| Parameter | Type |
|---|---|
name | K |
pluginClass | | PluginMap[K] | ((...args) => PluginMap[K]) |
Returns
EditorHost
Call Signature
installPlugin(name, pluginClass): EditorHost;Defined in: core/editor-host.d.ts:29
Parameters
| Parameter | Type |
|---|---|
name | string |
pluginClass | | IEditorPlugin | ((...args) => IEditorPlugin) |
Returns
EditorHost
uninstallPlugin()
Call Signature
uninstallPlugin<K>(pluginName): EditorHost;Defined in: core/editor-host.d.ts:30
Type Parameters
| Type Parameter |
|---|
K extends keyof PluginMap |
Parameters
| Parameter | Type |
|---|---|
pluginName | K |
Returns
EditorHost
Call Signature
uninstallPlugin(pluginName): EditorHost;Defined in: core/editor-host.d.ts:31
Parameters
| Parameter | Type |
|---|---|
pluginName | string |
Returns
EditorHost
getPlugin()
Call Signature
getPlugin<K>(pluginName): PluginMap[K];Defined in: core/editor-host.d.ts:32
Type Parameters
| Type Parameter |
|---|
K extends keyof PluginMap |
Parameters
| Parameter | Type |
|---|---|
pluginName | K |
Returns
PluginMap[K]
Call Signature
getPlugin<T>(pluginName): T;Defined in: core/editor-host.d.ts:33
Type Parameters
| Type Parameter | Default type |
|---|---|
T extends IEditorPlugin | IEditorPlugin |
Parameters
| Parameter | Type |
|---|---|
pluginName | string |
Returns
T
executeCommand()
executeCommand(command): void;Defined in: core/editor-host.d.ts:34
Parameters
| Parameter | Type |
|---|---|
command | ICommand |
Returns
void
undo()
undo(): void;Defined in: core/editor-host.d.ts:35
Returns
void
redo()
redo(): void;Defined in: core/editor-host.d.ts:36
Returns
void
setStatus()
setStatus(newStatus): void;Defined in: core/editor-host.d.ts:38
Parameters
| Parameter | Type |
|---|---|
newStatus | Partial<IEditorState> |
Returns
void
toJSON()
toJSON(): string;Defined in: core/editor-host.d.ts:39
Returns
string
loadJSON()
loadJSON(jsonStr): void;Defined in: core/editor-host.d.ts:40
Parameters
| Parameter | Type |
|---|---|
jsonStr | string |
Returns
void
使用示例
创建并配置 EditorHost
import { EditorHost, ToolbarManagerPlugin, SelectionPlugin } from 'vkedit'
const host = new EditorHost()
// 安装核心插件(顺序很重要)
host.installPlugin('toolbar', ToolbarManagerPlugin)
host.installPlugin('selection', SelectionPlugin)
// 设置画布
host.setCanvasSize(210, 297) // A4 尺寸(毫米)在 Vue 组件中使用
<script setup lang="ts">
import { EditorHost } from 'vkedit'
import { ref, onUnmounted } from 'vue'
const host = ref(new EditorHost())
onUnmounted(() => {
host.value.destroy()
})
</script>生命周期管理
在 Vue 组件的 onUnmounted 中调用 host.destroy() 释放资源。未销毁的 EditorHost 会保留 Konva Stage 和事件监听,导致内存泄漏。
插件安装顺序
ToolbarManagerPlugin 必须第一个安装。其他插件安装时可能需要向工具栏注册按钮,如果 ToolbarManagerPlugin 未安装会报错。