@@ -16,7 +16,7 @@ class JsonPathPreviewer extends Component {
1616 evalJsonPath ( json , jsonPath ) {
1717 try {
1818 return jp . paths ( json , jsonPath ) ;
19- } catch ( e ) {
19+ } catch ( e ) {
2020 return [ ] ;
2121 }
2222 }
@@ -25,22 +25,22 @@ class JsonPathPreviewer extends Component {
2525 if ( Array . isArray ( jsonAsObject ) ) {
2626 const doesTraversingPathMatch = paths . filter ( oneOfPathsToRetrieve => oneOfPathsToRetrieve . join ( ',' ) === traversedPath . join ( ',' ) ) . length > 0 ;
2727 const isALengthPathMatchingThisCollection = paths . filter ( oneOfPathsToRetrieve => oneOfPathsToRetrieve . join ( ',' ) === [ ...traversedPath , 'length' ] . join ( ',' ) ) . length > 0 ;
28- return `${ carriageReturnTag + indentationIncrementationTag } ${ doesTraversingPathMatch ? highlightingTags . start : '' } [${ carriageReturnTag + indentationIncrementationTag } ${ jsonAsObject . map ( ( item , index ) =>
28+ return `${ carriageReturnTag + indentationIncrementationTag } ${ doesTraversingPathMatch ? highlightingTags . start : '' } [${ carriageReturnTag + indentationIncrementationTag } ${ jsonAsObject . map ( ( item , index ) =>
2929 this . tagPartOfJsonToHighlight ( item , paths , [ ...traversedPath , index ] )
3030 ) . join ( ',' + carriageReturnTag ) } ${ indentationDecrementationTag + carriageReturnTag } ]${
31- doesTraversingPathMatch ? highlightingTags . end : ''
32- } ${ isALengthPathMatchingThisCollection ? highlightingTags . start + '.length = ' + jsonAsObject . length + highlightingTags . end : '' } ${ indentationDecrementationTag } `;
31+ doesTraversingPathMatch ? highlightingTags . end : ''
32+ } ${ isALengthPathMatchingThisCollection ? highlightingTags . start + '.length = ' + jsonAsObject . length + highlightingTags . end : '' } ${ indentationDecrementationTag } `;
3333 }
3434
3535 if ( typeof jsonAsObject === 'object' ) {
3636 const doesTraversingPathMatch = paths . filter ( oneOfPathsToRetrieve => oneOfPathsToRetrieve . join ( ',' ) === traversedPath . join ( ',' ) ) . length > 0 ;
37- return `${ doesTraversingPathMatch ? highlightingTags . start : '' } {${ carriageReturnTag + indentationIncrementationTag } ${ Object . keys ( jsonAsObject ) . map ( key =>
37+ return `${ doesTraversingPathMatch ? highlightingTags . start : '' } {${ carriageReturnTag + indentationIncrementationTag } ${ Object . keys ( jsonAsObject ) . map ( key =>
3838 `"${ key } ": ${ this . tagPartOfJsonToHighlight ( jsonAsObject [ key ] , paths , [ ...traversedPath , key ] ) } `
3939 ) . join ( ',' + carriageReturnTag ) } ${ indentationDecrementationTag + carriageReturnTag } }${ doesTraversingPathMatch ? highlightingTags . end : '' } `;
4040 }
41-
41+
4242 const doesTraversingPathMatch = paths . filter ( oneOfPathsToRetrieve => oneOfPathsToRetrieve . join ( ',' ) === traversedPath . join ( ',' ) ) . length > 0 ;
43-
43+
4444 if ( typeof jsonAsObject === 'number' ) {
4545 return `${ doesTraversingPathMatch ? highlightingTags . start : '' } ${ jsonAsObject } ${ doesTraversingPathMatch ? highlightingTags . end : '' } ` ;
4646 } else {
@@ -54,11 +54,11 @@ class JsonPathPreviewer extends Component {
5454 return taggedJSON . split ( carriageReturnTag ) . map ( line => {
5555 if ( line . includes ( indentationIncrementationTag ) ) increments ++ ;
5656 if ( line . includes ( highlightingTags . start + '[' ) || line . includes ( highlightingTags . start + '{' ) ) isBlockHighlighted = true ;
57- const isLineSelectable = line . includes ( ':' ) ;
57+ // const isLineSelectable = line.includes(':');
5858 const toReturn = < React . Fragment >
59- < p className = { ( isBlockHighlighted ? 'highlighted ' : '' ) + ( isLineSelectable ? 'selectable' : '' ) } >
59+ < p className = { ( isBlockHighlighted ? 'highlighted ' : '' ) /* + (isLineSelectable ? 'selectable' : '')*/ } >
6060 { Array ( increments ) . fill ( < React . Fragment > </ React . Fragment > ) }
61- { line . replace ( new RegExp ( indentationIncrementationTag , 'g' ) , '' ) . replace ( new RegExp ( indentationDecrementationTag , 'g' ) , '' )
61+ { line . replace ( new RegExp ( indentationIncrementationTag , 'g' ) , '' ) . replace ( new RegExp ( indentationDecrementationTag , 'g' ) , '' )
6262 . split ( highlightingTags . start ) . map ( jsonPart => {
6363 const parts = jsonPart . split ( highlightingTags . end ) ;
6464 if ( parts . length === 2 ) {
@@ -75,14 +75,16 @@ class JsonPathPreviewer extends Component {
7575 }
7676
7777 render ( ) {
78- const { json, jsonPath} = this . props ;
78+ const { json, jsonPath } = this . props ;
7979
8080 const pathsEvaluated = this . evalJsonPath ( json , jsonPath ) ;
8181
8282 return (
83- < code >
84- { this . convertTaggedJsonAsReactComponent ( this . tagPartOfJsonToHighlight ( json , pathsEvaluated ) ) }
85- </ code >
83+ < div className = 'react-json-path-editor-jsoneditor-container' >
84+ < code >
85+ { this . convertTaggedJsonAsReactComponent ( this . tagPartOfJsonToHighlight ( json , pathsEvaluated ) ) }
86+ </ code >
87+ </ div >
8688 ) ;
8789 }
8890}
0 commit comments