@bevel-software/platform-core-frontend 0.4.1 → 0.5.1

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 (327) hide show
  1. package/THIRD-PARTY-NOTICES.md +5366 -0
  2. package/package.json +7 -4
  3. package/src/core/CoreAppShell.tsx +195 -56
  4. package/src/core/__tests__/AppChrome.test.tsx +125 -0
  5. package/src/core/__tests__/ShellRoutes.test.tsx +37 -2
  6. package/src/core/__tests__/bootstrap.test.ts +63 -0
  7. package/src/core/bootstrap.ts +73 -0
  8. package/src/core/events.ts +12 -0
  9. package/src/core/registry.ts +58 -9
  10. package/src/index.css +100 -11
  11. package/src/index.ts +24 -23
  12. package/src/lib/utils.ts +93 -117
  13. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +281 -0
  14. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +166 -1
  15. package/src/modules/access/api.ts +49 -0
  16. package/src/modules/access/components/ManageAccessDialog.tsx +786 -481
  17. package/src/modules/access/hooks/useFileAccess.ts +1 -1
  18. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +86 -0
  19. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +17 -1
  20. package/src/modules/admin/__tests__/admin.unread.test.tsx +61 -0
  21. package/src/modules/admin/components/AdminRolesPage.tsx +44 -38
  22. package/src/modules/admin/components/RolesCorruptedBanner.tsx +11 -10
  23. package/src/modules/admin/components/UserAccountsPage.tsx +36 -28
  24. package/src/modules/admin/state/admin.context.tsx +15 -6
  25. package/src/modules/auth/components/AccountPage.tsx +11 -11
  26. package/src/modules/auth/components/LoginScreen.tsx +12 -12
  27. package/src/modules/auth/services/sso.ts +47 -1
  28. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +277 -0
  29. package/src/modules/change-requests/__tests__/author.test.ts +48 -0
  30. package/src/modules/change-requests/__tests__/conflict.test.ts +73 -0
  31. package/src/modules/change-requests/__tests__/diff.test.ts +134 -0
  32. package/src/modules/change-requests/__tests__/propose.test.ts +93 -0
  33. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +72 -0
  34. package/src/modules/change-requests/change-requests.css +22 -0
  35. package/src/modules/change-requests/components/ChangeBox.tsx +277 -0
  36. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +713 -0
  37. package/src/modules/change-requests/components/ConflictHelp.tsx +47 -0
  38. package/src/modules/change-requests/components/CrFileTree.tsx +398 -0
  39. package/src/modules/change-requests/components/FileChangeBoxes.tsx +168 -0
  40. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +236 -0
  41. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +79 -0
  42. package/src/modules/change-requests/hooks/useFileOnBranch.ts +80 -0
  43. package/src/modules/change-requests/services/change-requests.api.ts +45 -0
  44. package/src/modules/change-requests/services/propose.api.ts +162 -0
  45. package/src/modules/change-requests/utils/author.ts +47 -0
  46. package/src/modules/change-requests/utils/conflict.ts +38 -0
  47. package/src/modules/change-requests/utils/diff.ts +80 -0
  48. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +27 -18
  49. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +36 -83
  50. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +5 -5
  51. package/src/modules/git/__tests__/PullRequestsForMe.test.tsx +147 -0
  52. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +2 -8
  53. package/src/modules/git/components/BranchSwitcher.tsx +68 -31
  54. package/src/modules/git/components/DiffView.tsx +4 -4
  55. package/src/modules/git/components/FileComparisonPanel.tsx +20 -20
  56. package/src/modules/git/components/FileHistoryPanel.tsx +71 -107
  57. package/src/modules/git/components/PullNeededBanner.tsx +6 -13
  58. package/src/modules/git/components/PullRequestsForMe.tsx +71 -36
  59. package/src/modules/git/components/UnifiedDiffView.tsx +4 -4
  60. package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +2 -2
  61. package/src/modules/git/hooks/useGitState.ts +15 -14
  62. package/src/modules/git/services/__tests__/error-messages.test.ts +4 -4
  63. package/src/modules/git/services/error-messages.ts +7 -7
  64. package/src/modules/git/services/git.api.ts +17 -11
  65. package/src/modules/git/services/pr-prompts.ts +2 -2
  66. package/src/modules/git/state/git.context.ts +10 -1
  67. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +224 -0
  68. package/src/modules/layout/__tests__/SidebarToggle.test.tsx +242 -0
  69. package/src/modules/layout/__tests__/breakpoints.test.ts +56 -0
  70. package/src/modules/layout/breakpoints.ts +6 -0
  71. package/src/modules/layout/components/AppLayout.tsx +17 -5
  72. package/src/modules/layout/components/DemoBanner.tsx +10 -1
  73. package/src/modules/layout/components/MaintenanceOverlay.tsx +3 -3
  74. package/src/modules/layout/components/MobileChatLayout.tsx +31 -26
  75. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +59 -24
  76. package/src/modules/layout/components/SidebarFrame.tsx +317 -0
  77. package/src/modules/layout/components/SidebarToggle.tsx +86 -0
  78. package/src/modules/layout/components/SlideOverlay.tsx +1 -1
  79. package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +40 -2
  80. package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +19 -3
  81. package/src/modules/layout/state/sidebar.ts +200 -0
  82. package/src/modules/library/__tests__/AddToGroupDialog.test.tsx +313 -0
  83. package/src/modules/library/__tests__/ChangeRequestDock.test.tsx +84 -0
  84. package/src/modules/library/__tests__/GroupJoinRequests.test.tsx +178 -0
  85. package/src/modules/library/__tests__/GroupPage.test.tsx +479 -0
  86. package/src/modules/library/__tests__/GroupsIndexPage.test.tsx +283 -0
  87. package/src/modules/library/__tests__/GroupsSidebar.contextmenu.test.tsx +175 -0
  88. package/src/modules/library/__tests__/GroupsSidebar.locked.test.tsx +96 -0
  89. package/src/modules/library/__tests__/GroupsSidebar.test.tsx +142 -0
  90. package/src/modules/library/__tests__/GroupsSidebarMenu.test.tsx +142 -0
  91. package/src/modules/library/__tests__/LibraryCard.test.tsx +149 -0
  92. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +378 -0
  93. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +347 -0
  94. package/src/modules/library/__tests__/LockedGroupView.test.tsx +203 -0
  95. package/src/modules/library/__tests__/NewGroupDialog.test.tsx +114 -0
  96. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +177 -0
  97. package/src/modules/library/__tests__/SkillPage.test.tsx +1063 -0
  98. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +259 -0
  99. package/src/modules/library/__tests__/ToolLogo.test.tsx +63 -0
  100. package/src/modules/library/__tests__/ToolPage.test.tsx +315 -0
  101. package/src/modules/library/__tests__/ToolSharePanel.test.tsx +36 -0
  102. package/src/modules/library/__tests__/ToolVarRow.test.tsx +260 -0
  103. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +197 -0
  104. package/src/modules/library/__tests__/auth-harness.tsx +37 -0
  105. package/src/modules/library/__tests__/oauth-fragment.test.ts +48 -0
  106. package/src/modules/library/__tests__/status.test.ts +113 -20
  107. package/src/modules/library/__tests__/useSkillDetail.test.tsx +102 -0
  108. package/src/modules/library/__tests__/useToolPage.test.tsx +146 -0
  109. package/src/modules/library/components/AccessRequestsBanner.tsx +101 -0
  110. package/src/modules/library/components/AddToGroupDialog.tsx +115 -0
  111. package/src/modules/library/components/ChangeRequestDock.tsx +52 -28
  112. package/src/modules/library/components/DeleteGroupDialog.tsx +87 -0
  113. package/src/modules/library/components/GroupIndexRow.tsx +63 -0
  114. package/src/modules/library/components/GroupJoinRequests.tsx +56 -0
  115. package/src/modules/library/components/GroupPage.tsx +373 -0
  116. package/src/modules/library/components/GroupsIndexPage.tsx +222 -0
  117. package/src/modules/library/components/GroupsSidebar.tsx +338 -0
  118. package/src/modules/library/components/GroupsSidebarMenu.tsx +160 -0
  119. package/src/modules/library/components/LibraryCard.tsx +123 -102
  120. package/src/modules/library/components/LibraryLayout.tsx +344 -0
  121. package/src/modules/library/components/LibraryPage.tsx +111 -227
  122. package/src/modules/library/components/LockGlyph.tsx +31 -0
  123. package/src/modules/library/components/LockedGroupView.tsx +159 -0
  124. package/src/modules/library/components/ManagedGroupRequests.tsx +70 -0
  125. package/src/modules/library/components/NewGroupDialog.tsx +112 -0
  126. package/src/modules/library/components/NewSkillPanel.tsx +151 -0
  127. package/src/modules/library/components/PageActions.tsx +156 -0
  128. package/src/modules/library/components/PendingSkillReview.tsx +63 -0
  129. package/src/modules/library/components/PersonalAddDialog.tsx +88 -0
  130. package/src/modules/library/components/PersonalGroupPage.tsx +125 -0
  131. package/src/modules/library/components/StatusDot.tsx +25 -0
  132. package/src/modules/library/components/ToolLogo.tsx +171 -0
  133. package/src/modules/library/components/group-page-parts.tsx +419 -0
  134. package/src/modules/library/components/skill-page/SkillFileEditor.tsx +134 -0
  135. package/src/modules/library/components/skill-page/SkillFilePane.tsx +117 -0
  136. package/src/modules/library/components/skill-page/SkillFileTabs.tsx +112 -0
  137. package/src/modules/library/components/skill-page/SkillPage.tsx +673 -0
  138. package/src/modules/library/components/skill-page/tab-ids.ts +33 -0
  139. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +175 -0
  140. package/src/modules/library/components/tool-page/ToolPage.tsx +228 -0
  141. package/src/modules/library/components/tool-page/ToolSharePanel.tsx +45 -0
  142. package/src/modules/library/components/tool-page/ToolVarRow.tsx +289 -0
  143. package/src/modules/library/hooks/useJoinRequests.ts +114 -0
  144. package/src/modules/library/hooks/useLibraryData.ts +134 -119
  145. package/src/modules/library/hooks/useSkillDetail.ts +119 -74
  146. package/src/modules/library/hooks/useToolPage.ts +145 -0
  147. package/src/modules/library/library.css +33 -245
  148. package/src/modules/library/routes/LibraryRoutes.tsx +134 -0
  149. package/src/modules/library/routes/WorkspaceItemRoute.tsx +74 -0
  150. package/src/modules/library/routes/library-paths.ts +191 -0
  151. package/src/modules/library/services/groups.api.ts +189 -0
  152. package/src/modules/library/services/library.api.ts +291 -164
  153. package/src/modules/library/services/tools.api.ts +60 -0
  154. package/src/modules/library/state/library-context.ts +22 -0
  155. package/src/modules/library/state/library-data.tsx +223 -0
  156. package/src/modules/library/state/toast.context.ts +32 -0
  157. package/src/modules/library/state/toast.tsx +84 -42
  158. package/src/modules/library/utils/clipboard.ts +33 -0
  159. package/src/modules/library/utils/group-summary.ts +68 -0
  160. package/src/modules/library/utils/names.ts +30 -0
  161. package/src/modules/library/utils/navigate-external.ts +15 -0
  162. package/src/modules/library/utils/oauth-fragment.ts +32 -0
  163. package/src/modules/library/utils/personal-group.ts +36 -0
  164. package/src/modules/library/utils/status.ts +108 -25
  165. package/src/modules/library/utils/toast-duration.ts +16 -0
  166. package/src/modules/onboarding/__tests__/onboarding.test.tsx +533 -0
  167. package/src/modules/onboarding/agent-clients.ts +48 -0
  168. package/src/modules/onboarding/components/ConnectAgentPill.tsx +133 -0
  169. package/src/modules/onboarding/components/RootLanding.tsx +54 -0
  170. package/src/modules/onboarding/components/WelcomePage.tsx +364 -0
  171. package/src/modules/onboarding/paths.ts +9 -0
  172. package/src/modules/onboarding/state/onboarding.ts +191 -0
  173. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +10 -10
  174. package/src/modules/pr/services/pr-approvals.api.ts +19 -0
  175. package/src/modules/pr/services/pr-cancel.api.ts +11 -0
  176. package/src/modules/review/components/BinaryChangePlaceholder.tsx +3 -3
  177. package/src/modules/review/components/DiffViewer.tsx +4 -4
  178. package/src/modules/review/components/MarkdownDiffViewer.tsx +84 -26
  179. package/src/modules/review/components/ReviewFileRow.tsx +10 -10
  180. package/src/modules/review/components/ReviewPanel.tsx +49 -17
  181. package/src/modules/review/components/ReviewPanelSurface.tsx +1 -1
  182. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +122 -0
  183. package/src/modules/review/hooks/__tests__/useReviewState.test.ts +1 -1
  184. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +273 -171
  185. package/src/modules/secrets-vault/components/SecretsPage.tsx +147 -110
  186. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +109 -92
  187. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +35 -4
  188. package/src/modules/secrets-vault/services/connect.api.ts +24 -3
  189. package/src/modules/settings/components/DeploymentPage.tsx +90 -0
  190. package/src/modules/settings/components/SettingsLayout.tsx +135 -0
  191. package/src/modules/settings/components/SettingsNav.tsx +114 -0
  192. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +110 -0
  193. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +249 -0
  194. package/src/modules/settings/settings-nav-items.tsx +166 -0
  195. package/src/modules/setup/__tests__/setup.test.tsx +540 -0
  196. package/src/modules/setup/components/SetupGate.tsx +67 -0
  197. package/src/modules/setup/components/SetupScreen.tsx +573 -0
  198. package/src/modules/setup/services/setup.api.ts +106 -0
  199. package/src/modules/setup/utils/git-host.ts +34 -0
  200. package/src/modules/toolbar/components/AppSwitcher.tsx +38 -15
  201. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +50 -50
  202. package/src/modules/toolbar/components/ProfileMenu.tsx +294 -0
  203. package/src/modules/toolbar/components/Toolbar.tsx +56 -54
  204. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +176 -122
  205. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +252 -77
  206. package/src/modules/tools/ToolsExplorerPage.tsx +45 -40
  207. package/src/modules/workspace/__tests__/design-system-parity.test.ts +133 -0
  208. package/src/modules/workspace/__tests__/testFixtures.ts +2 -0
  209. package/src/modules/workspace/components/EditorTabs.tsx +82 -50
  210. package/src/modules/workspace/components/FileExplorer.tsx +413 -189
  211. package/src/modules/workspace/components/FilePaneCard.tsx +53 -0
  212. package/src/modules/workspace/components/FileRoute.tsx +89 -84
  213. package/src/modules/workspace/components/FileViewer.tsx +700 -294
  214. package/src/modules/workspace/components/KbDocumentShell.tsx +138 -0
  215. package/src/modules/workspace/components/KbFileRail.tsx +128 -0
  216. package/src/modules/workspace/components/KbPageHeader.tsx +390 -0
  217. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +87 -3
  218. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +293 -39
  219. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +1 -16
  220. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +462 -44
  221. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +84 -0
  222. package/src/modules/workspace/components/__tests__/KbFileRail.test.tsx +83 -0
  223. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +192 -0
  224. package/src/modules/workspace/components/renderers/CopyAnchorButton.tsx +64 -0
  225. package/src/modules/workspace/components/renderers/CsvRenderer.tsx +8 -8
  226. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +18 -9
  227. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +14 -14
  228. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +2 -2
  229. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +31 -165
  230. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +18 -5
  231. package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +27 -10
  232. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +2 -2
  233. package/src/modules/workspace/components/renderers/TextRenderer.tsx +11 -5
  234. package/src/modules/workspace/components/renderers/ToolForm.tsx +24 -24
  235. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +27 -27
  236. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -11
  237. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +66 -0
  238. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +17 -1
  239. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +1 -1
  240. package/src/modules/workspace/components/renderers/__tests__/MermaidDiagram.test.tsx +58 -0
  241. package/src/modules/workspace/components/renderers/__tests__/lazyRenderer.test.tsx +68 -0
  242. package/src/modules/workspace/components/renderers/__tests__/rendererLayout.test.ts +64 -0
  243. package/src/modules/workspace/components/renderers/__tests__/sanitizeDocxHtml.test.ts +0 -0
  244. package/src/modules/workspace/components/renderers/chunk-boundary.tsx +71 -0
  245. package/src/modules/workspace/components/renderers/index.ts +78 -2
  246. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +241 -0
  247. package/src/modules/workspace/components/renderers/lazyRenderer.tsx +59 -0
  248. package/src/modules/workspace/components/renderers/sanitizeDocxHtml.ts +91 -0
  249. package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +59 -0
  250. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +237 -0
  251. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +185 -0
  252. package/src/modules/workspace/hooks/useAutoGrowTextarea.ts +30 -0
  253. package/src/modules/workspace/hooks/useLastCommit.ts +66 -0
  254. package/src/modules/workspace/hooks/useLinksOut.ts +56 -0
  255. package/src/modules/workspace/hooks/useOpenChangeRequests.ts +20 -0
  256. package/src/modules/workspace/hooks/useWorkspaceState.ts +123 -14
  257. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +1 -1
  258. package/src/modules/workspace/services/workspace.api.ts +9 -2
  259. package/src/modules/workspace/state/open-change-requests.context.ts +35 -0
  260. package/src/modules/workspace/state/open-change-requests.tsx +185 -0
  261. package/src/modules/workspace/state/workspace.context.ts +9 -0
  262. package/src/modules/workspace/utils/__tests__/diff.test.ts +87 -0
  263. package/src/modules/workspace/utils/diff.ts +130 -53
  264. package/src/modules/workspace/utils/fileTree.ts +7 -4
  265. package/src/modules/workspace/workspace.css +28 -0
  266. package/src/shared/components/Badge.tsx +62 -0
  267. package/src/shared/components/Banner.tsx +58 -0
  268. package/src/shared/components/Button.tsx +90 -0
  269. package/src/shared/components/Dialog.tsx +6 -6
  270. package/src/shared/components/Field.tsx +45 -0
  271. package/src/shared/components/IconButton.tsx +74 -0
  272. package/src/shared/components/ListRow.tsx +96 -0
  273. package/src/shared/components/Menu.tsx +88 -0
  274. package/src/shared/components/PageShell.tsx +8 -5
  275. package/src/shared/components/Surface.tsx +86 -0
  276. package/src/shared/components/__tests__/primitives.test.tsx +333 -0
  277. package/src/shared/components/index.ts +48 -0
  278. package/src/shared/components/useDismissableMenu.ts +71 -0
  279. package/src/shared/theme/__tests__/accent-contrast.test.ts +84 -0
  280. package/src/shared/theme/index.css +12 -0
  281. package/src/shared/theme/measure.ts +64 -0
  282. package/src/shared/theme/shadows.css +34 -0
  283. package/src/shared/theme/tokens.css +193 -0
  284. package/src/test-setup.ts +9 -0
  285. package/src/modules/access/components/AccessRestrictedBanner.tsx +0 -31
  286. package/src/modules/access/components/NodeOwnersBanner.tsx +0 -30
  287. package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +0 -82
  288. package/src/modules/git/components/ProtectedBranchBanner.tsx +0 -42
  289. package/src/modules/library/__tests__/DetailDialog.test.tsx +0 -200
  290. package/src/modules/library/__tests__/diff.test.ts +0 -62
  291. package/src/modules/library/__tests__/loadout.test.tsx +0 -72
  292. package/src/modules/library/components/CompareView.tsx +0 -357
  293. package/src/modules/library/components/DetailDialog.tsx +0 -566
  294. package/src/modules/library/components/GearIcon.tsx +0 -12
  295. package/src/modules/library/components/LoadoutSidebar.tsx +0 -156
  296. package/src/modules/library/components/StatusGem.tsx +0 -21
  297. package/src/modules/library/components/SuggestChange.tsx +0 -171
  298. package/src/modules/library/components/particles.ts +0 -50
  299. package/src/modules/library/state/loadout.tsx +0 -129
  300. package/src/modules/library/utils/diff.ts +0 -102
  301. package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +0 -93
  302. package/src/modules/pr/__tests__/PrCancelButton.test.tsx +0 -158
  303. package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +0 -44
  304. package/src/modules/pr/__tests__/PrMergeButton.test.tsx +0 -360
  305. package/src/modules/pr/__tests__/bucketize-comments.test.ts +0 -85
  306. package/src/modules/pr/__tests__/parsePatch.test.ts +0 -104
  307. package/src/modules/pr/__tests__/usePrViewerState.test.ts +0 -72
  308. package/src/modules/pr/components/PrApprovalBadge.tsx +0 -80
  309. package/src/modules/pr/components/PrCancelButton.tsx +0 -99
  310. package/src/modules/pr/components/PrCancelConfirmDialog.tsx +0 -119
  311. package/src/modules/pr/components/PrCommentComposer.tsx +0 -92
  312. package/src/modules/pr/components/PrCommentThread.tsx +0 -168
  313. package/src/modules/pr/components/PrCommentsPanel.tsx +0 -143
  314. package/src/modules/pr/components/PrDiffPane.tsx +0 -425
  315. package/src/modules/pr/components/PrFileRow.tsx +0 -164
  316. package/src/modules/pr/components/PrFilesList.tsx +0 -53
  317. package/src/modules/pr/components/PrHeader.tsx +0 -45
  318. package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +0 -58
  319. package/src/modules/pr/components/PrMergeButton.tsx +0 -268
  320. package/src/modules/pr/components/PrMergeConfirmDialog.tsx +0 -112
  321. package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +0 -110
  322. package/src/modules/pr/components/PrViewer.tsx +0 -364
  323. package/src/modules/pr/hooks/usePrViewerState.ts +0 -150
  324. package/src/modules/pr/state/pr-viewer.context.ts +0 -34
  325. package/src/modules/pr/utils/bucketize-comments.ts +0 -55
  326. package/src/modules/pr/utils/parsePatch.ts +0 -57
  327. package/src/modules/toolbar/components/AdminMenu.tsx +0 -271
