Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
cac4b1d4
authored
May 12, 2025
by
heheer
Committed by
GitHub
May 12, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix monaco editor default value (#4793)
* fix monaco editor default value * fix
parent
0ef3d402
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
6 deletions
+26
-6
packages/web/components/common/Textarea/JsonEditor/index.tsx
+23
-5
projects/app/src/web/core/chat/context/chatItemContext.tsx
+3
-1
No files found.
packages/web/components/common/Textarea/JsonEditor/index.tsx
View file @
cac4b1d4
import
React
,
{
useEffect
,
useCallback
,
useRef
,
useState
}
from
'react'
;
import
React
,
{
useEffect
,
useCallback
,
useRef
,
useState
,
useMemo
}
from
'react'
;
import
Editor
,
{
type
Monaco
,
loader
,
useMonaco
}
from
'@monaco-editor/react'
;
import
Editor
,
{
type
Monaco
,
loader
,
useMonaco
}
from
'@monaco-editor/react'
;
import
{
Box
,
type
BoxProps
}
from
'@chakra-ui/react'
;
import
{
Box
,
type
BoxProps
}
from
'@chakra-ui/react'
;
import
MyIcon
from
'../../Icon'
;
import
MyIcon
from
'../../Icon'
;
...
@@ -169,10 +169,27 @@ const JSONEditor = ({
...
@@ -169,10 +169,27 @@ const JSONEditor = ({
document
.
addEventListener
(
'mouseup'
,
handleMouseUp
);
document
.
addEventListener
(
'mouseup'
,
handleMouseUp
);
},
[]);
},
[]);
const
formatedValue
=
useMemo
(()
=>
{
if
(
typeof
value
===
'string'
)
{
return
value
;
}
if
(
value
===
undefined
||
value
===
null
)
{
return
''
;
}
try
{
return
JSON
.
stringify
(
value
,
null
,
2
);
}
catch
(
error
)
{
console
.
error
(
'JSON stringify error:'
,
error
);
return
String
(
value
)
||
''
;
}
},
[
value
]);
const
onBlur
=
useCallback
(()
=>
{
const
onBlur
=
useCallback
(()
=>
{
if
(
!
v
alue
)
return
;
if
(
!
formatedV
alue
)
return
;
// replace {{xx}} to true
// replace {{xx}} to true
const
replaceValue
=
v
alue
?.
replace
(
/{{
(
.*
?)
}}/g
,
'true'
);
const
replaceValue
=
formatedV
alue
?.
replace
(
/{{
(
.*
?)
}}/g
,
'true'
);
try
{
try
{
JSON
.
parse
(
replaceValue
);
JSON
.
parse
(
replaceValue
);
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -181,7 +198,8 @@ const JSONEditor = ({
...
@@ -181,7 +198,8 @@ const JSONEditor = ({
title
:
t
(
'common:json_parse_error'
)
title
:
t
(
'common:json_parse_error'
)
});
});
}
}
},
[
value
]);
},
[
formatedValue
,
toast
,
t
]);
const
beforeMount
=
useCallback
((
monaco
:
Monaco
)
=>
{
const
beforeMount
=
useCallback
((
monaco
:
Monaco
)
=>
{
monaco
.
languages
.
json
.
jsonDefaults
.
setDiagnosticsOptions
({
monaco
.
languages
.
json
.
jsonDefaults
.
setDiagnosticsOptions
({
validate
:
false
,
validate
:
false
,
...
@@ -241,7 +259,7 @@ const JSONEditor = ({
...
@@ -241,7 +259,7 @@ const JSONEditor = ({
theme=
"JSONEditorTheme"
theme=
"JSONEditorTheme"
beforeMount=
{
beforeMount
}
beforeMount=
{
beforeMount
}
defaultValue=
{
defaultValue
}
defaultValue=
{
defaultValue
}
value=
{
v
alue
}
value=
{
formatedV
alue
}
onChange=
{
(
e
)
=>
{
onChange=
{
(
e
)
=>
{
onChange
?.(
e
||
''
);
onChange
?.(
e
||
''
);
if
(
!
e
)
{
if
(
!
e
)
{
...
...
projects/app/src/web/core/chat/context/chatItemContext.tsx
View file @
cac4b1d4
...
@@ -151,7 +151,9 @@ const ChatItemContextProvider = ({
...
@@ -151,7 +151,9 @@ const ChatItemContextProvider = ({
});
});
}
}
variablesForm
.
setValue
(
'variables'
,
newVariableValue
);
Object
.
entries
(
newVariableValue
).
forEach
(([
key
,
value
])
=>
{
variablesForm
.
setValue
(
`variables.
${
key
}
`
,
value
);
});
},
},
[
variablesForm
]
[
variablesForm
]
);
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment