Skip to content

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

Defined in: commands/add-element-command.d.ts:5

Extends

Constructors

Constructor

ts
new AddElementCommand(host, element): AddElementCommand;

Defined in: commands/add-element-command.d.ts:9

Parameters

ParameterType
hostEditorHost
elementIGraphicElement

Returns

AddElementCommand

Overrides

BaseCommand.constructor

Properties

name

ts
name: string;

Defined in: commands/add-element-command.d.ts:7

Overrides

BaseCommand.name


timestamp

ts
timestamp: number;

Defined in: commands/base-command.d.ts:5

Inherited from

BaseCommand.timestamp


description?

ts
optional description?: string;

Defined in: commands/base-command.d.ts:6

Inherited from

BaseCommand.description

Methods

execute()

ts
execute(): void;

Defined in: commands/add-element-command.d.ts:10

Returns

void

Overrides

BaseCommand.execute


undo()

ts
undo(): void;

Defined in: commands/add-element-command.d.ts:11

Returns

void

Overrides

BaseCommand.undo


canMergeWith()

ts
canMergeWith(command): boolean;

Defined in: commands/add-element-command.d.ts:12

Parameters

ParameterType
commandICommand

Returns

boolean

Overrides

BaseCommand.canMergeWith


redo()

ts
redo(): void;

Defined in: commands/base-command.d.ts:11

Returns

void

Inherited from

BaseCommand.redo


mergeWith()?

ts
optional mergeWith(command): ICommand;

Defined in: commands/base-command.d.ts:13

Parameters

ParameterType
commandICommand

Returns

ICommand

Inherited from

BaseCommand.mergeWith


使用示例

添加矩形元素

typescript
import { AddElementCommand } from 'vkedit'

host.executeCommand(new AddElementCommand({
  type: 'rect',
  x: 10, y: 10,
  width: 50, height: 30,
  fill: '#6366f1',
}))

添加文本元素

typescript
host.executeCommand(new AddElementCommand({
  type: 'text',
  x: 10, y: 50,
  text: 'Hello vkedit',
  fontSize: 14,
  fontFamily: 'PingFang SC',
}))

自动进入撤销栈

通过 executeCommand 执行的命令自动进入撤销栈,用户可通过 Ctrl+Z 撤销。无需手动管理撤销栈。

type 字段必须正确

elementData.type 必须与已安装的图形插件匹配。如果未安装 TextPlugin 但尝试添加 type: 'text' 的元素,会报错。

基于 MIT 许可发布