@@ -64,7 +64,7 @@ class JsonDiffViewer extends HTMLElement {
6464 } ,
6565 } ) ;
6666 #stats = { } ;
67- #showOnlyChanged = false ;
67+ #showOnlyChanged = true ;
6868
6969 static observedAttributes = [ "left" , "right" ] ;
7070 constructor ( ) {
@@ -139,6 +139,8 @@ class JsonDiffViewer extends HTMLElement {
139139 this . shadowRoot . innerHTML = `<style>${ styles } </style><div class="empty">Provide left and right JSON</div>` ;
140140 return ;
141141 }
142+ const panel = this . shadowRoot . querySelector ( '.panel' ) ;
143+ const scroll = { top : panel ?. scrollTop || 0 , left : panel ?. scrollLeft || 0 } ;
142144 this . shadowRoot . innerHTML = `
143145 <style>${ styles } </style>
144146 <div class="stats">
@@ -163,6 +165,10 @@ class JsonDiffViewer extends HTMLElement {
163165 . join ( "" ) }
164166 </div>` ;
165167 this . #bind( ) ;
168+ this . shadowRoot . querySelectorAll ( '.panel' ) . forEach ( p => {
169+ p . scrollTop = scroll . top ;
170+ p . scrollLeft = scroll . left ;
171+ } ) ;
166172 }
167173
168174 #renderNode( node , side , path , root = true , placeholderParam = false ) {
@@ -173,10 +179,11 @@ class JsonDiffViewer extends HTMLElement {
173179 const hidden = placeholder ? ' style="visibility: hidden;"' : "" ;
174180 const keyHtml = buildKeyHtml ( node . key , root , placeholder ) ;
175181
176- if ( value === undefined ) {
177- if ( ! node . children ?. length ) {
178- return `<div class="node${ rootClass } "><div class="line placeholder">${ keyHtml } </div></div>` ;
179- }
182+ if ( value === undefined && ! node . children ?. length ) {
183+ const otherValue = side === 'left' ? node . right : node . left ;
184+ const [ val , type ] = format ( otherValue ) ;
185+ const hiddenKey = buildKeyHtml ( node . key , root , true ) ;
186+ return `<div class="node${ rootClass } "><div class="line placeholder">${ hiddenKey } <span class="val-${ type } " style="visibility: hidden;">${ val } </span></div></div>` ;
180187 }
181188
182189 if ( value !== undefined && ! node . isArray && ! node . isObject ) {
0 commit comments