CustomAction>= v1.9.0
CustomAction:
{}Custom actions allow you to add your own functionality to the editor. Unlike BuiltInAction, custom actions must provide a handler
function.
Example
Section titled “Example”
// Add a custom action with keyboard shortcuteditor.setActions([ { id: 'custom.insert-signature', label: 'Insert Signature', shortcuts: ['Mod+Shift+S'], handler: () => { editor.insertTextAtCursor('\n\nBest regards,\nJohn Doe'); }, },]);
// Add a custom action with custom iconeditor.setActions([ { id: 'custom.save', label: 'Save Document', icon: 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiPi4uLjwvc3ZnPg==', handler: async () => { const doc = await editor.currentDocument().saveDocument(); await fetch('/api/save', { method: 'POST', }); }, },]);
// Add a conditional action (disabled when no cursor/selection)editor.setActions([ { id: 'custom.insert-date', label: "Insert Today's Date", isEnabled: () => editor.hasActiveCursor(), handler: () => { editor.insertTextAtCursor(date); }, },]);BuiltInActionfor built-in actions with default implementations.ToolbarActionItemfor adding custom actions to the toolbar.
Properties
Section titled “Properties”id:
string
Unique identifier for this action (must not be a BuiltInActionId)
label:
string
description?
Section titled “description?”
optionaldescription:string
shortcuts?
Section titled “shortcuts?”
optionalshortcuts:string[]
Keyboard shortcuts for the action. Use “Cmd” as the modifier key - it will be resolved to:
- “Ctrl” on Windows/Linux (for keyboard handling)
- ”⌘” on Mac (for keyboard handling)
- “Ctrl” or ”⌘” for display based on platform
Examples:
- “Cmd+B” becomes “Ctrl+B” on Windows, “⌘B” on Mac
- “Cmd+Shift+P” becomes “Ctrl+Shift+P” on Windows, ”⌘⇧P” on Mac
optionalicon:string
Icon as data URI (e.g., data:image/svg+xml;base64,… or data:image/png;base64,…). Only data:image/ URIs are allowed for security.
isEnabled()?
Section titled “isEnabled()?”
optionalisEnabled: () =>boolean
Optional function to determine if this action should be enabled
Returns
Section titled “Returns”handler()
Section titled “handler()”Handler function that executes when the action is triggered (required for custom actions)