Methods and Events
Complete reference guide for all Beefree SDK methods, callbacks, and events.
Overview
Beefree SDK provides a comprehensive set of methods, callback functions, and events that allow you to control the editor programmatically and respond to user interactions. This guide serves as your single source of truth for all available SDK interactions.
TypeScript Definitions: For complete type safety and detailed parameter information, reference the official TypeScript definitions: Beefree SDK Types
How Methods and Events Work
Beefree SDK is built on an event-driven architecture, a software design pattern where components communicate through events rather than direct method calls. In this architecture, methods are functions you call to trigger actions in the SDK (like saving or loading templates), while events are notifications the SDK sends back to your application when something happens (like content changes or errors). This decoupled approach allows your application to respond to SDK activities asynchronously, making integrations more flexible and scalable. Learn more about event-driven architecture on MDN Web Docs.
When you initialize Beefree SDK, you get an instance that exposes various methods for programmatic control. Additionally, you can configure callback functions in your beeConfig to respond to user actions and editor events.
const bee = new BeefreeSDK(token);
const beeInstance = bee.start(beeConfig, template);
// Use methods to control the editor
beeInstance.save();
beeInstance.preview();
// Configure callbacks to respond to events
const beeConfig = {
container: 'editor-container',
onSave: function(jsonFile, htmlFile) {
// Handle save event
},
onChange: function(jsonFile, response) {
// Handle content changes
}
};Instance Methods
These methods are available on the Beefree SDK instance and allow you to control the editor programmatically.
Core Methods
beeInstance.start(templateToLoad, userInfo, templateInfo, options)
Description: Initializes and starts the builder with optional template data
Parameters:
templateToLoad(optional): JSON string with template structureuserInfo(optional): User information object for collaborative featurestemplateInfo(optional): Template metadataoptions(optional): Additional configuration options
Returns: Promise that resolves when editor is ready
Usage:
beeInstance.load(template)
Description: Loads a JSON template into the editor
Parameters:
template: JSON string with template structure
Returns: Promise that resolves when template is loaded
Usage:
beeInstance.reload(template)
Description: Reloads a template without showing loading dialog (seamless reload)
Parameters:
template: JSON string with template structure
Use Cases: Custom undo/redo, real-time content injection
Usage:
Control Methods
beeInstance.save()
Description: Programmatically triggers the save action
Triggers:
onSavecallback with JSON and HTML filesUsage:
beeInstance.saveAsTemplate()
Description: Programmatically triggers save as template action
Triggers:
onSaveAsTemplatecallback with JSON fileUsage:
beeInstance.send()
Description: Programmatically triggers send action (Email Builder only)
Triggers:
onSendcallback with HTML fileUsage:
Preview and View Methods
beeInstance.togglePreview()
Description: Toggles preview mode on/off
Triggers:
onTogglePreviewcallbackUsage:
beeInstance.toggleStructure()
Description: Toggles visibility of structure outlines in the editor
Usage:
beeInstance.toggleMergeTagsPreview()
Description: Toggles visibility of merge tag sample content
Usage:
Advanced Methods
beeInstance.execCommand(command)
Description: Executes specific editor commands for highlighting, scrolling, focusing, or selecting elements
Parameters:
command: Object defining the action and target
Actions:
highlight,scroll,focus,selectUsage:
beeInstance.loadWorkspace(type)
Description: Loads a specific workspace type
Parameters:
type: Workspace type ('default', 'mixed', 'amp_only', 'html_only')
Triggers:
onLoadWorkspacecallbackUsage:
beeInstance.loadConfig(config)
Description: Updates editor configuration dynamically
Parameters:
config: Configuration object with updated settings
Usage:
File Manager Methods
File Manager applications have a simplified method set focused on file selection and management workflows.
Callback Functions
Callback functions are configured in your beeConfig and are triggered by user actions or editor events.
Save and Template Callbacks
onSave
Trigger: User clicks save button or
beeInstance.save()is calledParameters:
(jsonFile, htmlFile, ampHtml, templateVersion, language)jsonFile: Template structure as JSON stringhtmlFile: Rendered HTML outputampHtml: AMP HTML version (if applicable)templateVersion: Template version numberlanguage: Template language code
Usage:
onSaveAsTemplate
Trigger: User clicks "Save as Template" or
beeInstance.saveAsTemplate()is calledParameters:
(jsonFile)jsonFile: Template structure as JSON string
Usage:
onAutoSave
Trigger: Automatic save based on
autosaveconfigurationParameters:
(jsonFile)jsonFile: Template structure as JSON string
Usage:
onSend
Trigger: User clicks send button or
beeInstance.send()is called (Email Builder only)Parameters:
(htmlFile)htmlFile: Rendered HTML ready for sending
Usage:
Content Change Callbacks
onChange
Trigger: Template content is modified (requires
trackChanges: true)Parameters:
(jsonFile, response)jsonFile: Updated template JSONresponse: Change details object with patches and metadata
Usage:
onRemoteChange
Trigger: Changes made by other users in collaborative editing sessions
Parameters:
(jsonFile, response)jsonFile: Updated template JSON from remote userresponse: Change details from remote user
Usage:
Loading and Workspace Callbacks
onLoad
Trigger: Template is loaded into the editor
Parameters:
(jsonFile)jsonFile: Loaded template JSON
Usage:
onLoadWorkspace
Trigger: Workspace is successfully loaded
Parameters:
(workspace)workspace: Workspace configuration object
Usage:
Error and Warning Callbacks
onError
Trigger: Errors occur in the editor
Parameters:
(errorMessage)errorMessage: Error description string
Usage:
onWarning
Trigger: Warnings are generated by the editor
Parameters:
(alertMessage)alertMessage: Warning description string
Usage:
Preview and View Callbacks
onPreview
Trigger: Preview button is clicked
Parameters:
(status)status: Boolean indicating preview state
Usage:
onTogglePreview
Trigger: Preview is toggled on/off
Parameters:
(status)status: Boolean indicating preview state
Usage:
onViewChange
Trigger: User navigates between different SDK views
Parameters:
(view)view: String indicating current view
Possible Values:
'editor': Main editor view'preview': Preview mode'fileManager': File Manager opened'imageEditor': Image Editor opened
Usage:
File Management Callbacks
onFilePickerInsert
Trigger: Insert button clicked in File Manager applications
Parameters:
(data)data: Object containing file information
Usage:
onFilePickerCancel
Trigger: Cancel/X button clicked in File Manager applications
Parameters: None
Usage:
Collaboration Callbacks
onComment
Trigger: Comments or comment threads change
Parameters:
(commentData)commentData: Comment information object
Usage:
Event Configuration Examples
Basic Event Handling
Advanced Event Handling
File Manager Configuration
Method Chaining and Async Operations
Many SDK methods return promises, allowing for proper async handling:
Best Practices
Error Handling
Always implement
onErrorcallback for production applicationsProvide user-friendly error messages
Log errors for debugging and monitoring
Performance
Use
onChangejudiciously withtrackChanges: trueImplement debouncing for frequent operations
Consider using
onAutoSavefor background saves
User Experience
Provide feedback for all user actions
Use
onViewChangeto guide users through different modesImplement proper loading states
Collaboration
Use
onRemoteChangeto show real-time collaborationImplement conflict resolution for simultaneous edits
Provide clear indicators of other users' activities
Development
Reference TypeScript definitions for complete type safety
Test all callback implementations thoroughly
Use method chaining for complex workflows
TypeScript Support
For complete type definitions and IntelliSense support, reference the official types:
TypeScript Definitions: Beefree SDK Types
This comprehensive guide covers all available methods, callbacks, and events in Beefree SDK. Use it as your reference for implementing complete editor control and event handling in your applications.
TypeScript Definitions: Beefree SDK Types
Last updated
Was this helpful?

