AI Text Tool for Editor.js

July 3, 2026 ยท View on GitHub

AI Text Tool for Editor.js

AI suggestion text Tool for the Editor.js based on the default Paragraph Tool.

While writing, you get an AI suggestion after a configurable delay. Accept or decline it with keyboard shortcuts.

image

Using an older version? See the 1.2.0 readme.

Installation

npm i @alkhipce/editorjs-aitext
import AIText from '@alkhipce/editorjs-aitext'

Usage

var editor = EditorJS({
  ...

  tools: {
    ...
      aiText: {
        // if you do not use TypeScript you need to remove "as unknown as ToolConstructable" construction
        // type ToolConstructable imported from @editorjs/editorjs package
        class: AIText as unknown as ToolConstructable,
        config: {
          // here you need to provide your own suggestion provider (e.g., request to your backend)
          // this callback function must accept a string and return a Promise<string>
          callback: (text: string) => {
            return new Promise(resolve => {
              setTimeout(() => {
                resolve('AI: ' + text)
              }, 1000)
            })
          },
          acceptKeys: ['AltLeft', 'AltRight', 'Tab'], // default
          declineKeys: ['Escape', 'Backspace'],      // default
          debounceTimeout: 2000,               // default
          icon: '<svg>...</svg>',
          loaderIcon: '<svg>...</svg>',
        }
      },
  }

  ...
});

Config

FieldTypeDefaultDescription
callback(text: string) => Promise<string>โ€”Required. Called with current block content, must return a suggestion string
acceptKeysstring[]['AltLeft', 'AltRight', 'Tab']Keys that accept the suggestion (values are KeyboardEvent.code)
declineKeysstring[]['Escape', 'Backspace']Keys that decline the suggestion
debounceTimeoutnumber2000Delay in ms after last input before requesting a suggestion
iconstringbuilt-in SVGCustom SVG icon for the toolbox
loaderIconstringbuilt-in SVGCustom SVG icon for the loader shown while fetching

Output

{
  "type": "aiText",
  "data": {
    "text": "paragraph text here"
  }
}