ref0-git 0.0.0-stage → 0.2.0

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.
Files changed (385) hide show
  1. package/app/apps/github/.dev.vars.example +6 -0
  2. package/app/apps/github/README.md +70 -0
  3. package/app/apps/github/THIRD_PARTY_NOTICES.md +214 -0
  4. package/app/apps/github/components.json +25 -0
  5. package/app/apps/github/generated/git-rest.ts +10444 -0
  6. package/app/apps/github/generated/routeTree.gen.ts +1242 -0
  7. package/app/apps/github/migrations/postgres/0001_auth.sql +46 -0
  8. package/app/apps/github/migrations/sql/0001_auth.sql +19 -0
  9. package/app/apps/github/migrations/sql/0002_passkeys.sql +9 -0
  10. package/app/apps/github/migrations/sql/0003_orgs.sql +22 -0
  11. package/app/apps/github/migrations/sql/0004_avatars.sql +6 -0
  12. package/app/apps/github/package.json +80 -0
  13. package/app/apps/github/src/branches/branch-list.tsx +385 -0
  14. package/app/apps/github/src/branches/branches.ts +55 -0
  15. package/app/apps/github/src/clients/allowed.ts +213 -0
  16. package/app/apps/github/src/clients/at-most.ts +17 -0
  17. package/app/apps/github/src/clients/avatars.ts +410 -0
  18. package/app/apps/github/src/clients/cached.ts +65 -0
  19. package/app/apps/github/src/clients/calls.ts +160 -0
  20. package/app/apps/github/src/clients/clients.ts +82 -0
  21. package/app/apps/github/src/clients/graphql.ts +50 -0
  22. package/app/apps/github/src/clients/host-answer.ts +28 -0
  23. package/app/apps/github/src/clients/host-calls.ts +382 -0
  24. package/app/apps/github/src/clients/icon-bytes.ts +203 -0
  25. package/app/apps/github/src/clients/proxy.ts +59 -0
  26. package/app/apps/github/src/clients/session-ended.ts +18 -0
  27. package/app/apps/github/src/clients/transfers.ts +212 -0
  28. package/app/apps/github/src/code/breadcrumbs.tsx +50 -0
  29. package/app/apps/github/src/code/code-page.tsx +147 -0
  30. package/app/apps/github/src/code/code-tree.tsx +338 -0
  31. package/app/apps/github/src/code/controls.tsx +230 -0
  32. package/app/apps/github/src/code/file-view.tsx +450 -0
  33. package/app/apps/github/src/code/files.ts +332 -0
  34. package/app/apps/github/src/code/folder-list.tsx +122 -0
  35. package/app/apps/github/src/code/go-to-file.tsx +131 -0
  36. package/app/apps/github/src/code/highlighted.tsx +58 -0
  37. package/app/apps/github/src/code/lines.ts +46 -0
  38. package/app/apps/github/src/code/load.ts +147 -0
  39. package/app/apps/github/src/code/markdown-files.ts +58 -0
  40. package/app/apps/github/src/code/places.ts +88 -0
  41. package/app/apps/github/src/code/ref-pages.ts +179 -0
  42. package/app/apps/github/src/code/ref-switcher.tsx +203 -0
  43. package/app/apps/github/src/code/refs.ts +142 -0
  44. package/app/apps/github/src/code/repo-home.tsx +240 -0
  45. package/app/apps/github/src/code/repo.ts +105 -0
  46. package/app/apps/github/src/code/saved-reads.ts +199 -0
  47. package/app/apps/github/src/code/saved.ts +110 -0
  48. package/app/apps/github/src/code/tree-fold.ts +186 -0
  49. package/app/apps/github/src/code/trees.ts +136 -0
  50. package/app/apps/github/src/components/avatar-picture.ts +53 -0
  51. package/app/apps/github/src/components/avatar-url.ts +16 -0
  52. package/app/apps/github/src/components/confirm-action.tsx +100 -0
  53. package/app/apps/github/src/components/count.tsx +24 -0
  54. package/app/apps/github/src/components/create-button.tsx +38 -0
  55. package/app/apps/github/src/components/file-icons/file-icons.css +225 -0
  56. package/app/apps/github/src/components/file-icons/file-icons.tsx +138 -0
  57. package/app/apps/github/src/components/filter.tsx +35 -0
  58. package/app/apps/github/src/components/hotkeys/hotkeys.tsx +255 -0
  59. package/app/apps/github/src/components/item-list.tsx +65 -0
  60. package/app/apps/github/src/components/language-dot.tsx +29 -0
  61. package/app/apps/github/src/components/list-toolbar.tsx +82 -0
  62. package/app/apps/github/src/components/markdown/editor.tsx +57 -0
  63. package/app/apps/github/src/components/markdown/markdown.css +177 -0
  64. package/app/apps/github/src/components/markdown/markdown.tsx +82 -0
  65. package/app/apps/github/src/components/owner-card.tsx +196 -0
  66. package/app/apps/github/src/components/pull-status.tsx +34 -0
  67. package/app/apps/github/src/components/recent.ts +41 -0
  68. package/app/apps/github/src/components/relative-time.tsx +78 -0
  69. package/app/apps/github/src/components/repos/icon-hashes.ts +91 -0
  70. package/app/apps/github/src/components/repos/new-repo-form.tsx +196 -0
  71. package/app/apps/github/src/components/repos/repo-icon.tsx +47 -0
  72. package/app/apps/github/src/components/repos/repo-list.tsx +528 -0
  73. package/app/apps/github/src/components/repos/your-repos.tsx +124 -0
  74. package/app/apps/github/src/components/review-state.tsx +75 -0
  75. package/app/apps/github/src/components/route-dialog.tsx +137 -0
  76. package/app/apps/github/src/components/save-button.tsx +58 -0
  77. package/app/apps/github/src/components/shell/app-shell.tsx +164 -0
  78. package/app/apps/github/src/components/shell/create-org-dialog.tsx +118 -0
  79. package/app/apps/github/src/components/shell/create-row.tsx +49 -0
  80. package/app/apps/github/src/components/shell/link-menu.tsx +94 -0
  81. package/app/apps/github/src/components/shell/nav-user.tsx +97 -0
  82. package/app/apps/github/src/components/shell/owner-repos.tsx +247 -0
  83. package/app/apps/github/src/components/shell/owner-switcher.tsx +104 -0
  84. package/app/apps/github/src/components/shell/repo-switcher.tsx +179 -0
  85. package/app/apps/github/src/components/shell/sections.ts +31 -0
  86. package/app/apps/github/src/components/shell/submenu-chevron.ts +147 -0
  87. package/app/apps/github/src/components/signin/device-card.tsx +139 -0
  88. package/app/apps/github/src/components/signin/login-form.tsx +88 -0
  89. package/app/apps/github/src/components/signin/signin-page.tsx +33 -0
  90. package/app/apps/github/src/components/signin/signup-form.tsx +106 -0
  91. package/app/apps/github/src/components/states/live-status.tsx +42 -0
  92. package/app/apps/github/src/components/states/states.tsx +126 -0
  93. package/app/apps/github/src/components/tab-indicator.tsx +143 -0
  94. package/app/apps/github/src/components/theme-choice.tsx +108 -0
  95. package/app/apps/github/src/components/theme-provider.tsx +126 -0
  96. package/app/apps/github/src/components/tones.ts +23 -0
  97. package/app/apps/github/src/components/ui/alert-dialog.tsx +187 -0
  98. package/app/apps/github/src/components/ui/alert.tsx +78 -0
  99. package/app/apps/github/src/components/ui/avatar.tsx +106 -0
  100. package/app/apps/github/src/components/ui/badge.tsx +51 -0
  101. package/app/apps/github/src/components/ui/breadcrumb.tsx +124 -0
  102. package/app/apps/github/src/components/ui/button-group.tsx +87 -0
  103. package/app/apps/github/src/components/ui/button.tsx +61 -0
  104. package/app/apps/github/src/components/ui/calendar.tsx +221 -0
  105. package/app/apps/github/src/components/ui/card.tsx +102 -0
  106. package/app/apps/github/src/components/ui/checkbox.tsx +26 -0
  107. package/app/apps/github/src/components/ui/collapsible.tsx +19 -0
  108. package/app/apps/github/src/components/ui/combobox.tsx +304 -0
  109. package/app/apps/github/src/components/ui/command.tsx +208 -0
  110. package/app/apps/github/src/components/ui/dialog.tsx +156 -0
  111. package/app/apps/github/src/components/ui/dropdown-menu.tsx +290 -0
  112. package/app/apps/github/src/components/ui/empty.tsx +100 -0
  113. package/app/apps/github/src/components/ui/field.tsx +236 -0
  114. package/app/apps/github/src/components/ui/hover-card.tsx +48 -0
  115. package/app/apps/github/src/components/ui/input-group.tsx +163 -0
  116. package/app/apps/github/src/components/ui/input.tsx +19 -0
  117. package/app/apps/github/src/components/ui/item.tsx +201 -0
  118. package/app/apps/github/src/components/ui/kbd.tsx +27 -0
  119. package/app/apps/github/src/components/ui/label.tsx +33 -0
  120. package/app/apps/github/src/components/ui/popover.tsx +87 -0
  121. package/app/apps/github/src/components/ui/radio-group.tsx +35 -0
  122. package/app/apps/github/src/components/ui/select.tsx +198 -0
  123. package/app/apps/github/src/components/ui/separator.tsx +22 -0
  124. package/app/apps/github/src/components/ui/sheet.tsx +138 -0
  125. package/app/apps/github/src/components/ui/sidebar.tsx +724 -0
  126. package/app/apps/github/src/components/ui/skeleton.tsx +13 -0
  127. package/app/apps/github/src/components/ui/sonner.tsx +47 -0
  128. package/app/apps/github/src/components/ui/styles.css +242 -0
  129. package/app/apps/github/src/components/ui/table.tsx +113 -0
  130. package/app/apps/github/src/components/ui/tabs.tsx +79 -0
  131. package/app/apps/github/src/components/ui/textarea.tsx +17 -0
  132. package/app/apps/github/src/components/ui/title.ts +6 -0
  133. package/app/apps/github/src/components/ui/toggle-group.tsx +89 -0
  134. package/app/apps/github/src/components/ui/toggle.tsx +42 -0
  135. package/app/apps/github/src/components/ui/tooltip.tsx +63 -0
  136. package/app/apps/github/src/components/user-avatar.tsx +145 -0
  137. package/app/apps/github/src/components/view-tabs.tsx +42 -0
  138. package/app/apps/github/src/context/context.ts +133 -0
  139. package/app/apps/github/src/diffs/blobs.ts +94 -0
  140. package/app/apps/github/src/diffs/diff-view.tsx +155 -0
  141. package/app/apps/github/src/diffs/files.ts +121 -0
  142. package/app/apps/github/src/diffs/hunks.tsx +454 -0
  143. package/app/apps/github/src/diffs/patch.ts +131 -0
  144. package/app/apps/github/src/diffs/rows.ts +137 -0
  145. package/app/apps/github/src/history/commit-diff.ts +54 -0
  146. package/app/apps/github/src/history/commit-list.tsx +207 -0
  147. package/app/apps/github/src/history/commit-page.tsx +147 -0
  148. package/app/apps/github/src/history/history.ts +129 -0
  149. package/app/apps/github/src/hooks/allowed.ts +31 -0
  150. package/app/apps/github/src/hooks/answers.ts +65 -0
  151. package/app/apps/github/src/hooks/avatars.ts +54 -0
  152. package/app/apps/github/src/hooks/draft.ts +38 -0
  153. package/app/apps/github/src/hooks/open-counts.ts +127 -0
  154. package/app/apps/github/src/hooks/profiles.ts +120 -0
  155. package/app/apps/github/src/hooks/repos.ts +440 -0
  156. package/app/apps/github/src/hooks/use-mobile.ts +19 -0
  157. package/app/apps/github/src/hooks/viewer.ts +39 -0
  158. package/app/apps/github/src/inbox/count.ts +70 -0
  159. package/app/apps/github/src/inbox/inbox-item.tsx +66 -0
  160. package/app/apps/github/src/inbox/inbox-page.tsx +572 -0
  161. package/app/apps/github/src/inbox/marks.ts +130 -0
  162. package/app/apps/github/src/inbox/release-tags.ts +65 -0
  163. package/app/apps/github/src/inbox/search.ts +97 -0
  164. package/app/apps/github/src/inbox/subjects.ts +184 -0
  165. package/app/apps/github/src/inbox/subscription-controls.tsx +184 -0
  166. package/app/apps/github/src/inbox/subscriptions.ts +189 -0
  167. package/app/apps/github/src/inbox/threads.ts +198 -0
  168. package/app/apps/github/src/issues/changes.ts +332 -0
  169. package/app/apps/github/src/issues/counts.ts +62 -0
  170. package/app/apps/github/src/issues/issue-list.tsx +682 -0
  171. package/app/apps/github/src/issues/issue-page.tsx +533 -0
  172. package/app/apps/github/src/issues/issues.ts +566 -0
  173. package/app/apps/github/src/issues/label-dialog.tsx +310 -0
  174. package/app/apps/github/src/issues/labels-page.tsx +119 -0
  175. package/app/apps/github/src/issues/new-issue.tsx +79 -0
  176. package/app/apps/github/src/issues/parts.tsx +71 -0
  177. package/app/apps/github/src/issues/picker.tsx +298 -0
  178. package/app/apps/github/src/issues/search.ts +238 -0
  179. package/app/apps/github/src/issues/sidebar.tsx +236 -0
  180. package/app/apps/github/src/lib/cn.ts +8 -0
  181. package/app/apps/github/src/lib/highlighting.ts +13 -0
  182. package/app/apps/github/src/live/follow.ts +129 -0
  183. package/app/apps/github/src/live/sse.ts +74 -0
  184. package/app/apps/github/src/live/use-follow.ts +37 -0
  185. package/app/apps/github/src/markdown/README.md +53 -0
  186. package/app/apps/github/src/markdown/allowed-html.ts +69 -0
  187. package/app/apps/github/src/markdown/context.ts +206 -0
  188. package/app/apps/github/src/markdown/images.ts +81 -0
  189. package/app/apps/github/src/markdown/lookup.ts +122 -0
  190. package/app/apps/github/src/markdown/patches.ts +299 -0
  191. package/app/apps/github/src/markdown/query.ts +25 -0
  192. package/app/apps/github/src/markdown/references.ts +158 -0
  193. package/app/apps/github/src/markdown/render.ts +103 -0
  194. package/app/apps/github/src/names/owners.ts +51 -0
  195. package/app/apps/github/src/names/repos.ts +24 -0
  196. package/app/apps/github/src/palette/palette.tsx +547 -0
  197. package/app/apps/github/src/palette/recent.ts +116 -0
  198. package/app/apps/github/src/palette/rows.tsx +455 -0
  199. package/app/apps/github/src/palette/server.ts +104 -0
  200. package/app/apps/github/src/palette/targets.ts +306 -0
  201. package/app/apps/github/src/policy.ts +600 -0
  202. package/app/apps/github/src/private-repos.ts +47 -0
  203. package/app/apps/github/src/pulls/compare-page.tsx +342 -0
  204. package/app/apps/github/src/pulls/files-tab.tsx +776 -0
  205. package/app/apps/github/src/pulls/live.ts +124 -0
  206. package/app/apps/github/src/pulls/merge-box.tsx +367 -0
  207. package/app/apps/github/src/pulls/merge-button.ts +86 -0
  208. package/app/apps/github/src/pulls/pull-list.tsx +235 -0
  209. package/app/apps/github/src/pulls/pull-page.tsx +474 -0
  210. package/app/apps/github/src/pulls/pull.ts +468 -0
  211. package/app/apps/github/src/pulls/pulls.ts +318 -0
  212. package/app/apps/github/src/pulls/review.ts +350 -0
  213. package/app/apps/github/src/pulls/search.ts +130 -0
  214. package/app/apps/github/src/queue/queue-page.tsx +405 -0
  215. package/app/apps/github/src/queue/queue.ts +231 -0
  216. package/app/apps/github/src/releases/latest-release.tsx +55 -0
  217. package/app/apps/github/src/releases/overview.tsx +30 -0
  218. package/app/apps/github/src/releases/release-form.tsx +353 -0
  219. package/app/apps/github/src/releases/release-list.tsx +173 -0
  220. package/app/apps/github/src/releases/release-view.tsx +183 -0
  221. package/app/apps/github/src/releases/releases.ts +308 -0
  222. package/app/apps/github/src/releases/tag-list.tsx +134 -0
  223. package/app/apps/github/src/router.tsx +46 -0
  224. package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +33 -0
  225. package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +28 -0
  226. package/app/apps/github/src/routes/$owner/$repo/_code.tsx +11 -0
  227. package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +19 -0
  228. package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +19 -0
  229. package/app/apps/github/src/routes/$owner/$repo/_releases.tsx +23 -0
  230. package/app/apps/github/src/routes/$owner/$repo/branches.tsx +39 -0
  231. package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +34 -0
  232. package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +42 -0
  233. package/app/apps/github/src/routes/$owner/$repo/compare/$.tsx +19 -0
  234. package/app/apps/github/src/routes/$owner/$repo/index.tsx +24 -0
  235. package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +50 -0
  236. package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +53 -0
  237. package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +43 -0
  238. package/app/apps/github/src/routes/$owner/$repo/labels.tsx +22 -0
  239. package/app/apps/github/src/routes/$owner/$repo/pull/$number/checks.tsx +15 -0
  240. package/app/apps/github/src/routes/$owner/$repo/pull/$number/commits.tsx +15 -0
  241. package/app/apps/github/src/routes/$owner/$repo/pull/$number/files.tsx +15 -0
  242. package/app/apps/github/src/routes/$owner/$repo/pull/$number/index.tsx +19 -0
  243. package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +52 -0
  244. package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +48 -0
  245. package/app/apps/github/src/routes/$owner/$repo/queue.tsx +22 -0
  246. package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +58 -0
  247. package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +40 -0
  248. package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +35 -0
  249. package/app/apps/github/src/routes/$owner/$repo/route.tsx +102 -0
  250. package/app/apps/github/src/routes/$owner/$repo/settings/access.tsx +9 -0
  251. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +16 -0
  252. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/new.tsx +25 -0
  253. package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +17 -0
  254. package/app/apps/github/src/routes/$owner/$repo/settings/route.tsx +28 -0
  255. package/app/apps/github/src/routes/$owner/$repo/settings/rules.tsx +12 -0
  256. package/app/apps/github/src/routes/$owner/$repo/tokens.tsx +16 -0
  257. package/app/apps/github/src/routes/$owner/index.tsx +45 -0
  258. package/app/apps/github/src/routes/-nav.tsx +293 -0
  259. package/app/apps/github/src/routes/-root-testing.ts +107 -0
  260. package/app/apps/github/src/routes/__root.tsx +225 -0
  261. package/app/apps/github/src/routes/api.auth.$.ts +18 -0
  262. package/app/apps/github/src/routes/downloads/$owner/$repo/$asset.tsx +10 -0
  263. package/app/apps/github/src/routes/file-icons[.]svg.ts +21 -0
  264. package/app/apps/github/src/routes/icons/$owner/$repo.tsx +14 -0
  265. package/app/apps/github/src/routes/icons/$owner/index.tsx +14 -0
  266. package/app/apps/github/src/routes/icons/index.tsx +12 -0
  267. package/app/apps/github/src/routes/index.tsx +48 -0
  268. package/app/apps/github/src/routes/login.tsx +24 -0
  269. package/app/apps/github/src/routes/login_.code.tsx +31 -0
  270. package/app/apps/github/src/routes/new.tsx +91 -0
  271. package/app/apps/github/src/routes/notifications.tsx +20 -0
  272. package/app/apps/github/src/routes/orgs/$owner/issues.tsx +8 -0
  273. package/app/apps/github/src/routes/orgs/$owner/pulls.tsx +8 -0
  274. package/app/apps/github/src/routes/orgs/$owner/releases.tsx +8 -0
  275. package/app/apps/github/src/routes/orgs/$owner/route.tsx +25 -0
  276. package/app/apps/github/src/routes/orgs/$owner/settings.tsx +30 -0
  277. package/app/apps/github/src/routes/orgs/$owner/tokens.tsx +15 -0
  278. package/app/apps/github/src/routes/settings.tsx +54 -0
  279. package/app/apps/github/src/routes/signup.tsx +24 -0
  280. package/app/apps/github/src/routes/uploads/$owner/$repo/$release.tsx +10 -0
  281. package/app/apps/github/src/seed/acme.ts +498 -0
  282. package/app/apps/github/src/seed/licenses.ts +114 -0
  283. package/app/apps/github/src/seed/seed.ts +538 -0
  284. package/app/apps/github/src/server.ts +97 -0
  285. package/app/apps/github/src/settings/account-avatar.tsx +43 -0
  286. package/app/apps/github/src/settings/avatar-section.tsx +140 -0
  287. package/app/apps/github/src/settings/avatar.ts +58 -0
  288. package/app/apps/github/src/settings/general-settings.tsx +439 -0
  289. package/app/apps/github/src/settings/general.ts +73 -0
  290. package/app/apps/github/src/settings/hook-form.tsx +195 -0
  291. package/app/apps/github/src/settings/hook-list.tsx +166 -0
  292. package/app/apps/github/src/settings/hooks.ts +87 -0
  293. package/app/apps/github/src/settings/org-settings.tsx +228 -0
  294. package/app/apps/github/src/settings/orgs.ts +116 -0
  295. package/app/apps/github/src/settings/rule-list.tsx +72 -0
  296. package/app/apps/github/src/settings/rules.ts +27 -0
  297. package/app/apps/github/src/settings/settings-layout.tsx +114 -0
  298. package/app/apps/github/src/signin/approval.ts +186 -0
  299. package/app/apps/github/src/signin/auth-client.ts +127 -0
  300. package/app/apps/github/src/signin/auth.ts +753 -0
  301. package/app/apps/github/src/signin/avatars.ts +126 -0
  302. package/app/apps/github/src/signin/client-ip.ts +39 -0
  303. package/app/apps/github/src/signin/credentials.ts +26 -0
  304. package/app/apps/github/src/signin/device-code.ts +95 -0
  305. package/app/apps/github/src/signin/device-prompt.ts +125 -0
  306. package/app/apps/github/src/signin/errors.ts +135 -0
  307. package/app/apps/github/src/signin/host-session.ts +68 -0
  308. package/app/apps/github/src/signin/orgs.ts +283 -0
  309. package/app/apps/github/src/signin/owner-names.ts +183 -0
  310. package/app/apps/github/src/signin/person-lock.ts +104 -0
  311. package/app/apps/github/src/signin/seal.ts +88 -0
  312. package/app/apps/github/src/signin/seed-people.ts +92 -0
  313. package/app/apps/github/src/signin/session.ts +48 -0
  314. package/app/apps/github/src/signin/unborn.ts +110 -0
  315. package/app/apps/github/src/signin/viewer-orgs.ts +47 -0
  316. package/app/apps/github/src/signin/viewer.ts +74 -0
  317. package/app/apps/github/src/signin/with-headers.ts +14 -0
  318. package/app/apps/github/src/tokens/tokens-page.tsx +529 -0
  319. package/app/apps/github/src/tokens/tokens.ts +54 -0
  320. package/app/apps/github/tsconfig.json +25 -0
  321. package/app/apps/github/tsconfig.worker.json +24 -0
  322. package/app/apps/github/vite.config.ts +21 -0
  323. package/app/pnpm-workspace.yaml +216 -0
  324. package/app/tsconfig.base.json +127 -0
  325. package/dist/LICENSE +202 -0
  326. package/dist/cli/child.mjs +42 -0
  327. package/dist/cli/commands.mjs +23 -0
  328. package/dist/cli/credentials.mjs +84 -0
  329. package/dist/cli/documents.mjs +214 -0
  330. package/dist/cli/events.mjs +55 -0
  331. package/dist/cli/failure.mjs +105 -0
  332. package/dist/cli/folders.mjs +32 -0
  333. package/dist/cli/git-remote-ref0.d.mts +1 -0
  334. package/dist/cli/git-remote-ref0.mjs +29 -0
  335. package/dist/cli/git.mjs +48 -0
  336. package/dist/cli/helpers.mjs +51 -0
  337. package/dist/cli/hosts.mjs +127 -0
  338. package/dist/cli/node.mjs +15 -0
  339. package/dist/cli/output.mjs +135 -0
  340. package/dist/cli/prompt.mjs +35 -0
  341. package/dist/cli/queue.mjs +215 -0
  342. package/dist/cli/ref0-git.d.mts +1 -0
  343. package/dist/cli/ref0-git.mjs +144 -0
  344. package/dist/cli/repos.mjs +162 -0
  345. package/dist/cli/resources.mjs +131 -0
  346. package/dist/cli/run-end.mjs +57 -0
  347. package/dist/cli/runtime.mjs +50 -0
  348. package/dist/cli/setup.mjs +1410 -0
  349. package/dist/cli/sign-in.mjs +162 -0
  350. package/dist/cli/sign-ins.mjs +79 -0
  351. package/dist/cli/sqlite.mjs +28 -0
  352. package/dist/cli/tokens.mjs +141 -0
  353. package/dist/cli/vendor.mjs +123 -0
  354. package/dist/init/app.mjs +231 -0
  355. package/dist/init/astro.mjs +49 -0
  356. package/dist/init/choices.mjs +497 -0
  357. package/dist/init/cloudflare.mjs +324 -0
  358. package/dist/init/create.mjs +151 -0
  359. package/dist/init/detect.mjs +297 -0
  360. package/dist/init/files.mjs +75 -0
  361. package/dist/init/frameworks.mjs +248 -0
  362. package/dist/init/git-module.mjs +49 -0
  363. package/dist/init/github-routes.mjs +66 -0
  364. package/dist/init/jsonc.mjs +143 -0
  365. package/dist/init/metadata.mjs +48 -0
  366. package/dist/init/mounts.mjs +109 -0
  367. package/dist/init/next.mjs +205 -0
  368. package/dist/init/node-app.mjs +189 -0
  369. package/dist/init/node.mjs +458 -0
  370. package/dist/init/nuxt.mjs +115 -0
  371. package/dist/init/output.mjs +21 -0
  372. package/dist/init/plan.mjs +82 -0
  373. package/dist/init/range-major.mjs +257 -0
  374. package/dist/init/react-router.mjs +59 -0
  375. package/dist/init/routes.mjs +148 -0
  376. package/dist/init/shell.mjs +4 -0
  377. package/dist/init/stores.mjs +51 -0
  378. package/dist/init/sveltekit.mjs +139 -0
  379. package/dist/init/template.mjs +142 -0
  380. package/dist/init/templates.mjs +343 -0
  381. package/dist/init/vercel.mjs +383 -0
  382. package/dist/init/versions.mjs +32 -0
  383. package/dist/init/workspace.mjs +20 -0
  384. package/package.json +52 -3
  385. package/README.md +0 -3
