Elements are the fundamental building blocks of a Canvas Editor document. Every piece of content—text, images, tables, controls—is represented as an IElement object.
Every element must have these fundamental properties:
interface IElementBasic { value: string // The content/text of the element (required) id?: string // Unique identifier for the element type?: ElementType // Element type (TEXT, IMAGE, TABLE, etc.) extension?: unknown // Custom data for your application externalId?: string // External reference ID}
The value property is the only required field. For text elements, it contains the actual text. For images, it’s the base64 data URL or image URL.
interface IElementStyle { font?: string // Font family (e.g., 'Arial', 'Microsoft YaHei') size?: number // Font size in pixels width?: number // Element width (for images, separators) height?: number // Element height (for images) bold?: boolean // Bold text color?: string // Text color (hex or rgb) highlight?: string // Background highlight color italic?: boolean // Italic text underline?: boolean // Underlined text strikeout?: boolean // Strikethrough text rowFlex?: RowFlex // Row alignment (LEFT, CENTER, RIGHT, JUSTIFY) rowMargin?: number // Row spacing/margin letterSpacing?: number // Letter spacing textDecoration?: ITextDecoration // Advanced text decoration}
// Get entire document structureconst data = editor.command.getValue()// Returns: { header: IElement[], main: IElement[], footer: IElement[] }// Get specific element by IDconst element = editor.command.getElementById({ id: 'element-id' })// Get current selectionconst range = editor.command.getRange()const selectedText = editor.command.getRangeText()
// Delete by IDeditor.command.executeDeleteElementById({ id: 'element-id' })// Delete by concept ID (for grouped elements)editor.command.executeDeleteElementById({ conceptId: 'concept-id' })// Backspace at cursoreditor.command.executeBackspace()
The editor can generate IDs internally for certain operations, but you should provide your own IDs for elements you need to reference or update programmatically.