@@ -2,27 +2,45 @@ import { Component, Prop, Part } from '@pictogrammers/element';
22
33import PgJsonArray from '../jsonArray/jsonArray' ;
44import PgJsonObject from '../jsonObject/jsonObject' ;
5+ import PgJsonString from '../jsonString/jsonString' ;
6+ import PgJsonBoolean from '../jsonBoolean/jsonBoolean' ;
7+ import PgJsonNumber from '../jsonNumber/jsonNumber' ;
58
69import template from './json.html' ;
710import style from './json.css' ;
811
12+ function getType ( value ) {
13+ if ( typeof value === 'string' ) {
14+ return PgJsonString ;
15+ }
16+ if ( typeof value === 'boolean' ) {
17+ return PgJsonBoolean ;
18+ }
19+ if ( typeof value === 'number' ) {
20+ return PgJsonNumber ;
21+ }
22+ }
23+
924function unwrapObject ( obj : any ) {
1025 return Object . keys ( obj ) . map ( ( key ) => {
1126 if ( Array . isArray ( obj [ key ] ) ) {
1227 return {
1328 key,
1429 value : unwrapArray ( obj [ key ] ) ,
30+ type : PgJsonArray ,
1531 } ;
1632 }
1733 if ( typeof obj [ key ] === 'object' ) {
1834 return {
1935 key,
2036 value : unwrapObject ( obj [ key ] ) ,
37+ type : PgJsonObject ,
2138 } ;
2239 }
2340 return {
2441 key,
2542 value : obj [ key ] ,
43+ type : getType ( obj [ key ] ) ,
2644 } ;
2745 } ) ;
2846}
@@ -33,17 +51,20 @@ function unwrapArray(items: any) {
3351 return {
3452 key : i . toString ( ) ,
3553 value : unwrapArray ( item ) ,
54+ type : PgJsonArray ,
3655 } ;
3756 }
3857 if ( typeof item === 'object' ) {
3958 return {
4059 key : i . toString ( ) ,
4160 value : unwrapObject ( item ) ,
61+ type : PgJsonObject ,
4262 } ;
4363 }
4464 return {
4565 key : i . toString ( ) ,
4666 value : item ,
67+ type : getType ( item ) ,
4768 }
4869 } ) ;
4970}
0 commit comments