@@ -0,0 +1,63 @@
1
+ import { Tooltip as TooltipPrimitive } from "@base-ui/react/tooltip"
2
+ import { cn } from "#/lib/cn"
3
+
4
+ function TooltipProvider({
5
+ delay = 0,
6
+ ...props
7
+ }: TooltipPrimitive.Provider.Props) {
8
+ return (
9
+ <TooltipPrimitive.Provider
10
+ data-slot="tooltip-provider"
11
+ delay={delay}
12
+ {...props}
13
+ />
14
+ )
15
+ }
16
+
17
+ function Tooltip({ ...props }: TooltipPrimitive.Root.Props) {
18
+ return <TooltipPrimitive.Root data-slot="tooltip" {...props} />
19
+ }
20
+
21
+ function TooltipTrigger({ ...props }: TooltipPrimitive.Trigger.Props) {
22
+ return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />
23
+ }
24
+
25
+ function TooltipContent({
26
+ className,
27
+ side = "top",
28
+ sideOffset = 4,
29
+ align = "center",
30
+ alignOffset = 0,
31
+ children,
32
+ ...props
33
+ }: TooltipPrimitive.Popup.Props &
34
+ Pick<
35
+ TooltipPrimitive.Positioner.Props,
36
+ "align" | "alignOffset" | "side" | "sideOffset"
37
+ >) {
38
+ return (
39
+ <TooltipPrimitive.Portal>
40
+ <TooltipPrimitive.Positioner
41
+ align={align}
42
+ alignOffset={alignOffset}
43
+ side={side}
44
+ sideOffset={sideOffset}
45
+ className="isolate z-50"
46
+ >
47
+ <TooltipPrimitive.Popup
48
+ data-slot="tooltip-content"
49
+ className={cn(
50
+ "z-50 inline-flex w-fit max-w-xs origin-(--transform-origin) items-center gap-1.5 rounded-sm bg-foreground px-3 py-1.5 text-meta text-background has-data-[slot=kbd]:pr-1.5 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
51
+ className
52
+ )}
53
+ {...props}
54
+ >
55
+ {children}
56
+ <TooltipPrimitive.Arrow className="z-50 size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground data-[side=bottom]:top-1 data-[side=inline-end]:top-1/2! data-[side=inline-end]:-left-1 data-[side=inline-end]:-translate-y-1/2 data-[side=inline-start]:top-1/2! data-[side=inline-start]:-right-1 data-[side=inline-start]:-translate-y-1/2 data-[side=left]:top-1/2! data-[side=left]:-right-1 data-[side=left]:-translate-y-1/2 data-[side=right]:top-1/2! data-[side=right]:-left-1 data-[side=right]:-translate-y-1/2 data-[side=top]:-bottom-2.5" />
57
+ </TooltipPrimitive.Popup>
58
+ </TooltipPrimitive.Positioner>
59
+ </TooltipPrimitive.Portal>
60
+ )
61
+ }
62
+
63
+ export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
@@ -0,0 +1,145 @@
1
+ import { cn } from '#/lib/cn';
2
+ import { useQuery } from '@tanstack/react-query';
3
+ import { useEffect, useState } from 'react';
4
+
5
+ import { avatarAt } from '../hooks/avatars.ts';
6
+ import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar.tsx';
7
+
8
+ /** Whose a login is: a person's, or an org's, whose avatar is square. */
9
+ export type Account = 'user' | 'org';
10
+
11
+ /**
12
+ * Each kind's ground, the one colour its DiceBear picture is drawn on: Pixelbot's Cool preset's for
13
+ * a person, and the first of Planets' own for an org. An avatar fills its shape with it while its
14
+ * picture loads, so the picture lands on the same colour and nothing shifts or pops in empty.
15
+ */
16
+ export const groundOf: Readonly<Record<Account, string>> = { user: '#0b1220', org: '#17233f' };
17
+
18
+ /** A login's initial, for an avatar until its picture shows. */
19
+ const initialOf = (login: string) => login.slice(0, 1).toUpperCase();
20
+
21
+ /**
22
+ * How long an avatar shows nothing before its initial, while its picture loads. A picture this page
23
+ * has shown before is drawn or loaded by then, so moving between pages never flashes the initial.
24
+ */
25
+ export const initialAfterMs = 150;
26
+
27
+ /** DiceBear and its two styles, once loaded: it loads when the first avatar draws, not with the page. */
28
+ let pictures: typeof import('./avatar-picture.ts') | undefined;
29
+
30
+ let loading: Promise<void> | undefined;
31
+
32
+ /** Loads DiceBear once, for every avatar on every page. */
33
+ const loadPictures = () =>
34
+ (loading ??= import('./avatar-picture.ts').then((loaded) => {
35
+ pictures = loaded;
36
+ }));
37
+
38
+ /** How long DiceBear's prefetch waits for an idle moment, which a hidden tab may never have. */
39
+ export const prefetchWithinMs = 2000;
40
+
41
+ /**
42
+ * Loads DiceBear once the browser is idle after the page's first paint, or after `prefetchWithinMs`
43
+ * at most, so most pages never wait on it, and answers what cancels that. Without
44
+ * `requestIdleCallback`, as in Safari, it loads on the next task.
45
+ */
46
+ export const prefetchPicturesWhenIdle = (): (() => void) => {
47
+ const load = () => void loadPictures();
48
+
49
+ if ('requestIdleCallback' in window) {
50
+ const idle = requestIdleCallback(load, { timeout: prefetchWithinMs });
51
+
52
+ return () => cancelIdleCallback(idle);
53
+ }
54
+
55
+ const next = setTimeout(load, 0);
56
+
57
+ return () => clearTimeout(next);
58
+ };
59
+
60
+ /**
61
+ * A login's DiceBear picture once `drawn`, and undefined until then. Once DiceBear has loaded, it's
62
+ * there on the avatar's first render, from `avatar-picture.ts`' recent pictures, so an avatar that
63
+ * mounts again on the next page shows its picture at once.
64
+ */
65
+ function useDrawn(login: string, account: Account, drawn: boolean): string | undefined {
66
+ const [, setLoaded] = useState(pictures !== undefined);
67
+
68
+ useEffect(() => {
69
+ if (!drawn || pictures !== undefined) return;
70
+
71
+ let live = true;
72
+ void loadPictures().then(() => {
73
+ if (live) setLoaded(true);
74
+ });
75
+
76
+ return () => {
77
+ live = false;
78
+ };
79
+ }, [drawn]);
80
+
81
+ return drawn ? pictures?.pictureOf(login, account) : undefined;
82
+ }
83
+
84
+ /**
85
+ * A login's picture: its upload, as `named` says or else once `GET /users/{login}` names one, or
86
+ * DiceBear's once either says there's none or the read fails, and undefined while it's asked.
87
+ * `uploaded` says it's the account's own. A login the page's answer named is never asked after.
88
+ */
89
+ function usePicture(
90
+ login: string,
91
+ account: Account,
92
+ named: string | null | undefined,
93
+ ): { readonly picture: string | undefined; readonly uploaded: boolean } {
94
+ const asked = useQuery({ ...avatarAt(login), enabled: named === undefined });
95
+ const upload = named === undefined ? (asked.isSuccess ? asked.data : undefined) : named;
96
+ const drawn = upload === null || (named === undefined && asked.isError);
97
+ const picture = useDrawn(login, account, drawn);
98
+
99
+ return upload === undefined || upload === null
100
+ ? { picture, uploaded: false }
101
+ : { picture: upload, uploaded: true };
102
+ }
103
+
104
+ /**
105
+ * A person's or an org's avatar: its picture, its shape filled with its kind's ground while the
106
+ * picture loads, and its login's initial once that has taken `initialAfterMs`, or failed. It's
107
+ * decorative, since the login is always written beside it. An org's is square, as on GitHub. The
108
+ * picture is the one its account uploaded (Q757), or else `avatar-picture.ts`'s DiceBear drawing:
109
+ * Pixelbot for a person, Planets for an org.
110
+ */
111
+ export function UserAvatar({
112
+ login,
113
+ account,
114
+ upload,
115
+ size = 'default',
116
+ }: {
117
+ readonly login: string;
118
+ readonly account: Account;
119
+ /**
120
+ * Its uploaded picture, as the answer that named `login` gave its `avatar_url`, or `null` for
121
+ * none. Left out where the page has the login alone, when the avatar asks `GET /users/{login}`.
122
+ */
123
+ readonly upload?: string | null | undefined;
124
+ /** `xl` is a settings page's, 64px, as `RepoIcon`'s. */
125
+ readonly size?: 'sm' | 'default' | 'lg' | 'xl';
126
+ }) {
127
+ const { picture, uploaded } = usePicture(login, account, upload);
128
+ const square = account === 'org' && 'rounded-md after:rounded-md';
129
+ const xl = size === 'xl';
130
+
131
+ return (
132
+ <Avatar
133
+ size={xl ? 'default' : size}
134
+ className={cn(xl && 'size-16', square)}
135
+ // DiceBear's ground until its picture covers it. An upload may be see-through, so it gets none.
136
+ style={uploaded ? undefined : { backgroundColor: groundOf[account] }}
137
+ aria-hidden
138
+ >
139
+ {picture !== undefined && <AvatarImage src={picture} alt="" className={cn(square)} />}
140
+ <AvatarFallback delay={initialAfterMs} className={cn(xl && 'text-2xl', square)}>
141
+ {initialOf(login)}
142
+ </AvatarFallback>
143
+ </Avatar>
144
+ );
145
+ }
@@ -0,0 +1,42 @@
1
+ import type { ReactElement } from 'react';
2
+
3
+ import { TabsList, TabsTrigger } from './ui/tabs.tsx';
4
+
5
+ /** One of a thing's views: its value in its `Tabs`, its name, and its page, where it has one. */
6
+ export interface View {
7
+ readonly value: string;
8
+ readonly label: string;
9
+ /** The link to the view's own page, as a Markdown file's code is at `?plain=1`. */
10
+ readonly link?: ReactElement;
11
+ }
12
+
13
+ /**
14
+ * A thing's few views, such as a comment's Write and Preview or a Markdown file's Preview and
15
+ * Code: shadcn's tabs on their muted track, the current one raised on it. Put it in a `Tabs` whose
16
+ * value is the current view's. A view with a `link` is that link, as Base UI's tabs as links are,
17
+ * and its `Tabs` has no panels: the page is the view.
18
+ */
19
+ export function ViewTabs({
20
+ label,
21
+ views,
22
+ }: {
23
+ /** The list's name, where the page doesn't already say what its views are of. */
24
+ readonly label?: string;
25
+ readonly views: readonly View[];
26
+ }) {
27
+ return (
28
+ <TabsList aria-label={label}>
29
+ {views.map(({ value, label: name, link }) =>
30
+ link === undefined ? (
31
+ <TabsTrigger key={value} value={value}>
32
+ {name}
33
+ </TabsTrigger>
34
+ ) : (
35
+ <TabsTrigger key={value} value={value} nativeButton={false} render={link}>
36
+ {name}
37
+ </TabsTrigger>
38
+ ),
39
+ )}
40
+ </TabsList>
41
+ );
42
+ }
@@ -0,0 +1,133 @@
1
+ import type { Caller, GitAuthorize, GitServer, Result, TokenCalls } from '@ref0/git';
2
+ import type { GitHubAuthorize } from '@ref0/github';
3
+ import type {} from '@tanstack/react-start';
4
+
5
+ /**
6
+ * One request's answer from the drop-in or Git, in this Worker: never the app's, and never a
7
+ * network hop. `server.ts` gives it to every request through Start's request context.
8
+ */
9
+ export type ApiFetch = (request: Request) => Promise<Response>;
10
+
11
+ /** One of the host's push rules, as a repo's settings show it: its name, and the refs it covers. */
12
+ export interface ShownRule {
13
+ readonly name: string;
14
+ readonly covers: readonly string[];
15
+ }
16
+
17
+ /**
18
+ * Who the browser is signed in as, the Git token the server calls the APIs with for them, its ID,
19
+ * and when it expires, in milliseconds since the epoch: the session ends with it. `signin/auth.ts`'
20
+ * `sessionFrom` reads it from Better Auth's session.
21
+ */
22
+ export interface Session {
23
+ readonly login: string;
24
+ readonly token: string;
25
+ readonly tokenId: string;
26
+ readonly expiresAt: number;
27
+ }
28
+
29
+ /** A session cookie's name, and the path and `Secure` it was set with, which clearing it names. */
30
+ export interface SessionCookie {
31
+ readonly name: string;
32
+ readonly path: string;
33
+ readonly secure: boolean;
34
+ }
35
+
36
+ /** A picture as the app keeps it: its sniffed type, its bytes, and their SHA-256 in hex. */
37
+ export interface StoredIcon {
38
+ readonly type: string;
39
+ readonly bytes: Uint8Array;
40
+ readonly hash: string;
41
+ }
42
+
43
+ /** Whose picture an avatar is: a person's, an org's, or a repo's, its icon. */
44
+ export type AvatarKind = 'user' | 'org' | 'repo';
45
+
46
+ /**
47
+ * The app's avatars (Q757), each under its kind and an ID a rename keeps: a repo's REST `id`, and a
48
+ * person's or an org's row ID in Better Auth's tables.
49
+ */
50
+ export interface Avatars {
51
+ readonly get: (kind: AvatarKind, id: string) => Promise<StoredIcon | undefined>;
52
+ /** The stored picture's hash alone, which an API answer's `avatar_url` carries. */
53
+ readonly hash: (kind: AvatarKind, id: string) => Promise<string | undefined>;
54
+ /** The stored pictures' hashes for `ids`, in one read, by ID: an ID with no picture is left out. */
55
+ readonly hashes: (
56
+ kind: AvatarKind,
57
+ ids: readonly string[],
58
+ ) => Promise<ReadonlyMap<string, string>>;
59
+ readonly put: (kind: AvatarKind, id: string, icon: StoredIcon) => Promise<void>;
60
+ readonly remove: (kind: AvatarKind, id: string) => Promise<void>;
61
+ }
62
+
63
+ /** Who holds a login: a person or an org, by the ID Better Auth gave its row, which a rename keeps. */
64
+ export interface Account {
65
+ readonly kind: 'user' | 'org';
66
+ readonly id: string;
67
+ }
68
+
69
+ /**
70
+ * A person's place in an org: `admin` for its owners and admins, and `since`, when their member row
71
+ * was written, in milliseconds. Better Auth deletes the row when they leave and writes a new one
72
+ * when they join again, while a role change updates it in place, so `since` is when this
73
+ * membership began.
74
+ */
75
+ export interface Membership {
76
+ readonly admin: boolean;
77
+ readonly since: number;
78
+ }
79
+
80
+ /** Who holds a login, and who runs an org, as an avatar's route asks the host's directory. */
81
+ export interface Accounts {
82
+ /** The person or org holding `login`, or `undefined` when neither does. */
83
+ readonly account: (login: string) => Promise<Account | undefined>;
84
+ /** The person `login`'s membership of the org `org`, or `undefined` when they aren't in it. */
85
+ readonly membership: (org: string, login: string) => Promise<Membership | undefined>;
86
+ }
87
+
88
+ /** What `server.ts` hands each request, which server routes and functions read. */
89
+ export interface AppContext {
90
+ readonly api: ApiFetch;
91
+ /** The key host sessions are sealed under, from `SESSION_SECRET`. */
92
+ readonly sealKey: CryptoKey;
93
+ /** Better Auth's routes, at `/api/auth/*`: sign-up, sign-in and sign-out. */
94
+ readonly auth: (request: Request) => Promise<Response>;
95
+ /** The request's signed-in person and their session's Git token, or `undefined` for a visitor. */
96
+ readonly session: (request: Request) => Promise<Session | undefined>;
97
+ /**
98
+ * Ends the request's session once Git refuses its token: Better Auth deletes it, and its delete
99
+ * hook revokes the token, so the cookie names no one from then on.
100
+ */
101
+ readonly endSession: (request: Request) => Promise<void>;
102
+ /** Better Auth's session cookie, as the browser holds it, which a page clears once it ended. */
103
+ readonly sessionCookie: () => Promise<SessionCookie>;
104
+ /** Git's `identify`: the caller a request's credential names, as the drop-in finds it. */
105
+ readonly identify: (request: Request) => Promise<Result<Caller>>;
106
+ /** The host's say on Git's own operations, which a host call is held to: Git's `authorize`. */
107
+ readonly authorize: GitAuthorize;
108
+ /** The host's say on a GitHub operation: the `authorize` the drop-in was made with. */
109
+ readonly authorizeGitHub: GitHubAuthorize;
110
+ /** The push rules Git was made with, each by name and the refs it covers on every repo. */
111
+ readonly rules: readonly ShownRule[];
112
+ /** People's, orgs' and repos' pictures, in `AUTH_DB` beside Better Auth's tables. */
113
+ readonly avatars: Avatars;
114
+ /** The host's people and orgs, by login. */
115
+ readonly accounts: Accounts;
116
+ /**
117
+ * Git's own calls, which skip `authorize`: the repo and token lists an org's Tokens page reads
118
+ * once its read of the person's role decided what they see.
119
+ */
120
+ readonly git: HostGit;
121
+ }
122
+
123
+ /** Git's direct calls a host call reads with, as host code. */
124
+ export interface HostGit {
125
+ readonly repos: Pick<GitServer['repos'], 'list'>;
126
+ readonly tokens?: Pick<TokenCalls, 'list'> | undefined;
127
+ }
128
+
129
+ declare module '@tanstack/react-start' {
130
+ interface Register {
131
+ server: { requestContext: AppContext };
132
+ }
133
+ }
@@ -0,0 +1,94 @@
1
+ import { github } from '../clients/clients.ts';
2
+ import { repoPath, type ChangedFile, type Revisions } from './files.ts';
3
+
4
+ /** A side of a file's diff: its name and its text, or `null` where the file isn't. */
5
+ export interface Side {
6
+ readonly name: string;
7
+ readonly contents: string;
8
+ }
9
+
10
+ /**
11
+ * A file's two sides, read whole for **Load diff**, or why they can't be diffed here: a side
12
+ * that isn't text, or one past `diffedBytesMost`, which the browser would take too long on.
13
+ */
14
+ export type LoadedFile =
15
+ | { readonly kind: 'text'; readonly old: Side | null; readonly new: Side | null }
16
+ | { readonly kind: 'binary' }
17
+ | { readonly kind: 'too-large' }
18
+ | { readonly kind: 'unchanged' };
19
+
20
+ /** The most bytes a side may hold for the browser to diff it. */
21
+ export const diffedBytesMost = 1024 * 1024;
22
+
23
+ /** A file's path before the change: a rename's old one, or its own. */
24
+ const oldName = (file: ChangedFile) => file.previous_filename ?? file.filename;
25
+
26
+ /** The blob at `path` in commit `ref`, by the contents API's answer, or `undefined`. */
27
+ const blobAt = async (revisions: Revisions, path: string, signal: AbortSignal) => {
28
+ const answer = await github.GET('/repos/{owner}/{repo}/contents/{path}', {
29
+ params: { path: { ...repoPath(revisions.repo), path }, query: { ref: revisions.base } },
30
+ signal,
31
+ });
32
+ const found = answer.data;
33
+ if (found === undefined) throw new Error(`${path} didn't load at ${revisions.base}`);
34
+
35
+ return Array.isArray(found) || found.type !== 'file' ? undefined : found.sha;
36
+ };
37
+
38
+ /** A blob's bytes through `git/blobs`, and its size as Git counts it. */
39
+ const blobBytes = async (repo: string, sha: string, signal: AbortSignal) => {
40
+ const answer = await github.GET('/repos/{owner}/{repo}/git/blobs/{file_sha}', {
41
+ params: { path: { ...repoPath(repo), file_sha: sha } },
42
+ signal,
43
+ });
44
+ const blob = answer.data;
45
+ if (blob === undefined) throw new Error(`Blob ${sha} didn't load (${answer.response.status})`);
46
+
47
+ if (blob.size !== null && blob.size > diffedBytesMost) return 'too-large';
48
+
49
+ return Uint8Array.from(atob(blob.content.replaceAll('\n', '')), (char) => char.charCodeAt(0));
50
+ };
51
+
52
+ const utf8 = new TextDecoder();
53
+
54
+ /** A side's text, or `undefined` for bytes Git would call binary: any NUL in its first 8,000. */
55
+ const textOf = (bytes: Uint8Array) =>
56
+ bytes.subarray(0, 8000).includes(0) ? undefined : utf8.decode(bytes);
57
+
58
+ /**
59
+ * `file`'s two sides between `revisions`, read through `git/blobs`, for a file GitHub's REST
60
+ * lists with no patch: the new blob by its `sha`, and the old by the path it had in `base`.
61
+ */
62
+ export const loadFile = async (
63
+ file: ChangedFile,
64
+ revisions: Revisions,
65
+ signal: AbortSignal,
66
+ ): Promise<LoadedFile> => {
67
+ const added = file.status === 'added';
68
+ const removed = file.status === 'removed';
69
+ const oldSha = added ? undefined : await blobAt(revisions, oldName(file), signal);
70
+ const newSha = removed ? undefined : (file.sha ?? undefined);
71
+ // A rename, or a mode change, with its blob unchanged; a binary change counts no lines either.
72
+ if (oldSha !== undefined && oldSha === newSha) return { kind: 'unchanged' };
73
+
74
+ const read = async (sha: string | undefined) =>
75
+ sha === undefined ? undefined : blobBytes(revisions.repo, sha, signal);
76
+ const [oldBytes, newBytes] = await Promise.all([read(oldSha), read(newSha)]);
77
+ if (oldBytes === 'too-large' || newBytes === 'too-large') return { kind: 'too-large' };
78
+
79
+ const oldText = oldBytes === undefined ? undefined : textOf(oldBytes);
80
+ const newText = newBytes === undefined ? undefined : textOf(newBytes);
81
+
82
+ if (
83
+ (oldBytes !== undefined && oldText === undefined) ||
84
+ (newBytes !== undefined && newText === undefined)
85
+ ) {
86
+ return { kind: 'binary' };
87
+ }
88
+
89
+ return {
90
+ kind: 'text',
91
+ old: oldText === undefined ? null : { name: oldName(file), contents: oldText },
92
+ new: newText === undefined ? null : { name: file.filename, contents: newText },
93
+ };
94
+ };
@@ -0,0 +1,155 @@
1
+ import { useInfiniteQuery } from '@tanstack/react-query';
2
+ import { ClientOnly } from '@tanstack/react-router';
3
+ import { createClientOnlyFn } from '@tanstack/react-start';
4
+ import { ChevronRightIcon } from 'lucide-react';
5
+ import { lazy, Suspense, useCallback } from 'react';
6
+
7
+ import { ItemList } from '../components/item-list.tsx';
8
+ import { Alert, AlertDescription } from '../components/ui/alert.tsx';
9
+ import { Badge } from '../components/ui/badge.tsx';
10
+ import { Button } from '../components/ui/button.tsx';
11
+ import { Card } from '../components/ui/card.tsx';
12
+ import {
13
+ Collapsible,
14
+ CollapsibleContent,
15
+ CollapsibleTrigger,
16
+ } from '../components/ui/collapsible.tsx';
17
+ import { FileIcon } from '../components/file-icons/file-icons.tsx';
18
+ import { Item, ItemContent, ItemTitle } from '../components/ui/item.tsx';
19
+ import { Skeleton } from '../components/ui/skeleton.tsx';
20
+ import type { FileList, FilePage, Notes, Revisions } from './files.ts';
21
+
22
+ /**
23
+ * The hunks' module, which brings `@pierre/diffs` and Shiki: Start's build drops it from the
24
+ * server's, so the Worker carries neither, and the browser loads it once a diff shows.
25
+ */
26
+ const loadHunks = createClientOnlyFn(() => import('./hunks.tsx'));
27
+
28
+ const Hunks = lazy(() => loadHunks());
29
+
30
+ /** A list's first page, which names no cursor. */
31
+ const firstPage: string | undefined = undefined;
32
+
33
+ /** Lines added and removed, as GitHub's file list shows them: a file's, or the whole diff's. */
34
+ function Counts({
35
+ additions,
36
+ deletions,
37
+ }: {
38
+ readonly additions: number;
39
+ readonly deletions: number;
40
+ }) {
41
+ return (
42
+ <span className="flex shrink-0 gap-1 font-mono">
43
+ <Badge variant="outline" className="text-success">
44
+ +{additions.toLocaleString('en')}
45
+ </Badge>
46
+ <Badge variant="outline" className="text-destructive">
47
+ −{deletions.toLocaleString('en')}
48
+ </Badge>
49
+ </span>
50
+ );
51
+ }
52
+
53
+ /**
54
+ * A pull request's or a comparison's diff: the changed files first, as their pages load, then
55
+ * each file's hunks, drawn as it scrolls into view. A file GitHub's REST sends with no patch
56
+ * stays collapsed, with **Load diff**. The server's page holds the file list alone. `notes`, when
57
+ * given, show under the lines they're on.
58
+ */
59
+ export function DiffView({
60
+ list,
61
+ revisions,
62
+ notes,
63
+ }: {
64
+ readonly list: FileList;
65
+ readonly revisions: Revisions;
66
+ readonly notes?: Notes;
67
+ }) {
68
+ const pages = useInfiniteQuery({
69
+ queryKey: ['diff-files', ...list.key],
70
+ queryFn: ({ pageParam, signal }) => list.page(pageParam, signal),
71
+ initialPageParam: firstPage,
72
+ getNextPageParam: (last: FilePage) => last.next,
73
+ });
74
+ const files = pages.data?.pages.flatMap((page) => page.files) ?? [];
75
+ const added = files.reduce((sum, file) => sum + file.additions, 0);
76
+ const removed = files.reduce((sum, file) => sum + file.deletions, 0);
77
+ const { hasNextPage, isFetchingNextPage, fetchNextPage } = pages;
78
+ const onEnd = useCallback(() => {
79
+ if (hasNextPage && !isFetchingNextPage) void fetchNextPage();
80
+ }, [hasNextPage, isFetchingNextPage, fetchNextPage]);
81
+
82
+ if (pages.isPending) {
83
+ return (
84
+ <div aria-label="Loading the changed files" className="flex flex-col gap-4">
85
+ <Skeleton className="h-9" />
86
+ <Skeleton className="h-40" />
87
+ </div>
88
+ );
89
+ }
90
+
91
+ if (pages.isError) {
92
+ return (
93
+ <Alert variant="destructive">
94
+ <AlertDescription>{pages.error.message}</AlertDescription>
95
+ </Alert>
96
+ );
97
+ }
98
+
99
+ return (
100
+ <div className="flex flex-col gap-4">
101
+ <nav aria-label="Changed files">
102
+ <Card className="gap-0 py-0">
103
+ <Collapsible defaultOpen>
104
+ <div className="flex flex-wrap items-center justify-between gap-2 px-3 py-2">
105
+ {/* Open is where it starts, so open draws no ground of its own, as a menu's does: only a hover. */}
106
+ <CollapsibleTrigger
107
+ render={
108
+ <Button
109
+ variant="ghost"
110
+ size="sm"
111
+ className="group -ml-2 aria-expanded:bg-transparent aria-expanded:hover:bg-hover"
112
+ />
113
+ }
114
+ >
115
+ <ChevronRightIcon
116
+ aria-hidden
117
+ data-icon="inline-start"
118
+ className="transition-transform group-data-panel-open:rotate-90"
119
+ />
120
+ {files.length} {files.length === 1 ? 'file' : 'files'} changed
121
+ {hasNextPage ? ' so far' : ''}
122
+ </CollapsibleTrigger>
123
+ <Counts additions={added} deletions={removed} />
124
+ </div>
125
+ <CollapsibleContent>
126
+ <ItemList
127
+ className="border-t"
128
+ rows={files}
129
+ keyOf={(file, index) => `${index}:${file.filename}`}
130
+ row={(file, index) => (
131
+ <Item role="listitem" size="xs" className="flex-nowrap justify-between">
132
+ <ItemContent className="min-w-0">
133
+ <ItemTitle className="flex w-full items-center gap-2 font-mono font-normal">
134
+ <FileIcon path={file.filename} />
135
+ <a className="truncate hover:underline" href={`#diff-${index}`}>
136
+ {file.filename}
137
+ </a>
138
+ </ItemTitle>
139
+ </ItemContent>
140
+ <Counts additions={file.additions} deletions={file.deletions} />
141
+ </Item>
142
+ )}
143
+ />
144
+ </CollapsibleContent>
145
+ </Collapsible>
146
+ </Card>
147
+ </nav>
148
+ <ClientOnly fallback={null}>
149
+ <Suspense fallback={<Skeleton className="h-40" />}>
150
+ <Hunks files={files} revisions={revisions} notes={notes} onEnd={onEnd} />
151
+ </Suspense>
152
+ </ClientOnly>
153
+ </div>
154
+ );
155
+ }