repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | "use client" |
| #2 | |
| #3 | import type React from "react" |
| #4 | |
| #5 | import { useState, useEffect } from "react" |
| #6 | import { AlertCircle, CheckCircle2 } from "lucide-react" |
| #7 | import { Alert, AlertDescription } from "./ui/alert" |
| #8 | import { Button } from "./ui/button" |
| #9 | import { Textarea } from "./ui/textarea" |
| #10 | |
| #11 | interface JsonEditorProps { |
| #12 | value: any |
| #13 | onChange: (value: any) => void |
| #14 | } |
| #15 | |
| #16 | export function JsonEditor({ value, onChange }: JsonEditorProps) { |
| #17 | const [jsonString, setJsonString] = useState("") |
| #18 | const [error, setError] = useState<string | null>(null) |
| #19 | const [isValid, setIsValid] = useState(true) |
| #20 | |
| #21 | useEffect(() => { |
| #22 | try { |
| #23 | setJsonString(JSON.stringify(value, null, 2)) |
| #24 | setIsValid(true) |
| #25 | setError(null) |
| #26 | } catch (err) { |
| #27 | setError("Invalid JSON object") |
| #28 | setIsValid(false) |
| #29 | } |
| #30 | }, [value]) |
| #31 | |
| #32 | const handleTextChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => { |
| #33 | setJsonString(e.target.value) |
| #34 | try { |
| #35 | JSON.parse(e.target.value) |
| #36 | setIsValid(true) |
| #37 | setError(null) |
| #38 | } catch (err) { |
| #39 | setError("Invalid JSON syntax") |
| #40 | setIsValid(false) |
| #41 | } |
| #42 | } |
| #43 | |
| #44 | const handleApply = () => { |
| #45 | try { |
| #46 | const parsed = JSON.parse(jsonString) |
| #47 | onChange(parsed) |
| #48 | setIsValid(true) |
| #49 | setError(null) |
| #50 | } catch (err) { |
| #51 | setError("Failed to apply changes: Invalid JSON") |
| #52 | } |
| #53 | } |
| #54 | |
| #55 | return ( |
| #56 | <div className="space-y-4"> |
| #57 | <div className="relative"> |
| #58 | <Textarea value={jsonString} onChange={handleTextChange} className="font-mono h-[600px] resize-none" /> |
| #59 | <div className="absolute top-3 right-3"> |
| #60 | {isValid ? ( |
| #61 | <CheckCircle2 className="h-5 w-5 text-green-500" /> |
| #62 | ) : ( |
| #63 | <AlertCircle className="h-5 w-5 text-red-500" /> |
| #64 | )} |
| #65 | </div> |
| #66 | </div> |
| #67 | |
| #68 | {error && ( |
| #69 | <Alert variant="destructive"> |
| #70 | <AlertDescription>{error}</AlertDescription> |
| #71 | </Alert> |
| #72 | )} |
| #73 | |
| #74 | <Button onClick={handleApply} disabled={!isValid} className="w-full"> |
| #75 | Apply Changes |
| #76 | </Button> |
| #77 | </div> |
| #78 | ) |
| #79 | } |