1
- " use strict"
1
+ ' use strict' ;
2
2
3
3
//import react and reactDom for browser rendering
4
- import React from " react"
5
- import ReactDom from " react-dom"
4
+ import React from ' react' ;
5
+ import ReactDom from ' react-dom' ;
6
6
7
- import Moment from " moment"
7
+ import Moment from ' moment' ;
8
8
9
9
//import the react-json-view component (installed with npm)
10
- import JsonViewer from " ./../../src/js/index"
10
+ import JsonViewer from ' ./../../src/js/index' ;
11
11
12
12
//render 2 different examples of the react-json-view component
13
13
ReactDom . render (
14
14
< div >
15
15
{ /* just pass in your JSON to the src attribute */ }
16
16
< JsonViewer
17
17
sortKeys
18
- style = { { padding : " 30px" , backgroundColor : " white" } }
18
+ style = { { padding : ' 30px' , backgroundColor : ' white' } }
19
19
src = { getExampleJson1 ( ) }
20
20
collapseStringsAfterLength = { 12 }
21
21
onEdit = { e => {
22
- console . log ( " edit callback" , e )
23
- if ( e . new_value == " error" ) {
24
- return false
22
+ console . log ( ' edit callback' , e ) ;
23
+ if ( e . new_value == ' error' ) {
24
+ return false ;
25
25
}
26
26
} }
27
27
onDelete = { e => {
28
- console . log ( " delete callback" , e )
28
+ console . log ( ' delete callback' , e ) ;
29
29
} }
30
30
onAdd = { e => {
31
- console . log ( " add callback" , e )
32
- if ( e . new_value == " error" ) {
33
- return false
31
+ console . log ( ' add callback' , e ) ;
32
+ if ( e . new_value == ' error' ) {
33
+ return false ;
34
34
}
35
35
} }
36
36
onSelect = { e => {
37
- console . log ( " select callback" , e )
38
- console . log ( e . namespace )
37
+ console . log ( ' select callback' , e ) ;
38
+ console . log ( e . namespace ) ;
39
39
} }
40
40
displayObjectSize = { true }
41
- name = { " dev-server" }
41
+ name = { ' dev-server' }
42
42
enableClipboard = { copy => {
43
- console . log ( " you copied to clipboard!" , copy )
43
+ console . log ( ' you copied to clipboard!' , copy ) ;
44
44
} }
45
45
shouldCollapse = { ( { src, namespace, type } ) => {
46
- if ( type === " array" && src . indexOf ( " test" ) > - 1 ) {
47
- return true
48
- } else if ( namespace . indexOf ( " moment" ) > - 1 ) {
49
- return true
46
+ if ( type === ' array' && src . indexOf ( ' test' ) > - 1 ) {
47
+ return true ;
48
+ } else if ( namespace . indexOf ( ' moment' ) > - 1 ) {
49
+ return true ;
50
50
}
51
- return false
51
+ return false ;
52
52
} }
53
53
defaultValue = ""
54
54
/>
@@ -62,26 +62,26 @@ ReactDom.render(
62
62
validationMessage = "You're doing something wrong."
63
63
collapseStringsAfterLength = { 15 }
64
64
onEdit = { e => {
65
- console . log ( e )
66
- if ( e . new_value === " error" ) {
67
- return false
65
+ console . log ( e ) ;
66
+ if ( e . new_value === ' error' ) {
67
+ return false ;
68
68
}
69
69
} }
70
70
onDelete = { e => {
71
- console . log ( e )
71
+ console . log ( e ) ;
72
72
} }
73
73
onAdd = { e => {
74
- console . log ( e )
75
- if ( e . new_value === " error" ) {
76
- return false
74
+ console . log ( e ) ;
75
+ if ( e . new_value === ' error' ) {
76
+ return false ;
77
77
}
78
78
} }
79
79
name = { false }
80
80
iconStyle = "triangle"
81
81
shouldCollapse = { ( { src, type } ) =>
82
- type === " object" &&
82
+ type === ' object' &&
83
83
src . constructor &&
84
- src . constructor . name === " Moment"
84
+ src . constructor . name === ' Moment'
85
85
}
86
86
/>
87
87
@@ -91,7 +91,7 @@ ReactDom.render(
91
91
< JsonViewer
92
92
src = { getExampleJson2 ( ) }
93
93
collapsed = { true }
94
- name = { " feature_set" }
94
+ name = { ' feature_set' }
95
95
displayDataTypes = { false }
96
96
indentWidth = { 2 }
97
97
/>
@@ -102,7 +102,7 @@ ReactDom.render(
102
102
< JsonViewer
103
103
src = { getExampleJson2 ( ) }
104
104
collapsed = { 1 }
105
- name = { " feature_set" }
105
+ name = { ' feature_set' }
106
106
displayDataTypes = { false }
107
107
indentWidth = { 5 }
108
108
/>
@@ -113,7 +113,7 @@ ReactDom.render(
113
113
< JsonViewer
114
114
src = { getExampleJson3 ( ) }
115
115
collapsed = { true }
116
- name = { " collapsed_by_default_example" }
116
+ name = { ' collapsed_by_default_example' }
117
117
indentWidth = { 8 }
118
118
displayObjectSize = { false }
119
119
displayDataTypes = { false }
@@ -127,7 +127,7 @@ ReactDom.render(
127
127
src = { getExampleArray ( ) }
128
128
theme = "solarized"
129
129
onEdit = { edit => {
130
- console . log ( edit )
130
+ console . log ( edit ) ;
131
131
} }
132
132
/>
133
133
@@ -138,25 +138,25 @@ ReactDom.render(
138
138
enableClipboard = { false }
139
139
src = { getExampleJson1 ( ) }
140
140
shouldCollapse = { ( { src, namespace, type } ) =>
141
- namespace . indexOf ( " moment" ) > - 1
141
+ namespace . indexOf ( ' moment' ) > - 1
142
142
}
143
143
theme = { {
144
- base00 : " white" ,
145
- base01 : " #ddd" ,
146
- base02 : " #ddd" ,
147
- base03 : " #444" ,
148
- base04 : " purple" ,
149
- base05 : " #444" ,
150
- base06 : " #444" ,
151
- base07 : " #444" ,
152
- base08 : " #444" ,
153
- base09 : " rgba(70, 70, 230, 1)" ,
154
- base0A : " rgba(70, 70, 230, 1)" ,
155
- base0B : " rgba(70, 70, 230, 1)" ,
156
- base0C : " rgba(70, 70, 230, 1)" ,
157
- base0D : " rgba(70, 70, 230, 1)" ,
158
- base0E : " rgba(70, 70, 230, 1)" ,
159
- base0F : " rgba(70, 70, 230, 1)"
144
+ base00 : ' white' ,
145
+ base01 : ' #ddd' ,
146
+ base02 : ' #ddd' ,
147
+ base03 : ' #444' ,
148
+ base04 : ' purple' ,
149
+ base05 : ' #444' ,
150
+ base06 : ' #444' ,
151
+ base07 : ' #444' ,
152
+ base08 : ' #444' ,
153
+ base09 : ' rgba(70, 70, 230, 1)' ,
154
+ base0A : ' rgba(70, 70, 230, 1)' ,
155
+ base0B : ' rgba(70, 70, 230, 1)' ,
156
+ base0C : ' rgba(70, 70, 230, 1)' ,
157
+ base0D : ' rgba(70, 70, 230, 1)' ,
158
+ base0E : ' rgba(70, 70, 230, 1)' ,
159
+ base0F : ' rgba(70, 70, 230, 1)'
160
160
} }
161
161
/>
162
162
@@ -168,8 +168,8 @@ ReactDom.render(
168
168
src = { getExampleJson4 ( ) }
169
169
/>
170
170
</ div > ,
171
- document . getElementById ( " app-container" )
172
- )
171
+ document . getElementById ( ' app-container' )
172
+ ) ;
173
173
174
174
/*-------------------------------------------------------------------------*/
175
175
/* the following functions just contain test json data for display */
@@ -178,108 +178,108 @@ ReactDom.render(
178
178
//just a function to get an example JSON object
179
179
function getExampleJson1 ( ) {
180
180
return {
181
- string : " this is a test string" ,
181
+ string : ' this is a test string' ,
182
182
integer : 42 ,
183
183
empty_array : [ ] ,
184
184
empty_object : { } ,
185
- array : [ 1 , 2 , 3 , " test" ] ,
185
+ array : [ 1 , 2 , 3 , ' test' ] ,
186
186
float : - 2.757 ,
187
187
undefined_var : undefined ,
188
188
parent : {
189
189
sibling1 : true ,
190
190
sibling2 : false ,
191
191
sibling3 : null ,
192
192
isString : value => {
193
- if ( typeof value === " string" ) {
194
- return " string"
193
+ if ( typeof value === ' string' ) {
194
+ return ' string' ;
195
195
} else {
196
- return " other"
196
+ return ' other' ;
197
197
}
198
198
}
199
199
} ,
200
- string_number : " 1234" ,
200
+ string_number : ' 1234' ,
201
201
date : new Date ( ) ,
202
202
moment : Moment ( ) ,
203
203
regexp : / [ 0 - 9 ] / gi
204
- }
204
+ } ;
205
205
}
206
206
207
207
//and another a function to get an example JSON object
208
208
function getExampleJson2 ( ) {
209
209
return {
210
210
normalized : {
211
- " 1-grams" : {
211
+ ' 1-grams' : {
212
212
body : 1 ,
213
213
testing : 1
214
214
} ,
215
- " 2-grams" : {
216
- " testing body" : 1
215
+ ' 2-grams' : {
216
+ ' testing body' : 1
217
217
} ,
218
- " 3-grams" : { }
218
+ ' 3-grams' : { }
219
219
} ,
220
220
noun_phrases : {
221
221
body : 1
222
222
} ,
223
223
lemmatized : {
224
- " 1-grams" : {
224
+ ' 1-grams' : {
225
225
test : 1 ,
226
226
body : 1
227
227
} ,
228
- " 2-grams" : {
229
- " test body" : 1
228
+ ' 2-grams' : {
229
+ ' test body' : 1
230
230
} ,
231
- " 3-grams" : { }
231
+ ' 3-grams' : { }
232
232
} ,
233
233
dependency : {
234
- " 1-grams" : {
234
+ ' 1-grams' : {
235
235
testingVERBROOTtestingVERB : 1 ,
236
236
bodyNOUNdobjtestingVERB : 1
237
237
} ,
238
- " 2-grams" : {
239
- " testingVERBROOTtestingVERB bodyNOUNdobjtestingVERB" : 1
238
+ ' 2-grams' : {
239
+ ' testingVERBROOTtestingVERB bodyNOUNdobjtestingVERB' : 1
240
240
} ,
241
- " 3-grams" : { }
241
+ ' 3-grams' : { }
242
242
}
243
- }
243
+ } ;
244
244
}
245
245
246
246
function getExampleJson3 ( ) {
247
247
return {
248
248
example_information :
249
- " this example has the collapsed prop set to true and the indentWidth prop is set to 8" ,
249
+ ' this example has the collapsed prop set to true and the indentWidth prop is set to 8' ,
250
250
default_collapsed : true ,
251
251
collapsed_array : [
252
- " you expanded me" ,
253
- " try collapsing and expanding the root node" ,
254
- " i will still be expanded" ,
252
+ ' you expanded me' ,
253
+ ' try collapsing and expanding the root node' ,
254
+ ' i will still be expanded' ,
255
255
{
256
256
leaf_node : true
257
257
}
258
258
]
259
- }
259
+ } ;
260
260
}
261
261
262
262
function getExampleJson4 ( ) {
263
263
const large_array = new Array ( 225 ) . fill (
264
- " this is a large array full of items"
265
- )
264
+ ' this is a large array full of items'
265
+ ) ;
266
266
267
- large_array . push ( getExampleArray ( ) )
267
+ large_array . push ( getExampleArray ( ) ) ;
268
268
269
- large_array . push ( new Array ( 75 ) . fill ( Math . random ( ) ) )
269
+ large_array . push ( new Array ( 75 ) . fill ( Math . random ( ) ) ) ;
270
270
271
- return large_array
271
+ return large_array ;
272
272
}
273
273
274
274
function getExampleArray ( ) {
275
275
return [
276
- " you can also display arrays!" ,
276
+ ' you can also display arrays!' ,
277
277
new Date ( ) ,
278
278
1 ,
279
279
2 ,
280
280
3 ,
281
281
{
282
282
pretty_cool : true
283
283
}
284
- ]
284
+ ] ;
285
285
}
0 commit comments