@carlosstenzel/opencode-git-sidebar 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/gui.tsx CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  Style,
10
10
  type SessionPanelMenuItem,
11
11
  } from "@opencode/plugin/gui"
12
- import { createEffect, createMemo, createSignal, For, onCleanup, onMount, Show } from "solid-js"
12
+ import { createEffect, createMemo, createSignal, For, on, onCleanup, onMount, Show } from "solid-js"
13
13
  import {
14
14
  CHANGE_KINDS,
15
15
  type ChangeKind,
@@ -21,7 +21,12 @@ import {
21
21
  splitPath,
22
22
  statBlocks,
23
23
  } from "./diff"
24
+ import { buildGraph, type Graph, type GraphRow } from "./graph"
25
+ import { GraphCanvas } from "./graph-canvas"
26
+ import { laneWidth } from "./graph-theme"
24
27
  import { Git } from "./rpc"
28
+ import { capture, createLatestGuard, errorMessage, relative } from "./ui-helpers.js"
29
+ import { load, type LoadDeps } from "./gui-load.js"
25
30
  import { css } from "./style"
26
31
 
27
32
  type Status = {
@@ -52,6 +57,8 @@ type Commit = {
52
57
  author: string
53
58
  date: string
54
59
  files: string[]
60
+ parents: string[]
61
+ refs: string[]
55
62
  }
56
63
 
57
64
  type Change = {
@@ -78,6 +85,15 @@ type DiffState = { text: string; parsed: ParsedDiff; truncated: boolean; error?:
78
85
  // Rows the diff viewer renders at once; a longer diff shows the rest on demand.
79
86
  const DIFF_PAGE = 2000
80
87
 
88
+ // A div acting as a button: Enter or Space activates it, and Space must not scroll the pane.
89
+ function keyActivate(run: () => void) {
90
+ return (event: KeyboardEvent) => {
91
+ if (event.key !== "Enter" && event.key !== " ") return
92
+ event.preventDefault()
93
+ run()
94
+ }
95
+ }
96
+
81
97
  function sumStats(items: FileItem[]): Stats | undefined {
82
98
  let additions = 0
83
99
  let deletions = 0
@@ -112,21 +128,9 @@ type Issue = {
112
128
  type Result = { ok: boolean; text: string }
113
129
  type Tab = "branches" | "commits" | "pulls" | "issues" | "files"
114
130
  type BranchAction = "checkout" | "create" | "delete" | "merge"
115
-
116
- function relative(iso: string) {
117
- if (!iso) return ""
118
- const date = new Date(iso)
119
- const diff = Date.now() - date.getTime()
120
- if (!Number.isFinite(diff)) return ""
121
- if (diff < 60_000) return "agora"
122
- const minutes = Math.floor(diff / 60_000)
123
- if (minutes < 60) return `${minutes}m`
124
- const hours = Math.floor(minutes / 60)
125
- if (hours < 24) return `${hours}h`
126
- const days = Math.floor(hours / 24)
127
- if (days < 30) return `${days}d`
128
- return new Date(iso).toLocaleDateString()
129
- }
131
+ type BranchView = "list" | "graph"
132
+ type GraphState = { layout: Graph; commits: Commit[] }
133
+ type GraphEntry = { row: GraphRow; commit: Commit }
130
134
 
131
135
  export default Plugin.define({
132
136
  i18n: {
@@ -196,10 +200,16 @@ export default Plugin.define({
196
200
  "git.tab.pulls": "PRs",
197
201
  "git.tab.issues": "Issues",
198
202
  "git.tab.files": "Files",
203
+ "git.view.list": "List",
204
+ "git.view.graph": "Graph",
205
+ "git.graph.loading": "Loading graph…",
199
206
  "git.filter": "Filter branches",
200
207
  "git.filter.placeholder": "name or commit",
201
208
  "git.files": "files",
202
209
  "git.noRepo": "No Git repository in this session directory.",
210
+ "git.now": "now",
211
+ "git.loading": "Loading…",
212
+ "git.retry": "Retry",
203
213
  "git.branches.empty": "No branches match this filter.",
204
214
  "git.commits.empty": "No commits yet.",
205
215
  "git.pulls.empty": "No open pull requests.",
@@ -295,10 +305,16 @@ export default Plugin.define({
295
305
  "git.tab.pulls": "PRs",
296
306
  "git.tab.issues": "Issues",
297
307
  "git.tab.files": "Arquivos",
308
+ "git.view.list": "Lista",
309
+ "git.view.graph": "Grafo",
310
+ "git.graph.loading": "Carregando grafo…",
298
311
  "git.filter": "Filtrar branches",
299
312
  "git.filter.placeholder": "nome ou commit",
300
313
  "git.files": "arquivos",
301
314
  "git.noRepo": "Sem repositório Git neste diretório da sessão.",
315
+ "git.now": "agora",
316
+ "git.loading": "Carregando…",
317
+ "git.retry": "Tentar novamente",
302
318
  "git.branches.empty": "Nenhuma branch corresponde ao filtro.",
303
319
  "git.commits.empty": "Ainda não há commits.",
304
320
  "git.pulls.empty": "Nenhum PR aberto.",
@@ -332,6 +348,12 @@ export default Plugin.define({
332
348
 
333
349
  setup(ctx) {
334
350
  const ui = ctx.ui
351
+ const guard = createLatestGuard()
352
+ onCleanup(() => guard.invalidate())
353
+ const graphGuard = createLatestGuard()
354
+ onCleanup(() => graphGuard.invalidate())
355
+ const lastDirRef = { current: "" }
356
+ let graphDir = ""
335
357
  const panelKey = () => `${ctx.id}:main`
336
358
  const directory = () => ctx.sessions.current()?.directory
337
359
 
@@ -342,13 +364,21 @@ export default Plugin.define({
342
364
  const [commits, setCommits] = createSignal<Commit[]>([])
343
365
  const [changes, setChanges] = createSignal<Change[]>([])
344
366
  const [busy, setBusy] = createSignal(false)
367
+ const [loaded, setLoaded] = createSignal(false)
345
368
  const [error, setError] = createSignal<string>()
346
369
  const [tab, setTab] = createSignal<Tab>("branches")
347
370
  const [filter, setFilter] = createSignal("")
371
+ const [view, setView] = createSignal<BranchView>("list")
372
+ const [graph, setGraph] = createSignal<GraphState>()
373
+ const [graphLoading, setGraphLoading] = createSignal(false)
348
374
  const [expanded, setExpanded] = createSignal<string>()
349
375
  const [selected, setSelected] = createSignal<Set<string>>(new Set())
350
376
  const [collapsed, setCollapsed] = createSignal<ReadonlySet<ChangeKind>>(new Set())
351
377
 
378
+ // Scroll host of the commit/branch lists: offsetTop of a `data-graph-row` is
379
+ // relative to it, so the overlapping GraphCanvas can align its dots.
380
+ let graphScroll: HTMLDivElement | undefined
381
+
352
382
  const filteredBranches = createMemo(() => {
353
383
  const query = filter().trim().toLowerCase()
354
384
  if (!query) return branches()
@@ -358,6 +388,49 @@ export default Plugin.define({
358
388
  )
359
389
  })
360
390
 
391
+ // `%D` keeps decoration prefixes; branch matching needs the plain names.
392
+ function decorationNames(refs: string[]): string[] {
393
+ return refs.map((ref) => {
394
+ const name = ref.startsWith("HEAD -> ") ? ref.slice("HEAD -> ".length) : ref
395
+ return name.startsWith("tag: ") ? name.slice("tag: ".length) : name
396
+ })
397
+ }
398
+
399
+ // A graph row can carry several refs; prefer a branch the user can still act on.
400
+ function branchAt(commit: Commit): Branch | undefined {
401
+ if (!commit.refs.length) return undefined
402
+ const names = new Set(decorationNames(commit.refs))
403
+ const matches = branches().filter((branch) => names.has(branch.name))
404
+ const isRemote = (branch: Branch) =>
405
+ branch.name.startsWith("origin/") || branch.name.startsWith("upstream/")
406
+ // Prefer a local branch so the row keeps its current/ahead-behind affordances.
407
+ return (
408
+ matches.find((branch) => branch.current) ??
409
+ matches.find((branch) => !isRemote(branch)) ??
410
+ matches[0]
411
+ )
412
+ }
413
+
414
+ const commitGraph = createMemo(() => buildGraph(commits()))
415
+
416
+ const graphRows = createMemo(() => {
417
+ const state = graph()
418
+ if (!state) return { rows: [] as GraphEntry[], lanes: 0 }
419
+ const query = filter().trim().toLowerCase()
420
+ const commits = query
421
+ ? state.commits.filter((commit) =>
422
+ [commit.subject, commit.hash, commit.short, ...decorationNames(commit.refs)].some((text) =>
423
+ text.toLowerCase().includes(query),
424
+ ),
425
+ )
426
+ : state.commits
427
+ const layout = query ? buildGraph(commits) : state.layout
428
+ return {
429
+ lanes: layout.lanes,
430
+ rows: layout.rows.map((row, index) => ({ row, commit: commits[index] })),
431
+ }
432
+ })
433
+
361
434
  const fileItems = createMemo<FileItem[]>(() =>
362
435
  changes().map((change) => ({ change, ...classify(change.status), ...splitPath(change.path) })),
363
436
  )
@@ -625,6 +698,112 @@ export default Plugin.define({
625
698
  )
626
699
  }
627
700
 
701
+ function BranchActions(props: { branch: Branch }) {
702
+ return (
703
+ <Show when={!props.branch.current}>
704
+ <div class="gs-actions" onClick={(event) => event.stopPropagation()}>
705
+ <ui.Tooltip value={ctx.t("git.branch.checkout")}>
706
+ <ui.IconButton
707
+ icon="arrow-right"
708
+ label={ctx.t("git.branch.checkout")}
709
+ size="small"
710
+ busy={busy()}
711
+ onClick={() => void branchAct("checkout", props.branch.name)}
712
+ />
713
+ </ui.Tooltip>
714
+ <ui.Tooltip value={ctx.t("git.branch.merge")}>
715
+ <ui.IconButton
716
+ icon="branch-out"
717
+ label={ctx.t("git.branch.merge")}
718
+ size="small"
719
+ busy={busy()}
720
+ onClick={() => void branchAct("merge", props.branch.name)}
721
+ />
722
+ </ui.Tooltip>
723
+ <ui.Tooltip value={ctx.t("git.branch.delete")}>
724
+ <ui.IconButton
725
+ icon="close"
726
+ label={ctx.t("git.branch.delete")}
727
+ size="small"
728
+ busy={busy()}
729
+ onClick={() => void branchAct("delete", props.branch.name)}
730
+ />
731
+ </ui.Tooltip>
732
+ </div>
733
+ </Show>
734
+ )
735
+ }
736
+
737
+ // Graph view of every branch tip: read-only rows, with branch actions still available.
738
+ function BranchGraph() {
739
+ return (
740
+ <Show when={!graphLoading()} fallback={<div class="gs-empty">{ctx.t("git.graph.loading")}</div>}>
741
+ <Show
742
+ when={graphRows().rows.length > 0}
743
+ fallback={<div class="gs-empty">{ctx.t("git.commits.empty")}</div>}
744
+ >
745
+ <GraphCanvas
746
+ rows={() => graphRows().rows.map((entry) => entry.row)}
747
+ commits={() => graphRows().rows.map((entry) => entry.commit)}
748
+ lanes={() => graphRows().lanes}
749
+ target={() => graphScroll}
750
+ />
751
+ <For each={graphRows().rows}>
752
+ {(entry) => {
753
+ const branch = () => branchAt(entry.commit)
754
+ return (
755
+ <div
756
+ class="gs-row gs-row-static gs-graphrow"
757
+ data-graph-row="true"
758
+ style={{ "padding-left": `${8 + laneWidth(graphRows().lanes)}px` }}
759
+ >
760
+ <ui.Icon name={branch()?.current ? "check" : "branch"} size="small" />
761
+ <div class="gs-row-main">
762
+ <div class="gs-name">{entry.commit.subject || entry.commit.short}</div>
763
+ <div class="gs-detail">
764
+ <span class="gs-mono">{entry.commit.short}</span>
765
+ </div>
766
+ <Show when={entry.commit.refs.length > 0}>
767
+ <div class="gs-chips">
768
+ <For each={entry.commit.refs.slice(0, 3)}>
769
+ {(ref) => (
770
+ <span class="gs-ref" title={ref}>
771
+ {ref}
772
+ </span>
773
+ )}
774
+ </For>
775
+ <Show when={entry.commit.refs.length > 3}>
776
+ <span class="gs-ref" title={entry.commit.refs.join(", ")}>
777
+ +{entry.commit.refs.length - 3}
778
+ </span>
779
+ </Show>
780
+ </div>
781
+ </Show>
782
+ </div>
783
+ <Show when={branch()}>
784
+ {(current) => (
785
+ <>
786
+ <div class="gs-chips">
787
+ <Show when={current().ahead > 0}>
788
+ <span class="gs-chip">{ctx.t("git.ahead", { count: current().ahead })}</span>
789
+ </Show>
790
+ <Show when={current().behind > 0}>
791
+ <span class="gs-chip">{ctx.t("git.behind", { count: current().behind })}</span>
792
+ </Show>
793
+ </div>
794
+ <BranchActions branch={current()} />
795
+ </>
796
+ )}
797
+ </Show>
798
+ </div>
799
+ )
800
+ }}
801
+ </For>
802
+ </Show>
803
+ </Show>
804
+ )
805
+ }
806
+
628
807
  function DiffLineView(props: { row: DiffRow }) {
629
808
  const row = props.row
630
809
  if (row.kind === "file")
@@ -880,49 +1059,63 @@ export default Plugin.define({
880
1059
  )
881
1060
  }
882
1061
 
883
- async function load() {
884
- const dir = directory()
885
- if (!dir) {
886
- setStatus(undefined)
887
- setPulls([])
888
- setIssues([])
889
- setBranches([])
890
- setCommits([])
891
- setChanges([])
892
- setSelected(new Set<string>())
893
- return
894
- }
895
- setBusy(true)
896
- setError(undefined)
897
- try {
898
- const [nextStatus, nextPulls, nextIssues, nextBranches, nextCommits, nextChanges] = (await Promise.all([
899
- ctx.client.rpc(Git).status({ directory: dir }),
900
- ctx.client.rpc(Git).pulls({ directory: dir }),
901
- ctx.client.rpc(Git).issues({ directory: dir }),
902
- ctx.client.rpc(Git).branches({ directory: dir, limit: 60 }),
903
- ctx.client.rpc(Git).commits({ directory: dir, limit: 20 }),
904
- ctx.client.rpc(Git).changes({ directory: dir }),
905
- ])) as [Status, Pull[], Issue[], Branch[], Commit[], Change[]]
906
- setStatus(nextStatus)
907
- setPulls(nextPulls)
908
- setIssues(nextIssues)
909
- setBranches(nextBranches)
910
- setCommits(nextCommits)
911
- setChanges(nextChanges)
912
- const valid = new Set(nextChanges.map((change) => change.path))
913
- setSelected(new Set([...selected()].filter((path) => valid.has(path))))
914
- } catch (cause) {
915
- setError(cause instanceof Error ? cause.message : String(cause))
916
- } finally {
917
- setBusy(false)
918
- }
919
- }
920
-
921
- createEffect(() => {
922
- directory()
923
- void load()
1062
+ createEffect(on(directory, (current) => void load(current, {
1063
+ directory,
1064
+ guard,
1065
+ rpc: {
1066
+ status: (d) => ctx.client.rpc(Git).status({ directory: d }) as Promise<Status>,
1067
+ pulls: (d) => ctx.client.rpc(Git).pulls({ directory: d }) as Promise<Pull[]>,
1068
+ issues: (d) => ctx.client.rpc(Git).issues({ directory: d }) as Promise<Issue[]>,
1069
+ branches: (d, l = 60) => ctx.client.rpc(Git).branches({ directory: d, limit: l }) as Promise<Branch[]>,
1070
+ commits: (d, l = 20) => ctx.client.rpc(Git).commits({ directory: d, limit: l }) as Promise<Commit[]>,
1071
+ changes: (d) => ctx.client.rpc(Git).changes({ directory: d }) as Promise<Change[]>,
1072
+ },
1073
+ setStatus,
1074
+ setPulls,
1075
+ setIssues,
1076
+ setBranches,
1077
+ setCommits,
1078
+ setChanges,
1079
+ setSelected,
1080
+ selected: () => selected(),
1081
+ setBusy,
1082
+ setLoaded,
1083
+ setError,
1084
+ lastDirRef,
1085
+ })))
1086
+
1087
+ const buildDeps = (): LoadDeps => ({
1088
+ directory,
1089
+ guard,
1090
+ rpc: {
1091
+ status: (d) => ctx.client.rpc(Git).status({ directory: d }) as Promise<Status>,
1092
+ pulls: (d) => ctx.client.rpc(Git).pulls({ directory: d }) as Promise<Pull[]>,
1093
+ issues: (d) => ctx.client.rpc(Git).issues({ directory: d }) as Promise<Issue[]>,
1094
+ branches: (d, l = 60) => ctx.client.rpc(Git).branches({ directory: d, limit: l }) as Promise<Branch[]>,
1095
+ commits: (d, l = 20) => ctx.client.rpc(Git).commits({ directory: d, limit: l }) as Promise<Commit[]>,
1096
+ changes: (d) => ctx.client.rpc(Git).changes({ directory: d }) as Promise<Change[]>,
1097
+ },
1098
+ setStatus,
1099
+ setPulls,
1100
+ setIssues,
1101
+ setBranches,
1102
+ setCommits,
1103
+ setChanges,
1104
+ setSelected,
1105
+ selected: () => selected(),
1106
+ setBusy,
1107
+ setLoaded,
1108
+ setError,
1109
+ lastDirRef,
924
1110
  })
925
1111
 
1112
+ // Refreshing state also refreshes the branch graph, otherwise commits made
1113
+ // after this panel opened stay invisible there until the view is toggled.
1114
+ const reload = async () => {
1115
+ await load(directory(), buildDeps())
1116
+ if (view() === "graph") await loadGraph()
1117
+ }
1118
+
926
1119
  function openPanel() {
927
1120
  const session = ctx.sessions.current()
928
1121
  if (session) ctx.layout.open(panelKey(), session)
@@ -956,20 +1149,20 @@ export default Plugin.define({
956
1149
  }
957
1150
  setBusy(true)
958
1151
  try {
959
- const result = (await (() => {
1152
+ const result = await capture(async (): Promise<Result> => {
960
1153
  switch (kind) {
961
1154
  case "push":
962
- return ctx.client.rpc(Git).push({ directory: dir })
1155
+ return (await ctx.client.rpc(Git).push({ directory: dir })) as Result
963
1156
  case "pull":
964
- return ctx.client.rpc(Git).pull({ directory: dir })
1157
+ return (await ctx.client.rpc(Git).pull({ directory: dir })) as Result
965
1158
  case "pr":
966
- return ctx.client.rpc(Git).pr({ directory: dir })
1159
+ return (await ctx.client.rpc(Git).pr({ directory: dir })) as Result
967
1160
  case "commit":
968
- return ctx.client.rpc(Git).commit({ directory: dir, message })
1161
+ return (await ctx.client.rpc(Git).commit({ directory: dir, message })) as Result
969
1162
  }
970
- })()) as Result
1163
+ }) as Result
971
1164
  await notify(result)
972
- await load()
1165
+ await reload()
973
1166
  } finally {
974
1167
  setBusy(false)
975
1168
  }
@@ -998,10 +1191,12 @@ export default Plugin.define({
998
1191
  if (!confirmed) return
999
1192
  setBusy(true)
1000
1193
  try {
1001
- const result = (await ctx.client.rpc(Git).commitSelected({ directory: dir, message, files })) as Result
1194
+ const result = await capture(async (): Promise<Result> => {
1195
+ return (await ctx.client.rpc(Git).commitSelected({ directory: dir, message, files })) as Result
1196
+ }) as Result
1002
1197
  await notify(result)
1003
1198
  if (result.ok) clearFiles()
1004
- await load()
1199
+ await reload()
1005
1200
  } finally {
1006
1201
  setBusy(false)
1007
1202
  }
@@ -1052,16 +1247,50 @@ export default Plugin.define({
1052
1247
  }
1053
1248
  setBusy(true)
1054
1249
  try {
1055
- const result = (await ctx.client
1056
- .rpc(Git)
1057
- .branchAction({ directory: dir, action: kind, name: target })) as Result
1250
+ const result = await capture(async (): Promise<Result> => {
1251
+ return (await ctx.client
1252
+ .rpc(Git)
1253
+ .branchAction({ directory: dir, action: kind, name: target })) as Result
1254
+ }) as Result
1058
1255
  await notify(result)
1059
- await load()
1256
+ await reload()
1060
1257
  } finally {
1061
1258
  setBusy(false)
1062
1259
  }
1063
1260
  }
1064
1261
 
1262
+ async function loadGraph() {
1263
+ const dir = directory()
1264
+ if (!dir) return
1265
+ // A different directory must never show the previous repository's graph.
1266
+ if (dir !== graphDir) {
1267
+ graphDir = dir
1268
+ setGraph(undefined)
1269
+ setError(undefined)
1270
+ }
1271
+ const token = graphGuard.next()
1272
+ setGraphLoading(true)
1273
+ try {
1274
+ const commits = (await ctx.client
1275
+ .rpc(Git)
1276
+ .commits({ directory: dir, limit: 100, all: true })) as Commit[]
1277
+ if (!graphGuard.isCurrent(token)) return
1278
+ setGraph({ layout: buildGraph(commits), commits })
1279
+ setError(undefined)
1280
+ } catch (cause) {
1281
+ if (!graphGuard.isCurrent(token)) return
1282
+ setError(errorMessage(cause))
1283
+ } finally {
1284
+ if (graphGuard.isCurrent(token)) setGraphLoading(false)
1285
+ }
1286
+ }
1287
+
1288
+ createEffect(
1289
+ on([view, directory], ([mode, dir]) => {
1290
+ if (mode === "graph" && dir) void loadGraph()
1291
+ }),
1292
+ )
1293
+
1065
1294
  ctx.add(Style, css)
1066
1295
 
1067
1296
  ctx.add(Panel, {
@@ -1083,7 +1312,14 @@ export default Plugin.define({
1083
1312
  render: () => (
1084
1313
  <div class="gs-root">
1085
1314
  <Show when={error()}>
1086
- {(message) => <div class="gs-error">{ctx.t("git.error")}: {message()}</div>}
1315
+ {(message) => (
1316
+ <div class="gs-error" role="alert">
1317
+ {ctx.t("git.error")}: {message()}
1318
+ <ui.Button size="small" onClick={() => { setError(undefined); void reload() }}>
1319
+ {ctx.t("git.retry")}
1320
+ </ui.Button>
1321
+ </div>
1322
+ )}
1087
1323
  </Show>
1088
1324
 
1089
1325
  <div class="gs-card">
@@ -1166,7 +1402,7 @@ export default Plugin.define({
1166
1402
  label={ctx.t("git.refresh")}
1167
1403
  size="small"
1168
1404
  busy={busy()}
1169
- onClick={() => void load()}
1405
+ onClick={() => void reload()}
1170
1406
  />
1171
1407
  </ui.Tooltip>
1172
1408
  <ui.Button size="small" busy={busy()} onClick={() => void act("push")}>
@@ -1181,82 +1417,84 @@ export default Plugin.define({
1181
1417
  <ui.Button size="small" busy={busy()} onClick={() => void act("pr")}>
1182
1418
  {ctx.t("git.pr")}
1183
1419
  </ui.Button>
1184
- <ui.Tooltip value={ctx.t("git.branch.create")}>
1185
- <ui.IconButton
1186
- icon="branch-out"
1187
- label={ctx.t("git.branch.create")}
1188
- size="small"
1189
- busy={busy()}
1190
- onClick={() => void branchAct("create")}
1191
- />
1192
- </ui.Tooltip>
1193
1420
  </div>
1194
1421
 
1195
- <Show when={status()} fallback={<div class="gs-empty">{ctx.t("git.noRepo")}</div>}>
1422
+ <Show
1423
+ when={status()?.repo}
1424
+ fallback={
1425
+ busy() && !loaded()
1426
+ ? <div class="gs-empty">{ctx.t("git.loading")}</div>
1427
+ : <div class="gs-empty">{ctx.t("git.noRepo")}</div>
1428
+ }
1429
+ >
1196
1430
  <Show when={tab() !== "files"} fallback={<FilesPane />}>
1197
- <div class="gs-scroll">
1431
+ <div class="gs-scroll" ref={(element) => (graphScroll = element)}>
1198
1432
  <Show when={tab() === "branches"}>
1199
- <ui.TextInput
1200
- label={ctx.t("git.filter")}
1201
- placeholder={ctx.t("git.filter.placeholder")}
1202
- type="search"
1203
- value={filter()}
1204
- onInput={setFilter}
1205
- />
1206
- <Show
1207
- when={filteredBranches().length > 0}
1208
- fallback={<div class="gs-empty">{ctx.t("git.branches.empty")}</div>}
1209
- >
1210
- <For each={filteredBranches()}>
1211
- {(branch) => (
1212
- <div class="gs-row">
1213
- <ui.Icon name={branch.current ? "check" : "branch"} size="small" />
1214
- <div class="gs-row-main">
1215
- <div class="gs-name">{branch.name}</div>
1216
- <div class="gs-sub">{branch.subject || branch.hash}</div>
1217
- </div>
1218
- <div class="gs-chips">
1219
- <Show when={branch.ahead > 0}>
1220
- <span class="gs-chip">{ctx.t("git.ahead", { count: branch.ahead })}</span>
1221
- </Show>
1222
- <Show when={branch.behind > 0}>
1223
- <span class="gs-chip">{ctx.t("git.behind", { count: branch.behind })}</span>
1224
- </Show>
1225
- </div>
1226
- <Show when={!branch.current}>
1227
- <div class="gs-actions" onClick={(event) => event.stopPropagation()}>
1228
- <ui.Tooltip value={ctx.t("git.branch.checkout")}>
1229
- <ui.IconButton
1230
- icon="arrow-right"
1231
- label={ctx.t("git.branch.checkout")}
1232
- size="small"
1233
- busy={busy()}
1234
- onClick={() => void branchAct("checkout", branch.name)}
1235
- />
1236
- </ui.Tooltip>
1237
- <ui.Tooltip value={ctx.t("git.branch.merge")}>
1238
- <ui.IconButton
1239
- icon="branch-out"
1240
- label={ctx.t("git.branch.merge")}
1241
- size="small"
1242
- busy={busy()}
1243
- onClick={() => void branchAct("merge", branch.name)}
1244
- />
1245
- </ui.Tooltip>
1246
- <ui.Tooltip value={ctx.t("git.branch.delete")}>
1247
- <ui.IconButton
1248
- icon="close"
1249
- label={ctx.t("git.branch.delete")}
1250
- size="small"
1251
- busy={busy()}
1252
- onClick={() => void branchAct("delete", branch.name)}
1253
- />
1254
- </ui.Tooltip>
1433
+ <div class="gs-viewtoggle" role="tablist" aria-label={ctx.t("git.tab.branches")}>
1434
+ <button
1435
+ type="button"
1436
+ role="tab"
1437
+ aria-selected={view() === "list"}
1438
+ disabled={busy()}
1439
+ onClick={() => setView("list")}
1440
+ >
1441
+ {ctx.t("git.view.list")}
1442
+ </button>
1443
+ <button
1444
+ type="button"
1445
+ role="tab"
1446
+ aria-selected={view() === "graph"}
1447
+ disabled={busy()}
1448
+ onClick={() => setView("graph")}
1449
+ >
1450
+ {ctx.t("git.view.graph")}
1451
+ </button>
1452
+ </div>
1453
+ <div class="gs-branchbar">
1454
+ <ui.TextInput
1455
+ class="gs-branchfilter"
1456
+ label={ctx.t("git.filter")}
1457
+ placeholder={ctx.t("git.filter.placeholder")}
1458
+ type="search"
1459
+ value={filter()}
1460
+ onInput={setFilter}
1461
+ />
1462
+ <ui.Tooltip value={ctx.t("git.branch.create")}>
1463
+ <ui.IconButton
1464
+ icon="branch-out"
1465
+ label={ctx.t("git.branch.create")}
1466
+ size="small"
1467
+ busy={busy()}
1468
+ onClick={() => void branchAct("create")}
1469
+ />
1470
+ </ui.Tooltip>
1471
+ </div>
1472
+ <Show when={view() === "list"} fallback={<BranchGraph />}>
1473
+ <Show
1474
+ when={filteredBranches().length > 0}
1475
+ fallback={<div class="gs-empty">{ctx.t("git.branches.empty")}</div>}
1476
+ >
1477
+ <For each={filteredBranches()}>
1478
+ {(branch) => (
1479
+ <div class="gs-row">
1480
+ <ui.Icon name={branch.current ? "check" : "branch"} size="small" />
1481
+ <div class="gs-row-main">
1482
+ <div class="gs-name">{branch.name}</div>
1483
+ <div class="gs-sub">{branch.subject || branch.hash}</div>
1255
1484
  </div>
1256
- </Show>
1257
- </div>
1258
- )}
1259
- </For>
1485
+ <div class="gs-chips">
1486
+ <Show when={branch.ahead > 0}>
1487
+ <span class="gs-chip">{ctx.t("git.ahead", { count: branch.ahead })}</span>
1488
+ </Show>
1489
+ <Show when={branch.behind > 0}>
1490
+ <span class="gs-chip">{ctx.t("git.behind", { count: branch.behind })}</span>
1491
+ </Show>
1492
+ </div>
1493
+ <BranchActions branch={branch} />
1494
+ </div>
1495
+ )}
1496
+ </For>
1497
+ </Show>
1260
1498
  </Show>
1261
1499
  </Show>
1262
1500
 
@@ -1265,20 +1503,57 @@ export default Plugin.define({
1265
1503
  when={commits().length > 0}
1266
1504
  fallback={<div class="gs-empty">{ctx.t("git.commits.empty")}</div>}
1267
1505
  >
1506
+ <GraphCanvas
1507
+ rows={() => commitGraph().rows}
1508
+ commits={commits}
1509
+ lanes={() => commitGraph().lanes}
1510
+ target={() => graphScroll}
1511
+ />
1268
1512
  <For each={commits()}>
1269
1513
  {(commit) => (
1270
1514
  <>
1271
1515
  <div
1272
- class="gs-row"
1516
+ class="gs-row gs-graphrow"
1517
+ data-graph-row="true"
1518
+ style={{ "padding-left": `${8 + laneWidth(commitGraph().lanes)}px` }}
1519
+ role={commit.files.length > 0 ? "button" : undefined}
1520
+ tabIndex={commit.files.length > 0 ? 0 : undefined}
1521
+ aria-expanded={
1522
+ commit.files.length > 0 ? expanded() === commit.hash : undefined
1523
+ }
1524
+ aria-controls={
1525
+ commit.files.length > 0 && expanded() === commit.hash
1526
+ ? `gs-files-${commit.hash}`
1527
+ : undefined
1528
+ }
1273
1529
  onClick={() => setExpanded(expanded() === commit.hash ? undefined : commit.hash)}
1530
+ onKeyDown={keyActivate(() =>
1531
+ setExpanded(expanded() === commit.hash ? undefined : commit.hash),
1532
+ )}
1274
1533
  >
1275
1534
  <span class="gs-mono">{commit.short}</span>
1276
1535
  <div class="gs-row-main">
1277
1536
  <div class="gs-name">{commit.subject}</div>
1537
+ <Show when={commit.refs.length > 0}>
1538
+ <div class="gs-chips">
1539
+ <For each={commit.refs.slice(0, 2)}>
1540
+ {(ref) => (
1541
+ <span class="gs-ref" title={ref}>
1542
+ {ref}
1543
+ </span>
1544
+ )}
1545
+ </For>
1546
+ <Show when={commit.refs.length > 2}>
1547
+ <span class="gs-ref" title={commit.refs.join(", ")}>
1548
+ +{commit.refs.length - 2}
1549
+ </span>
1550
+ </Show>
1551
+ </div>
1552
+ </Show>
1278
1553
  <div class="gs-detail">
1279
1554
  <span>{commit.author}</span>
1280
1555
  <span>·</span>
1281
- <span>{relative(commit.date)}</span>
1556
+ <span>{relative(commit.date, ctx.t("git.now"))}</span>
1282
1557
  </div>
1283
1558
  </div>
1284
1559
  <span class="gs-chip">
@@ -1286,7 +1561,7 @@ export default Plugin.define({
1286
1561
  </span>
1287
1562
  </div>
1288
1563
  <Show when={expanded() === commit.hash && commit.files.length > 0}>
1289
- <div class="gs-files">
1564
+ <div class="gs-files" id={`gs-files-${commit.hash}`}>
1290
1565
  <For each={commit.files}>{(file) => <div class="gs-file">{file}</div>}</For>
1291
1566
  </div>
1292
1567
  </Show>
@@ -1303,7 +1578,13 @@ export default Plugin.define({
1303
1578
  >
1304
1579
  <For each={pulls()}>
1305
1580
  {(pull) => (
1306
- <div class="gs-row" onClick={() => void ctx.system.openExternal(pull.url)}>
1581
+ <div
1582
+ class="gs-row"
1583
+ role="button"
1584
+ tabIndex={0}
1585
+ onClick={() => void ctx.system.openExternal(pull.url)}
1586
+ onKeyDown={keyActivate(() => void ctx.system.openExternal(pull.url))}
1587
+ >
1307
1588
  <ui.Icon
1308
1589
  name={
1309
1590
  pull.checks === "success"
@@ -1332,12 +1613,18 @@ export default Plugin.define({
1332
1613
  >
1333
1614
  <For each={issues()}>
1334
1615
  {(issue) => (
1335
- <div class="gs-row" onClick={() => void ctx.system.openExternal(issue.url)}>
1616
+ <div
1617
+ class="gs-row"
1618
+ role="button"
1619
+ tabIndex={0}
1620
+ onClick={() => void ctx.system.openExternal(issue.url)}
1621
+ onKeyDown={keyActivate(() => void ctx.system.openExternal(issue.url))}
1622
+ >
1336
1623
  <ui.Icon name="bullet-list" size="small" />
1337
1624
  <div class="gs-row-main">
1338
1625
  <div class="gs-name">#{issue.number} {issue.title}</div>
1339
1626
  <div class="gs-sub">
1340
- {[issue.author, relative(issue.date)].filter(Boolean).join(" · ")}
1627
+ {[issue.author, relative(issue.date, ctx.t("git.now"))].filter(Boolean).join(" · ")}
1341
1628
  </div>
1342
1629
  <Show when={issue.labels.length > 0}>
1343
1630
  <div class="gs-chips">