fix/pretify json when paste content (#5216)

This commit is contained in:
Faisal Amir 2025-06-09 11:04:29 +07:00 committed by GitHub
parent 46c7f02827
commit 44b5310a6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -41,6 +41,21 @@ export default function EditJsonMCPserver({
}
}, [open, initialData])
const handlePaste = (e: React.ClipboardEvent) => {
const pastedText = e.clipboardData.getData('text')
try {
const parsedJson = JSON.parse(pastedText)
const prettifiedJson = JSON.stringify(parsedJson, null, 2)
e.preventDefault()
setJsonContent(prettifiedJson)
setError(null)
} catch (error) {
e.preventDefault()
setError('Invalid JSON format in pasted content')
console.error('Paste error:', error)
}
}
const handleSave = () => {
try {
const parsedData = JSON.parse(jsonContent)
@ -69,6 +84,7 @@ export default function EditJsonMCPserver({
language="json"
placeholder="Enter JSON configuration"
onChange={(e) => setJsonContent(e.target.value)}
onPaste={handlePaste}
style={{
fontFamily: 'ui-monospace',
backgroundColor: 'transparent',