steven-tey / novel

Notion-style WYSIWYG editor with AI-powered autocompletion.
https://novel.sh
Apache License 2.0
12.47k stars 1.03k forks source link

How to get JSON output on save? #279

Open erbill opened 7 months ago

erbill commented 7 months ago

I'm using npm i novel and trying to customize Editor to export JSON data on save. Currently using

<Editor onUpdate={(editor) => { if (editor) { const content = editor.getJSON(); // Get the editor's content in JSON format console.log(content); // Log the content to the console setEditorData(content); } }} />

  but getting an Argument of type 'JSONContent' is not assignable to parameter of type 'SetStateAction<EditorContent | null>'.

Property 'blocks' is missing in type 'JSONContent' but required in type 'EditorContent'.ts(2345) page.tsx(17, 3): 'blocks' is declared here. Error

I tried adding `type Block = { type: string; data: { text: string; [key: string]: any; // Additional properties for different block types }; };

type EditorContent = { blocks: Block[]; };` but still not having JSON output.

Is there any default function for controlling exports?

andrewdoro commented 7 months ago

They this looks like a type error SetStateAction<EditorContent | null> because the editor export type for json is JSONContent New version exports a type for it:

import {type JSONContent} from "novel";

Also see usage here: https://github.com/steven-tey/novel/blob/main/apps/web/components/tailwind/editor.tsx