This plugin adds an AI WYSIWYG Editor to your Next.js Supabase SaaS application.
This plugin adds an AI Editor component Next.js application. You can import this component anywhere in your application.
It is built with Lexical, a text editor framework for React, by Meta.
This plugin is currently experimental and not yet officially released.
Using the Plugin
Installation
To install the plugin, you can use git subtrees from your original repository:
After running this command, you will have the plugin in your repository at plugins/text-editor. Once pulled, you can apply any customization you need.
Using the CLI
If you're using the CLI, you can run the following command to install the plugin:
Follow the instructions to install the plugin.
Add the plugin as a workspace in your package.json
You can do so by adding the following to your package.json file:
Add it next to the other workspaces in your package.json file.
Add the paths alias to the TypeScript configuration
To make sure that the TypeScript compiler can find the plugin, you will need to add the following paths alias to your tsconfig.json file, in addition to the other paths aliases that you may have.
If not yet present, add the following to your tsconfig.json file:
You only need to add this once, even if you have multiple plugins.
Installing dependencies
To install the dependencies, you can run the following command:
NPM will install the dependencies in the plugins/text-editor folder as an NPM workspace.
Add the required API handlers
You will need to add the following API handlers to your application:
api/ai/autocomplete/route.ts
api/ai/edit/route.ts
Edit Route
To add the edit route, create a file at src/app/api/ai/edit/route.ts with the following content:
Autocomplete Route
To add the autocomplete route, create a file at src/app/api/ai/autocomplete/route.ts with the following content:
Style
Import the CSS file at plugins/text-editor/editor.css into your global CSS file at src/app/styles/globals.css:
Using the plugin
To use the plugin, you can import the component from the plugin folder.
NB: the example below uses rxjs, which is a dependency not included in the kit. I do recommend using it, but you can use any other library to handle debouncing and other logic that you may need if you want to use autosaving for your application.
Now, import the component EditorContainer anywhere in your application: