Skip to content

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

Defined in: core/editor-host.d.ts:4

Constructors

Constructor

ts
new EditorHost(): EditorHost;

Returns

EditorHost

Properties

contentLayer

ts
contentLayer: any;

Defined in: core/editor-host.d.ts:9


contentGroup

ts
contentGroup: any;

Defined in: core/editor-host.d.ts:10


stage

ts
stage: any;

Defined in: core/editor-host.d.ts:11


stageState

ts
stageState: object;

Defined in: core/editor-host.d.ts:13

viewportWidth

ts
viewportWidth: number;

viewportHeight

ts
viewportHeight: number;

wrapperEl

ts
wrapperEl: HTMLElement | null;

currentCursorMode

ts
currentCursorMode: CursorMode;

mouseStageX

ts
mouseStageX: number;

mouseStageY

ts
mouseStageY: number;

spacePressed

ts
spacePressed: boolean;

isPanning

ts
isPanning: boolean;

offsetX

ts
offsetX: number;

offsetY

ts
offsetY: number;

Accessors

status

Get Signature

ts
get status(): IEditorState;

Defined in: core/editor-host.d.ts:37

Returns

IEditorState

Methods

emit()

ts
emit<K>(event, payload): void;

Defined in: core/editor-host.d.ts:25

Type Parameters

Type Parameter
K extends keyof EventMap

Parameters

ParameterType
eventK
payloadParameters<EventMap[K]>[0]

Returns

void


on()

ts
on<K>(event, handler): void;

Defined in: core/editor-host.d.ts:26

Type Parameters

Type Parameter
K extends keyof EventMap

Parameters

ParameterType
eventK
handlerEventMap[K]

Returns

void


off()

ts
off<K>(event, handler): void;

Defined in: core/editor-host.d.ts:27

Type Parameters

Type Parameter
K extends keyof EventMap

Parameters

ParameterType
eventK
handlerEventMap[K]

Returns

void


installPlugin()

Call Signature

ts
installPlugin<K>(name, pluginClass): EditorHost;

Defined in: core/editor-host.d.ts:28

Type Parameters
Type Parameter
K extends keyof PluginMap
Parameters
ParameterType
nameK
pluginClass| PluginMap[K] | ((...args) => PluginMap[K])
Returns

EditorHost

Call Signature

ts
installPlugin(name, pluginClass): EditorHost;

Defined in: core/editor-host.d.ts:29

Parameters
ParameterType
namestring
pluginClass| IEditorPlugin | ((...args) => IEditorPlugin)
Returns

EditorHost


uninstallPlugin()

Call Signature

ts
uninstallPlugin<K>(pluginName): EditorHost;

Defined in: core/editor-host.d.ts:30

Type Parameters
Type Parameter
K extends keyof PluginMap
Parameters
ParameterType
pluginNameK
Returns

EditorHost

Call Signature

ts
uninstallPlugin(pluginName): EditorHost;

Defined in: core/editor-host.d.ts:31

Parameters
ParameterType
pluginNamestring
Returns

EditorHost


getPlugin()

Call Signature

ts
getPlugin<K>(pluginName): PluginMap[K];

Defined in: core/editor-host.d.ts:32

Type Parameters
Type Parameter
K extends keyof PluginMap
Parameters
ParameterType
pluginNameK
Returns

PluginMap[K]

Call Signature

ts
getPlugin<T>(pluginName): T;

Defined in: core/editor-host.d.ts:33

Type Parameters
Type ParameterDefault type
T extends IEditorPluginIEditorPlugin
Parameters
ParameterType
pluginNamestring
Returns

T


executeCommand()

ts
executeCommand(command): void;

Defined in: core/editor-host.d.ts:34

Parameters

ParameterType
commandICommand

Returns

void


undo()

ts
undo(): void;

Defined in: core/editor-host.d.ts:35

Returns

void


redo()

ts
redo(): void;

Defined in: core/editor-host.d.ts:36

Returns

void


setStatus()

ts
setStatus(newStatus): void;

Defined in: core/editor-host.d.ts:38

Parameters

ParameterType
newStatusPartial<IEditorState>

Returns

void


toJSON()

ts
toJSON(): string;

Defined in: core/editor-host.d.ts:39

Returns

string


loadJSON()

ts
loadJSON(jsonStr): void;

Defined in: core/editor-host.d.ts:40

Parameters

ParameterType
jsonStrstring

Returns

void


使用示例

创建并配置 EditorHost

typescript
import { EditorHost, ToolbarManagerPlugin, SelectionPlugin } from 'vkedit'

const host = new EditorHost()

// 安装核心插件(顺序很重要)
host.installPlugin('toolbar', ToolbarManagerPlugin)
host.installPlugin('selection', SelectionPlugin)

// 设置画布
host.setCanvasSize(210, 297) // A4 尺寸(毫米)

在 Vue 组件中使用

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 未安装会报错。

基于 MIT 许可发布