@@ -13,51 +13,55 @@ import { nodePasteRule, type PasteRuleFinder } from "@tiptap/core";
1313import EditorMenu from "./EditorMenu" ;
1414import { useEffect } from "react" ;
1515
16- const ImageFinder : PasteRuleFinder = / d a t a : i m a g e \/ / g;
16+ const getExtensions = ( ) => {
17+ const ImageFinder : PasteRuleFinder = / d a t a : i m a g e \/ / g;
1718
18- const ImageExtended = Image . extend ( {
19- name : "ImageExtended" ,
20- addPasteRules ( ) {
21- return [
22- nodePasteRule ( {
23- find : ImageFinder ,
24- type : this . type ,
25- getAttributes ( match ) {
26- if ( match . input ) {
27- return {
28- src : match . input ,
29- } ;
30- }
31- } ,
32- } ) ,
33- ] ;
34- } ,
35- } ) ;
19+ const ImageExtended = Image . extend ( {
20+ name : "ImageExtended" ,
21+ addPasteRules ( ) {
22+ return [
23+ nodePasteRule ( {
24+ find : ImageFinder ,
25+ type : this . type ,
26+ getAttributes ( match ) {
27+ if ( match . input ) {
28+ return {
29+ src : match . input ,
30+ } ;
31+ }
32+ } ,
33+ } ) ,
34+ ] ;
35+ } ,
36+ } ) ;
37+
38+ const lowlight = createLowlight ( common ) ;
3639
37- const lowlight = createLowlight ( common ) ;
40+ // define your extension array
41+ const extensions = [
42+ StarterKit . configure ( {
43+ codeBlock : false ,
44+ } ) ,
45+ CodeBlockLowlight . configure ( {
46+ lowlight,
47+ } ) ,
48+ Placeholder . configure ( { placeholder : "Start typing..." } ) ,
49+ Link . configure ( { openOnClick : true , autolink : true } ) ,
50+ TaskList ,
51+ TaskItem . configure ( {
52+ nested : true ,
53+ } ) ,
54+ ImageExtended ,
55+ ] ;
3856
39- // define your extension array
40- const extensions = [
41- StarterKit . configure ( {
42- codeBlock : false ,
43- } ) ,
44- CodeBlockLowlight . configure ( {
45- lowlight,
46- } ) ,
47- Placeholder . configure ( { placeholder : "Start typing..." } ) ,
48- Link . configure ( { openOnClick : true , autolink : true } ) ,
49- TaskList ,
50- TaskItem . configure ( {
51- nested : true ,
52- } ) ,
53- ImageExtended ,
54- ] ;
57+ return extensions ;
58+ } ;
5559
5660const Editor = ( ) => {
5761 const [ content , setContent ] = useAtom ( contentAtom ) ;
5862
5963 const editor = useEditor ( {
60- extensions,
64+ extensions : getExtensions ( ) ,
6165 content : content ? JSON . parse ( content ) : "" ,
6266 onUpdate : ( { editor } ) => {
6367 setContent ( JSON . stringify ( editor . getJSON ( ) ) ) ;
@@ -71,18 +75,21 @@ const Editor = () => {
7175 } ) ;
7276
7377 useEffect ( ( ) => {
74- const unsubscribe = $storage . subscribe ! ( 'st-content' , ( value ) => {
75- if ( editor ) {
76- editor . commands . setContent ( value ? JSON . parse ( value ) : "" ) ;
77- }
78- } , null ) ;
78+ const unsubscribe = $storage . subscribe ! (
79+ "st-content" ,
80+ ( value ) => {
81+ if ( editor ) {
82+ editor . commands . setContent ( value ? JSON . parse ( value ) : "" ) ;
83+ }
84+ } ,
85+ null
86+ ) ;
7987
8088 return ( ) => {
8189 unsubscribe ( ) ;
8290 } ;
8391 } , [ editor ] ) ;
8492
85-
8693 return (
8794 < >
8895 { editor && (
0 commit comments