Overview
TheEditor class is the main entry point for Canvas Editor. It manages the entire editor lifecycle, from initialization to destruction, and provides access to all core functionality through its public API.
Constructor
The Editor constructor requires a container element, initial data, and optional configuration:Parameters
container: HTMLDivElement
container: HTMLDivElement
The DOM element that will host the editor. Must be a
div element. The editor will render its canvas inside this container.data: IEditorData | IElement[]
data: IEditorData | IElement[]
Initial document content. Can be:
- Simple array:
IElement[]- Sets the main content area - Full document:
IEditorData- Includes header, main, footer, and graffiti
options: IEditorOption
options: IEditorOption
Configuration object to customize editor behavior:
Core Properties
command
Execute operations and retrieve data
listener
Legacy event handlers (callback-based)
eventBus
Modern event system (pub/sub pattern)
register
Register custom context menus and shortcuts
Additional Properties
Lifecycle
Initialization
When you create a new Editor instance, the constructor:
- Merges provided options with defaults
- Deep clones the data to prevent mutations
- Formats element lists (header, main, footer)
- Initializes the Draw engine with the container
- Sets up Command, ContextMenu, and Shortcut systems
- Registers the destroy method
Active State
The editor is now ready to use. You can:
- Execute commands via
editor.command - Listen to events via
editor.listeneroreditor.eventBus - Register custom functionality via
editor.register - Load plugins via
editor.use(plugin)
Complete Example
FAQ
Can I create multiple editor instances on the same page?
Can I create multiple editor instances on the same page?
Yes, you can create multiple independent editor instances, each with their own container:Each instance manages its own state and operates independently.
What happens if I don't call destroy()?
What happens if I don't call destroy()?
The editor will continue to listen for events and hold references in memory, potentially causing memory leaks in single-page applications. Always call
destroy() when removing an editor instance.Can I change options after initialization?
Can I change options after initialization?
Yes, use the Note: Some options like
executeUpdateOptions() command:width, height, mode, and pageMode cannot be updated after initialization.How do I switch between edit and read-only modes?
How do I switch between edit and read-only modes?
Use the
executeMode() command:Next Steps
Elements
Learn about the element data structure
Commands
Explore available commands
Event System
Subscribe to editor events
API Reference
Complete API documentation