Skip to content
Document Authoring DA  API Docs v2.0.0
npmGitHub

BuiltInAction>= v1.9.0

BuiltInAction:

Built-in actions have pre-defined IDs from BuiltInActionId and automatically use default handlers if not provided. This allows you to customize things without having to reimplement internal functionality.

If an override omits capabilities, it keeps the built-in action’s capabilities. For example, document.export-pdf keeps document.read, and formatting.bold keeps document.change. Set capabilities only when your override changes what the action does.

import { defaultActions } from '@nutrient-sdk/document-authoring';
// Remove all built-in actions except bold built-in (handler auto-populated)
editor.setActions([{ id: 'formatting.bold', label: 'Bold', shortcuts: ['Mod+B'] }]);
// Override the default handler for bold
editor.setActions([
...defaultActions.filter(({ id }) => id !== 'formatting.bold'),
{
id: 'formatting.bold',
label: 'Bold',
shortcuts: ['Mod+B'],
handler: () => {
console.log('Custom bold implementation');
},
},
]);
// Customize shortcuts and labels while keeping default behavior
editor.setActions([
...defaultActions.filter(({ id }) => id !== 'document.export-pdf'),
{ id: 'document.export-pdf', label: 'Download PDF', shortcuts: ['Mod+P'] },
]);

id: BuiltInActionId

The built-in action to configure. ActionCalls describes what each one does and the arguments it takes.


label: string

Text shown for the action in the command palette and on ToolbarActionItem buttons.

If the label is the same as the action’s default label in defaultActions, it keeps its built-in translation for UIOptions.locale. Any other label is an override that the editor shows untranslated in every locale.


optional description: string


optional capabilities: readonly ActionCapability[]

What kind of change the action makes, which decides the editor modes it can run in. If omitted, the built-in action’s capabilities are kept; if set, they replace them. setActions() throws on values that are not an ActionCapability.


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

Replaces the built-in availability check rather than adding to it. Receives no action arguments. If omitted, the built-in check is kept. For revision.accept and revision.reject, replacing this check can enable a control for an operation that canPerformTrackedChange denies. Core still blocks that operation when the built-in handler runs. Mode checks still apply.

boolean


optional handler: (…args) => void | Promise<void>

Replaces the built-in handler. If omitted, the SDK uses its built-in handler and validates its arguments. A replacement handler is responsible for validating its own arguments. Mode and isEnabled checks still apply.

…any[]

void | Promise<void>