1.0.3 • Published 10 months ago

editorjs-plugin-textaction v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Text Action Tool

Text Action is a custom tool for the Editor.js framework that provides a simple text area and submit button interface for various use cases like AI-generated text requests or other prompt-based actions. This library is intended to be used mainly while creating documents with the Editor.js framework.

Installation

Install via NPM or Yarn

Get the package:

npm i editorjs-plugin-textaction

Include the module in your application:

import TextAction from 'editorjs-plugin-textaction';

Usage

Add the TextAction Tool to the tools property of the Editor.js initial configuration.

const editor = new EditorJS({
  ...
  tools: {
    textAction: {
      class: TextAction,
    }
  }
  ...
});

Or initialize the TextAction Tool with additional configuration options:

const editor = new EditorJS({
  ...
  tools: {
    textAction: {
      class: TextAction,
      config: {
        placeholder: 'Enter your prompt here',
        rows: 5,
        buttonText: 'Submit',
        onSubmit: async ({data, block}) => {
          // Handle submission logic
          console.log(`Submitted value: ${data.value}`);
          // You may perform an API call or any async operation here
          block.remove();
        },
      },
    },
  },
  ...
});

Config Params

FieldTypeDescription
placeholderstringPlaceholder text for the textarea input
rowsnumberNumber of rows for the textarea input
buttonTextstringText for the submit button
onSubmitfunctionCallback function executed on submit. Receives the submitted data and the block object for additional handling (like block removal).

Output Data

When saving data, the TextAction Tool returns the following structure:

FieldTypeDescription
valuestringThe current value of the text area
placeholderstringThe placeholder text used for the textarea
rowsnumberNumber of rows of the textarea
buttonTextstringText displayed on the submit button
onSubmitfunctionCallback function executed on submit

Example:

const outputData = {
    type : "textAction",
    data: {
        value: "Submitted text",
        placeholder: "Enter something",
        rows: 5,
        buttonText: "Submit",
        onSubmit: async ({data, block}) => {
            // Handle submission logic
            console.log(`Submitted value: ${data.value}`);
            // You may perform an API call or any async operation here
            block.remove();
        }
    }
}

Note: The onSubmit function is not serialized when it's json.

Theme

This tool supports both light and dark themes. To enable the dark theme, simply add a dark class to the parent element of the editor:

<div id="editorjs" class="dark"></div>

License

This project is licensed under the MIT License.

1.0.3

10 months ago

1.0.2

10 months ago

1.0.0

10 months ago