fix/pretify json when paste content (#5216)
This commit is contained in:
parent
46c7f02827
commit
44b5310a6a
@ -41,6 +41,21 @@ export default function EditJsonMCPserver({
|
|||||||
}
|
}
|
||||||
}, [open, initialData])
|
}, [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 = () => {
|
const handleSave = () => {
|
||||||
try {
|
try {
|
||||||
const parsedData = JSON.parse(jsonContent)
|
const parsedData = JSON.parse(jsonContent)
|
||||||
@ -69,6 +84,7 @@ export default function EditJsonMCPserver({
|
|||||||
language="json"
|
language="json"
|
||||||
placeholder="Enter JSON configuration"
|
placeholder="Enter JSON configuration"
|
||||||
onChange={(e) => setJsonContent(e.target.value)}
|
onChange={(e) => setJsonContent(e.target.value)}
|
||||||
|
onPaste={handlePaste}
|
||||||
style={{
|
style={{
|
||||||
fontFamily: 'ui-monospace',
|
fontFamily: 'ui-monospace',
|
||||||
backgroundColor: 'transparent',
|
backgroundColor: 'transparent',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user