本页由脚本自动生成,请勿手动编辑。如需补充说明,请使用
::: 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
| Parameter | Type |
|---|---|
host | EditorHost |
element | IGraphicElement |
Returns
AddElementCommand
Overrides
Properties
name
ts
name: string;Defined in: commands/add-element-command.d.ts:7
Overrides
timestamp
ts
timestamp: number;Defined in: commands/base-command.d.ts:5
Inherited from
description?
ts
optional description?: string;Defined in: commands/base-command.d.ts:6
Inherited from
Methods
execute()
ts
execute(): void;Defined in: commands/add-element-command.d.ts:10
Returns
void
Overrides
undo()
ts
undo(): void;Defined in: commands/add-element-command.d.ts:11
Returns
void
Overrides
canMergeWith()
ts
canMergeWith(command): boolean;Defined in: commands/add-element-command.d.ts:12
Parameters
| Parameter | Type |
|---|---|
command | ICommand |
Returns
boolean
Overrides
redo()
ts
redo(): void;Defined in: commands/base-command.d.ts:11
Returns
void
Inherited from
mergeWith()?
ts
optional mergeWith(command): ICommand;Defined in: commands/base-command.d.ts:13
Parameters
| Parameter | Type |
|---|---|
command | ICommand |
Returns
Inherited from
使用示例
添加矩形元素
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' 的元素,会报错。