@bevel-software/platform-core-frontend 0.26.0 → 0.27.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 (187) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +87 -25
  3. package/src/core/ProductName.tsx +49 -0
  4. package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
  5. package/src/core/__tests__/core-contributions.test.ts +16 -0
  6. package/src/core/core-contributions.ts +17 -0
  7. package/src/core/registry.ts +51 -1
  8. package/src/index.css +23 -5
  9. package/src/index.ts +5 -0
  10. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
  11. package/src/modules/access/components/ManageAccessDialog.tsx +1 -1
  12. package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
  13. package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
  14. package/src/modules/auth/components/LoginScreen.tsx +4 -1
  15. package/src/modules/auth/services/account.api.ts +28 -1
  16. package/src/modules/auth/services/sso.ts +1 -2
  17. package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
  18. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
  19. package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
  20. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
  21. package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
  22. package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
  23. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
  24. package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
  25. package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
  26. package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
  27. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
  28. package/src/modules/change-requests/services/change-requests.api.ts +15 -2
  29. package/src/modules/change-requests/utils/readFailure.ts +22 -0
  30. package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
  31. package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
  32. package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
  33. package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
  34. package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
  35. package/src/modules/embed/__tests__/mount.test.tsx +157 -0
  36. package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
  37. package/src/modules/embed/components/EmbedView.tsx +545 -0
  38. package/src/modules/embed/embed-config.ts +132 -0
  39. package/src/modules/embed/embed-host.ts +120 -0
  40. package/src/modules/embed/mount.tsx +80 -0
  41. package/src/modules/embed/services/embed-token.ts +22 -0
  42. package/src/modules/embed/services/embed.api.ts +158 -0
  43. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
  44. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
  45. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
  46. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
  47. package/src/modules/git/branch-delete-menu-item.tsx +24 -0
  48. package/src/modules/git/components/BranchSwitcher.tsx +29 -5
  49. package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
  50. package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
  51. package/src/modules/git/components/PullNeededBanner.tsx +15 -49
  52. package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
  53. package/src/modules/git/index.ts +15 -0
  54. package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
  55. package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
  56. package/src/modules/git/services/error-messages.ts +58 -1
  57. package/src/modules/git/services/pull-failure.ts +68 -0
  58. package/src/modules/git/state/branch-delete-confirm.ts +46 -0
  59. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
  60. package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
  61. package/src/modules/layout/breakpoints.ts +8 -0
  62. package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
  63. package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
  64. package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
  65. package/src/modules/library/components/LibraryPage.tsx +22 -0
  66. package/src/modules/library/components/PluginExtras.tsx +23 -6
  67. package/src/modules/library/components/PluginPage.tsx +6 -1
  68. package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
  69. package/src/modules/library/services/plugins.api.ts +4 -1
  70. package/src/modules/library/state/plugins-revision.ts +28 -0
  71. package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
  72. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
  73. package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +109 -0
  74. package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1001 -0
  75. package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +392 -0
  76. package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
  77. package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
  78. package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
  79. package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
  80. package/src/modules/onboarding/components/GetStartedColumn.tsx +651 -0
  81. package/src/modules/onboarding/components/InviteButton.tsx +35 -0
  82. package/src/modules/onboarding/components/InviteDialog.tsx +424 -0
  83. package/src/modules/onboarding/components/RootLanding.tsx +8 -24
  84. package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
  85. package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
  86. package/src/modules/onboarding/first-page-prompt.ts +89 -0
  87. package/src/modules/onboarding/invite-emails.ts +175 -0
  88. package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
  89. package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
  90. package/src/modules/onboarding/state/agent-connection.ts +167 -0
  91. package/src/modules/onboarding/state/invite-dialog.context.ts +32 -0
  92. package/src/modules/onboarding/state/invite-dialog.tsx +31 -0
  93. package/src/modules/onboarding/state/onboarding.ts +133 -59
  94. package/src/modules/onboarding/state/starter-packs.ts +169 -0
  95. package/src/modules/settings/settings-nav-items.tsx +8 -3
  96. package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
  97. package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
  98. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
  99. package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
  100. package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
  101. package/src/modules/setup/__tests__/setup.test.tsx +56 -15
  102. package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
  103. package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
  104. package/src/modules/setup/components/SetupGate.tsx +46 -1
  105. package/src/modules/setup/components/SetupScreen.tsx +81 -84
  106. package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
  107. package/src/modules/setup/services/setup.api.ts +3 -3
  108. package/src/modules/setup/utils/suggested-branch.ts +27 -0
  109. package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
  110. package/src/modules/toolbar/commands/actions.tsx +324 -0
  111. package/src/modules/toolbar/commands/command-menu.ts +44 -0
  112. package/src/modules/toolbar/commands/useCommandActions.ts +69 -0
  113. package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
  114. package/src/modules/toolbar/components/AppSwitcher.tsx +106 -22
  115. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
  116. package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
  117. package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
  118. package/src/modules/toolbar/components/Toolbar.tsx +10 -0
  119. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +187 -54
  120. package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
  121. package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +832 -0
  122. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
  123. package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
  124. package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
  125. package/src/modules/toolbar/search/rank.ts +111 -0
  126. package/src/modules/toolbar/search/sources.ts +169 -0
  127. package/src/modules/workflow/hooks/useFileLock.ts +10 -7
  128. package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
  129. package/src/modules/workflow/services/lock.api.ts +17 -2
  130. package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
  131. package/src/modules/workspace/components/EditorTabs.tsx +39 -15
  132. package/src/modules/workspace/components/FileExplorer.tsx +39 -6
  133. package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
  134. package/src/modules/workspace/components/FileRoute.tsx +12 -7
  135. package/src/modules/workspace/components/FileViewer.tsx +271 -74
  136. package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
  137. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
  138. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
  139. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
  140. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
  141. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
  142. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
  143. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
  144. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
  145. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
  146. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
  147. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
  148. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
  149. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
  150. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
  151. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
  152. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
  153. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
  154. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
  155. package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
  156. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
  157. package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
  158. package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
  159. package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
  160. package/src/modules/workspace/components/renderers/index.ts +26 -0
  161. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
  162. package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
  163. package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
  164. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
  165. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
  166. package/src/modules/workspace/hooks/useCreatePage.ts +116 -0
  167. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
  168. package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
  169. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
  170. package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
  171. package/src/modules/workspace/routing/kb-routes.ts +66 -12
  172. package/src/modules/workspace/state/editable-page.ts +42 -0
  173. package/src/modules/workspace/state/workspace.context.ts +13 -4
  174. package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
  175. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
  176. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
  177. package/src/modules/workspace/utils/display-file-name.ts +102 -0
  178. package/src/modules/workspace/utils/fileTree.ts +49 -14
  179. package/src/modules/workspace/utils/treeConfirm.ts +15 -0
  180. package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
  181. package/src/shared/components/ConfirmProvider.tsx +156 -0
  182. package/src/shared/components/Dialog.tsx +7 -0
  183. package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
  184. package/src/shared/components/confirm-context.ts +94 -0
  185. package/src/shared/components/index.ts +3 -0
  186. package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
  187. package/src/modules/onboarding/welcome-state.ts +0 -36
