Skip to content
Document Authoring DA  API Docs v1.18.0
npmGitHub

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.

import { defaultActions } from '@nutrient-sdk/document-authoring';
// Add a custom action with keyboard shortcut
editor.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 icon
editor.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',
body: JSON.stringify(doc),
});
},
},
]);
// Add a conditional action (disabled when no cursor/selection)
editor.setActions([
{
id: 'custom.insert-date',
label: "Insert Today's Date",
isEnabled: () => editor.hasActiveCursor(),
handler: () => {
const date = new Date().toLocaleDateString();
editor.insertTextAtCursor(date);
},
},
]);

id: string

Unique identifier for this action (must not be a BuiltInActionId)


label: string


optional description: string


optional shortcuts: string[]

Keyboard shortcuts for the action. Use “Mod” as the primary modifier key - it will be automatically resolved to:

  • “Ctrl” on Windows/Linux
  • ”⌘” (Command) on Mac

Examples:

  • “Mod+B” becomes “Ctrl+B” on Windows, “⌘B” on Mac
  • “Mod+Shift+P” becomes “Ctrl+Shift+P” on Windows, ”⌘⇧P” on Mac

optional icon: 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.


optional isEnabled: () => boolean

Optional function to determine if this action should be enabled

boolean


handler: () => void | Promise<void>

Handler function that executes when the action is triggered (required for custom actions)

void | Promise<void>