Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@alkhipce/editorjs-aitext

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alkhipce/editorjs-aitext

Open AI text tool for Editor.js

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
115
increased by8.49%
Maintainers
1
Weekly downloads
 
Created
Source

AI Text Tool for Editor.js

AI suggestion text Tool for the Editor.js based on the default Paragraph Tool and OpenAI Node.js library.

While writing with this tool you will get some OpenAI suggestion after 2 seconds delay. You can accept or decline it.

image

Bindings:

Accept suggestion: 'Right or Left ALT buttons'
Decline suggestion: 'Backspace or ESC buttons'

Installation

Get the package

npm i @alkhipce/editorjs-aitext

Include module at your application

import AIText from '@alkhipce/editorjs-aitext'

Usage for ver >= 1.2.0

If your project uses versions lower than 1.2.0, please read the old tutorial below

Add a new Tool to the tools property of the Editor.js initial config.

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)
            })
          },
        }
      },
  }

  ...
});

Usage for ver < 1.2.0

Add a new Tool to the tools property of the Editor.js initial config.

var editor = EditorJS({
  ...

  tools: {
    ...
      aiText: {
        // if you do not use TypeScript you need to remove "as unknown as ToolConstructable" construction
        class: AIText as unknown as ToolConstructable,
        config: {
          openaiKey: 'YOUR_OPEN_AI_KEY'
        }
      },
  }

  ...
});

Config Params

The AI Text Tool supports these configuration parameters:

FieldTypeDescription
placeholderstringThe placeholder. Will be shown only in the first paragraph when the whole editor is empty.
preserveBlankboolean(default: false) Whether or not to keep blank paragraphs when saving editor data
(DEPRECATED) openaiKeystringRequired parameter
callbackfunctionRequired parameter. This callback function has to accept a string and return Promise

Output data

FieldTypeDescription
textstringparagraph's text
{
  "type": "aiText",
  "data": {
    "text": "Check out our projects on a <a href=\"https://github.com/codex-team\">GitHub page</a>."
  }
}

Roadmap

  1. Add types (done)
  2. Add styles file
  3. Improve loader icon

Keywords

FAQs

Package last updated on 31 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc