File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -58,9 +58,9 @@ const Editor = () => {
5858
5959 const editor = useEditor ( {
6060 extensions,
61- content : content ,
61+ content : content ? JSON . parse ( content ) : "" ,
6262 onUpdate : ( { editor } ) => {
63- setContent ( editor . getHTML ( ) ) ;
63+ setContent ( JSON . stringify ( editor . getJSON ( ) ) ) ;
6464 } ,
6565 editorProps : {
6666 attributes : {
@@ -73,7 +73,7 @@ const Editor = () => {
7373 useEffect ( ( ) => {
7474 const unsubscribe = $storage . subscribe ! ( 'st-content' , ( value ) => {
7575 if ( editor ) {
76- editor . commands . setContent ( value ) ;
76+ editor . commands . setContent ( value ? JSON . parse ( value ) : "" ) ;
7777 }
7878 } , null ) ;
7979
Original file line number Diff line number Diff line change @@ -73,9 +73,17 @@ export const $storage = getStorage();
7373
7474const ST_CONTENT_KEY = "st-content" ;
7575
76+
77+ const defaultContent = {
78+ "type" : "doc" ,
79+ "content" : Array ( 20 ) . fill ( {
80+ "type" : "paragraph"
81+ } )
82+ } ;
83+
7684export const contentAtom = atomWithStorage < string | null > (
7785 ST_CONTENT_KEY ,
78- "<p></p>" . repeat ( 20 ) ,
86+ JSON . stringify ( defaultContent ) ,
7987 $storage ,
8088 {
8189 getOnInit : true ,
You can’t perform that action at this time.
0 commit comments