@@ -3,7 +3,6 @@ import Editor from "react-simple-code-editor";
3
3
import Prism from "prismjs" ;
4
4
import "prismjs/components/prism-json" ;
5
5
import "prismjs/themes/prism.css" ;
6
- import { Button } from "@/components/ui/button" ;
7
6
8
7
interface JsonEditorProps {
9
8
value : string ;
@@ -16,49 +15,25 @@ const JsonEditor = ({
16
15
onChange,
17
16
error : externalError ,
18
17
} : JsonEditorProps ) => {
19
- const [ editorContent , setEditorContent ] = useState ( value ) ;
18
+ const [ editorContent , setEditorContent ] = useState ( value || "" ) ;
20
19
const [ internalError , setInternalError ] = useState < string | undefined > (
21
20
undefined ,
22
21
) ;
23
22
24
23
useEffect ( ( ) => {
25
- setEditorContent ( value ) ;
24
+ setEditorContent ( value || "" ) ;
26
25
} , [ value ] ) ;
27
26
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
-
36
27
const handleEditorChange = ( newContent : string ) => {
37
28
setEditorContent ( newContent ) ;
38
29
setInternalError ( undefined ) ;
39
30
onChange ( newContent ) ;
40
31
} ;
41
32
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
-
53
33
const displayError = internalError || externalError ;
54
34
55
35
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" >
62
37
< div
63
38
className = { `border rounded-md ${
64
39
displayError
0 commit comments