@@ -126,10 +126,21 @@ vi.mock('../../../workflow/hooks/useFileLock', async (importOriginal) => {
126
126
  };
127
127
  });
128
128
 
129
+ // The starter-pack question the empty state asks a new knowledge base's
130
+ // admin. Not offered unless a test says so.
131
+ const starterPacksMock = vi.hoisted(() => ({
132
+ fetchStarterPacks: vi.fn(async () => ({ offered: false, chosen: null, packs: [], chosenPack: null }) as unknown),
133
+ chooseStarterPack: vi.fn(async () => ({}) as unknown),
134
+ }));
135
+ vi.mock('../../../onboarding/services/starter-packs.api', async (importOriginal) => ({
136
+ ...(await importOriginal<typeof import('../../../onboarding/services/starter-packs.api')>()),
137
+ ...starterPacksMock,
138
+ }));
139
+
129
140
  import { FileViewer } from '../FileViewer';
130
141
  // The lock API is mocked above; import the mocked fns so individual tests can
131
142
  // override the acquire outcome (e.g. a 403 on enter-edit).
132
- import { acquireLock as acquireLockMock, LockApiError } from '../../../workflow/services/lock.api';
143
+ import { acquireLock as acquireLockMock, getLock as getLockMock, LockApiError } from '../../../workflow/services/lock.api';
133
144
  import { WorkspaceContext, type WorkspaceContextValue } from '../../state/workspace.context';
134
145
  import { GitContext, type GitContextValue } from '../../../git/state/git.context';
135
146
  import { ReviewContext, type ReviewContextValue } from '../../../review/state/review.context';
