@@ -3,7 +3,6 @@ import Editor from "react-simple-code-editor";
33import Prism from "prismjs" ;
44import "prismjs/components/prism-json" ;
55import "prismjs/themes/prism.css" ;
6- import { Button } from "@/components/ui/button" ;
76
87interface JsonEditorProps {
98 value : string ;
@@ -16,49 +15,25 @@ const JsonEditor = ({
1615 onChange,
1716 error : externalError ,
1817} : JsonEditorProps ) => {
19- const [ editorContent , setEditorContent ] = useState ( value ) ;
18+ const [ editorContent , setEditorContent ] = useState ( value || "" ) ;
2019 const [ internalError , setInternalError ] = useState < string | undefined > (
2120 undefined ,
2221 ) ;
2322
2423 useEffect ( ( ) => {
25- setEditorContent ( value ) ;
24+ setEditorContent ( value || "" ) ;
2625 } , [ value ] ) ;
2726
28- const formatJson = ( json : string ) : string => {
29- try {
30- return JSON . stringify ( JSON . parse ( json ) , null , 2 ) ;
31- } catch {
32- return json ;
33- }
34- } ;
35-
3627 const handleEditorChange = ( newContent : string ) => {
3728 setEditorContent ( newContent ) ;
3829 setInternalError ( undefined ) ;
3930 onChange ( newContent ) ;
4031 } ;
4132
42- const handleFormatJson = ( ) => {
43- try {
44- const formatted = formatJson ( editorContent ) ;
45- setEditorContent ( formatted ) ;
46- onChange ( formatted ) ;
47- setInternalError ( undefined ) ;
48- } catch ( err ) {
49- setInternalError ( err instanceof Error ? err . message : "Invalid JSON" ) ;
50- }
51- } ;
52-
5333 const displayError = internalError || externalError ;
5434
5535 return (
56- < div className = "relative space-y-2" >
57- < div className = "flex justify-end" >
58- < Button variant = "outline" size = "sm" onClick = { handleFormatJson } >
59- Format JSON
60- </ Button >
61- </ div >
36+ < div className = "relative" >
6237 < div
6338 className = { `border rounded-md ${
6439 displayError
0 commit comments