@@ -29,7 +29,7 @@ function getDiff(ours: Description, theirs: Description) {
2929 diff [ key ] = { ours : ours [ key ] , theirs : theirs [ key ] } ;
3030 else if ( Array . isArray ( val ) ) {
3131 const arrayDiff = { ours : [ ] as string [ ] , theirs : [ ] as string [ ] } ;
32- const vals = new Set ( [ ...ours [ key ] , ...theirs [ key ] ] ) ;
32+ const vals = new Set ( [ ...( ours [ key ] ?? [ ] ) , ...( theirs [ key ] ?? [ ] ) ] ) ;
3333 vals . forEach ( ( val ) => {
3434 const inOurs = ours [ key ] ?. includes ( val ) ;
3535 const inTheirs = theirs [ key ] ?. includes ( val ) ;
@@ -82,9 +82,8 @@ export class DiffTree extends LitElement {
8282 > ( ) ;
8383 @query ( "md-icon-button" ) expandButton ! : HTMLElement ;
8484
85- get expanded ( ) : boolean {
86- return this . expandButton ?. hasAttribute ( "selected" ) ;
87- }
85+ @property ( { type : Boolean } )
86+ expanded = false ;
8887
8988 get ourHasher ( ) : ReturnType < typeof newHasher > | undefined {
9089 return this . ours ? this . hashers . get ( this . ours . ownerDocument ) : undefined ;
@@ -145,11 +144,13 @@ export class DiffTree extends LitElement {
145144 elementDiff [ id ] ??= { } ;
146145 elementDiff [ id ] . theirs = element ;
147146 } ) ;
147+ const expanded = Object . keys ( elementDiff ) . length === 1 ;
148148 return Object . entries ( elementDiff ) . map ( ( [ id , { ours, theirs } ] ) => {
149149 return html `<diff- tree
150150 .ours = ${ ours }
151151 .theirs = ${ theirs }
152152 .hashers = ${ this . hashers }
153+ .expanded = ${ expanded }
153154 > </ diff- tree> ` ;
154155 } ) ;
155156 } ) }
@@ -170,6 +171,7 @@ export class DiffTree extends LitElement {
170171 <td> </ td>
171172 <td> ${ name } </ td>
172173 <td> ${ ours } </ td>
174+ <td class= "arrow" > →</ td>
173175 <td> ${ theirs } </ td>
174176 </ tr> ` ,
175177 ) }
@@ -180,10 +182,11 @@ export class DiffTree extends LitElement {
180182 <td> ${ ns } </ td>
181183 <td> ${ k } </ td>
182184 <td> ${ ( d as { ours : string } ) . ours } </ td>
185+ <td class= "arrow" > →</ td>
183186 <td> ${ ( d as { theirs : string } ) . theirs } </ td>
184187 </ tr> ` ,
185188 ) ,
186- ) } ,
189+ ) }
187190 </ table> ` ;
188191 }
189192
@@ -194,15 +197,14 @@ export class DiffTree extends LitElement {
194197 renderElement ( ) {
195198 const element = this . ours ?? this . theirs ;
196199 if ( ! element ) return nothing ;
197- const id = identity ( element ) ;
200+ const id = identity ( element ) || element . tagName ;
198201 const tag = element . tagName ;
199202 const description = this . ourDescription ?? this . theirDescription ;
200203 const hash = this . ourHash ?? this . theirHash ;
201- return html `<md- icon- butto n to ggle @click = ${ ( ) => this . requestUpdate ( ) } >
202- <md- icon> unfold_more </ md- icon>
203- <md- icon slot= "selected" > unfold_less </ md- icon>
204- </ md- icon- butto n>
205- <p> ${ this . ours ? "-" : "+" } ${ id } </ p>
204+ return html `<a @click = ${ ( ) => ( this . expanded = ! this . expanded ) }
205+ > <md- icon> ${ this . expanded ? "arrow_drop_down" : "arrow_right" } </ md- icon>
206+ ${ this . ours ? "-" : "+" } ${ id } </ a
207+ >
206208 ${ this . expanded ? this . renderDiff ( ) : "" } ` ;
207209 }
208210
@@ -220,23 +222,17 @@ export class DiffTree extends LitElement {
220222
221223 Object . keys ( this . ourDescription ?? { } ) . forEach ( ( key ) => { } ) ;
222224
223- return html `<md- icon- butto n to ggle @click = ${ ( ) => this . requestUpdate ( ) } >
224- <md- icon> unfold_more </ md- icon>
225- <md- icon slot= "selected" > unfold_less </ md- icon>
226- </ md- icon- butto n>
227- <p>
228- ${ identity ( this . ours ) || this . ours . tagName }
229- <md- icon style= "--md-icon-size: 1em" > arrow_forward </ md- icon> ${ identity (
230- this . theirs ,
231- ) || this . theirs . tagName }
232- </ p>
225+ return html `<a @click = ${ ( ) => ( this . expanded = ! this . expanded ) }
226+ > <md- icon> ${ this . expanded ? "arrow_drop_down" : "arrow_right" } </ md- icon>
227+ ${ identity ( this . ours ) || this . ours . tagName } </ a
228+ >
233229 ${ this . expanded ? this . renderDiff ( ) : "" } ` ;
234230 }
235231
236232 static styles = css `
237- md-icon-button {
238- float : left ;
239- transform : scale ( 0.6 ) ;
233+ md-icon {
234+ position : relative ;
235+ top : 6 px ;
240236 }
241237 div {
242238 margin-left : 1em ;
@@ -296,7 +292,7 @@ export class DiffTree extends LitElement {
296292 border : 0.25em solid var (--oscd-base2 );
297293 table-layout : auto;
298294 border-collapse : collapse;
299- width : max-content ;
295+ max- width: 100 % ;
300296 margin-left : 1.2em ;
301297 margin-bottom : 0.3em ;
302298 background : none;
0 commit comments