@@ -1,6 +1,22 @@
1
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
1
+ import {
2
+ useCallback,
3
+ useEffect,
4
+ useLayoutEffect,
5
+ useMemo,
6
+ useRef,
7
+ useState,
8
+ type ReactNode,
9
+ } from 'react';
2
10
  import { X, Lock, Loader2, ChevronDown, Check, Globe } from 'lucide-react';
3
11
  import type { FileTreeEntry } from '@bevel-software/platform-shared';
12
+ import {
13
+ Badge,
14
+ Banner,
15
+ Button,
16
+ Dialog,
17
+ MenuItem,
18
+ MenuPanel,
19
+ } from '../../../shared/components';
4
20
  import { useWorkspace } from '../../workspace/state/workspace.context';
5
21
  import { useAuth } from '../../auth/state/auth.context';
6
22
  import {
@@ -20,6 +36,29 @@ import {
20
36
  interface Props {
21
37
  entry: FileTreeEntry;
22
38
  onClose: () => void;
39
+ /**
40
+ * The workspace (branch) whose access is read and edited. Defaults to the
41
+ * ambient `WorkspaceContext` — which is what the file explorer wants, since
42
+ * it edits the branch the user is looking at.
43
+ *
44
+ * The Library is the other case: its surfaces describe the DEFAULT branch
45
+ * regardless of which branch happens to be open, so a group's access edit
46
+ * has to be pinned to it. Without this the same click would splice
47
+ * `access.md` on whatever branch the context last had open — a rule written
48
+ * into a draft nobody merges, silently doing nothing.
49
+ */
50
+ workspaceId?: string;
51
+ /**
52
+ * Retarget the sheet at an ancestor folder — the prototype's
53
+ * `Manage <Folder> →` (proto:3647).
54
+ *
55
+ * The dialog cannot do this itself: it takes a fixed `entry`, and the caller
56
+ * owns the state that chooses it. Every existing call site already holds
57
+ * exactly that state, so wiring it is one line each. Omitted ⇒ the link does
58
+ * not render, and an inherited grant stays read-only — which is the honest
59
+ * fallback, not a silent no-op.
60
+ */
61
+ onManageAncestor?: (entry: FileTreeEntry) => void;
23
62
  }
24
63
 
25
64
  type Role = 'Owner' | 'Can edit' | 'Can read' | 'Can download';
@@ -122,7 +161,19 @@ function ancestorsFromSources(sources: GrantSources | undefined): string[] {
122
161
  /** The checklist order; download is independent and rendered separately. */
123
162
  const TIER_ROLES: Role[] = ['Owner', 'Can edit', 'Can read'];
124
163
 
125
- const AVATAR_COLORS = ['#863bff', '#0ea5e9', '#16a34a', '#f59e0b', '#ec4899', '#7e14ff'];
164
+ /**
165
+ * Muted identity tones (bg/fg pairs) — the same family as the Library's
166
+ * monogram marks, so a person's avatar and a tool's logo read as one system
167
+ * instead of one calm grid with saturated Drive-style discs in the middle.
168
+ */
169
+ const AVATAR_TONES = [
170
+ { bg: '#eaf1ea', fg: '#4f7a52' },
171
+ { bg: '#e9eefb', fg: '#4560a8' },
172
+ { bg: '#fbeeea', fg: '#a85a41' },
173
+ { bg: '#f2eafa', fg: '#6f4a9b' },
174
+ { bg: '#e7f2f4', fg: '#3d7783' },
175
+ { bg: '#faf0e2', fg: '#8a6a2f' },
176
+ ];
126
177
 
127
178
  function initials(label: string): string {
128
179
  const parts = label.replace(/[<>]/g, '').trim().split(/[\s@.]+/).filter(Boolean);
@@ -131,10 +182,10 @@ function initials(label: string): string {
131
182
  return (parts[0][0] + parts[1][0]).toUpperCase();
132
183
  }
133
184
 
134
- function avatarColor(seed: string): string {
185
+ function avatarTone(seed: string): { bg: string; fg: string } {
135
186
  let h = 0;
136
187
  for (let i = 0; i < seed.length; i++) h = (h * 31 + seed.charCodeAt(i)) | 0;
137
- return AVATAR_COLORS[Math.abs(h) % AVATAR_COLORS.length];
188
+ return AVATAR_TONES[Math.abs(h) % AVATAR_TONES.length];
138
189
  }
139
190
 
140
191
  const EMAIL_RE = /^[^<>\s@]+@[^<>\s@]+\.[^<>\s@]+$/;
@@ -178,6 +229,136 @@ function summarizeVerbs(v: VerbSet): string {
178
229
  return parts.length ? parts.join(', ') : 'No access';
179
230
  }
180
231
 
232
+ /** Gap between a trigger and its menu, and the minimum inset from a viewport edge. */
233
+ const MENU_GAP = 4;
234
+ const MENU_MARGIN = 8;
235
+ /**
236
+ * `MenuPanel`'s own `min-w-[200px]`. We position a box and the panel renders
237
+ * inside it, so the two must agree: a narrower requested width would place a
238
+ * 192px box that paints 200px wide, and a right-aligned menu would overhang its
239
+ * trigger by the difference.
240
+ */
241
+ const MENU_MIN_WIDTH = 200;
242
+
243
+ /**
244
+ * A dropdown panel that escapes the dialog's scroll container.
245
+ *
246
+ * `Dialog` renders its body inside `overflow-y-auto` so a long access list
247
+ * scrolls under the pinned header and footer. An ABSOLUTELY positioned menu in
248
+ * that box is clipped by it: open the verb menu on a low grantee row and
249
+ * everything past the first item or two — "Remove access" included — is cut off
250
+ * at the body's edge, unreachable without scrolling the list out from under the
251
+ * menu.
252
+ *
253
+ * `position: fixed` is the fix, because an overflow ancestor doesn't clip a
254
+ * descendant whose containing block is the viewport. Deliberately NOT a portal:
255
+ * the panel stays inside `Dialog`'s focus trap, which queries its own subtree,
256
+ * so the items remain Tab-reachable. Being fixed, it has to be re-anchored to
257
+ * the trigger's measured rect on scroll and resize — the same shape
258
+ * `BranchSwitcher` uses for its portaled menu — and, because both boxes can
259
+ * change size with the menu still open, whenever either one is resized.
260
+ *
261
+ * The anchor is the panel's own DOM PARENT — i.e. render this where the
262
+ * `absolute` panel used to sit, and it lines up against the same box `absolute`
263
+ * measured. That's not just brevity: a ref passed down from the parent is NOT
264
+ * attached yet when this component's layout effect runs (React attaches refs
265
+ * bottom-up, children first), so the first placement would silently no-op and
266
+ * the panel would stay hidden.
267
+ */
268
+ function AnchoredMenu({
269
+ /**
270
+ * Panel width in px, or `'anchor'` to match the trigger (the combobox case).
271
+ * Clamped up to {@link MENU_MIN_WIDTH} either way.
272
+ */
273
+ width = MENU_MIN_WIDTH,
274
+ /** Which edge lines up with the anchor's. */
275
+ align = 'right',
276
+ className = '',
277
+ children,
278
+ }: {
279
+ width?: number | 'anchor';
280
+ align?: 'left' | 'right';
281
+ className?: string;
282
+ children: ReactNode;
283
+ }) {
284
+ const panelRef = useRef<HTMLDivElement>(null);
285
+ const [pos, setPos] = useState<{ top: number; left: number; width: number } | null>(null);
286
+
287
+ useLayoutEffect(() => {
288
+ const panel = panelRef.current;
289
+ const anchorEl = panel?.parentElement ?? null;
290
+ const place = () => {
291
+ const el = panelRef.current;
292
+ const anchor = el?.parentElement?.getBoundingClientRect();
293
+ if (!anchor || !el) return;
294
+ const w = Math.max(width === 'anchor' ? anchor.width : width, MENU_MIN_WIDTH);
295
+ // Width BEFORE height: the panel wraps and grows taller when narrower, so
296
+ // measuring at the wrong width picks the wrong side to open on.
297
+ el.style.width = `${w}px`;
298
+ const h = el.offsetHeight;
299
+ const left = Math.max(
300
+ MENU_MARGIN,
301
+ Math.min(
302
+ align === 'right' ? anchor.right - w : anchor.left,
303
+ window.innerWidth - w - MENU_MARGIN,
304
+ ),
305
+ );
306
+ // Below by default. Flip above only when the panel would run off the
307
+ // bottom AND there is actually room up there — otherwise a tall menu on a
308
+ // low trigger would just lose its top instead of its bottom.
309
+ const below = anchor.bottom + MENU_GAP;
310
+ const above = anchor.top - MENU_GAP - h;
311
+ const top =
312
+ below + h > window.innerHeight - MENU_MARGIN && above >= MENU_MARGIN ? above : below;
313
+ // Keep the previous object when nothing moved. `place` runs on every
314
+ // scroll frame and on every observed resize, and a fresh object each time
315
+ // would re-render for nothing — and, since the panel is what's observed,
316
+ // feed the observer its own output.
317
+ setPos((prev) =>
318
+ prev && prev.top === top && prev.left === left && prev.width === w
319
+ ? prev
320
+ : { top, left, width: w },
321
+ );
322
+ };
323
+ place();
324
+ // Both measured boxes move under us while the menu is open, and neither
325
+ // move fires scroll or resize. The trigger relabels itself as verbs are
326
+ // toggled ("Can edit" → "Owner, Can download"), which shifts `anchor.right`
327
+ // out from under a right-aligned panel; the panel itself grows and shrinks
328
+ // as the suggestion list follows what's typed, so one measured to fit below
329
+ // ends up hanging off the bottom it was checked against.
330
+ const observer = new ResizeObserver(place);
331
+ if (anchorEl) observer.observe(anchorEl);
332
+ if (panel) observer.observe(panel);
333
+ window.addEventListener('resize', place);
334
+ // Capture phase: the dialog body is what scrolls, and scroll events don't
335
+ // bubble to `window`.
336
+ window.addEventListener('scroll', place, true);
337
+ return () => {
338
+ observer.disconnect();
339
+ window.removeEventListener('resize', place);
340
+ window.removeEventListener('scroll', place, true);
341
+ };
342
+ }, [width, align]);
343
+
344
+ return (
345
+ <div
346
+ ref={panelRef}
347
+ className="fixed z-[60]"
348
+ style={{
349
+ top: pos?.top ?? 0,
350
+ left: pos?.left ?? 0,
351
+ width: pos?.width ?? (typeof width === 'number' ? width : undefined),
352
+ // Covers the measuring pass only. `useLayoutEffect` places the panel
353
+ // before the browser paints, so an unpositioned one is never on screen.
354
+ visibility: pos ? undefined : 'hidden',
355
+ }}
356
+ >
357
+ <MenuPanel className={`w-full ${className}`}>{children}</MenuPanel>
358
+ </div>
359
+ );
360
+ }
361
+
181
362
  /**
182
363
  * Google-Drive-style "Manage access" sheet. Reads the resolved access for a KB
183
364
  * path and lets anyone who can write the path's access config share it: add one
@@ -189,8 +370,16 @@ function summarizeVerbs(v: VerbSet): string {
189
370
  * the user can't write the access config, the add affordance is disabled and
190
371
  * names the owners to ask.
191
372
  */
192
- export function ManageAccessDialog({ entry, onClose }: Props) {
193
- const { workspaceId, kbDirName } = useWorkspace();
373
+ export function ManageAccessDialog({
374
+ entry,
375
+ onClose,
376
+ workspaceId: workspaceIdProp,
377
+ onManageAncestor,
378
+ }: Props) {
379
+ // `kbDirName` stays context-sourced: it names the clone directory, which is
380
+ // the same on every branch.
381
+ const { workspaceId: ctxWorkspaceId, kbDirName } = useWorkspace();
382
+ const workspaceId = workspaceIdProp ?? ctxWorkspaceId;
194
383
  const { user } = useAuth();
195
384
  const [data, setData] = useState<AccessResponse | null>(null);
196
385
  const [loading, setLoading] = useState(true);
@@ -269,13 +458,9 @@ export function ManageAccessDialog({ entry, onClose }: Props) {
269
458
  };
270
459
  }, [workspaceId, repoRelative, targetKind]);
271
460
 
272
- useEffect(() => {
273
- const onKey = (e: KeyboardEvent) => {
274
- if (e.key === 'Escape') onClose();
275
- };
276
- document.addEventListener('keydown', onKey);
277
- return () => document.removeEventListener('keydown', onKey);
278
- }, [onClose]);
461
+ // Escape / backdrop / focus trapping all belong to the shared `Dialog` now —
462
+ // including the layering that lets the nested "Remove from parent?" modal
463
+ // take Escape without also closing this one.
279
464
 
280
465
  // Debounced autocomplete. People are withheld server-side until q ≥ 2 chars.
281
466
  const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null);
@@ -329,10 +514,14 @@ export function ManageAccessDialog({ entry, onClose }: Props) {
329
514
  const key = `u:${u.email.toLowerCase()}`;
330
515
  let row = rows.get(key);
331
516
  if (!row) {
517
+ const label = u.name || u.email;
332
518
  row = {
333
519
  key,
334
- label: u.name || u.email,
335
- sub: u.email,
520
+ label,
521
+ // Only a real display name earns the second line — a nameless user
522
+ // would otherwise render the same email twice, burning a row of the
523
+ // scarce width on a duplicate.
524
+ sub: label.toLowerCase() === u.email.toLowerCase() ? undefined : u.email,
336
525
  isRole: false,
337
526
  isYou: u.email.toLowerCase() === myEmail,
338
527
  principal: { kind: 'user', email: u.email, displayName: u.name || u.email },
@@ -378,7 +567,56 @@ export function ManageAccessDialog({ entry, onClose }: Props) {
378
567
  () => principals.filter((p) => p.manage !== 'direct'),
379
568
  [principals],
380
569
  );
381
- const [showInherited, setShowInherited] = useState(false);
570
+
571
+ /**
572
+ * The inherited rows, ONE GROUP PER GRANTING FOLDER — the prototype's shape
573
+ * (proto:3637-3649) and, more to the point, its reasoning:
574
+ *
575
+ * "Inheritance, said as a sentence instead of labelled as a concept.
576
+ * 'People invited to KnowledgeBase' needs no explaining — it names the
577
+ * folder, and the folder is both what it means and where it changes. One
578
+ * collapsed row per granting folder, because two folders granting
579
+ * different people is the normal case and merging them would hide which
580
+ * one to open."
581
+ *
582
+ * This used to be a single "Inherited access (N) — from parent folders &
583
+ * roles" disclosure. That heading names the CONCEPT, which the reader either
584
+ * already understands or is not helped by, and merging every ancestor into
585
+ * one list threw away the only fact that makes an inherited grant
586
+ * actionable: which folder to go and edit.
587
+ *
588
+ * A principal granted by two folders appears under BOTH, deliberately — that
589
+ * is the truth, and it is exactly the case a merged list hides.
590
+ *
591
+ * Rows with no ancestor at all (a role that grants at the workspace level,
592
+ * `manage: 'external'`) have no folder to file under, so they keep a group of
593
+ * their own at the end rather than being dropped.
594
+ */
595
+ const inheritedByFolder = useMemo(() => {
596
+ const byFolder = new Map<string, PrincipalRow[]>();
597
+ const external: PrincipalRow[] = [];
598
+ for (const row of inheritedRows) {
599
+ if (row.ancestors.length === 0) {
600
+ external.push(row);
601
+ continue;
602
+ }
603
+ for (const a of row.ancestors) {
604
+ const list = byFolder.get(a);
605
+ if (list) list.push(row);
606
+ else byFolder.set(a, [row]);
607
+ }
608
+ }
609
+ // Deepest folder first: the nearest ancestor is the one most likely to be
610
+ // the one you meant, and it is the one whose rule wins.
611
+ const folders = [...byFolder.entries()].sort(
612
+ (a, b) => b[0].split('/').length - a[0].split('/').length,
613
+ );
614
+ return { folders, external };
615
+ }, [inheritedRows]);
616
+
617
+ /** Which folder group is expanded, or `'roles'`, or null. One at a time —
618
+ * as in the prototype, where `state.accOpen` holds a single value. */
619
+ const [openGroup, setOpenGroup] = useState<string | null>(null);
382
620
 
383
621
  const governed = repoRelative !== null;
384
622
  // The dialog can mutate only if the current user can write this path's access
@@ -459,7 +697,7 @@ export function ManageAccessDialog({ entry, onClose }: Props) {
459
697
  // picked (e.g. only "Can download"): record it as a failure so the chip
460
698
  // stays visible and the user is told why, rather than a no-op clear.
461
699
  if (isEveryoneRole(principal) && verbsForPrincipal.length === 0) {
462
- failures.push(`${label}: "Everyone" can only be granted read access — select "Can read".`);
700
+ failures.push(`${label}: "Everyone" can only be granted read access. Select "Can read".`);
463
701
  continue;
464
702
  }
465
703
  for (const verb of verbsForPrincipal) {
@@ -718,515 +956,582 @@ export function ManageAccessDialog({ entry, onClose }: Props) {
718
956
 
719
957
  // One grantee row. Direct rows get the inline verb editor; inherited rows are
720
958
  // read-only with a Remove that opens the cascade flow; external rows are
721
- // read-only with no action. `dense` trims the avatar/labels in the collapsed
722
- // inherited section so a deep folder chain doesn't overflow.
723
- const renderRow = (p: PrincipalRow) => (
724
- <div key={p.key} className="flex items-center gap-3 py-2 group">
725
- <div
726
- className="w-9 h-9 rounded-full flex items-center justify-center text-[13px] font-bold text-white shrink-0"
727
- style={{ background: p.isRole ? '#64748b' : avatarColor(p.label) }}
728
- >
729
- {initials(p.label)}
730
- </div>
731
- <div className="flex-1 min-w-0">
732
- <div className="text-sm text-slate-900 font-medium truncate">
733
- {p.label}
734
- {p.isYou && <span className="text-slate-400 font-normal"> (you)</span>}
735
- {p.isRole && (
736
- <span className="ml-1.5 text-[10px] uppercase tracking-wide text-slate-400">role</span>
737
- )}
738
- </div>
739
- {p.sub && <div className="text-xs text-slate-500 truncate">{p.sub}</div>}
740
- </div>
741
- {canManage && p.manage === 'inherited' ? (
742
- // Inherited from a parent folder — read-only here. Leaf folder name only
743
- // (full path on hover); Remove opens the "Remove from parent?" flow.
744
- <div className="flex items-center gap-2 shrink-0">
959
+ // read-only with no action.
960
+ const renderRow = (p: PrincipalRow) => {
961
+ const tone = avatarTone(p.label);
962
+ return (
963
+ // Wrapping, with a floor under the name block: on a narrow panel the meta
964
+ // cluster (via… / verbs / Remove) drops to its own line rather than
965
+ // squeezing the name to zero width — which left the `Role` badge sitting
966
+ // on top of the "via …" label and pushed Remove off the panel's edge.
967
+ <div key={p.key} className="flex flex-wrap items-center gap-x-3 gap-y-1 py-2">
968
+ {p.isRole ? (
969
+ <span className="flex size-9 shrink-0 items-center justify-center rounded-full bg-sunken text-detail font-bold text-ink-muted">
970
+ {initials(p.label)}
971
+ </span>
972
+ ) : (
745
973
  <span
746
- className="text-xs text-slate-400 italic max-w-[10rem] truncate"
747
- title={p.ancestors.map(folderPath).join(', ')}
974
+ className="flex size-9 shrink-0 items-center justify-center rounded-full text-detail font-bold"
975
+ style={{ backgroundColor: tone.bg, color: tone.fg }}
748
976
  >
749
- via {p.ancestors.map(folderLabel).join(', ')}
977
+ {initials(p.label)}
750
978
  </span>
751
- <span className="text-sm text-slate-400">{summarizeVerbs(p.verbs)}</span>
752
- <button
753
- type="button"
754
- disabled={busy}
755
- onClick={() => doRevoke(p)}
756
- className="px-2 py-1 rounded text-sm text-red-600 hover:bg-red-50 disabled:cursor-not-allowed"
757
- >
758
- Remove
759
- </button>
979
+ )}
980
+ <div className="min-w-36 flex-1">
981
+ <div className="flex min-w-0 items-center gap-1.5">
982
+ <span className="truncate text-ui font-medium text-ink">{p.label}</span>
983
+ {p.isYou && <span className="shrink-0 text-ui text-ink-faint">(you)</span>}
984
+ {p.isRole && (
985
+ <Badge tone="outline" size="xs" className="shrink-0 uppercase">
986
+ Role
987
+ </Badge>
988
+ )}
989
+ </div>
990
+ {p.sub && <div className="truncate text-detail text-ink-muted">{p.sub}</div>}
760
991
  </div>
761
- ) : canManage && p.manage === 'external' ? (
762
- // No file-backed grant to remove here — managed elsewhere (a group's
763
- // membership, the everyone policy, or admin rescue).
764
- <span
765
- className="text-sm text-slate-400 shrink-0"
766
- title="Granted via a role or policy — manage it there"
767
- >
768
- {summarizeVerbs(p.verbs)}
769
- </span>
770
- ) : canManage ? (
771
- <div className="relative shrink-0">
772
- <button
773
- type="button"
774
- disabled={busy}
775
- onClick={() => setOpenRowKey((k) => (k === p.key ? null : p.key))}
776
- className="px-2 py-1 rounded text-sm text-slate-600 flex items-center gap-1 hover:bg-slate-100 disabled:cursor-not-allowed"
992
+ {canManage && p.manage === 'inherited' ? (
993
+ // Inherited from a parent folder — read-only here. Leaf folder name only
994
+ // (full path on hover); Remove opens the "Remove from parent?" flow.
995
+ <div className="ml-auto flex max-w-full shrink-0 items-center gap-2">
996
+ <span
997
+ className="min-w-0 max-w-40 truncate text-detail italic text-ink-faint"
998
+ title={p.ancestors.map(folderPath).join(', ')}
999
+ >
1000
+ via {p.ancestors.map(folderLabel).join(', ')}
1001
+ </span>
1002
+ <span className="whitespace-nowrap text-detail text-ink-faint">
1003
+ {summarizeVerbs(p.verbs)}
1004
+ </span>
1005
+ <Button variant="danger" size="tiny" disabled={busy} onClick={() => doRevoke(p)}>
1006
+ Remove
1007
+ </Button>
1008
+ </div>
1009
+ ) : canManage && p.manage === 'external' ? (
1010
+ // No file-backed grant to remove here — managed elsewhere (a group's
1011
+ // membership, the everyone policy, or admin rescue).
1012
+ <span
1013
+ className="ml-auto shrink-0 text-detail text-ink-faint"
1014
+ title="Granted via a role or policy. Manage it there"
777
1015
  >
778
1016
  {summarizeVerbs(p.verbs)}
779
- <ChevronDown size={14} />
780
- </button>
781
- {openRowKey === p.key && (
782
- <div className="absolute right-0 z-20 mt-1 bg-white border border-slate-200 rounded-lg shadow-lg w-44 py-1">
783
- {TIER_ROLES.map((role) => {
784
- const k = ROLE_TO_KEY[role];
785
- const checked = p.verbs[k];
786
- const disabled =
787
- busy ||
788
- (role === 'Can edit' && p.verbs.owner) ||
789
- (role === 'Can read' && (p.verbs.owner || p.verbs.write));
790
- return (
791
- <button
792
- key={role}
793
- type="button"
794
- disabled={disabled}
795
- onClick={() => doToggleVerb(p.principal, role, checked)}
796
- className="w-full flex items-center gap-2 px-3 py-1.5 text-sm hover:bg-slate-50 disabled:opacity-50 disabled:cursor-not-allowed"
797
- >
798
- <span className="w-4 h-4 border border-slate-300 rounded flex items-center justify-center shrink-0">
799
- {checked && <Check size={12} className="text-bevel" />}
800
- </span>
801
- <span className="flex-1 text-left">{role}</span>
802
- </button>
803
- );
804
- })}
805
- <div className="border-t border-slate-100 my-1" />
806
- {(() => {
807
- const checked = p.verbs.download;
808
- const disabled = busy || p.verbs.owner;
809
- return (
810
- <button
811
- type="button"
812
- disabled={disabled}
813
- onClick={() => doToggleVerb(p.principal, 'Can download', checked)}
814
- className="w-full flex items-center gap-2 px-3 py-1.5 text-sm hover:bg-slate-50 disabled:opacity-50 disabled:cursor-not-allowed"
815
- >
816
- <span className="w-4 h-4 border border-slate-300 rounded flex items-center justify-center shrink-0">
817
- {checked && <Check size={12} className="text-bevel" />}
818
- </span>
819
- <span className="flex-1 text-left">Can download</span>
820
- </button>
821
- );
822
- })()}
823
- <div className="border-t border-slate-100 my-1" />
824
- <button
825
- type="button"
826
- disabled={busy}
827
- onClick={() => {
828
- setOpenRowKey(null);
829
- doRevoke(p);
830
- }}
831
- className="w-full text-left px-3 py-1.5 text-sm text-red-600 hover:bg-red-50 disabled:cursor-not-allowed"
832
- >
833
- Remove access
834
- </button>
835
- </div>
836
- )}
837
- </div>
838
- ) : (
839
- <span className="text-sm text-slate-500 shrink-0">{summarizeVerbs(p.verbs)}</span>
840
- )}
841
- </div>
842
- );
1017
+ </span>
1018
+ ) : canManage ? (
1019
+ <div className="ml-auto shrink-0">
1020
+ <Button
1021
+ variant="quiet"
1022
+ size="sm"
1023
+ disabled={busy}
1024
+ onClick={() => setOpenRowKey((k) => (k === p.key ? null : p.key))}
1025
+ trailingIcon={<ChevronDown size={14} />}
1026
+ >
1027
+ {summarizeVerbs(p.verbs)}
1028
+ </Button>
1029
+ {openRowKey === p.key && (
1030
+ <AnchoredMenu>
1031
+ {TIER_ROLES.map((role) => {
1032
+ const k = ROLE_TO_KEY[role];
1033
+ const checked = p.verbs[k];
1034
+ const disabled =
1035
+ busy ||
1036
+ (role === 'Can edit' && p.verbs.owner) ||
1037
+ (role === 'Can read' && (p.verbs.owner || p.verbs.write));
1038
+ return (
1039
+ <MenuItem
1040
+ key={role}
1041
+ disabled={disabled}
1042
+ active={checked}
1043
+ onClick={() => doToggleVerb(p.principal, role, checked)}
1044
+ trailing={checked ? <Check size={14} className="text-accent" /> : undefined}
1045
+ >
1046
+ {role}
1047
+ </MenuItem>
1048
+ );
1049
+ })}
1050
+ <div className="my-1 border-t border-line" />
1051
+ {(() => {
1052
+ const checked = p.verbs.download;
1053
+ const disabled = busy || p.verbs.owner;
1054
+ return (
1055
+ <MenuItem
1056
+ disabled={disabled}
1057
+ active={checked}
1058
+ onClick={() => doToggleVerb(p.principal, 'Can download', checked)}
1059
+ trailing={checked ? <Check size={14} className="text-accent" /> : undefined}
1060
+ >
1061
+ Can download
1062
+ </MenuItem>
1063
+ );
1064
+ })()}
1065
+ <div className="my-1 border-t border-line" />
1066
+ <MenuItem
1067
+ tone="danger"
1068
+ disabled={busy}
1069
+ onClick={() => {
1070
+ setOpenRowKey(null);
1071
+ doRevoke(p);
1072
+ }}
1073
+ >
1074
+ Remove access
1075
+ </MenuItem>
1076
+ </AnchoredMenu>
1077
+ )}
1078
+ </div>
1079
+ ) : (
1080
+ <span className="ml-auto shrink-0 text-detail text-ink-muted">
1081
+ {summarizeVerbs(p.verbs)}
1082
+ </span>
1083
+ )}
1084
+ </div>
1085
+ );
1086
+ };
843
1087
 
844
1088
  return (
845
- <div
846
- className="fixed inset-0 z-[70] bg-slate-900/45 flex items-center justify-center p-4"
847
- onMouseDown={(e) => {
848
- if (e.target === e.currentTarget) onClose();
849
- }}
850
- >
851
- <div
852
- role="dialog"
853
- aria-modal="true"
854
- aria-labelledby="manage-access-title"
855
- className="w-full max-w-[540px] max-h-[86vh] overflow-auto bg-white rounded-2xl shadow-2xl"
1089
+ <>
1090
+ <Dialog
1091
+ open
1092
+ onClose={onClose}
1093
+ title="Manage access"
1094
+ size="lg"
1095
+ footer={
1096
+ <Button variant="primary" size="sm" onClick={onClose}>
1097
+ Done
1098
+ </Button>
1099
+ }
856
1100
  >
857
- <div className="flex items-start justify-between gap-3 px-6 pt-5 pb-2">
858
- <div className="min-w-0">
859
- <h2 id="manage-access-title" className="text-lg font-bold text-slate-900">
860
- Manage access
861
- </h2>
862
- <div className="mt-0.5 text-sm text-slate-500 truncate" title={entry.relativePath}>
863
- {entry.name}
864
- </div>
865
- </div>
866
- <button
867
- type="button"
868
- onClick={onClose}
869
- className="p-1.5 rounded hover:bg-slate-100 text-slate-600 hover:text-slate-900 shrink-0"
870
- aria-label="Close"
871
- >
872
- <X size={16} />
873
- </button>
874
- </div>
1101
+ <p className="truncate text-detail text-ink-muted" title={entry.relativePath}>
1102
+ {entry.name}
1103
+ </p>
875
1104
 
876
- <div className="px-6 pb-2">
877
- {governed && canManage && (
878
- <div className="my-3">
879
- <div className="flex gap-2 relative">
880
- <div className="flex-1 relative">
881
- <div className="w-full border border-slate-200 rounded-lg px-2 py-1.5 flex flex-wrap items-center gap-1.5 focus-within:ring-2 focus-within:ring-bevel/40">
882
- {pickedChips.map((c) => {
883
- const label = c.kind === 'role' ? c.role : c.displayName || c.email;
884
- return (
885
- <span
886
- key={principalKey(c)}
887
- className="inline-flex items-center gap-1 bg-slate-100 text-slate-700 rounded px-2 py-1 text-xs"
888
- >
889
- {label}
890
- <button
891
- type="button"
892
- onClick={() => removeChip(c)}
893
- className="text-slate-400 hover:text-red-600"
894
- aria-label={`Remove ${label}`}
895
- >
896
- <X size={12} />
897
- </button>
898
- </span>
899
- );
900
- })}
901
- <input
902
- value={query}
903
- onChange={(e) => setQuery(e.target.value)}
904
- onKeyDown={(e) => {
905
- if (e.key === 'Enter' && addPending) {
906
- e.preventDefault();
907
- addChip(addPending);
908
- }
909
- }}
910
- placeholder={pickedChips.length ? '' : 'Add people or roles…'}
911
- className="flex-1 min-w-[8rem] px-1 py-1 text-sm focus:outline-none"
912
- />
913
- </div>
914
- {query.trim() && suggest && (suggest.groups.length > 0 || suggest.people.length > 0) && (
915
- <div className="absolute z-10 left-0 right-0 mt-1 bg-white border border-slate-200 rounded-lg shadow-lg max-h-56 overflow-auto">
916
- {suggest.groups.map((g) => (
1105
+ {governed && canManage && (
1106
+ <div className="mt-3">
1107
+ {/* `items-start`, not `items-stretch`: the buttons are `rounded-full`,
1108
+ so stretching them to match the chip box turned Share into a
1109
+ circle the moment a chip wrapped the box onto a second line.
1110
+ `flex-wrap` lets them drop below the box rather than crushing it. */}
1111
+ <div className="relative flex flex-wrap items-start gap-1.5">
1112
+ <div className="relative min-w-48 flex-1">
1113
+ {/* A TextField that grew chips: same border, radius and focus
1114
+ treatment as the primitive, wrapped so the chips can wrap. */}
1115
+ <div className="flex w-full flex-wrap items-center gap-1.5 rounded-md border border-line-strong bg-surface px-2 py-1 focus-within:border-transparent focus-within:outline-2 focus-within:-outline-offset-1 focus-within:outline-accent">
1116
+ {pickedChips.map((c) => {
1117
+ const label = c.kind === 'role' ? c.role : c.displayName || c.email;
1118
+ return (
1119
+ <span
1120
+ key={principalKey(c)}
1121
+ className="inline-flex items-center gap-1 rounded-sm bg-sunken px-2 py-0.5 text-detail text-ink"
1122
+ >
1123
+ {label}
917
1124
  <button
918
- key={`g:${g}`}
919
1125
  type="button"
920
- onClick={() => addChip({ kind: 'role', role: g })}
921
- className="w-full text-left px-3 py-2 text-sm hover:bg-slate-50 flex items-center gap-2"
1126
+ onClick={() => removeChip(c)}
1127
+ className="rounded-xs text-ink-faint hover:text-danger"
1128
+ aria-label={`Remove ${label}`}
922
1129
  >
923
- <span className="w-6 h-6 rounded-full bg-slate-500 text-white text-[10px] flex items-center justify-center">
924
- {initials(g)}
925
- </span>
926
- <span className="flex-1">{g}</span>
927
- <span className="text-[10px] uppercase tracking-wide text-slate-400">
928
- role
929
- </span>
1130
+ <X size={12} />
930
1131
  </button>
931
- ))}
932
- {suggest.people.map((p) => (
933
- <button
1132
+ </span>
1133
+ );
1134
+ })}
1135
+ <input
1136
+ value={query}
1137
+ onChange={(e) => setQuery(e.target.value)}
1138
+ onKeyDown={(e) => {
1139
+ if (e.key === 'Enter' && addPending) {
1140
+ e.preventDefault();
1141
+ addChip(addPending);
1142
+ }
1143
+ }}
1144
+ placeholder={pickedChips.length ? '' : 'Add people or roles…'}
1145
+ className="min-w-32 flex-1 bg-transparent px-1 py-1 text-ui text-ink placeholder:text-ink-faint focus:outline-none"
1146
+ />
1147
+ </div>
1148
+ {query.trim() && suggest && (suggest.groups.length > 0 || suggest.people.length > 0) && (
1149
+ <AnchoredMenu width="anchor" align="left" className="max-h-56 overflow-auto">
1150
+ {suggest.groups.map((g) => (
1151
+ <MenuItem
1152
+ key={`g:${g}`}
1153
+ onClick={() => addChip({ kind: 'role', role: g })}
1154
+ trailing={
1155
+ <span className="text-label uppercase text-ink-faint">role</span>
1156
+ }
1157
+ >
1158
+ <span className="flex size-6 shrink-0 items-center justify-center rounded-full bg-sunken text-label font-bold text-ink-muted">
1159
+ {initials(g)}
1160
+ </span>
1161
+ <span className="min-w-0 flex-1 truncate">{g}</span>
1162
+ </MenuItem>
1163
+ ))}
1164
+ {suggest.people.map((p) => {
1165
+ const tone = avatarTone(p.name || p.email);
1166
+ return (
1167
+ <MenuItem
934
1168
  key={`p:${p.email}`}
935
- type="button"
936
1169
  onClick={() => addChip({ kind: 'user', email: p.email, displayName: p.name })}
937
- className="w-full text-left px-3 py-2 text-sm hover:bg-slate-50 flex items-center gap-2"
1170
+ trailing={
1171
+ <span className="max-w-40 truncate text-meta text-ink-faint">
1172
+ {p.email}
1173
+ </span>
1174
+ }
938
1175
  >
939
1176
  <span
940
- className="w-6 h-6 rounded-full text-white text-[10px] flex items-center justify-center"
941
- style={{ background: avatarColor(p.name || p.email) }}
1177
+ className="flex size-6 shrink-0 items-center justify-center rounded-full text-label font-bold"
1178
+ style={{ backgroundColor: tone.bg, color: tone.fg }}
942
1179
  >
943
1180
  {initials(p.name || p.email)}
944
1181
  </span>
945
- <span className="flex-1 truncate">{p.name || p.email}</span>
946
- <span className="text-xs text-slate-400 truncate">{p.email}</span>
947
- </button>
948
- ))}
949
- </div>
950
- )}
951
- </div>
1182
+ <span className="min-w-0 flex-1 truncate">{p.name || p.email}</span>
1183
+ </MenuItem>
1184
+ );
1185
+ })}
1186
+ </AnchoredMenu>
1187
+ )}
1188
+ </div>
1189
+
1190
+ <div className="shrink-0">
1191
+ <Button
1192
+ variant="outline"
1193
+ size="sm"
1194
+ className="max-w-44"
1195
+ onClick={() => setVerbOpen((o) => !o)}
1196
+ trailingIcon={<ChevronDown size={14} className="shrink-0" />}
1197
+ >
1198
+ <span className="truncate">{summarizeVerbs(effectiveNewVerbs)}</span>
1199
+ </Button>
1200
+ {verbOpen && (
1201
+ <AnchoredMenu>
1202
+ {TIER_ROLES.map((role) => {
1203
+ const k = ROLE_TO_KEY[role];
1204
+ const checked = effectiveNewVerbs[k];
1205
+ const disabled =
1206
+ (role === 'Can edit' && effectiveNewVerbs.owner) ||
1207
+ (role === 'Can read' && (effectiveNewVerbs.owner || effectiveNewVerbs.write));
1208
+ return (
1209
+ <MenuItem
1210
+ key={role}
1211
+ disabled={disabled}
1212
+ active={checked}
1213
+ aria-pressed={checked}
1214
+ onClick={() => setNewVerbs((v) => ({ ...v, [k]: !v[k] }))}
1215
+ trailing={checked ? <Check size={14} className="text-accent" /> : undefined}
1216
+ >
1217
+ {role}
1218
+ </MenuItem>
1219
+ );
1220
+ })}
1221
+ <div className="my-1 border-t border-line" />
1222
+ <MenuItem
1223
+ disabled={effectiveNewVerbs.owner}
1224
+ active={effectiveNewVerbs.download}
1225
+ aria-pressed={effectiveNewVerbs.download}
1226
+ onClick={() => setNewVerbs((v) => ({ ...v, download: !v.download }))}
1227
+ trailing={
1228
+ effectiveNewVerbs.download ? (
1229
+ <Check size={14} className="text-accent" />
1230
+ ) : undefined
1231
+ }
1232
+ >
1233
+ Can download
1234
+ </MenuItem>
1235
+ </AnchoredMenu>
1236
+ )}
1237
+ </div>
1238
+
1239
+ <Button
1240
+ variant="primary"
1241
+ size="sm"
1242
+ className="shrink-0"
1243
+ disabled={pickedChips.length === 0 || grantVerbs.length === 0 || busy}
1244
+ onClick={doGrant}
1245
+ leadingIcon={busy ? <Loader2 size={14} className="animate-spin" /> : undefined}
1246
+ >
1247
+ Share
1248
+ </Button>
1249
+ </div>
1250
+ {query.trim() && !addPending && !suggest?.peopleWithheld && (
1251
+ <p className="mt-1.5 text-detail text-ink-muted">
1252
+ Type a full email to add someone, or pick a role from the list.
1253
+ </p>
1254
+ )}
1255
+ {pickedChips.some(isEveryoneRole) && (
1256
+ <p className="mt-1.5 text-detail text-ink-muted">
1257
+ “Everyone” makes this {targetKind} publicly readable: it can only be granted read access.
1258
+ </p>
1259
+ )}
1260
+ {mutateError && (
1261
+ <Banner tone="danger" role="alert" className="mt-2 whitespace-pre-line">
1262
+ {mutateError}
1263
+ </Banner>
1264
+ )}
1265
+ </div>
1266
+ )}
952
1267
 
953
- <div className="relative">
954
- <button
955
- type="button"
956
- onClick={() => setVerbOpen((o) => !o)}
957
- className="h-full px-3 rounded-lg border border-slate-200 text-sm text-slate-700 flex items-center gap-1 hover:bg-slate-50 max-w-[12rem]"
1268
+ {!governed ? (
1269
+ <p className="py-8 text-center text-ui text-ink-muted">
1270
+ This item isn't part of the knowledge base, so it isn't governed by access control.
1271
+ </p>
1272
+ ) : loading ? (
1273
+ <p className="flex items-center justify-center gap-2 py-8 text-ui text-ink-muted">
1274
+ <Loader2 size={16} className="animate-spin" /> Loading access…
1275
+ </p>
1276
+ ) : error ? (
1277
+ <Banner tone="danger" role="alert" className="my-3">
1278
+ Couldn't load access: {error}
1279
+ </Banner>
1280
+ ) : (
1281
+ <>
1282
+ {!canManage && (
1283
+ <Banner tone="neutral" role="note" className="mt-3">
1284
+ Only people with edit access can share this {targetKind}.
1285
+ {ownerNames && <> Ask an owner: {ownerNames}.</>}
1286
+ </Banner>
1287
+ )}
1288
+
1289
+ {/* Names WHICH RULE you are editing, and adapts to the target
1290
+ (proto:3625: `On this ` + file|folder). The sheet mixes rules
1291
+ set HERE with rules inherited from above, so a heading that
1292
+ says only "People with access" leaves the reader to work out
1293
+ which of the two lists below is which. The count rides it, as
1294
+ on every band in the app. */}
1295
+ <h3 className="mb-1 mt-4 flex items-baseline gap-2 text-label uppercase text-ink-faint">
1296
+ On this {targetKind}
1297
+ {directRows.length > 0 && (
1298
+ <span className="text-meta normal-case tabular-nums">{directRows.length}</span>
1299
+ )}
1300
+ </h3>
1301
+
1302
+ {data && !data.readers.restricted && (
1303
+ <div className="flex items-center gap-3 py-1.5">
1304
+ <span className="flex size-8 shrink-0 items-center justify-center rounded-full bg-ok-soft text-ok">
1305
+ <Globe size={16} />
1306
+ </span>
1307
+ <div className="min-w-0 flex-1">
1308
+ <div className="text-ui text-ink">Anyone can read</div>
1309
+ <div className="text-detail text-ink-muted">
1310
+ Public: every signed-in user can read this {targetKind}
1311
+ </div>
1312
+ </div>
1313
+ {canManage && (
1314
+ <Button
1315
+ variant="danger"
1316
+ size="tiny"
1317
+ className="shrink-0"
1318
+ disabled={busy}
1319
+ onClick={removePublicRead}
958
1320
  >
959
- <span className="truncate">{summarizeVerbs(effectiveNewVerbs)}</span>
960
- <ChevronDown size={14} className="shrink-0" />
961
- </button>
962
- {verbOpen && (
963
- <div className="absolute right-0 z-10 mt-1 bg-white border border-slate-200 rounded-lg shadow-lg w-44 py-1">
964
- {TIER_ROLES.map((role) => {
965
- const k = ROLE_TO_KEY[role];
966
- const checked = effectiveNewVerbs[k];
967
- const disabled =
968
- (role === 'Can edit' && effectiveNewVerbs.owner) ||
969
- (role === 'Can read' && (effectiveNewVerbs.owner || effectiveNewVerbs.write));
970
- return (
971
- <button
972
- key={role}
973
- type="button"
974
- disabled={disabled}
975
- aria-pressed={checked}
976
- onClick={() => setNewVerbs((v) => ({ ...v, [k]: !v[k] }))}
977
- className="w-full flex items-center gap-2 px-3 py-1.5 text-sm hover:bg-slate-50 disabled:opacity-50 disabled:cursor-not-allowed"
978
- >
979
- <span className="w-4 h-4 border border-slate-300 rounded flex items-center justify-center shrink-0">
980
- {checked && <Check size={12} className="text-bevel" />}
981
- </span>
982
- <span className="flex-1 text-left">{role}</span>
983
- </button>
984
- );
985
- })}
986
- <div className="border-t border-slate-100 my-1" />
1321
+ Remove
1322
+ </Button>
1323
+ )}
1324
+ </div>
1325
+ )}
1326
+
1327
+ {directRows.length === 0 ? (
1328
+ <p className="py-2 text-ui text-ink-muted">
1329
+ {inheritedRows.length > 0
1330
+ ? 'No one is granted directly here. Everyone below inherits access from a parent folder.'
1331
+ : 'No explicit grants at this path.'}
1332
+ </p>
1333
+ ) : (
1334
+ directRows.map(renderRow)
1335
+ )}
1336
+
1337
+ {inheritedRows.length > 0 && (
1338
+ <div className="mt-3 border-t border-line pt-2">
1339
+ {inheritedByFolder.folders.map(([ancestor, rows]) => {
1340
+ const open = openGroup === ancestor;
1341
+ return (
1342
+ <div key={ancestor}>
987
1343
  <button
988
1344
  type="button"
989
- disabled={effectiveNewVerbs.owner}
990
- aria-pressed={effectiveNewVerbs.download}
991
- onClick={() => setNewVerbs((v) => ({ ...v, download: !v.download }))}
992
- className="w-full flex items-center gap-2 px-3 py-1.5 text-sm hover:bg-slate-50 disabled:opacity-50 disabled:cursor-not-allowed"
1345
+ aria-expanded={open}
1346
+ title={folderPath(ancestor)}
1347
+ onClick={() => setOpenGroup(open ? null : ancestor)}
1348
+ className="flex w-full items-center gap-1.5 rounded-xs py-1 text-detail text-ink-muted hover:text-ink"
993
1349
  >
994
- <span className="w-4 h-4 border border-slate-300 rounded flex items-center justify-center shrink-0">
995
- {effectiveNewVerbs.download && <Check size={12} className="text-bevel" />}
1350
+ <ChevronDown
1351
+ size={14}
1352
+ className={`shrink-0 transition-transform ${open ? 'rotate-180' : '-rotate-90'}`}
1353
+ />
1354
+ <span className="min-w-0 truncate">
1355
+ People invited to <b className="font-semibold">{folderLabel(ancestor)}</b>
1356
+ </span>
1357
+ <span className="ml-auto shrink-0 tabular-nums text-ink-faint">
1358
+ {rows.length}
996
1359
  </span>
997
- <span className="flex-1 text-left">Can download</span>
998
1360
  </button>
1361
+ {open && (
1362
+ <div className="mb-1">
1363
+ {rows.map(renderRow)}
1364
+ {/* The folder is both what the heading means and
1365
+ where it changes (proto:3647). Without this the
1366
+ only act available on an inherited grant is the
1367
+ destructive one behind Remove. */}
1368
+ {onManageAncestor && kbDirName && (
1369
+ <Button
1370
+ variant="quiet"
1371
+ size="tiny"
1372
+ className="mt-0.5"
1373
+ onClick={() => {
1374
+ const dir = ancestor.replace(/\/?access\.md$/, '');
1375
+ onManageAncestor({
1376
+ // The same name the button just said. A
1377
+ // root-level `access.md` leaves `dir` empty,
1378
+ // and `''.split('/').pop()` is `''` — a
1379
+ // dialog with no title.
1380
+ name: folderLabel(ancestor),
1381
+ relativePath: `${kbDirName}/${dir}`,
1382
+ type: 'directory',
1383
+ });
1384
+ }}
1385
+ >
1386
+ {`Manage ${folderLabel(ancestor)} →`}
1387
+ </Button>
1388
+ )}
1389
+ </div>
1390
+ )}
999
1391
  </div>
1000
- )}
1001
- </div>
1002
-
1003
- <button
1004
- type="button"
1005
- disabled={pickedChips.length === 0 || grantVerbs.length === 0 || busy}
1006
- onClick={doGrant}
1007
- className="px-4 rounded-lg text-sm font-medium bg-bevel hover:bg-bevel-deep text-white disabled:bg-bevel/40 disabled:cursor-not-allowed flex items-center gap-1.5"
1008
- >
1009
- {busy && <Loader2 size={14} className="animate-spin" />}
1010
- Share
1011
- </button>
1012
- </div>
1013
- {query.trim() && !addPending && !suggest?.peopleWithheld && (
1014
- <div className="mt-1.5 text-xs text-slate-500">
1015
- Type a full email to add someone, or pick a role from the list.
1016
- </div>
1017
- )}
1018
- {pickedChips.some(isEveryoneRole) && (
1019
- <div className="mt-1.5 text-xs text-slate-500">
1020
- “Everyone” makes this {targetKind} publicly readable — it can only be granted read access.
1021
- </div>
1022
- )}
1023
- {mutateError && (
1024
- <div className="mt-2 text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3 py-2">
1025
- {mutateError}
1026
- </div>
1027
- )}
1028
- </div>
1029
- )}
1030
-
1031
- {!governed ? (
1032
- <div className="py-8 text-center text-sm text-slate-500">
1033
- This item isn't part of the knowledge base, so it isn't governed by access control.
1034
- </div>
1035
- ) : loading ? (
1036
- <div className="flex items-center gap-2 py-8 justify-center text-sm text-slate-500">
1037
- <Loader2 size={16} className="animate-spin" /> Loading access…
1038
- </div>
1039
- ) : error ? (
1040
- <div className="py-6 text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3">
1041
- Couldn't load access: {error}
1042
- </div>
1043
- ) : (
1044
- <>
1045
- {!canManage && (
1046
- <div className="flex items-center gap-3 bg-bevel-soft rounded-lg px-3 py-2.5 mb-3 text-sm text-bevel-deep">
1047
- <span className="flex-1">
1048
- Only people with edit access can share this {targetKind}.
1049
- {ownerNames && <> Ask an owner: {ownerNames}.</>}
1050
- </span>
1051
- </div>
1052
- )}
1053
-
1054
- <div className="text-sm font-bold text-slate-700 my-2">People with access</div>
1392
+ );
1393
+ })}
1055
1394
 
1056
- {data && !data.readers.restricted && (
1057
- <div className="flex items-center gap-3 py-1.5">
1058
- <span className="w-8 h-8 rounded-full bg-emerald-600 text-white flex items-center justify-center shrink-0">
1059
- <Globe size={16} />
1060
- </span>
1061
- <div className="flex-1 min-w-0">
1062
- <div className="text-sm text-slate-800">Anyone can read</div>
1063
- <div className="text-xs text-slate-500">Public — every signed-in user can read this {targetKind}</div>
1064
- </div>
1065
- {canManage && (
1395
+ {/* A role that grants at the workspace level belongs to no
1396
+ folder, so it cannot be filed under one. Named for what it
1397
+ is rather than swept into the folder groups. */}
1398
+ {inheritedByFolder.external.length > 0 && (
1399
+ <div>
1066
1400
  <button
1067
1401
  type="button"
1068
- disabled={busy}
1069
- onClick={removePublicRead}
1070
- className="text-xs text-slate-500 hover:text-red-600 disabled:opacity-50 px-2 py-1"
1402
+ aria-expanded={openGroup === 'roles'}
1403
+ onClick={() => setOpenGroup(openGroup === 'roles' ? null : 'roles')}
1404
+ className="flex w-full items-center gap-1.5 rounded-xs py-1 text-detail text-ink-muted hover:text-ink"
1071
1405
  >
1072
- Remove
1406
+ <ChevronDown
1407
+ size={14}
1408
+ className={`shrink-0 transition-transform ${openGroup === 'roles' ? 'rotate-180' : '-rotate-90'}`}
1409
+ />
1410
+ <span className="min-w-0 truncate">People with access through a role</span>
1411
+ <span className="ml-auto shrink-0 tabular-nums text-ink-faint">
1412
+ {inheritedByFolder.external.length}
1413
+ </span>
1073
1414
  </button>
1074
- )}
1075
- </div>
1076
- )}
1077
-
1078
- {directRows.length === 0 ? (
1079
- <div className="text-sm text-slate-500 py-2">
1080
- {inheritedRows.length > 0
1081
- ? 'No one is granted directly here — everyone below inherits access from a parent folder.'
1082
- : 'No explicit grants at this path.'}
1083
- </div>
1084
- ) : (
1085
- directRows.map(renderRow)
1086
- )}
1087
-
1088
- {inheritedRows.length > 0 && (
1089
- <div className="mt-3 border-t border-slate-100 pt-2">
1090
- <button
1091
- type="button"
1092
- onClick={() => setShowInherited((v) => !v)}
1093
- className="w-full flex items-center gap-1.5 py-1 text-sm font-medium text-slate-500 hover:text-slate-700"
1094
- >
1095
- <ChevronDown
1096
- size={14}
1097
- className={`transition-transform ${showInherited ? 'rotate-180' : ''}`}
1098
- />
1099
- Inherited access ({inheritedRows.length})
1100
- <span className="font-normal text-slate-400">
1101
- — from parent folders &amp; roles
1102
- </span>
1103
- </button>
1104
- {showInherited && <div className="mt-1">{inheritedRows.map(renderRow)}</div>}
1105
- </div>
1106
- )}
1107
-
1108
- <div className="flex items-center gap-3 border-t border-slate-100 mt-4 pt-4">
1109
- <div className="w-9 h-9 rounded-full bg-slate-100 text-slate-600 flex items-center justify-center shrink-0">
1110
- <Lock size={16} />
1111
- </div>
1112
- <div className="flex-1">
1113
- <div className="text-sm font-semibold text-slate-800">Restricted</div>
1114
- <div className="text-xs text-slate-500">
1115
- Only people granted access can edit this item.
1415
+ {openGroup === 'roles' && (
1416
+ <div className="mb-1">{inheritedByFolder.external.map(renderRow)}</div>
1417
+ )}
1116
1418
  </div>
1117
- </div>
1419
+ )}
1118
1420
  </div>
1119
- </>
1120
- )}
1121
- </div>
1421
+ )}
1122
1422
 
1123
- <div className="flex items-center justify-end gap-3 px-6 py-4">
1124
- <button
1125
- type="button"
1126
- onClick={onClose}
1127
- className="px-5 py-2 rounded-lg text-sm font-medium bg-bevel hover:bg-bevel-deep text-white"
1128
- >
1129
- Done
1130
- </button>
1131
- </div>
1132
- </div>
1423
+ <div className="mt-4 flex items-center gap-3 border-t border-line pt-4">
1424
+ <span className="flex size-9 shrink-0 items-center justify-center rounded-full bg-sunken text-ink-muted">
1425
+ <Lock size={16} />
1426
+ </span>
1427
+ <div className="flex-1">
1428
+ <div className="text-ui font-semibold text-ink">Restricted</div>
1429
+ <div className="text-detail text-ink-muted">
1430
+ Only people granted access can edit this item.
1431
+ </div>
1432
+ </div>
1433
+ </div>
1434
+ </>
1435
+ )}
1436
+ </Dialog>
1133
1437
 
1134
1438
  {confirmRemove && (
1135
- <div
1136
- className="fixed inset-0 z-[80] bg-slate-900/40 flex items-center justify-center p-4"
1137
- onMouseDown={(e) => {
1138
- if (e.target === e.currentTarget && !busy) setConfirmRemove(null);
1139
- }}
1439
+ <Dialog
1440
+ open
1441
+ busy={busy}
1442
+ onClose={() => setConfirmRemove(null)}
1443
+ size="md"
1444
+ title={
1445
+ confirmRemove.ancestors.length ? 'Remove from parent folder?' : 'Restrict access here?'
1446
+ }
1140
1447
  >
1141
- <div role="dialog" aria-modal="true" className="bg-white rounded-2xl shadow-xl w-full max-w-md p-6">
1142
- {(() => {
1143
- // When the flow was triggered by unchecking ONE verb, the whole
1144
- // confirmation is scoped to it ("their EDIT access", "remove EDIT
1145
- // from the parent"); otherwise it's the whole principal.
1146
- const va = confirmRemove.verb ? `${VERB_NOUN[confirmRemove.verb]} access` : 'access';
1147
- return (
1148
- <>
1149
- <h3 className="text-lg font-semibold text-slate-900">
1150
- {confirmRemove.ancestors.length ? 'Remove from parent folder?' : 'Restrict access here?'}
1151
- </h3>
1152
- <p className="mt-2 text-sm text-slate-600">
1153
- {confirmRemove.ancestors.length ? (
1154
- <>
1155
- {confirmRemove.label}'s {va} here is inherited from{' '}
1156
- <span className="font-medium" title={confirmRemove.ancestors.map(folderPath).join(', ')}>
1157
- {confirmRemove.ancestors.map(folderLabel).join(', ')}
1158
- </span>
1159
- . Remove their {va} from the parent — which also removes it from other items in
1160
- that folder — or restrict just this {targetKind} while leaving the parent grant
1161
- intact.
1162
- </>
1163
- ) : (
1164
- <>
1165
- {confirmRemove.label}'s {va} here comes from a role or policy, not a grant on
1166
- this {targetKind}. You can't remove it here — but you can restrict their {va} on
1167
- just this {targetKind} by adding a block.
1168
- </>
1169
- )}
1170
- </p>
1171
- </>
1172
- );
1173
- })()}
1448
+ {(() => {
1449
+ // When the flow was triggered by unchecking ONE verb, the whole
1450
+ // confirmation is scoped to it ("their EDIT access", "remove EDIT
1451
+ // from the parent"); otherwise it's the whole principal.
1452
+ const va = confirmRemove.verb ? `${VERB_NOUN[confirmRemove.verb]} access` : 'access';
1453
+ return (
1454
+ <p className="text-ui leading-relaxed text-ink-muted">
1455
+ {confirmRemove.ancestors.length ? (
1456
+ <>
1457
+ {confirmRemove.label}'s {va} here is inherited from{' '}
1458
+ <span
1459
+ className="font-medium text-ink"
1460
+ title={confirmRemove.ancestors.map(folderPath).join(', ')}
1461
+ >
1462
+ {confirmRemove.ancestors.map(folderLabel).join(', ')}
1463
+ </span>
1464
+ . Remove their {va} from the parent: which also removes it from other items in
1465
+ that folder: or restrict just this {targetKind} while leaving the parent grant
1466
+ intact.
1467
+ </>
1468
+ ) : (
1469
+ <>
1470
+ {confirmRemove.label}'s {va} here comes from a role or policy, not a grant on
1471
+ this {targetKind}. You can't remove it here. But you can restrict their {va} on
1472
+ just this {targetKind} by adding a block.
1473
+ </>
1474
+ )}
1475
+ </p>
1476
+ );
1477
+ })()}
1174
1478
 
1175
- {mutateError && (
1176
- <div className="mt-3 text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3 py-2">
1177
- {mutateError}
1178
- </div>
1179
- )}
1479
+ {mutateError && (
1480
+ <Banner tone="danger" role="alert" className="mt-3 whitespace-pre-line">
1481
+ {mutateError}
1482
+ </Banner>
1483
+ )}
1180
1484
 
1181
- <div className="mt-5 flex flex-col gap-2">
1182
- {confirmRemove.ancestors.length === 1 && (
1183
- <button
1184
- type="button"
1185
- disabled={busy}
1186
- onClick={() => doRemoveFromParent(confirmRemove.principal, confirmRemove.ancestors[0], confirmRemove.verb)}
1187
- className="w-full px-4 py-2.5 rounded-lg text-sm font-medium bg-bevel hover:bg-bevel-deep text-white disabled:bg-bevel/40 disabled:cursor-not-allowed"
1188
- >
1189
- Remove from {folderLabel(confirmRemove.ancestors[0])}
1190
- </button>
1191
- )}
1192
- {confirmRemove.ancestors.length > 1 && (
1193
- <>
1194
- <div className="text-xs text-slate-500">
1195
- Inherited from multiple folders — remove from one at a time:
1196
- </div>
1197
- {confirmRemove.ancestors.map((a) => (
1198
- <button
1199
- key={a}
1200
- type="button"
1201
- disabled={busy}
1202
- onClick={() => doRemoveFromParent(confirmRemove.principal, a, confirmRemove.verb)}
1203
- className="w-full px-4 py-2.5 rounded-lg text-sm font-medium bg-bevel hover:bg-bevel-deep text-white disabled:bg-bevel/40 disabled:cursor-not-allowed"
1204
- >
1205
- Remove from {folderLabel(a)}
1206
- </button>
1207
- ))}
1208
- </>
1209
- )}
1210
- <button
1211
- type="button"
1212
- disabled={busy}
1213
- onClick={() => doDenyHere(confirmRemove.principal, confirmRemove.verb)}
1214
- className="w-full px-4 py-2.5 rounded-lg text-sm font-medium border border-slate-300 text-slate-700 hover:bg-slate-50 disabled:cursor-not-allowed"
1215
- >
1216
- Restrict just this {targetKind}
1217
- </button>
1218
- <button
1219
- type="button"
1485
+ <div className="mt-4 flex flex-col gap-2">
1486
+ {confirmRemove.ancestors.length === 1 && (
1487
+ <Button
1488
+ variant="primary"
1489
+ className="w-full"
1220
1490
  disabled={busy}
1221
- onClick={() => setConfirmRemove(null)}
1222
- className="w-full px-4 py-2 rounded-lg text-sm text-slate-500 hover:bg-slate-50 disabled:cursor-not-allowed"
1491
+ onClick={() =>
1492
+ doRemoveFromParent(confirmRemove.principal, confirmRemove.ancestors[0], confirmRemove.verb)
1493
+ }
1223
1494
  >
1224
- Cancel
1225
- </button>
1226
- </div>
1495
+ Remove from {folderLabel(confirmRemove.ancestors[0])}
1496
+ </Button>
1497
+ )}
1498
+ {confirmRemove.ancestors.length > 1 && (
1499
+ <>
1500
+ <p className="text-detail text-ink-muted">
1501
+ Inherited from multiple folders. Remove from one at a time:
1502
+ </p>
1503
+ {confirmRemove.ancestors.map((a) => (
1504
+ <Button
1505
+ key={a}
1506
+ variant="primary"
1507
+ className="w-full"
1508
+ disabled={busy}
1509
+ onClick={() => doRemoveFromParent(confirmRemove.principal, a, confirmRemove.verb)}
1510
+ >
1511
+ Remove from {folderLabel(a)}
1512
+ </Button>
1513
+ ))}
1514
+ </>
1515
+ )}
1516
+ <Button
1517
+ variant="outline"
1518
+ className="w-full"
1519
+ disabled={busy}
1520
+ onClick={() => doDenyHere(confirmRemove.principal, confirmRemove.verb)}
1521
+ >
1522
+ Restrict just this {targetKind}
1523
+ </Button>
1524
+ <Button
1525
+ variant="quiet"
1526
+ className="w-full"
1527
+ disabled={busy}
1528
+ onClick={() => setConfirmRemove(null)}
1529
+ >
1530
+ Cancel
1531
+ </Button>
1227
1532
  </div>
1228
- </div>
1533
+ </Dialog>
1229
1534
  )}
1230
- </div>
1535
+ </>
1231
1536
  );
1232
1537
  }