@@ -41,6 +41,12 @@ export interface JsonNodeElement extends JsonNodesStubElement {
4141 * withsStubs is true by default, it makes sure, that opened stubs are represented
4242 */
4343 getOpenPaths ( withStubs ?: boolean ) : string [ ] [ ] ;
44+
45+ openNode ( dispatchEvent ?: boolean ) : Promise < boolean > ;
46+
47+ closeNode ( dispatchEvent ?: boolean ) : Promise < boolean > ;
48+
49+ toggleNode ( dispatchEvent ?: boolean ) : Promise < boolean > ;
4450}
4551
4652export class BigJsonViewerDom {
@@ -203,23 +209,23 @@ export class BigJsonViewerDom {
203209 }
204210 return false ;
205211 } ;
206- nodeElement . openNode = async ( ) => {
212+ nodeElement . openNode = async ( dispatchEvent = false ) => {
207213 if ( this . isOpenableNode ( node ) ) {
208- return await this . openNode ( nodeElement ) ;
214+ return await this . openNode ( nodeElement , dispatchEvent ) ;
209215 }
210216 return false ;
211217 } ;
212- nodeElement . closeNode = async ( ) => {
218+ nodeElement . closeNode = async ( dispatchEvent = false ) => {
213219 if ( this . isOpenableNode ( node ) ) {
214- return this . closeNode ( nodeElement ) ;
220+ return this . closeNode ( nodeElement , dispatchEvent ) ;
215221 }
216222 return false ;
217223 } ;
218- nodeElement . toggleNode = async ( ) => {
224+ nodeElement . toggleNode = async ( dispatchEvent = false ) => {
219225 if ( nodeElement . isNodeOpen ( ) ) {
220- return await nodeElement . closeNode ( ) ;
226+ return await nodeElement . closeNode ( dispatchEvent ) ;
221227 } else {
222- return await nodeElement . openNode ( ) ;
228+ return await nodeElement . openNode ( dispatchEvent ) ;
223229 }
224230 } ;
225231
@@ -253,7 +259,7 @@ export class BigJsonViewerDom {
253259 e . preventDefault ( ) ;
254260 const nodeElement = this . findNodeElement ( anchor ) ;
255261 if ( nodeElement ) {
256- nodeElement . toggleNode ( ) ;
262+ nodeElement . toggleNode ( true ) ;
257263 }
258264 } ) ;
259265 }
@@ -727,7 +733,11 @@ export class BigJsonViewerDom {
727733 }
728734 } else {
729735 const nodes = await this . getChildNodes ( node . path , 0 , limit ) ;
730- this . addChildNodes ( nodes , element ) ;
736+ this . addChildNodes (
737+ nodes ,
738+ element ,
739+ node . type === 'array' ? this . options . collapseSameValue : Infinity
740+ ) ;
731741 }
732742 return element ;
733743 }
@@ -765,6 +775,7 @@ export class BigJsonViewerDom {
765775 } else {
766776 this . openPaginationStub (
767777 stubElement ,
778+ node ,
768779 await this . getChildNodes ( node . path , start , limit ) ,
769780 true
770781 ) ;
@@ -779,6 +790,7 @@ export class BigJsonViewerDom {
779790 if ( ! stubElement . isNodeOpen ( ) ) {
780791 await this . openPaginationStub (
781792 stubElement ,
793+ node ,
782794 await this . getChildNodes ( node . path , start , limit )
783795 ) ;
784796 return true ;
@@ -821,21 +833,30 @@ export class BigJsonViewerDom {
821833
822834 protected openPaginationStub (
823835 stubElement : JsonNodesStubElement ,
836+ node : BigJsonViewerNode ,
824837 nodes : BigJsonViewerNode [ ] ,
825838 dispatchEvent = false
826839 ) {
827840 stubElement . headerElement . classList . add ( 'json-node-open' ) ;
828841 const children = document . createElement ( 'div' ) ;
829842 children . classList . add ( 'json-node-children' ) ;
830843 stubElement . childrenElement = children ;
831- this . addChildNodes ( nodes , children ) ;
844+ this . addChildNodes (
845+ nodes ,
846+ children ,
847+ node . type === 'array' ? this . options . collapseSameValue : Infinity
848+ ) ;
832849 stubElement . appendChild ( children ) ;
833850 if ( dispatchEvent ) {
834851 this . dispatchNodeEvent ( 'openStub' , stubElement ) ;
835852 }
836853 }
837854
838- protected addChildNodes ( nodes : BigJsonViewerNode [ ] , parent : HTMLElement ) {
855+ protected addChildNodes (
856+ nodes : BigJsonViewerNode [ ] ,
857+ parent : HTMLElement ,
858+ collapseSameValue : number
859+ ) {
839860 let lastValue : any ;
840861 let sameValueCount = 0 ;
841862
@@ -846,10 +867,10 @@ export class BigJsonViewerDom {
846867 lastValue === node . value
847868 ) {
848869 sameValueCount ++ ;
849- if ( sameValueCount >= this . options . collapseSameValue ) {
870+ if ( sameValueCount >= collapseSameValue ) {
850871 return ;
851872 }
852- } else if ( sameValueCount >= this . options . collapseSameValue ) {
873+ } else if ( sameValueCount >= collapseSameValue ) {
853874 parent . appendChild ( this . getCollapseIndicator ( sameValueCount ) ) ;
854875 parent . appendChild ( this . getNodeElement ( nodes [ i - 1 ] ) ) ;
855876 sameValueCount = 0 ;
@@ -859,11 +880,9 @@ export class BigJsonViewerDom {
859880 parent . appendChild ( this . getNodeElement ( node ) ) ;
860881 lastValue = node . value ;
861882 } ) ;
862- if ( sameValueCount >= this . options . collapseSameValue ) {
883+ if ( sameValueCount >= collapseSameValue ) {
863884 parent . appendChild (
864- this . getCollapseIndicator (
865- sameValueCount - this . options . collapseSameValue
866- )
885+ this . getCollapseIndicator ( sameValueCount - collapseSameValue )
867886 ) ;
868887 parent . appendChild ( this . getNodeElement ( nodes [ nodes . length - 1 ] ) ) ;
869888 }
0 commit comments