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,547 @@
1
+ import { useQueryClient } from '@tanstack/react-query';
2
+ import { useRouter } from '@tanstack/react-router';
3
+ import {
4
+ CopyIcon,
5
+ LoaderCircleIcon,
6
+ LogOutIcon,
7
+ MonitorIcon,
8
+ MoonIcon,
9
+ PlusIcon,
10
+ RotateCwIcon,
11
+ SearchIcon,
12
+ SunIcon,
13
+ UsersIcon,
14
+ } from 'lucide-react';
15
+ import { type KeyboardEvent, type ReactNode, useEffect, useRef, useState } from 'react';
16
+ import { toast } from 'sonner';
17
+
18
+ import { copyText } from '../code/controls.tsx';
19
+ import { commitHref } from '../code/places.ts';
20
+ import { hotkeys, Keys, onMac } from '../components/hotkeys/hotkeys.tsx';
21
+ import { useCreateOrg } from '../components/shell/app-shell.tsx';
22
+ import { useTheme } from '../components/theme-provider.tsx';
23
+ import { githubLookups } from '../markdown/lookup.ts';
24
+ import { Button } from '../components/ui/button.tsx';
25
+ import {
26
+ Command,
27
+ CommandDialog,
28
+ CommandEmpty,
29
+ CommandGroup,
30
+ CommandInput,
31
+ CommandItem,
32
+ CommandList,
33
+ CommandShortcut,
34
+ } from '../components/ui/command.tsx';
35
+ import { Kbd } from '../components/ui/kbd.tsx';
36
+ import { cn } from '../lib/cn.ts';
37
+ import { signOutAndLeave } from '../signin/auth-client.ts';
38
+ import { rememberPlace, visitedPlace } from './recent.ts';
39
+ import {
40
+ type Group,
41
+ type PaletteAt,
42
+ prefetchLists,
43
+ type Row,
44
+ type Status,
45
+ useAllowedAt,
46
+ useGroups,
47
+ } from './rows.tsx';
48
+ import { type ModeSymbol, symbols, type Typed, typedInto } from './targets.ts';
49
+
50
+ export type { PaletteAt } from './rows.tsx';
51
+
52
+ /**
53
+ * The command palette: "Find" under the owner switcher, a search button in a phone's
54
+ * top bar, and the dialog both open, which `F`, or ⌘K from anywhere, opens too. Opening reads
55
+ * nothing: it lists what the page and the switchers' reads already hold.
56
+ */
57
+
58
+ /** What the input says in each mode, before anything is typed. */
59
+ const placeholders: Record<ModeSymbol | 'none', string> = {
60
+ none: 'Search or jump to…',
61
+ '@': 'Search people and organizations',
62
+ '#': 'Search issues and pull requests, or type a number',
63
+ '/': 'Search files in this repository',
64
+ '>': 'Run a command',
65
+ '?': 'Pick a mode',
66
+ };
67
+
68
+ /** What an empty mode says, in its own words. */
69
+ const noMatches: Record<ModeSymbol | 'none', string> = {
70
+ none: 'No matches',
71
+ '@': 'No people match',
72
+ '#': 'No issues or pull requests match',
73
+ '/': 'No files match',
74
+ '>': 'No commands match',
75
+ '?': 'No modes match',
76
+ };
77
+
78
+ const segment = encodeURIComponent;
79
+
80
+ /** The commands `>` lists for where the palette is: creating, copying, theme, owners, signing out. */
81
+ const useCommands = (at: PaletteAt): readonly Row[] => {
82
+ const createOrg = useCreateOrg();
83
+ const { setTheme } = useTheme();
84
+ const allowed = useAllowedAt(at.here);
85
+ const { owner, repo, org } = at.here;
86
+ const home =
87
+ owner === undefined || repo === undefined ? undefined : `/${segment(owner)}/${segment(repo)}`;
88
+ const go = (id: string, label: string, href: string): Row => ({
89
+ id,
90
+ label,
91
+ icon: PlusIcon,
92
+ act: { kind: 'go', href },
93
+ });
94
+ const copyClone = (url: string) =>
95
+ void copyText(url).then((copied) =>
96
+ copied ? toast.success('Copied the clone URL') : toast.error("The clone URL didn't copy"),
97
+ );
98
+
99
+ return [
100
+ go(
101
+ 'command:new-repo',
102
+ 'Create repository',
103
+ owner !== undefined && org ? `/new?owner=${segment(owner)}` : '/new',
104
+ ),
105
+ ...(home === undefined
106
+ ? []
107
+ : [
108
+ // Each only where its list draws its own button: as the host's authorize allows.
109
+ ...(allowed.has('issue.create')
110
+ ? [go('command:new-issue', 'Create issue', `${home}/issues/new`)]
111
+ : []),
112
+ ...(allowed.has('release.create')
113
+ ? [go('command:new-release', 'Create release', `${home}/releases/new`)]
114
+ : []),
115
+ ]),
116
+ {
117
+ id: 'command:new-org',
118
+ label: 'Create organization',
119
+ icon: PlusIcon,
120
+ act: { kind: 'run', run: createOrg },
121
+ },
122
+ ...(at.cloneUrl === undefined
123
+ ? []
124
+ : [
125
+ {
126
+ id: 'command:copy-clone',
127
+ label: 'Copy clone URL',
128
+ icon: CopyIcon,
129
+ act: { kind: 'run', run: () => copyClone(at.cloneUrl ?? '') },
130
+ } satisfies Row,
131
+ ]),
132
+ ...(
133
+ [
134
+ ['light', 'Light', SunIcon],
135
+ ['dark', 'Dark', MoonIcon],
136
+ ['system', 'System', MonitorIcon],
137
+ ] as const
138
+ ).map(([theme, words, icon]): Row => ({
139
+ id: `command:theme-${theme}`,
140
+ label: `Switch theme: ${words}`,
141
+ icon,
142
+ act: { kind: 'run', run: () => setTheme(theme) },
143
+ })),
144
+ ...[at.viewer, ...at.orgs].flatMap((login): readonly Row[] =>
145
+ login === owner
146
+ ? []
147
+ : [
148
+ {
149
+ id: `command:owner-${login}`,
150
+ label: `Switch to ${login}`,
151
+ icon: UsersIcon,
152
+ act: { kind: 'go', href: at.ownerHref(login) },
153
+ },
154
+ ],
155
+ ),
156
+ {
157
+ id: 'command:sign-out',
158
+ label: 'Sign out',
159
+ icon: LogOutIcon,
160
+ act: { kind: 'run', run: () => void signOutAndLeave() },
161
+ },
162
+ ];
163
+ };
164
+
165
+ /** A group's line besides its rows: searching, a retry, only the first matches, or a hint. */
166
+ function StatusRow({ heading, status }: { readonly heading: string; readonly status: Status }) {
167
+ switch (status.kind) {
168
+ case 'searching':
169
+ return (
170
+ <CommandItem value={`status:${heading}`} disabled className="text-muted-foreground">
171
+ <LoaderCircleIcon className="animate-spin motion-reduce:animate-none" />
172
+ Searching…
173
+ </CommandItem>
174
+ );
175
+ case 'failed':
176
+ return (
177
+ <CommandItem
178
+ value={`status:${heading}`}
179
+ onSelect={status.retry}
180
+ className="text-destructive"
181
+ >
182
+ <RotateCwIcon />
183
+ {`${heading} didn't load. Retry`}
184
+ </CommandItem>
185
+ );
186
+ case 'incomplete':
187
+ return (
188
+ <CommandItem value={`status:${heading}`} disabled className="text-muted-foreground">
189
+ Showing the first matches
190
+ </CommandItem>
191
+ );
192
+ case 'hint':
193
+ return (
194
+ <CommandItem value={`status:${heading}`} disabled className="text-muted-foreground">
195
+ {status.words}
196
+ </CommandItem>
197
+ );
198
+ }
199
+ }
200
+
201
+ /** The palette's body, drawn only while it's open: what's typed starts empty each time. */
202
+ function PaletteBody({
203
+ at,
204
+ shown,
205
+ close,
206
+ }: {
207
+ readonly at: PaletteAt;
208
+ readonly shown: boolean;
209
+ readonly close: () => void;
210
+ }) {
211
+ const router = useRouter();
212
+ const [typed, setTyped] = useState<Typed>({ symbol: undefined, text: '' });
213
+ const commands = useCommands(at);
214
+ const groups = useGroups(at, typed, commands, setTyped);
215
+ const rows = groups.flatMap((group) => group.rows);
216
+ const mode = typed.symbol ?? 'none';
217
+ // Closed once the dialog starts closing, before its exit animation unmounts the body.
218
+ const open = useRef(true);
219
+ useEffect(() => {
220
+ open.current = shown;
221
+
222
+ return () => {
223
+ open.current = false;
224
+ };
225
+ }, [shown]);
226
+
227
+ const go = (href: string, newTab: boolean) => {
228
+ if (newTab) {
229
+ window.open(href, '_blank', 'noopener');
230
+
231
+ return;
232
+ }
233
+
234
+ close();
235
+ void router.navigate({ href });
236
+ };
237
+
238
+ const pick = (row: Row, newTab: boolean) => {
239
+ const { act } = row;
240
+
241
+ switch (act.kind) {
242
+ case 'go':
243
+ if (act.keep !== undefined) rememberPlace(at.viewer, act.keep);
244
+ go(act.href, newTab);
245
+
246
+ return;
247
+ case 'jump':
248
+ if (act.jump.kind === 'page') {
249
+ go(act.jump.target.href, newTab);
250
+
251
+ return;
252
+ }
253
+
254
+ void jumpToCommit(act.jump.commit, newTab);
255
+
256
+ return;
257
+ case 'run':
258
+ if (act.stays !== true) close();
259
+ act.run();
260
+ }
261
+ };
262
+
263
+ // A SHA names a commit only once the drop-in finds one it starts, as a comment's SHA does. A
264
+ // palette closed before the answer comes goes nowhere, and a lookup that fails says so.
265
+ const jumpToCommit = async (
266
+ commit: { readonly owner: string; readonly repo: string; readonly sha: string },
267
+ newTab: boolean,
268
+ ) => {
269
+ const sha = await githubLookups
270
+ .commit({ repo: `${commit.owner}/${commit.repo}`, sha: commit.sha })
271
+ .catch(() => null);
272
+ if (!open.current) return;
273
+
274
+ if (sha === null) {
275
+ toast.error(`Couldn't look up ${commit.sha} in ${commit.owner}/${commit.repo}`);
276
+
277
+ return;
278
+ }
279
+
280
+ if (sha === undefined) {
281
+ toast.error(`No commit ${commit.sha} in ${commit.owner}/${commit.repo}`);
282
+
283
+ return;
284
+ }
285
+
286
+ go(commitHref(commit, sha), newTab);
287
+ };
288
+
289
+ const keyDown = (event: KeyboardEvent<HTMLDivElement>) => {
290
+ const chord = onMac() ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey;
291
+
292
+ // The shell's keys listen on the window: the palette's own keys stop there.
293
+ if (chord && event.key.toLowerCase() === 'k') {
294
+ event.preventDefault();
295
+ event.stopPropagation();
296
+ close();
297
+
298
+ return;
299
+ }
300
+
301
+ if (chord && event.key === 'Enter') {
302
+ event.preventDefault();
303
+ event.stopPropagation();
304
+ const id = event.currentTarget
305
+ .querySelector<HTMLElement>('[cmdk-item][data-selected="true"]')
306
+ ?.getAttribute('data-value');
307
+ const row = rows.find((each) => each.id === id);
308
+ if (row !== undefined) pick(row, true);
309
+
310
+ return;
311
+ }
312
+
313
+ if (event.key === 'Backspace' && typed.text === '' && typed.symbol !== undefined) {
314
+ event.preventDefault();
315
+ setTyped({ symbol: undefined, text: '' });
316
+ }
317
+ };
318
+
319
+ return (
320
+ <Command shouldFilter={false} loop onKeyDown={keyDown} className="max-sm:h-full">
321
+ <CommandInput
322
+ value={typed.text}
323
+ onValueChange={(next) => setTyped(typedInto(typed, next))}
324
+ placeholder={placeholders[mode]}
325
+ aria-label="Search or jump to"
326
+ before={
327
+ typed.symbol === undefined ? undefined : (
328
+ <span
329
+ data-slot="palette-mode"
330
+ className="rounded-sm bg-muted px-1.5 font-mono text-meta text-foreground"
331
+ >
332
+ {typed.symbol}
333
+ </span>
334
+ )
335
+ }
336
+ />
337
+ <CommandList className="max-sm:max-h-none max-sm:flex-1">
338
+ <CommandEmpty>{noMatches[mode]}</CommandEmpty>
339
+ {groups.map((group) => (
340
+ <PaletteGroup key={group.heading} group={group} pick={pick} />
341
+ ))}
342
+ {mode === '?' && (
343
+ <p className="px-2 py-2 text-meta text-muted-foreground">
344
+ ↑ and ↓ move, Enter opens, ⌘Enter or Ctrl+Enter opens in a new tab, Backspace leaves a
345
+ mode, and Esc closes.
346
+ </p>
347
+ )}
348
+ </CommandList>
349
+ <ModeKeys symbol={typed.symbol} enter={(symbol) => setTyped({ symbol, text: '' })} />
350
+ </Command>
351
+ );
352
+ }
353
+
354
+ /**
355
+ * The palette's footer, so the modes can be found: with no mode, each of `symbols` as a key that
356
+ * enters it, only `?` on a phone; in a mode, Backspace, which leaves it. A key keeps focus in the
357
+ * input, as typing its symbol would.
358
+ */
359
+ function ModeKeys({
360
+ symbol,
361
+ enter,
362
+ }: {
363
+ readonly symbol: ModeSymbol | undefined;
364
+ readonly enter: (symbol: ModeSymbol | undefined) => void;
365
+ }) {
366
+ const keys =
367
+ symbol === undefined
368
+ ? symbols.map((each) => ({ key: each.symbol, word: each.word, to: each.symbol }))
369
+ : [{ key: 'Backspace', word: 'Clear mode', to: undefined }];
370
+
371
+ return (
372
+ <div
373
+ data-slot="palette-modes"
374
+ className="flex shrink-0 items-center gap-3 border-t p-2 text-meta text-muted-foreground"
375
+ // Enter or Space on a key presses it: cmdk, above, would run the selected row instead.
376
+ onKeyDown={(event) => {
377
+ if (event.key === 'Enter' || event.key === ' ') event.stopPropagation();
378
+ }}
379
+ >
380
+ {keys.map(({ key, word, to }) => (
381
+ <button
382
+ key={key}
383
+ type="button"
384
+ data-mode={to}
385
+ // Pressing a key leaves focus in the input; the click then enters its mode.
386
+ onMouseDown={(event) => event.preventDefault()}
387
+ onClick={(event) => {
388
+ enter(to);
389
+ event.currentTarget
390
+ .closest('[cmdk-root]')
391
+ ?.querySelector<HTMLInputElement>('[cmdk-input]')
392
+ ?.focus();
393
+ }}
394
+ className={cn(
395
+ // A phone's tap needs 32px of height, more than the key draws.
396
+ 'flex items-center gap-1.5 rounded-sm outline-hidden hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring max-sm:min-h-8',
397
+ to !== '?' && symbol === undefined && 'max-sm:hidden',
398
+ )}
399
+ >
400
+ <Kbd>{key}</Kbd>
401
+ {word}
402
+ </button>
403
+ ))}
404
+ </div>
405
+ );
406
+ }
407
+
408
+ /** One group: its rows, then its status line, or nothing when it has neither. */
409
+ function PaletteGroup({
410
+ group,
411
+ pick,
412
+ }: {
413
+ readonly group: Group;
414
+ readonly pick: (row: Row, newTab: boolean) => void;
415
+ }) {
416
+ if (group.rows.length === 0 && group.status === undefined) return null;
417
+
418
+ return (
419
+ <CommandGroup heading={group.heading}>
420
+ {group.rows.map((row) => (
421
+ <CommandItem key={row.id} value={row.id} onSelect={() => pick(row, false)}>
422
+ <row.icon className="text-muted-foreground" />
423
+ <span className="truncate">{row.label}</span>
424
+ {/* The registry's slot for a row's end, which hides the row's unused check. */}
425
+ {row.note !== undefined && (
426
+ <CommandShortcut className="max-w-1/2 truncate tracking-normal">
427
+ {row.note}
428
+ </CommandShortcut>
429
+ )}
430
+ </CommandItem>
431
+ ))}
432
+ {group.status !== undefined && <StatusRow heading={group.heading} status={group.status} />}
433
+ </CommandGroup>
434
+ );
435
+ }
436
+
437
+ /** The input-looking button under the owner switcher, with its `F`, and a phone's top-bar button. */
438
+ function PaletteTrigger({
439
+ open,
440
+ readAhead,
441
+ phone,
442
+ }: {
443
+ readonly open: () => void;
444
+ readonly readAhead: () => void;
445
+ readonly phone: boolean;
446
+ }) {
447
+ if (phone) {
448
+ return (
449
+ <Button
450
+ variant="ghost"
451
+ size="icon-sm"
452
+ aria-label="Find"
453
+ title="Find"
454
+ aria-haspopup="dialog"
455
+ data-hotkey={hotkeys.palette}
456
+ className="ml-auto md:hidden"
457
+ onClick={open}
458
+ onPointerEnter={readAhead}
459
+ onFocus={readAhead}
460
+ >
461
+ <SearchIcon />
462
+ </Button>
463
+ );
464
+ }
465
+
466
+ return (
467
+ <button
468
+ type="button"
469
+ aria-haspopup="dialog"
470
+ aria-keyshortcuts="F"
471
+ data-hotkey={hotkeys.palette}
472
+ data-slot="palette-trigger"
473
+ onClick={open}
474
+ onPointerEnter={readAhead}
475
+ onFocus={readAhead}
476
+ className="flex h-9 w-full min-w-0 items-center gap-2 rounded-md border border-sidebar-border bg-background px-2 text-left text-sm text-muted-foreground outline-hidden hover:border-ring/60 focus-visible:ring-2 focus-visible:ring-sidebar-ring group-data-[collapsible=icon]:size-8 group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-0 [&_svg]:size-4 [&_svg]:shrink-0"
477
+ >
478
+ <SearchIcon />
479
+ <span className="min-w-0 flex-1 truncate group-data-[collapsible=icon]:hidden">Find</span>
480
+ <Keys keys="f" className="group-data-[collapsible=icon]:hidden" />
481
+ </button>
482
+ );
483
+ }
484
+
485
+ /** What the shell draws of the palette: the sidebar's input, the phone's button, and the dialog. */
486
+ export interface PaletteParts {
487
+ readonly input: ReactNode;
488
+ readonly button: ReactNode;
489
+ readonly dialog: ReactNode;
490
+ }
491
+
492
+ /**
493
+ * The palette for `at`, or `undefined` for a visitor, whose shell has no owner switcher to put it
494
+ * under. Each page `path` names a repo, issue or pull request is kept as a recent place, and the
495
+ * lists it finds are read ahead once the page is idle.
496
+ */
497
+ export const usePalette = (at: PaletteAt | undefined, path: string): PaletteParts | undefined => {
498
+ const client = useQueryClient();
499
+ const [open, setOpen] = useState(false);
500
+ const owner = at?.here.owner;
501
+ const repo = at?.here.repo;
502
+ const viewer = at?.viewer;
503
+
504
+ useEffect(() => {
505
+ if (viewer === undefined || owner === undefined || repo === undefined) return;
506
+
507
+ const visited = visitedPlace(path, (first) => first === owner);
508
+ if (visited !== undefined) rememberPlace(viewer, visited);
509
+ }, [viewer, owner, repo, path]);
510
+
511
+ useEffect(() => {
512
+ if (at === undefined) return;
513
+
514
+ const readAhead = () => prefetchLists(client, at);
515
+
516
+ if ('requestIdleCallback' in window) {
517
+ const idle = requestIdleCallback(readAhead, { timeout: 2_000 });
518
+
519
+ return () => cancelIdleCallback(idle);
520
+ }
521
+
522
+ const next = setTimeout(readAhead, 0);
523
+
524
+ return () => clearTimeout(next);
525
+ }, [client, at === undefined, owner, repo]);
526
+
527
+ if (at === undefined) return undefined;
528
+
529
+ const readAhead = () => prefetchLists(client, at);
530
+ const show = () => setOpen(true);
531
+
532
+ return {
533
+ input: <PaletteTrigger open={show} readAhead={readAhead} phone={false} />,
534
+ button: <PaletteTrigger open={show} readAhead={readAhead} phone />,
535
+ dialog: (
536
+ <CommandDialog
537
+ open={open}
538
+ onOpenChange={setOpen}
539
+ title="Search or jump to"
540
+ description="Find a page, repository, issue, file or command. Type ? for the modes."
541
+ className="sm:max-w-lg max-sm:inset-0 max-sm:top-0 max-sm:left-0 max-sm:h-dvh max-sm:max-w-none max-sm:translate-x-0 max-sm:rounded-none! max-sm:ring-0"
542
+ >
543
+ <PaletteBody at={at} shown={open} close={() => setOpen(false)} />
544
+ </CommandDialog>
545
+ ),
546
+ };
547
+ };
@@ -0,0 +1,116 @@
1
+ import * as Option from 'effect/Option';
2
+ import * as Schema from 'effect/Schema';
3
+
4
+ /**
5
+ * The repos, issues and pull requests a person opened last, newest first, for the palette to
6
+ * offer before they type: the last 20, kept in this browser alone, under each account's own key,
7
+ * so another account's palette lists none of them. A sign-out, or a session that ends, drops every
8
+ * account's, as #630 drops saved reads: a private issue's title stays for no one else on the
9
+ * browser. Storage can be missing or refuse, as in a private window, so every read and write is
10
+ * wrapped, and a failure keeps none.
11
+ */
12
+
13
+ /** How many the palette keeps. */
14
+ export const recentMost = 20;
15
+
16
+ const storagePrefix = 'ref0-git:palette-recent:';
17
+
18
+ const storageKey = (viewer: string) => `${storagePrefix}${viewer}`;
19
+
20
+ const RecentPlace = Schema.Struct({
21
+ kind: Schema.Literals(['repo', 'issue', 'pull']),
22
+ /** Its words, such as `acme/web` or the issue's title. */
23
+ label: Schema.String,
24
+ /** Where it is, such as `acme/web#12`, under a title. */
25
+ note: Schema.optional(Schema.String),
26
+ href: Schema.String,
27
+ });
28
+
29
+ /** One place opened lately. */
30
+ export type RecentPlace = typeof RecentPlace.Type;
31
+
32
+ const decodeRecent = Schema.decodeUnknownOption(Schema.Array(RecentPlace));
33
+
34
+ /** `viewer`'s places, newest first: none when storage can't be read or holds something else. */
35
+ export const recentPlaces = (viewer: string): readonly RecentPlace[] => {
36
+ try {
37
+ const saved = localStorage.getItem(storageKey(viewer));
38
+ if (saved === null) return [];
39
+
40
+ const decoded = decodeRecent(JSON.parse(saved));
41
+
42
+ return Option.match(decoded, {
43
+ onNone: () => [],
44
+ onSome: (places) => places.slice(0, recentMost),
45
+ });
46
+ } catch {
47
+ return [];
48
+ }
49
+ };
50
+
51
+ /**
52
+ * Keeps `place` first in `viewer`'s list. A visit names an issue by where it is alone, with no note, so a title a
53
+ * pick already kept for the same page, with its place as the note, stays.
54
+ */
55
+ export const rememberPlace = (viewer: string, place: RecentPlace) => {
56
+ const kept = recentPlaces(viewer);
57
+ const before = kept.find((each) => each.href === place.href);
58
+ const titled = before?.note !== undefined && place.note === undefined ? before : place;
59
+ const next = [titled, ...kept.filter((each) => each.href !== place.href)].slice(0, recentMost);
60
+
61
+ try {
62
+ localStorage.setItem(storageKey(viewer), JSON.stringify(next));
63
+ } catch {
64
+ // Storage that refuses keeps the list it had: a palette without recents still works.
65
+ }
66
+ };
67
+
68
+ /** Drops every account's places, as a sign-out or an ended session does. */
69
+ export const forgetRecentPlaces = () => {
70
+ try {
71
+ const keys = Array.from({ length: localStorage.length }, (_, n) => localStorage.key(n));
72
+
73
+ for (const key of keys) if (key?.startsWith(storagePrefix)) localStorage.removeItem(key);
74
+ } catch {
75
+ // Storage that can't be read holds nothing the palette could list.
76
+ }
77
+ };
78
+
79
+ /** A path's segment as written, decoded, or as it is when it isn't encoded right. */
80
+ const decoded = (segment: string) => {
81
+ try {
82
+ return decodeURIComponent(segment);
83
+ } catch {
84
+ return segment;
85
+ }
86
+ };
87
+
88
+ const segmentsOf = (path: string) => path.split(/[?#]/)[0]?.split('/').filter(Boolean) ?? [];
89
+
90
+ /**
91
+ * The repo, issue or pull request a page's `path` is, as a visit to it keeps it, named by where
92
+ * it is: `/acme/web`, `/acme/web/issues/12` or `/acme/web/pull/12`, and their subpages. `owned`
93
+ * says whether a first segment is an owner, not one of the app's own pages.
94
+ */
95
+ export const visitedPlace = (
96
+ path: string,
97
+ owned: (first: string) => boolean,
98
+ ): RecentPlace | undefined => {
99
+ const [owner, repo, kind, number] = segmentsOf(path).map(decoded);
100
+ if (owner === undefined || repo === undefined || !owned(owner)) return undefined;
101
+
102
+ const name = `${owner}/${repo}`;
103
+ const home = `/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}`;
104
+
105
+ if (number !== undefined && /^[1-9][0-9]*$/.test(number)) {
106
+ if (kind === 'issues' || kind === 'pull') {
107
+ return {
108
+ kind: kind === 'issues' ? 'issue' : 'pull',
109
+ label: `${name}#${number}`,
110
+ href: `${home}/${kind}/${number}`,
111
+ };
112
+ }
113
+ }
114
+
115
+ return { kind: 'repo', label: name, href: home };
116
+ };