@@ -20,6 +20,7 @@ function buildFileRows(
2020 prefix : string ,
2121 actionName : string ,
2222 actionIcon : string ,
23+ interactive : boolean ,
2324) : { children : string [ ] , elements : Record < string , JsonRenderElement > } {
2425 const children : string [ ] = [ ]
2526 const elements : Record < string , JsonRenderElement > = { }
@@ -30,14 +31,29 @@ function buildFileRows(
3031 const rowId = `${ prefix } -row-${ i } `
3132 const statusId = `${ prefix } -status-${ i } `
3233 const fileId = `${ prefix } -file-${ i } `
33- const spacerId = `${ prefix } -spacer-${ i } `
34- const btnId = `${ prefix } -btn-${ i } `
3534
3635 children . push ( rowId )
36+ const rowChildren = [ statusId , fileId ]
37+
38+ if ( interactive ) {
39+ const spacerId = `${ prefix } -spacer-${ i } `
40+ const btnId = `${ prefix } -btn-${ i } `
41+ rowChildren . push ( spacerId , btnId )
42+ elements [ spacerId ] = {
43+ type : 'Stack' ,
44+ props : { direction : 'horizontal' , flex : 1 } ,
45+ }
46+ elements [ btnId ] = {
47+ type : 'Button' ,
48+ props : { icon : actionIcon , variant : 'ghost' } ,
49+ on : { press : { action : actionName , params : { file } } } ,
50+ }
51+ }
52+
3753 elements [ rowId ] = {
3854 type : 'Stack' ,
3955 props : { direction : 'horizontal' , gap : 8 , align : 'center' } ,
40- children : [ statusId , fileId , spacerId , btnId ] ,
56+ children : rowChildren ,
4157 }
4258 elements [ statusId ] = {
4359 type : 'Badge' ,
@@ -52,23 +68,20 @@ function buildFileRows(
5268 type : 'Text' ,
5369 props : { content : file , variant : 'code' } ,
5470 }
55- elements [ spacerId ] = {
56- type : 'Stack' ,
57- props : { direction : 'horizontal' , flex : 1 } ,
58- }
59- elements [ btnId ] = {
60- type : 'Button' ,
61- props : { icon : actionIcon , variant : 'ghost' } ,
62- on : { press : { action : actionName , params : { file } } } ,
63- }
6471 }
6572
6673 return { children, elements }
6774}
6875
69- export function buildSpec ( gitState : GitState ) : JsonRenderSpec {
70- const stagedRows = buildFileRows ( gitState . staged , 'staged' , 'git-ui:unstage' , 'ph:minus-circle' )
71- const unstagedRows = buildFileRows ( gitState . unstaged , 'unstaged' , 'git-ui:stage' , 'ph:plus-circle' )
76+ export function buildSpec ( gitState : GitState , options ?: { interactive ?: boolean } ) : JsonRenderSpec {
77+ const interactive = options ?. interactive ?? true
78+ const stagedRows = buildFileRows ( gitState . staged , 'staged' , 'git-ui:unstage' , 'ph:minus-circle' , interactive )
79+ const unstagedRows = buildFileRows ( gitState . unstaged , 'unstaged' , 'git-ui:stage' , 'ph:plus-circle' , interactive )
80+
81+ const rootChildren = [ 'header' , 'branch-info' ]
82+ if ( interactive )
83+ rootChildren . push ( 'commit-section' )
84+ rootChildren . push ( 'divider1' , 'staged-card' , 'unstaged-card' , 'commits-card' )
7285
7386 return {
7487 root : 'root' ,
@@ -79,12 +92,12 @@ export function buildSpec(gitState: GitState): JsonRenderSpec {
7992 'root' : {
8093 type : 'Stack' ,
8194 props : { direction : 'vertical' , gap : 12 , padding : 4 } ,
82- children : [ 'header' , 'branch-info' , 'commit-section' , 'divider1' , 'staged-card' , 'unstaged-card' , 'commits-card' ] ,
95+ children : rootChildren ,
8396 } ,
8497 'header' : {
8598 type : 'Stack' ,
8699 props : { direction : 'horizontal' , gap : 8 , align : 'center' , justify : 'space-between' } ,
87- children : [ 'title' , 'refresh-btn' ] ,
100+ children : interactive ? [ 'title' , 'refresh-btn' ] : [ 'title '] ,
88101 } ,
89102 'title' : {
90103 type : 'Text' ,
@@ -163,7 +176,9 @@ export function buildSpec(gitState: GitState): JsonRenderSpec {
163176 'unstaged-card' : {
164177 type : 'Card' ,
165178 props : { title : `Unstaged (${ gitState . unstaged . length } )` , collapsible : true } ,
166- children : gitState . unstaged . length > 0 ? [ 'unstaged-header' , 'unstaged-files' ] : [ 'unstaged-empty' ] ,
179+ children : gitState . unstaged . length > 0
180+ ? ( interactive ? [ 'unstaged-header' , 'unstaged-files' ] : [ 'unstaged-files' ] )
181+ : [ 'unstaged-empty' ] ,
167182 } ,
168183 'unstaged-header' : {
169184 type : 'Stack' ,
0 commit comments