@@ -187,7 +198,12 @@ function makeGit(
187
198
  */
188
199
  function LocationEcho() {
189
200
  const location = useLocation();
190
- return <div data-testid="location">{location.pathname}</div>;
201
+ return (
202
+ <>
203
+ <div data-testid="location">{location.pathname}</div>
204
+ <div data-testid="location-state">{JSON.stringify(location.state ?? null)}</div>
205
+ </>
206
+ );
191
207
  }
192
208
 
193
209
  function ViewerHarness({
@@ -203,6 +219,9 @@ function ViewerHarness({
203
219
  authUser = null,
204
220
  captureTyped = false,
205
221
  gitAvailability = 'ready',
222
+ routeState,
223
+ routePath,
224
+ workspaceBranch = 'main',
206
225
  }: {
207
226
  initialContent?: string;
208
227
  /** What git reports about itself; the history views need `'ready'`. */
@@ -231,6 +250,16 @@ function ViewerHarness({
231
250
  * tests keep the historical no-op.
232
251
  */
233
252
  captureTyped?: boolean;
253
+ /**
254
+ * Router state on the entry the viewer opens under. Given (or with
255
+ * `routePath`), the URL names the file the way `openWorkspacePath` builds
256
+ * it — `/workspace/<branch>/<path>` — instead of the bare branch.
257
+ */
258
+ routeState?: unknown;
259
+ /** The file the URL names, when it is not the open one. */
260
+ routePath?: string;
261
+ /** The branch the workspace is on, as the workspace state reports it. */
262
+ workspaceBranch?: string | null;
234
263
  }) {
235
264
  const [openFileContent, setOpenFileContent] = useState(initialContent);
236
265
  const [savedContent, setSavedContent] = useState(initialContent);
@@ -260,7 +289,7 @@ function ViewerHarness({
260
289
  kbDirName,
261
290
  fileTree,
262
291
  bootstrapError: null,
263
- workspaceBranch: 'main',
292
+ workspaceBranch,
264
293
  retryBootstrap: () => {},
265
294
  openTabs: tab ? [tab] : [],
266
295
  activeTab: tab,
@@ -373,7 +402,19 @@ function ViewerHarness({
373
402
  </AuthContext.Provider>
374
403
  );
375
404
  return (
376
- <MemoryRouter initialEntries={[`/workspace/${encodeURIComponent(urlBranch)}`]}>
405
+ <MemoryRouter
406
+ initialEntries={[
407
+ routeState !== undefined || routePath !== undefined
408
+ ? {
409
+ pathname: `/workspace/${encodeURIComponent(urlBranch)}/${(routePath ?? filePath ?? '')
410
+ .split('/')
411
+ .map(encodeURIComponent)
412
+ .join('/')}`,
413
+ state: routeState ?? null,
414
+ }
415
+ : `/workspace/${encodeURIComponent(urlBranch)}`,
416
+ ]}
417
+ >
377
418
  <Routes>
378
419
  <Route path="/workspace/:branch/*" element={tree} />
379
420
  </Routes>
@@ -656,8 +697,8 @@ describe('FileViewer', () => {
656
697
  // fix that 403 was swallowed (console.warn only) and the click just flickered
657
698
  // "Loading…" then reverted to "Edit" with no explanation. Now the refusal is
658
699
  // surfaced in the save-error banner so the user understands the file is
659
- // read-only to them. (Distinct from lock contention, which the "Locked by X"
660
- // banner already covers.)
700
+ // read-only to them. (Distinct from someone else editing, which the "X is
701
+ // editing this page" banner already covers.)
661
702
  it('surfaces an access-denied 403 on enter-edit instead of silently reverting', async () => {
662
703
  // Force the access lookup to fail → useFileAccess default-allows →
663
704
  // canWrite=true → the Edit button renders on a protected branch.
@@ -688,6 +729,26 @@ describe('FileViewer', () => {
688
729
  expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
689
730
  });
690
731
 
732
+ // Someone else has the page open for editing: the reader is told who, in
733
+ // plain words, and Edit says the same on hover.
734
+ it('says who is editing a page someone else has open', async () => {
735
+ vi.mocked(getLockMock).mockResolvedValueOnce({
736
+ branch: 'alice/draft',
737
+ path: 'knowledge-base/Knowledge/Foo.md',
738
+ holderUserId: 'u2',
739
+ holderName: 'Dana Lee',
740
+ acquiredAt: new Date().toISOString(),
741
+ lastHeartbeatAt: new Date().toISOString(),
742
+ expiresAt: new Date(Date.now() + 60_000).toISOString(),
743
+ });
744
+ render(<ViewerHarness initialContent="Base content" />);
745
+
746
+ const banner = await screen.findByText(/is editing this page\. You can edit it when they finish\./);
747
+ expect(banner).toHaveTextContent('Dana Lee is editing this page. You can edit it when they finish.');
748
+ expect(screen.queryByText(/Locked/)).not.toBeInTheDocument();
749
+ expect(screen.getByRole('button', { name: 'Edit' })).toHaveAttribute('title', 'Dana Lee is editing this page');
750
+ });
751
+
691
752
  // WP1 regression. The document column moved: the viewer pane used to be
692
753
  // `overflow-hidden` with a per-renderer scroller, and `editorContainerRef`
693
754
  // sat on that pane. It now sits on `KbDocumentShell`, which is what actually
@@ -945,6 +1006,37 @@ describe('FileViewer', () => {
945
1006
  expect(screen.queryByRole('menuitem', { name: /whole folder/i })).not.toBeInTheDocument();
946
1007
  });
947
1008
 
1009
+ it("calls a folder's access.md Who has access, says what it governs, and opens the folder's Manage access", async () => {
1010
+ const user = userEvent.setup();
1011
+ render(
1012
+ <ViewerHarness
1013
+ initialContent="read: everyone"
1014
+ filePath="knowledge-base/KnowledgeBase/Legal/access.md"
1015
+ />,
1016
+ );
1017
+
1018
+ const h1 = await screen.findByRole('heading', { level: 1 });
1019
+ expect(h1).toHaveTextContent('Who has access');
1020
+ expect(h1).toHaveAttribute('title', 'access.md');
1021
+ expect(screen.getByRole('note')).toHaveTextContent(
1022
+ 'This file controls who can see and change Legal. Change it with Manage access.',
1023
+ );
1024
+
1025
+ await user.click(screen.getByRole('button', { name: 'Manage access' }));
1026
+ expect(
1027
+ await screen.findByRole('dialog', {
1028
+ name: 'Manage access: directory knowledge-base/KnowledgeBase/Legal',
1029
+ }),
1030
+ ).toBeInTheDocument();
1031
+ });
1032
+
1033
+ it('says nothing about access on an ordinary page', async () => {
1034
+ render(<ViewerHarness initialContent="plain" />);
1035
+ await screen.findByRole('heading', { level: 1 });
1036
+ expect(screen.queryByText(/This file controls who can see and change/)).not.toBeInTheDocument();
1037
+ expect(screen.queryByRole('button', { name: 'Manage access' })).not.toBeInTheDocument();
1038
+ });
1039
+
948
1040
  // ── WP5: the rail ──
949
1041
 
950
1042
  // The rail lost its only trigger with the ⋯ menu's File details entry, so
@@ -1553,3 +1645,235 @@ describe('FileViewer: nothing open', () => {
1553
1645
  expect(await screen.findByRole('button', { name: /Charter/ })).toBeInTheDocument();
1554
1646
  });
1555
1647
  });
1648
+
1649
+ /**
1650
+ * "What does your team do?" stands where the empty state would, for exactly
1651
+ * as long as the server offers it, and hands back to the empty state with a
1652
+ * line saying what was added.
1653
+ */
1654
+ describe('FileViewer: the starter-pack question', () => {
1655
+ // A fresh sign-in per test: the starter answer is kept per signed-in user.
1656
+ const admin = () => ({ id: 'u-admin', email: 'ada@example.com', name: 'Ada' });
1657
+ const PACKS = [
1658
+ { id: 'engineering', name: 'Engineering', description: 'How you build.', order: 1 },
1659
+ { id: 'sales', name: 'Sales', description: 'What you sell.', order: 2 },
1660
+ ];
1661
+ // The pack lands on the default branch, so the question is asked there —
1662
+ // the branch the test setup pins as the default.
1663
+ const DEFAULT = 'target-company-state';
1664
+
1665
+ afterEach(() => {
1666
+ starterPacksMock.fetchStarterPacks.mockReset().mockResolvedValue({
1667
+ offered: false,
1668
+ chosen: null,
1669
+ packs: [],
1670
+ chosenPack: null,
1671
+ });
1672
+ });
1673
+
1674
+ it('replaces the empty state while it is offered', async () => {
1675
+ starterPacksMock.fetchStarterPacks.mockResolvedValue({ offered: true, chosen: null, packs: PACKS, chosenPack: null });
1676
+ render(<ViewerHarness filePath={null} authUser={admin()} workspaceBranch={DEFAULT} />);
1677
+ expect(await screen.findByRole('heading', { name: 'What does your team do?' })).toBeInTheDocument();
1678
+ expect(screen.getByRole('button', { name: 'Engineering' })).toBeInTheDocument();
1679
+ expect(screen.queryByRole('heading', { name: /Open a page/ })).toBeNull();
1680
+ });
1681
+
1682
+ it('is not there when it is not offered — a member, or a question already answered', async () => {
1683
+ render(<ViewerHarness filePath={null} authUser={admin()} workspaceBranch={DEFAULT} />);
1684
+ await waitFor(() => expect(starterPacksMock.fetchStarterPacks).toHaveBeenCalled());
1685
+ expect(await screen.findByRole('heading', { name: /Open a page/ })).toBeInTheDocument();
1686
+ expect(screen.queryByText('What does your team do?')).toBeNull();
1687
+ });
1688
+
1689
+ it('is not asked on another branch, where the pack would not land, even while it is offered', async () => {
1690
+ starterPacksMock.fetchStarterPacks.mockResolvedValue({ offered: true, chosen: null, packs: PACKS, chosenPack: null });
1691
+ render(<ViewerHarness filePath={null} authUser={admin()} workspaceBranch="alice/draft" />);
1692
+ expect(await screen.findByRole('heading', { name: /Open a page/ })).toBeInTheDocument();
1693
+ expect(screen.queryByText('What does your team do?')).toBeNull();
1694
+ expect(screen.queryByRole('button', { name: 'Engineering' })).toBeNull();
1695
+ });
1696
+
1697
+ it('waits for the branch to be known rather than asking on a guess, showing neither state meanwhile', async () => {
1698
+ starterPacksMock.fetchStarterPacks.mockResolvedValue({ offered: true, chosen: null, packs: PACKS, chosenPack: null });
1699
+ render(<ViewerHarness filePath={null} authUser={admin()} workspaceBranch={null} />);
1700
+ await waitFor(() => expect(starterPacksMock.fetchStarterPacks).toHaveBeenCalled());
1701
+ expect(screen.queryByText('What does your team do?')).toBeNull();
1702
+ expect(screen.queryByRole('heading', { name: /Open a page/ })).toBeNull();
1703
+ });
1704
+
1705
+ it('shows no reading empty state before the server has answered: the question must not flash in after it', async () => {
1706
+ let answer!: (a: unknown) => void;
1707
+ starterPacksMock.fetchStarterPacks.mockImplementation(() => new Promise((resolve) => (answer = resolve)));
1708
+ render(<ViewerHarness filePath={null} authUser={admin()} workspaceBranch={DEFAULT} />);
1709
+ await waitFor(() => expect(starterPacksMock.fetchStarterPacks).toHaveBeenCalled());
1710
+ expect(screen.queryByRole('heading', { name: /Open a page/ })).toBeNull();
1711
+ expect(screen.queryByText('What does your team do?')).toBeNull();
1712
+ answer({ offered: true, chosen: null, packs: PACKS, chosenPack: null });
1713
+ expect(await screen.findByRole('heading', { name: 'What does your team do?' })).toBeInTheDocument();
1714
+ });
1715
+
1716
+ it('after a choice, says what was added above the ordinary empty state', async () => {
1717
+ starterPacksMock.fetchStarterPacks
1718
+ .mockResolvedValueOnce({ offered: true, chosen: null, packs: PACKS, chosenPack: null })
1719
+ .mockResolvedValue({ offered: false, chosen: 'sales', packs: PACKS, chosenPack: null });
1720
+ starterPacksMock.chooseStarterPack.mockResolvedValue({
1721
+ id: 'sales',
1722
+ name: 'Sales',
1723
+ pages: 6,
1724
+ skills: 37,
1725
+ summary: 'Added 6 pages and 37 skills for Sales.',
1726
+ });
1727
+ render(<ViewerHarness filePath={null} authUser={admin()} workspaceBranch={DEFAULT} />);
1728
+
1729
+ await userEvent.click(await screen.findByRole('button', { name: 'Sales' }));
1730
+
1731
+ expect(await screen.findByRole('status')).toHaveTextContent('Added 6 pages and 37 skills for Sales.');
1732
+ expect(screen.getByRole('heading', { name: /Open a page/ })).toBeInTheDocument();
1733
+ expect(screen.queryByText('What does your team do?')).toBeNull();
1734
+ });
1735
+ });
1736
+
1737
+ /**
1738
+ * Opening a page straight into the editor, asked for by the navigation
1739
+ * (`openWorkspacePath(path, { edit: true })` → router state `startEditing`).
1740
+ * It goes through the same lock-then-reload as the Edit button, happens once,
1741
+ * and the request is taken off the history entry so a refresh or a Back
1742
+ * opens the page for reading.
1743
+ */
1744
+ describe('FileViewer: opening straight into the editor', () => {
1745
+ const NEW_PAGE = 'knowledge-base/KnowledgeBase/Untitled.md';
1746
+
1747
+ afterEach(() => {
1748
+ accessMock.result = {
1749
+ canWrite: true,
1750
+ canOwner: false,
1751
+ eligible: { roles: ['Admin'], users: [] },
1752
+ owners: EMPTY_ELIGIBLE,
1753
+ };
1754
+ vi.mocked(acquireLockMock).mockClear();
1755
+ });
1756
+
1757
+ it('enters edit mode once, caret under the title, and clears the request', async () => {
1758
+ const user = userEvent.setup();
1759
+ vi.mocked(acquireLockMock).mockClear();
1760
+ render(
1761
+ <ViewerHarness
1762
+ initialContent={'# Untitled\n\n'}
1763
+ filePath={NEW_PAGE}
1764
+ // Another key on the same entry survives the clean-up.
1765
+ routeState={{ startEditing: true, rawFile: true }}
1766
+ />,
1767
+ );
1768
+
1769
+ const textarea = (await screen.findByRole('textbox')) as HTMLTextAreaElement;
1770
+ expect(textarea.value).toBe('# Untitled\n\n');
1771
+ expect(textarea).toHaveFocus();
1772
+ expect(textarea.selectionStart).toBe(textarea.value.length);
1773
+ expect(screen.getByTestId('location-state')).toHaveTextContent('{"rawFile":true}');
1774
+ expect(screen.getByTestId('location')).toHaveTextContent('/workspace/alice%2Fdraft/knowledge-base/KnowledgeBase/Untitled.md');
1775
+ expect(acquireLockMock).toHaveBeenCalledTimes(1);
1776
+
1777
+ // Done is Done: with the request gone, nothing puts the editor back.
1778
+ await user.click(screen.getByRole('button', { name: 'Done' }));
1779
+ await waitFor(() => expect(screen.queryByRole('textbox')).not.toBeInTheDocument());
1780
+ await act(async () => {});
1781
+ expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
1782
+ expect(acquireLockMock).toHaveBeenCalledTimes(1);
1783
+ });
1784
+
1785
+ it('still opens the editor once the path URL has been swapped for the node-id URL', async () => {
1786
+ // `FileRoute` canonicalises a node's path URL to its id URL, sometimes
1787
+ // before the bytes land: the URL then names the id, and the request
1788
+ // carries the path it was made for.
1789
+ render(
1790
+ <ViewerHarness
1791
+ initialContent={'# Untitled\n\n'}
1792
+ filePath={NEW_PAGE}
1793
+ routePath="untitled_page"
1794
+ routeState={{ startEditing: true, startEditingPath: NEW_PAGE }}
1795
+ />,
1796
+ );
1797
+ expect(await screen.findByRole('textbox')).toBeInTheDocument();
1798
+ expect(screen.getByTestId('location-state')).toHaveTextContent('null');
1799
+ expect(acquireLockMock).toHaveBeenCalledTimes(1);
1800
+ });
1801
+
1802
+ it('leaves the caret alone on a later Edit by hand when the request was turned away', async () => {
1803
+ const user = userEvent.setup();
1804
+ // The request's enter-edit is refused by the lock …
1805
+ vi.mocked(acquireLockMock).mockRejectedValueOnce(
1806
+ new LockApiError(403, 'You don\'t have permission to write to this page.', {
1807
+ access: { path: NEW_PAGE, eligibleRoles: ['Admin'], eligibleUsers: [] },
1808
+ }),
1809
+ );
1810
+ render(
1811
+ <ViewerHarness
1812
+ initialContent={'# Long page\n\nA long body.'}
1813
+ filePath={NEW_PAGE}
1814
+ routeState={{ startEditing: true }}
1815
+ />,
1816
+ );
1817
+ await waitFor(() => expect(screen.getByTestId('location-state')).toHaveTextContent('null'));
1818
+ await waitFor(() => expect(screen.getByRole('button', { name: 'Edit' })).toBeEnabled());
1819
+ expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
1820
+
1821
+ // … so the Edit the reader then clicks is theirs, not the request's: the
1822
+ // caret is not sent to the end of the page, scrolling them away.
1823
+ const setSelectionRange = vi.spyOn(HTMLTextAreaElement.prototype, 'setSelectionRange');
1824
+ try {
1825
+ await user.click(screen.getByRole('button', { name: 'Edit' }));
1826
+ await screen.findByRole('textbox');
1827
+ await act(async () => {});
1828
+ expect(setSelectionRange).not.toHaveBeenCalled();
1829
+ } finally {
1830
+ setSelectionRange.mockRestore();
1831
+ }
1832
+ });
1833
+
1834
+ it('opens for reading when the navigation asked for nothing', async () => {
1835
+ render(<ViewerHarness initialContent="# Notes" filePath={NEW_PAGE} routePath={NEW_PAGE} />);
1836
+ expect(await screen.findByRole('button', { name: 'Edit' })).toBeEnabled();
1837
+ await act(async () => {});
1838
+ expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
1839
+ expect(acquireLockMock).not.toHaveBeenCalled();
1840
+ });
1841
+
1842
+ it('leaves another file alone: the request is for the file the URL names', async () => {
1843
+ render(
1844
+ <ViewerHarness
1845
+ initialContent="# Foo"
1846
+ filePath="knowledge-base/KnowledgeBase/Foo.md"
1847
+ routePath={NEW_PAGE}
1848
+ routeState={{ startEditing: true }}
1849
+ />,
1850
+ );
1851
+ await screen.findByRole('button', { name: 'Edit' });
1852
+ await act(async () => {});
1853
+ expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
1854
+ expect(acquireLockMock).not.toHaveBeenCalled();
1855
+ // Still pending, for when that file opens.
1856
+ expect(screen.getByTestId('location-state')).toHaveTextContent('{"startEditing":true}');
1857
+ });
1858
+
1859
+ it('consumes the request without editing a file the reader cannot write', async () => {
1860
+ accessMock.result = {
1861
+ canWrite: false,
1862
+ canOwner: false,
1863
+ eligible: { roles: ['Admin'], users: [] },
1864
+ owners: EMPTY_ELIGIBLE,
1865
+ };
1866
+ render(
1867
+ <ViewerHarness
1868
+ initialContent="official"
1869
+ branch="target-company-state"
1870
+ filePath={NEW_PAGE}
1871
+ routeState={{ startEditing: true }}
1872
+ />,
1873
+ );
1874
+ await waitFor(() => expect(screen.getByTestId('location-state')).toHaveTextContent('null'));
1875
+ expect(screen.getByRole('button', { name: 'Propose changes' })).toBeInTheDocument();
1876
+ expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
1877
+ expect(acquireLockMock).not.toHaveBeenCalled();
1878
+ });
1879
+ });
@@ -6,6 +6,7 @@ import { KbPageHeader, type KbPageHeaderProps } from '../KbPageHeader';
6
6
  function renderHeader(overrides: Partial<KbPageHeaderProps> = {}) {
7
7
  const props: KbPageHeaderProps = {
8
8
  path: 'knowledge-base/Knowledge/Invariant.md',
9
+ kbDirName: 'knowledge-base',
9
10
  canWrite: true,
10
11
  editMode: false,
11
12
  entering: false,
@@ -37,6 +38,20 @@ describe('KbPageHeader', () => {
37
38
  expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Invariant');
38
39
  });
39
40
 
41
+ it("titles a plugin's plugin.json Plugin settings, with the file name on hover", () => {
42
+ renderHeader({ path: 'knowledge-base/Plugins/GTM/plugin.json' });
43
+ const h1 = screen.getByRole('heading', { level: 1 });
44
+ expect(h1).toHaveTextContent('Plugin settings');
45
+ expect(h1).toHaveAttribute('title', 'plugin.json');
46
+ });
47
+
48
+ it("titles a folder's access.md Who has access, with the file name on hover", () => {
49
+ renderHeader({ path: 'knowledge-base/KnowledgeBase/Legal/access.md' });
50
+ const h1 = screen.getByRole('heading', { level: 1 });
51
+ expect(h1).toHaveTextContent('Who has access');
52
+ expect(h1).toHaveAttribute('title', 'access.md');
53
+ });
54
+
40
55
  it('leaves an unknown extension alone', () => {
41
56
  renderHeader({ path: 'Knowledge/roles.unknownext' });
42
57
  expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('roles.unknownext');
@@ -95,11 +110,11 @@ describe('KbPageHeader', () => {
95
110
  expect(screen.getByRole('button', { name: 'Edit' })).toBeInTheDocument();
96
111
  });
97
112
 
98
- it('disables Edit while someone else holds the lock and names the holder', () => {
113
+ it('disables Edit while someone else is editing and names them', () => {
99
114
  renderHeader({ lockedBy: 'Ali Raza' });
100
115
  const edit = screen.getByRole('button', { name: 'Edit' });
101
116
  expect(edit).toBeDisabled();
102
- expect(edit).toHaveAttribute('title', 'Locked by Ali Raza');
117
+ expect(edit).toHaveAttribute('title', 'Ali Raza is editing this page');
103
118
  });
104
119
 
105
120
  it('swaps Edit for Done in edit mode', () => {
@@ -6,11 +6,9 @@ import { useEffect, useState } from 'react';
6
6
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
7
7
  // @ts-expect-error — mammoth ships no .d.ts
8
8
  import mammoth from 'mammoth/mammoth.browser.js';
9
- import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
10
9
  import { RetryReadButton } from './RetryReadButton';
11
10
  import { useReadRetry } from './useReadRetry';
12
- import { authFetch } from '../../../../lib/api';
13
- import { rawFileUrl } from '../../services/workspace.api';
11
+ import { useRendererRawRead } from './rendererRawRead';
14
12
  import { sanitizeDocxHtml } from './sanitizeDocxHtml';
15
13
  import { DownloadFileButton } from './DownloadFileButton';
16
14
  import type { FileRendererProps } from './types';
@@ -33,16 +31,15 @@ import type { FileRendererProps } from './types';
33
31
  * ignores `onSave` / `onValueChange` / `readOnly`.
34
32
  */
35
33
  export function DocxRenderer({ filePath }: FileRendererProps) {
36
- const workspaceId = useRendererWorkspaceId();
37
- /** A past save, when Version history mounted this; null = the working tree. */
38
- const fileRef = useRendererFileRef();
39
34
  /**
40
- * The save as PRIMITIVES, hoisted out of the object so the read effect can
41
- * depend on exactly what it reads. Depending on `fileRef` itself would put
42
- * a context object in the dependency list.
35
+ * Where this file's bytes come from. In the app that is the workspace raw
36
+ * route under the session, for the workspace this viewer is pointed at and
37
+ * the save it is bound to; on a renderer surface (the embed) it is that
38
+ * surface's own route, with its own credential. Null until there is a
39
+ * workspace to read from — the same "nothing to read yet" the guard in the
40
+ * effect below has always had.
43
41
  */
44
- const versionRef = fileRef?.ref ?? null;
45
- const versionSide = fileRef?.side;
42
+ const rawRead = useRendererRawRead();
46
43
  const { attempt, retry } = useReadRetry();
47
44
  const [html, setHtml] = useState<string | null>(null);
48
45
  const [error, setError] = useState<string | null>(null);
@@ -50,14 +47,12 @@ export function DocxRenderer({ filePath }: FileRendererProps) {
50
47
  useEffect(() => {
51
48
  setHtml(null);
52
49
  setError(null);
53
- if (!workspaceId) return;
50
+ if (!rawRead) return;
54
51
 
55
52
  let cancelled = false;
56
53
  (async () => {
57
54
  try {
58
- const res = await authFetch(
59
- rawFileUrl(workspaceId, filePath, { ref: versionRef, side: versionSide }),
60
- );
55
+ const res = await rawRead.fetch(filePath);
61
56
  if (cancelled) return;
62
57
  if (!res.ok) {
63
58
  setError(`Failed to load Word document (HTTP ${res.status})`);
@@ -79,7 +74,7 @@ export function DocxRenderer({ filePath }: FileRendererProps) {
79
74
  return () => {
80
75
  cancelled = true;
81
76
  };
82
- }, [workspaceId, filePath, versionRef, versionSide, attempt]);
77
+ }, [rawRead, filePath, attempt]);
83
78
 
84
79
  if (error) {
85
80
  return (
@@ -2,6 +2,7 @@ import { createContext, useCallback, useContext, useState } from 'react';
2
2
  import { Download } from 'lucide-react';
3
3
  import { Button } from '../../../../shared/components';
4
4
  import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
5
+ import { useRendererSurface } from './rendererSurface';
5
6
  import { rawFileUrl } from '../../services/workspace.api';
6
7
  import { downloadViaBlob } from './downloadFile';
7
8
 
@@ -68,6 +69,7 @@ export function DownloadFileButton({
68
69
  */
69
70
  const versionRef = fileRef?.ref ?? null;
70
71
  const versionSide = fileRef?.side;
72
+ const surface = useRendererSurface();
71
73
  const canDownload = useContext(CanDownloadContext);
72
74
  const [busy, setBusy] = useState(false);
73
75
  const [error, setError] = useState<string | null>(null);
@@ -98,6 +100,10 @@ export function DownloadFileButton({
98
100
  }
99
101
  }, [workspaceId, busy, pending, filePath, fileName, versionRef, versionSide]);
100
102
 
103
+ // A surface that has no download route draws no download control — see
104
+ // `offersDownload`. After the hooks, never before them.
105
+ if (surface && !surface.offersDownload) return null;
106
+
101
107
  return (
102
108
  <span className="inline-flex items-center gap-2">
103
109
  {error && (
@@ -1,16 +1,15 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'react';
2
2
  import { Check, Copy, ExternalLink, Mail, Paperclip } from 'lucide-react';
3
- import { useRendererFileRef, useRendererWorkspaceId } from './rendererWorkspace';
4
3
  import { RetryReadButton } from './RetryReadButton';
5
4
  import { useReadRetry } from './useReadRetry';
6
- import { authFetch } from '../../../../lib/api';
7
- import { rawFileUrl } from '../../services/workspace.api';
5
+ import { useRendererRawRead } from './rendererRawRead';
8
6
  import { copyToClipboard } from '../../../../lib/clipboard';
9
7
  import { DownloadFileButton } from './DownloadFileButton';
10
8
  import { MAX_EMAIL_BYTES, attachmentLine, type EmailMessageView } from './emailMessage';
11
9
  import { buildEmailBody, type EmailLink } from './emailBody';
12
10
  import { readBodyCapped } from './readBodyCapped';
13
11
  import type { FileRendererProps } from './types';
12
+ import { useConfirm } from '../../../../shared/components';
14
13
 
15
14
  /**
16
15
  * The honest email view for `.eml` and `.msg`: labelled header fields, the
@@ -41,16 +40,15 @@ import type { FileRendererProps } from './types';
41
40
  * ignores `onSave` / `onValueChange` / `readOnly`.
42
41
  */
43
42
  export function EmailRenderer({ filePath }: FileRendererProps) {
44
- const workspaceId = useRendererWorkspaceId();
45
- /** A past save, when Version history mounted this; null = the working tree. */
46
- const fileRef = useRendererFileRef();
47
43
  /**
48
- * The save as PRIMITIVES, hoisted out of the object so the read effect can
49
- * depend on exactly what it reads. Depending on `fileRef` itself would put
50
- * a context object in the dependency list.
44
+ * Where this file's bytes come from. In the app that is the workspace raw
45
+ * route under the session, for the workspace this viewer is pointed at and
46
+ * the save it is bound to; on a renderer surface (the embed) it is that
47
+ * surface's own route, with its own credential. Null until there is a
48
+ * workspace to read from — the same "nothing to read yet" the guard in the
49
+ * effect below has always had.
51
50
  */
52
- const versionRef = fileRef?.ref ?? null;
53
- const versionSide = fileRef?.side;
51
+ const rawRead = useRendererRawRead();
54
52
  const { attempt, retry } = useReadRetry();
55
53
  const [view, setView] = useState<EmailMessageView | null>(null);
56
54
  // The sender's own markup, made safe to show. Rebuilt only when the message
@@ -64,7 +62,7 @@ export function EmailRenderer({ filePath }: FileRendererProps) {
64
62
  useEffect(() => {
65
63
  setView(null);
66
64
  setError(null);
67
- if (!workspaceId) return;
65
+ if (!rawRead) return;
68
66
 
69
67
  let cancelled = false;
70
68
  // Cleanup ABORTS, not just flags: flipping `cancelled` alone would let an
@@ -72,10 +70,7 @@ export function EmailRenderer({ filePath }: FileRendererProps) {
72
70
  const controller = new AbortController();
73
71
  (async () => {
74
72
  try {
75
- const res = await authFetch(
76
- rawFileUrl(workspaceId, filePath, { ref: versionRef, side: versionSide }),
77
- { signal: controller.signal },
78
- );
73
+ const res = await rawRead.fetch(filePath, { signal: controller.signal });
79
74
  if (cancelled) return;
80
75
  if (!res.ok) {
81
76
  setError(`Failed to load email (HTTP ${res.status})`);
@@ -109,7 +104,7 @@ export function EmailRenderer({ filePath }: FileRendererProps) {
109
104
  cancelled = true;
110
105
  controller.abort();
111
106
  };
112
- }, [workspaceId, filePath, versionRef, versionSide, attempt]);
107
+ }, [rawRead, filePath, attempt]);
113
108
 
114
109
  if (error) {
115
110
  return (
@@ -285,6 +280,7 @@ function CopyLinkButton({ url }: { url: string }): React.ReactElement {
285
280
  * navigates at all.
286
281
  */
287
282
  function EmailLinks({ links }: { links: readonly EmailLink[] }): React.ReactElement {
283
+ const confirm = useConfirm();
288
284
  return (
289
285
  <div className="mt-4 border-t border-line pt-3">
290
286
  <div className="mb-1 flex items-center gap-1.5 text-meta font-medium uppercase tracking-wide text-ink-faint">
@@ -304,13 +300,19 @@ function EmailLinks({ links }: { links: readonly EmailLink[] }): React.ReactElem
304
300
  type="button"
305
301
  className="shrink-0 text-ink-faint hover:text-ink"
306
302
  title="Open in a new tab"
307
- onClick={() => {
303
+ onClick={async () => {
308
304
  // Asked before anything opens, with the address in the prompt:
309
305
  // the reader decides against the REAL destination, not against
310
- // whatever text the sender chose to show.
311
- if (window.confirm(`Open this link?
306
+ // whatever text the sender chose to show. The Open click is
307
+ // itself the gesture the new tab rides on.
308
+ const { confirmed } = await confirm({
309
+ title: 'Open link',
310
+ message: `Open this link?
312
311
 
313
- ${link.url}`)) {
312
+ ${link.url}`,
313
+ confirmLabel: 'Open',
314
+ });
315
+ if (confirmed) {
314
316
  window.open(link.url, '_blank', 'noopener,noreferrer');
315
317
  }
316
318
  }}