8
8
type ErrorString ,
9
9
type NodeData ,
10
10
type JerError ,
11
+ type CollectionData ,
11
12
ERROR_DISPLAY_TIME ,
12
- CollectionData ,
13
13
} from './types'
14
14
import { Icon } from './Icons'
15
15
import { filterNode , isCollection } from './filterHelpers'
@@ -55,8 +55,17 @@ export const CollectionNode: React.FC<CollectionNodeProps> = ({
55
55
defaultValue,
56
56
translate,
57
57
customNodeDefinitions,
58
+ useJSON5Editor,
58
59
} = props
59
- const [ stringifiedValue , setStringifiedValue ] = useState ( JSON . stringify ( data , null , 2 ) )
60
+ const stringifyJson = useMemo ( ( ) => {
61
+ if ( ! useJSON5Editor ) return ( data : object ) => JSON . stringify ( data , null , 2 )
62
+ if ( useJSON5Editor instanceof Object ) {
63
+ return ( data : object ) => JSON5 . stringify ( data , useJSON5Editor )
64
+ }
65
+ return ( data : object ) => JSON5 . stringify ( data , { space : 2 } )
66
+ } , [ useJSON5Editor ] )
67
+
68
+ const [ stringifiedValue , setStringifiedValue ] = useState ( stringifyJson ( data ) )
60
69
const [ error , setError ] = useState < string | null > ( null )
61
70
62
71
const startCollapsed = collapseFilter ( incomingNodeData )
@@ -77,7 +86,7 @@ export const CollectionNode: React.FC<CollectionNodeProps> = ({
77
86
const [ isAnimating , setIsAnimating ] = useState ( false )
78
87
79
88
useEffect ( ( ) => {
80
- setStringifiedValue ( JSON . stringify ( data , null , 2 ) )
89
+ setStringifiedValue ( stringifyJson ( data ) )
81
90
} , [ data ] )
82
91
83
92
useEffect ( ( ) => {
@@ -249,7 +258,7 @@ export const CollectionNode: React.FC<CollectionNodeProps> = ({
249
258
const handleCancel = ( ) => {
250
259
setCurrentlyEditingElement ( null )
251
260
setError ( null )
252
- setStringifiedValue ( JSON . stringify ( data , null , 2 ) )
261
+ setStringifiedValue ( stringifyJson ( data ) )
253
262
}
254
263
255
264
// DERIVED VALUES (this makes the JSX logic less messy)
0 commit comments