@bevel-software/platform-core-frontend 0.15.1 → 0.19.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.
- package/THIRD-PARTY-NOTICES.md +2 -2
- package/package.json +3 -3
- package/src/core/CoreAppShell.tsx +16 -9
- package/src/core/__tests__/AppChrome.test.tsx +0 -3
- package/src/core/__tests__/events.test.ts +43 -0
- package/src/core/bootstrap.ts +11 -3
- package/src/core/events.ts +85 -3
- package/src/core/registry.ts +1 -1
- package/src/lib/__tests__/email.test.ts +44 -0
- package/src/lib/email.ts +37 -1
- package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +141 -0
- package/src/modules/access/__tests__/ManageAccessDialog.chip-truncation.test.tsx +204 -0
- package/src/modules/access/__tests__/ManageAccessDialog.download-read.test.tsx +234 -0
- package/src/modules/access/__tests__/ManageAccessDialog.edited-row-visible.test.tsx +160 -0
- package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +2 -2
- package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +166 -0
- package/src/modules/access/__tests__/ManageAccessDialog.restrict.test.tsx +510 -0
- package/src/modules/access/__tests__/ManageAccessDialog.row-menu-axes.test.tsx +299 -0
- package/src/modules/access/__tests__/ManageAccessDialog.row-menu-width.test.tsx +226 -0
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +721 -126
- package/src/modules/access/__tests__/ManageAccessDialog.unknown-email.test.tsx +314 -0
- package/src/modules/access/__tests__/manage-access-affordance.test.ts +14 -0
- package/src/modules/access/__tests__/tailwindDeclarations.ts +210 -0
- package/src/modules/access/api.ts +140 -6
- package/src/modules/access/components/ManageAccessDialog.tsx +1299 -561
- package/src/modules/access/manage-access-affordance.ts +17 -0
- package/src/modules/admin/__tests__/AddMemberInput.test.tsx +297 -0
- package/src/modules/admin/__tests__/AdminRolesPage.capabilities.test.tsx +2 -2
- package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +189 -0
- package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +1 -1
- package/src/modules/admin/__tests__/ConnectionKeysPage.test.tsx +266 -0
- package/src/modules/admin/__tests__/DirectoryGroupsPage.suggest.test.tsx +182 -0
- package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +165 -14
- package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +401 -4
- package/src/modules/admin/__tests__/group-members-path.test.ts +27 -0
- package/src/modules/admin/components/AddMemberInput.tsx +268 -0
- package/src/modules/admin/components/AdminRolesPage.tsx +97 -132
- package/src/modules/admin/components/ConnectionKeysPage.tsx +269 -0
- package/src/modules/admin/components/DirectoryGroupsPage.tsx +91 -39
- package/src/modules/admin/components/UserAccountsPage.tsx +271 -37
- package/src/modules/admin/components/connection-keys-grouping.ts +43 -0
- package/src/modules/admin/components/group-members-path.ts +32 -0
- package/src/modules/admin/services/connection-keys.api.ts +47 -0
- package/src/modules/admin/services/roles.api.ts +12 -1
- package/src/modules/auth/__tests__/AccountPage.test.tsx +50 -2
- package/src/modules/auth/components/AccountPage.tsx +73 -54
- package/src/modules/auth/components/LoginScreen.tsx +1 -0
- package/src/modules/auth/services/account.api.ts +78 -4
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +144 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +422 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +431 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +193 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +142 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +202 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +205 -13
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +271 -0
- package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +208 -0
- package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +286 -0
- package/src/modules/change-requests/__tests__/propose.concurrent.test.ts +273 -0
- package/src/modules/change-requests/__tests__/readFailure.test.ts +122 -0
- package/src/modules/change-requests/__tests__/useCrFileDiffs.test.tsx +238 -0
- package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +56 -1
- package/src/modules/change-requests/__tests__/useForkPointFile.test.tsx +79 -0
- package/src/modules/change-requests/components/BranchFilePreview.tsx +357 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +31 -2
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +862 -72
- package/src/modules/change-requests/components/CrFileTree.tsx +74 -58
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +19 -15
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +41 -7
- package/src/modules/change-requests/hooks/useCrFileDiffs.ts +181 -23
- package/src/modules/change-requests/hooks/useFileOnBranch.ts +70 -7
- package/src/modules/change-requests/hooks/useForkPointFile.ts +77 -0
- package/src/modules/change-requests/services/change-requests.api.ts +57 -1
- package/src/modules/change-requests/services/denied-file.api.ts +53 -0
- package/src/modules/change-requests/services/propose.api.ts +97 -8
- package/src/modules/change-requests/utils/approval.ts +15 -0
- package/src/modules/change-requests/utils/author.ts +32 -0
- package/src/modules/change-requests/utils/readFailure.ts +110 -0
- package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +20 -0
- package/src/modules/git/components/FileHistoryPanel.tsx +5 -0
- package/src/modules/git/components/PullRequestsForMe.tsx +51 -24
- package/src/modules/git/services/__tests__/error-messages.test.ts +29 -0
- package/src/modules/git/services/error-messages.ts +12 -0
- package/src/modules/git/services/pr-prompts.ts +5 -5
- package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +401 -0
- package/src/modules/layout/__tests__/SidebarFooterGrid.test.tsx +286 -0
- package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +61 -0
- package/src/modules/layout/components/AppLayout.tsx +2 -0
- package/src/modules/layout/components/MobileChatLayout.tsx +4 -1
- package/src/modules/layout/components/ResizableThreePaneLayout.tsx +4 -1
- package/src/modules/layout/components/SidebarFrame.tsx +108 -3
- package/src/modules/library/__tests__/AddToPluginDialog.test.tsx +171 -5
- package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +356 -0
- package/src/modules/library/__tests__/IntegrationsSetupReminder.test.tsx +60 -0
- package/src/modules/library/__tests__/LibraryCard.test.tsx +91 -10
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +242 -107
- package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +103 -98
- package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +20 -5
- package/src/modules/library/__tests__/LockedPluginView.test.tsx +97 -7
- package/src/modules/library/__tests__/NewPluginDialog.test.tsx +13 -4
- package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +79 -3
- package/src/modules/library/__tests__/PersonalPluginPage.test.tsx +201 -0
- package/src/modules/library/__tests__/PluginExtras.test.tsx +100 -9
- package/src/modules/library/__tests__/PluginJoinRequests.test.tsx +60 -1
- package/src/modules/library/__tests__/PluginPage.test.tsx +258 -6
- package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +16 -56
- package/src/modules/library/__tests__/PluginsSidebar.test.tsx +155 -152
- package/src/modules/library/__tests__/PluginsSidebarMenu.test.tsx +16 -0
- package/src/modules/library/__tests__/SharedViaPlugins.test.tsx +106 -0
- package/src/modules/library/__tests__/SkillPage.test.tsx +386 -80
- package/src/modules/library/__tests__/SkillsTree.test.tsx +293 -4
- package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +582 -71
- package/src/modules/library/__tests__/ToolPage.test.tsx +87 -4
- package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +173 -26
- package/src/modules/library/__tests__/auth-harness.tsx +9 -9
- package/src/modules/library/__tests__/card-row-menu.test.tsx +320 -0
- package/src/modules/library/__tests__/library-data.mapping.test.tsx +98 -0
- package/src/modules/library/__tests__/library-data.stale.test.tsx +121 -28
- package/src/modules/library/__tests__/library-data.test.ts +7 -0
- package/src/modules/library/__tests__/library-paths.test.ts +47 -4
- package/src/modules/library/__tests__/link-membership.test.ts +13 -4
- package/src/modules/library/__tests__/name-with-badges.test.tsx +273 -0
- package/src/modules/library/__tests__/newSkillMarkdown.test.ts +30 -0
- package/src/modules/library/__tests__/owner-pill.test.tsx +357 -0
- package/src/modules/library/__tests__/pending-tools.test.tsx +400 -0
- package/src/modules/library/__tests__/plugin-entries.test.ts +122 -0
- package/src/modules/library/__tests__/plugin-summary.test.ts +36 -1
- package/src/modules/library/__tests__/status.test.ts +82 -2
- package/src/modules/library/__tests__/tools.api.test.ts +44 -1
- package/src/modules/library/components/AccessRequestsBanner.tsx +85 -47
- package/src/modules/library/components/AddDialogTabs.tsx +103 -0
- package/src/modules/library/components/AddToPluginDialog.tsx +74 -18
- package/src/modules/library/components/IntegrationsSetupReminder.tsx +59 -0
- package/src/modules/library/components/ItemActionsMenu.tsx +288 -0
- package/src/modules/library/components/LibraryCard.tsx +146 -45
- package/src/modules/library/components/LibraryLayout.tsx +119 -256
- package/src/modules/library/components/LibraryPage.tsx +172 -39
- package/src/modules/library/components/LinkSkillPanel.tsx +1 -3
- package/src/modules/library/components/LockedPluginView.tsx +62 -34
- package/src/modules/library/components/NameWithBadges.tsx +164 -0
- package/src/modules/library/components/NewPluginDialog.tsx +16 -2
- package/src/modules/library/components/PageActions.tsx +11 -9
- package/src/modules/library/components/{PendingSkillReview.tsx → PendingItemReview.tsx} +14 -7
- package/src/modules/library/components/PersonalAddDialog.tsx +68 -18
- package/src/modules/library/components/PersonalPluginPage.tsx +121 -22
- package/src/modules/library/components/PluginExtras.tsx +140 -17
- package/src/modules/library/components/PluginIndexRow.tsx +47 -12
- package/src/modules/library/components/PluginPage.tsx +157 -41
- package/src/modules/library/components/PluginRows.tsx +286 -0
- package/src/modules/library/components/PluginsSidebar.tsx +239 -263
- package/src/modules/library/components/PluginsSidebarMenu.tsx +26 -1
- package/src/modules/library/components/ShareButton.tsx +17 -0
- package/src/modules/library/components/SkillsTree.tsx +141 -28
- package/src/modules/library/components/TeamRoute.tsx +15 -0
- package/src/modules/library/components/__tests__/upload-notices-once-per-page.test.tsx +144 -0
- package/src/modules/library/components/plugin-page-parts.tsx +103 -17
- package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +6 -12
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +5 -0
- package/src/modules/library/components/skill-page/SkillPage.tsx +274 -122
- package/src/modules/library/components/tool-page/DeleteToolDialog.tsx +218 -0
- package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +79 -178
- package/src/modules/library/components/tool-page/ToolPage.tsx +106 -16
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +42 -41
- package/src/modules/library/hooks/__tests__/useLibraryData.test.ts +98 -0
- package/src/modules/library/hooks/useLibraryData.ts +92 -19
- package/src/modules/library/routes/LibraryRoutes.tsx +14 -11
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +77 -27
- package/src/modules/library/routes/library-paths.ts +26 -28
- package/src/modules/library/services/library.api.ts +38 -20
- package/src/modules/library/services/plugins.api.ts +69 -8
- package/src/modules/library/services/teams.api.ts +15 -0
- package/src/modules/library/services/tools.api.ts +78 -0
- package/src/modules/library/state/library-data.tsx +170 -32
- package/src/modules/library/utils/personal-plugin.ts +13 -15
- package/src/modules/library/utils/plugin-entries.ts +134 -0
- package/src/modules/library/utils/plugin-summary.ts +75 -9
- package/src/modules/library/utils/status.ts +135 -33
- package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +8 -1
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +853 -760
- package/src/modules/onboarding/agent-clients.ts +55 -23
- package/src/modules/onboarding/components/ConnectAgentPill.tsx +5 -1
- package/src/modules/onboarding/components/WelcomePage.tsx +98 -62
- package/src/modules/pr/services/pr-merge.api.ts +2 -1
- package/src/modules/review/components/MarkdownDiffViewer.tsx +53 -8
- package/src/modules/review/components/ReviewPanel.tsx +15 -17
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +64 -0
- package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +25 -1
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +454 -117
- package/src/modules/secrets-vault/components/SecretsPage.tsx +48 -7
- package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +84 -5
- package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +425 -0
- package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +417 -82
- package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +105 -0
- package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +407 -0
- package/src/modules/secrets-vault/probe/SavedKeyProbeResult.tsx +98 -0
- package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +160 -0
- package/src/modules/secrets-vault/probe/probe-verdict.ts +108 -0
- package/src/modules/secrets-vault/probe/useSavedKeyProbe.ts +228 -0
- package/src/modules/secrets-vault/services/connect.api.ts +36 -5
- package/src/modules/secrets-vault/utils/connect-status.ts +98 -0
- package/src/modules/settings/components/ClaudeConnectionCard.tsx +9 -24
- package/src/modules/settings/components/ClaudeConnectionFields.tsx +23 -0
- package/src/modules/settings/components/DeploymentPage.tsx +10 -30
- package/src/modules/settings/components/MarketplaceSection.tsx +152 -0
- package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +67 -4
- package/src/modules/settings/components/__tests__/MarketplaceSection.test.tsx +325 -0
- package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +5 -5
- package/src/modules/settings/services/github-facade.api.ts +23 -0
- package/src/modules/settings/settings-nav-items.tsx +10 -2
- package/src/modules/setup/__tests__/setup.oidc.test.tsx +172 -0
- package/src/modules/setup/__tests__/setup.probe-refusal.test.tsx +123 -0
- package/src/modules/setup/__tests__/setup.test.tsx +497 -4
- package/src/modules/setup/__tests__/useSetupStatus.test.tsx +130 -0
- package/src/modules/setup/components/SetupGate.tsx +16 -16
- package/src/modules/setup/components/SetupScreen.tsx +521 -43
- package/src/modules/setup/hooks/useSetupStatus.ts +93 -0
- package/src/modules/setup/services/setup.api.ts +140 -3
- package/src/modules/setup/utils/__tests__/root-folders.test.ts +72 -0
- package/src/modules/setup/utils/root-folders.ts +46 -0
- package/src/modules/toolbar/assets/claude-setup/01-add-manually.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/02-add-configuration.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/03-connect-account.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/04-pick-instance.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/05-plugins-add.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/06-add-marketplace.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/07-paste-url-sync.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/08-install-plugins.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/09-select-repository.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/10-connector-not-added.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/11-add-custom-connector.webp +0 -0
- package/src/modules/toolbar/assets/claude-setup/README.md +68 -0
- package/src/modules/toolbar/components/AgentInstructionsCard.tsx +296 -0
- package/src/modules/toolbar/components/ClaudeMarketplaceCarousel.tsx +107 -0
- package/src/modules/toolbar/components/ClaudeRegistrationSteps.tsx +127 -0
- package/src/modules/toolbar/components/CoworkSetupSteps.tsx +100 -0
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +177 -118
- package/src/modules/toolbar/components/ScreenshotStep.tsx +77 -0
- package/src/modules/toolbar/components/SetupCarousel.tsx +177 -0
- package/src/modules/toolbar/components/__tests__/AgentInstructionsCard.test.tsx +370 -0
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +542 -42
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +2 -2
- package/src/modules/toolbar/components/__tests__/claude-setup-shots.test.ts +104 -0
- package/src/modules/toolbar/components/claude-connector-slide.tsx +38 -0
- package/src/modules/toolbar/components/claude-setup-shots.ts +167 -0
- package/src/modules/toolbar/components/deployment-address.ts +29 -0
- package/src/modules/toolbar/components/setup-step-parts.tsx +35 -0
- package/src/modules/toolbar/services/__tests__/agent-instructions.api.test.ts +89 -0
- package/src/modules/toolbar/services/agent-instructions.api.ts +167 -0
- package/src/modules/toolbar/services/external-api-keys.api.ts +6 -0
- package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +43 -0
- package/src/modules/workflow/state/EventBusProvider.tsx +122 -11
- package/src/modules/workflow/state/__tests__/EventBusProvider.storage.test.tsx +87 -0
- package/src/modules/workflow/state/__tests__/EventBusProvider.watch.test.tsx +223 -0
- package/src/modules/workflow/state/event-bus.context.ts +10 -0
- package/src/modules/workspace/__tests__/testFixtures.ts +5 -3
- package/src/modules/workspace/components/FileExplorer.tsx +1295 -191
- package/src/modules/workspace/components/FileRoute.tsx +353 -36
- package/src/modules/workspace/components/FileViewer.tsx +166 -45
- package/src/modules/workspace/components/KbDocumentShell.tsx +50 -6
- package/src/modules/workspace/components/KbPageHeader.tsx +120 -55
- package/src/modules/workspace/components/TreeActionConfirm.tsx +350 -0
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +2473 -129
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +731 -18
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +331 -12
- package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +39 -0
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +33 -20
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +4 -5
- package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +13 -4
- package/src/modules/workspace/components/renderers/EmailRenderer.tsx +4 -3
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +8 -14
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +75 -16
- package/src/modules/workspace/components/renderers/KbImage.tsx +180 -0
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +22 -6
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +48 -22
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +4 -5
- package/src/modules/workspace/components/renderers/PptxRenderer.tsx +4 -3
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +4 -3
- package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +12 -0
- package/src/modules/workspace/components/renderers/__tests__/DownloadFileButton.test.tsx +57 -9
- package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.test.tsx +13 -1
- package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +163 -0
- package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +237 -0
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +108 -14
- package/src/modules/workspace/components/renderers/__tests__/PptxRenderer.test.tsx +14 -1
- package/src/modules/workspace/components/renderers/__tests__/XlsxRenderer.test.tsx +16 -1
- package/src/modules/workspace/components/renderers/__tests__/rendererSelection.test.tsx +66 -1
- package/src/modules/workspace/components/renderers/index.ts +53 -2
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +25 -4
- package/src/modules/workspace/components/renderers/rendererWorkspace.ts +40 -0
- package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +174 -0
- package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +179 -1
- package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +122 -0
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +892 -7
- package/src/modules/workspace/hooks/useImageRevision.ts +101 -0
- package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +22 -3
- package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +55 -0
- package/src/modules/workspace/hooks/useWorkspaceState.ts +424 -66
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +279 -3
- package/src/modules/workspace/routing/kb-routes.ts +206 -29
- package/src/modules/workspace/services/__tests__/workspace.api.test.ts +57 -1
- package/src/modules/workspace/services/workspace.api.ts +57 -4
- package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +343 -0
- package/src/modules/workspace/state/__tests__/upload-lands-where-it-was-dropped.test.tsx +158 -0
- package/src/modules/workspace/state/open-change-requests.tsx +100 -12
- package/src/modules/workspace/state/workspace.context.ts +125 -19
- package/src/modules/workspace/utils/__tests__/file-trace.test.ts +73 -0
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +220 -6
- package/src/modules/workspace/utils/__tests__/pasteLink.test.ts +76 -0
- package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +364 -0
- package/src/modules/workspace/utils/__tests__/uploadError.test.ts +35 -0
- package/src/modules/workspace/utils/file-trace.ts +50 -0
- package/src/modules/workspace/utils/fileTree.ts +112 -36
- package/src/modules/workspace/utils/frontmatter.ts +8 -4
- package/src/modules/workspace/utils/pasteLink.ts +90 -0
- package/src/modules/workspace/utils/treeConfirm.ts +338 -0
- package/src/modules/workspace/utils/uploadError.ts +29 -0
- package/src/shared/__tests__/marketplace-url.test.ts +6 -1
- package/src/shared/components/Button.tsx +16 -2
- package/src/shared/components/Dialog.tsx +27 -11
- package/src/shared/components/Menu.tsx +13 -1
- package/src/shared/components/PageShell.tsx +13 -8
- package/src/shared/components/__tests__/primitives.test.tsx +116 -2
- package/src/shared/components/__tests__/useFocusHandoff.test.tsx +192 -0
- package/src/shared/components/index.ts +2 -0
- package/src/shared/components/useDismissableMenu.ts +32 -10
- package/src/shared/components/useFocusHandoff.ts +51 -0
- package/src/shared/components/useLatestRef.ts +28 -0
- package/src/shared/markdown/Markdown.tsx +12 -3
- package/src/shared/markdown/__tests__/escapeSpacesInLinkDestinations.test.ts +39 -0
- package/src/shared/markdown/hrefs.ts +50 -0
- package/src/shared/marketplace-url.ts +33 -5
- package/src/shared/mcp/ChatGptInstallLink.tsx +3 -3
- package/src/shared/mcp/ConnectionInstructions.tsx +38 -27
- package/src/shared/mcp/__tests__/connect-snippets.test.ts +3 -3
- package/src/shared/mcp/connect-snippets.ts +14 -9
- package/src/shared/mcp/index.ts +1 -1
- package/src/shared/theme/__tests__/header-band.test.ts +197 -0
- package/src/shared/theme/header.ts +75 -0
- package/src/shared/theme/measure.ts +7 -4
- package/src/shared/theme/tokens.css +25 -0
- package/src/modules/library/__tests__/PluginsIndexPage.test.tsx +0 -363
- package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +0 -97
- package/src/modules/library/components/PluginsIndexPage.tsx +0 -270
- package/src/modules/update-check/__tests__/UpdateBanner.test.tsx +0 -126
- package/src/modules/update-check/components/UpdateBanner.tsx +0 -92
- package/src/modules/update-check/services/update-check.api.ts +0 -24
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createContext, useCallback, useContext, useState } from 'react';
|
|
2
2
|
import { Download } from 'lucide-react';
|
|
3
3
|
import { Button } from '../../../../shared/components';
|
|
4
|
-
import {
|
|
4
|
+
import { useRendererWorkspaceId } from './rendererWorkspace';
|
|
5
|
+
import { rawFileUrl } from '../../services/workspace.api';
|
|
5
6
|
import { downloadViaBlob } from './downloadFile';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -27,12 +28,20 @@ export const CanDownloadContext = createContext<boolean | null>(null);
|
|
|
27
28
|
export function DownloadFileButton({
|
|
28
29
|
filePath,
|
|
29
30
|
size = 'tiny',
|
|
31
|
+
label = 'Download',
|
|
30
32
|
}: {
|
|
31
33
|
filePath: string;
|
|
32
34
|
/** `sm` where the download is the page's main affordance (pptx outline). */
|
|
33
35
|
size?: 'tiny' | 'sm';
|
|
36
|
+
/**
|
|
37
|
+
* What the button says. `Download` beside a rendering that is already on
|
|
38
|
+
* screen; the change-request dialog names the VERSION instead ("Download
|
|
39
|
+
* the proposed file"), because there the bytes are the only thing on offer
|
|
40
|
+
* and which branch they come from is the whole question.
|
|
41
|
+
*/
|
|
42
|
+
label?: string;
|
|
34
43
|
}) {
|
|
35
|
-
const
|
|
44
|
+
const workspaceId = useRendererWorkspaceId();
|
|
36
45
|
const canDownload = useContext(CanDownloadContext);
|
|
37
46
|
const [busy, setBusy] = useState(false);
|
|
38
47
|
const [error, setError] = useState<string | null>(null);
|
|
@@ -44,7 +53,7 @@ export function DownloadFileButton({
|
|
|
44
53
|
setError(null);
|
|
45
54
|
try {
|
|
46
55
|
const outcome = await downloadViaBlob(
|
|
47
|
-
|
|
56
|
+
rawFileUrl(workspaceId, filePath, { download: true }),
|
|
48
57
|
fileName,
|
|
49
58
|
);
|
|
50
59
|
if (!outcome.ok) {
|
|
@@ -81,7 +90,7 @@ export function DownloadFileButton({
|
|
|
81
90
|
: `Download ${fileName}`
|
|
82
91
|
}
|
|
83
92
|
>
|
|
84
|
-
{busy ? 'Downloading…' :
|
|
93
|
+
{busy ? 'Downloading…' : label}
|
|
85
94
|
</Button>
|
|
86
95
|
</span>
|
|
87
96
|
);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { Check, Copy, ExternalLink, Mail, Paperclip } from 'lucide-react';
|
|
3
|
-
import {
|
|
3
|
+
import { useRendererWorkspaceId } from './rendererWorkspace';
|
|
4
4
|
import { authFetch } from '../../../../lib/api';
|
|
5
|
+
import { rawFileUrl } from '../../services/workspace.api';
|
|
5
6
|
import { copyToClipboard } from '../../../../lib/clipboard';
|
|
6
7
|
import { DownloadFileButton } from './DownloadFileButton';
|
|
7
8
|
import { MAX_EMAIL_BYTES, attachmentLine, type EmailMessageView } from './emailMessage';
|
|
@@ -38,7 +39,7 @@ import type { FileRendererProps } from './types';
|
|
|
38
39
|
* ignores `onSave` / `onValueChange` / `readOnly`.
|
|
39
40
|
*/
|
|
40
41
|
export function EmailRenderer({ filePath }: FileRendererProps) {
|
|
41
|
-
const
|
|
42
|
+
const workspaceId = useRendererWorkspaceId();
|
|
42
43
|
const [view, setView] = useState<EmailMessageView | null>(null);
|
|
43
44
|
// The sender's own markup, made safe to show. Rebuilt only when the message
|
|
44
45
|
// changes — the sanitize + inline pass walks the whole body.
|
|
@@ -60,7 +61,7 @@ export function EmailRenderer({ filePath }: FileRendererProps) {
|
|
|
60
61
|
(async () => {
|
|
61
62
|
try {
|
|
62
63
|
const res = await authFetch(
|
|
63
|
-
|
|
64
|
+
rawFileUrl(workspaceId, filePath),
|
|
64
65
|
{ signal: controller.signal },
|
|
65
66
|
);
|
|
66
67
|
if (cancelled) return;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState, useCallback, useEffect, useRef } from 'react';
|
|
2
2
|
import { Pencil, Eye, RotateCw } from 'lucide-react';
|
|
3
|
-
import { useFileNav
|
|
3
|
+
import { useFileNav } from '../../routing/kb-routes';
|
|
4
4
|
import type { FileRendererProps, RendererSaveState } from './types';
|
|
5
5
|
import { buildSandboxedHtml, sanitizeAgentHtml } from './htmlSandbox';
|
|
6
6
|
|
|
@@ -14,7 +14,7 @@ export function HtmlRenderer({
|
|
|
14
14
|
onSaveStateChange,
|
|
15
15
|
readOnly = false,
|
|
16
16
|
}: FileRendererProps) {
|
|
17
|
-
const {
|
|
17
|
+
const { openLink } = useFileNav();
|
|
18
18
|
const [mode, setMode] = useState<'preview' | 'edit'>('preview');
|
|
19
19
|
const [value, setValue] = useState(content);
|
|
20
20
|
const [savedValue, setSavedValue] = useState(savedContent ?? content);
|
|
@@ -82,10 +82,10 @@ export function HtmlRenderer({
|
|
|
82
82
|
// Navigation bridge: agent HTML deep-links into the KB by calling
|
|
83
83
|
// `window.bevel.openNode(href)` or clicking an `<a>` whose href points at a
|
|
84
84
|
// node — both post a `bevel.navigate` message (the iframe sandbox can't
|
|
85
|
-
// navigate the host window itself).
|
|
86
|
-
// markdown renderer does (absolute `/workspace/…` URLs
|
|
87
|
-
//
|
|
88
|
-
// navigation so the URL reflects what's on screen.
|
|
85
|
+
// navigate the host window itself). `openLink` resolves the href the same
|
|
86
|
+
// way the markdown renderer does (absolute `/workspace/…` URLs keep their
|
|
87
|
+
// branch; relative paths resolve against this file) and routes it through
|
|
88
|
+
// the in-app navigation so the URL reflects what's on screen.
|
|
89
89
|
useEffect(() => {
|
|
90
90
|
function onNavMessage(event: MessageEvent) {
|
|
91
91
|
const iframeWin = iframeRef.current?.contentWindow;
|
|
@@ -94,17 +94,11 @@ export function HtmlRenderer({
|
|
|
94
94
|
if (!msg || typeof msg !== 'object' || msg.type !== 'bevel.navigate') return;
|
|
95
95
|
const href = typeof msg.href === 'string' ? msg.href : null;
|
|
96
96
|
if (!href) return;
|
|
97
|
-
|
|
98
|
-
openFile(href);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
let decoded = href;
|
|
102
|
-
try { decoded = decodeURIComponent(href); } catch { /* leave as-is */ }
|
|
103
|
-
openFile(resolveRelativePath(filePath, decoded));
|
|
97
|
+
openLink(href, filePath);
|
|
104
98
|
}
|
|
105
99
|
window.addEventListener('message', onNavMessage);
|
|
106
100
|
return () => window.removeEventListener('message', onNavMessage);
|
|
107
|
-
}, [
|
|
101
|
+
}, [openLink, filePath]);
|
|
108
102
|
|
|
109
103
|
const save = useCallback(async (): Promise<boolean> => {
|
|
110
104
|
if (readOnly || value === savedValue) return true;
|
|
@@ -1,36 +1,95 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Button } from '../../../../shared/components';
|
|
3
|
+
import { useRendererWorkspaceId } from './rendererWorkspace';
|
|
4
|
+
import { useImageRevision } from '../../hooks/useImageRevision';
|
|
3
5
|
import { authFetch } from '../../../../lib/api';
|
|
6
|
+
import { rawFileUrl } from '../../services/workspace.api';
|
|
4
7
|
import type { FileRendererProps } from './types';
|
|
5
8
|
|
|
9
|
+
/** How the read of one image ended. */
|
|
10
|
+
interface ImageRead {
|
|
11
|
+
objectUrl: string | null;
|
|
12
|
+
/**
|
|
13
|
+
* A failed read, NAMED. A non-ok response used to return silently, leaving
|
|
14
|
+
* the pane on "Loading image…" for as long as anyone cared to watch — which
|
|
15
|
+
* is the shape a 403 on a restricted file takes, and a 404 on a path the
|
|
16
|
+
* workspace's branch does not have (the change-request pane reads someone
|
|
17
|
+
* else's branch, where a file may well be absent).
|
|
18
|
+
*/
|
|
19
|
+
error: string | null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const NOT_READ: ImageRead = { objectUrl: null, error: null };
|
|
23
|
+
|
|
6
24
|
export function ImageRenderer({ filePath }: FileRendererProps) {
|
|
7
|
-
const
|
|
8
|
-
|
|
25
|
+
const workspaceId = useRendererWorkspaceId();
|
|
26
|
+
/**
|
|
27
|
+
* A replaced picture reaches an open pane. The `<img>` tags the markdown
|
|
28
|
+
* pipeline emits already carry this revision (`useWorkspaceImageResolver`);
|
|
29
|
+
* the whole-file image view was the one image on the page that stayed stale
|
|
30
|
+
* until a reload — including the change-request pane, which reads a branch
|
|
31
|
+
* its author may still be pushing to while a reviewer looks at it.
|
|
32
|
+
*/
|
|
33
|
+
const revision = useImageRevision(workspaceId);
|
|
34
|
+
// Blob and failure in ONE value, so the cleanup that drops the old blob
|
|
35
|
+
// drops the old failure with it — a second `useState` would need a reset in
|
|
36
|
+
// the effect body, which costs a cascading render on every path change.
|
|
37
|
+
const [read, setRead] = useState<ImageRead>(NOT_READ);
|
|
38
|
+
/**
|
|
39
|
+
* Bumped by Try again, and a dependency of the read below — which is the
|
|
40
|
+
* whole mechanism. A failure whose `workspaceId`, path and revision are all
|
|
41
|
+
* unchanged has nothing to re-trigger the effect, so a dropped connection or
|
|
42
|
+
* a 502 was terminal until the pane remounted; a reviewer with a dialog open
|
|
43
|
+
* had no way back to the picture. Automatic recovery on a path or revision
|
|
44
|
+
* change is untouched: those change the deps by themselves.
|
|
45
|
+
*/
|
|
46
|
+
const [attempt, setAttempt] = useState(0);
|
|
9
47
|
|
|
10
48
|
useEffect(() => {
|
|
11
49
|
if (!workspaceId) return;
|
|
12
50
|
|
|
13
51
|
let revoked = false;
|
|
14
52
|
(async () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
53
|
+
try {
|
|
54
|
+
const res = await authFetch(rawFileUrl(workspaceId, filePath, { version: revision }));
|
|
55
|
+
if (revoked) return;
|
|
56
|
+
if (!res.ok) {
|
|
57
|
+
setRead({ objectUrl: null, error: `Couldn't load this image (HTTP ${res.status}).` });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const blob = await res.blob();
|
|
61
|
+
if (revoked) return;
|
|
62
|
+
setRead({ objectUrl: URL.createObjectURL(blob), error: null });
|
|
63
|
+
} catch {
|
|
64
|
+
if (!revoked) setRead({ objectUrl: null, error: "Couldn't load this image." });
|
|
65
|
+
}
|
|
22
66
|
})();
|
|
23
67
|
|
|
24
68
|
return () => {
|
|
25
69
|
revoked = true;
|
|
26
|
-
|
|
27
|
-
if (prev) URL.revokeObjectURL(prev);
|
|
28
|
-
|
|
70
|
+
setRead((prev) => {
|
|
71
|
+
if (prev.objectUrl) URL.revokeObjectURL(prev.objectUrl);
|
|
72
|
+
// `prev` back when there is nothing to clear, so React bails out of
|
|
73
|
+
// the render rather than seeing a fresh object with the same fields.
|
|
74
|
+
return prev === NOT_READ ? prev : NOT_READ;
|
|
29
75
|
});
|
|
30
76
|
};
|
|
31
|
-
}, [workspaceId, filePath]);
|
|
77
|
+
}, [workspaceId, filePath, revision, attempt]);
|
|
78
|
+
|
|
79
|
+
if (read.error) {
|
|
80
|
+
return (
|
|
81
|
+
<div className="flex h-full flex-col items-center justify-center gap-3 p-4">
|
|
82
|
+
<p role="alert" className="text-detail text-danger">
|
|
83
|
+
{read.error}
|
|
84
|
+
</p>
|
|
85
|
+
<Button variant="outline" size="tiny" onClick={() => setAttempt((n) => n + 1)}>
|
|
86
|
+
Try again
|
|
87
|
+
</Button>
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
32
91
|
|
|
33
|
-
if (!objectUrl) {
|
|
92
|
+
if (!read.objectUrl) {
|
|
34
93
|
return (
|
|
35
94
|
<div className="flex items-center justify-center h-full text-ink-muted text-sm">
|
|
36
95
|
Loading image...
|
|
@@ -41,7 +100,7 @@ export function ImageRenderer({ filePath }: FileRendererProps) {
|
|
|
41
100
|
return (
|
|
42
101
|
<div className="flex items-center justify-center h-full overflow-auto">
|
|
43
102
|
<img
|
|
44
|
-
src={objectUrl}
|
|
103
|
+
src={read.objectUrl}
|
|
45
104
|
alt={filePath}
|
|
46
105
|
className="max-w-full max-h-full object-contain rounded-xs"
|
|
47
106
|
/>
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { useState, type HTMLAttributes, type ImgHTMLAttributes } from 'react';
|
|
2
|
+
import { ImageOff } from 'lucide-react';
|
|
3
|
+
import { isExternalHref } from '../../../../shared/markdown/hrefs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What a surface knows about an image `src` the page cannot serve as written.
|
|
7
|
+
* Returned by `resolveImage` in `useKbMarkdownComponents`.
|
|
8
|
+
*/
|
|
9
|
+
export type KbImageSource =
|
|
10
|
+
/** Serve these bytes; `path` names the workspace file if they fail to load. */
|
|
11
|
+
| { src: string; path: string }
|
|
12
|
+
/** Do not fetch. Show the placeholder with `note`, naming `path`. */
|
|
13
|
+
| { src: null; path: string; note: string };
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Turns the `src` an author wrote (`./assets/x.png`, `/workspace/<b>/<p>`)
|
|
17
|
+
* into a source the browser can load, or says why it will not be loaded.
|
|
18
|
+
* `null` means the resolver could not place the path at all (no workspace
|
|
19
|
+
* yet); the placeholder then names the raw src.
|
|
20
|
+
*/
|
|
21
|
+
export type KbImageResolver = (src: string) => KbImageSource | null;
|
|
22
|
+
|
|
23
|
+
const NO_SOURCE_NOTE =
|
|
24
|
+
'This image has no usable source. Inline data: images are not supported; save the file under ./assets/ and link it.';
|
|
25
|
+
|
|
26
|
+
const PLACEHOLDER_CLASS =
|
|
27
|
+
'inline-flex max-w-full items-center gap-1.5 rounded-sm border border-dashed border-line-strong bg-sunken px-2 py-1 align-middle text-xs text-ink-muted';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* What a placeholder inherits from the image it stands in for: the attributes
|
|
31
|
+
* that tie the image to the DOCUMENT, never the ones that draw it or name it.
|
|
32
|
+
* Its `id`, so a link to the figure still lands; `aria-describedby`, so a
|
|
33
|
+
* caption still describes it; its language and direction. `width`, `height`,
|
|
34
|
+
* `align` and the rest size a picture that is not there. `aria-label` and
|
|
35
|
+
* `aria-labelledby` stay behind: the placeholder's NAME must say the picture
|
|
36
|
+
* is missing, and `aria-labelledby` outranks the `aria-label` we set, so
|
|
37
|
+
* inheriting it would name the placeholder after the caption instead. The
|
|
38
|
+
* sanitizer keeps no other ARIA attribute on an image (hast-util-sanitize's
|
|
39
|
+
* `aria` list), so nothing that hides an element can arrive.
|
|
40
|
+
*/
|
|
41
|
+
const INHERITED_ATTRIBUTES = new Set(['id', 'lang', 'dir', 'aria-describedby']);
|
|
42
|
+
|
|
43
|
+
function inheritedAttributes(rest: ImgHTMLAttributes<HTMLImageElement>): HTMLAttributes<HTMLElement> {
|
|
44
|
+
const inherited: Record<string, unknown> = {};
|
|
45
|
+
for (const [name, value] of Object.entries(rest)) {
|
|
46
|
+
if (INHERITED_ATTRIBUTES.has(name)) inherited[name] = value;
|
|
47
|
+
}
|
|
48
|
+
return inherited;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* What an image leaves behind when there is nothing to show. A `role="img"`
|
|
53
|
+
* whose accessible name is the note, so a screen reader hears what a sighted
|
|
54
|
+
* reader sees; the alt text stays, so the author's description is not lost
|
|
55
|
+
* with the picture. A span, not a div: an image sits inside a paragraph, and
|
|
56
|
+
* a block there is invalid markup.
|
|
57
|
+
*
|
|
58
|
+
* With `onRetry` it is a button. The one failure nothing else clears is a
|
|
59
|
+
* load error on a URL that does not change (a network blip, a 403 that lifts,
|
|
60
|
+
* a file fixed on disk with no event), and the reader is the one who knows it
|
|
61
|
+
* is worth another try; retrying on our own would loop error → image → error.
|
|
62
|
+
*
|
|
63
|
+
* The author's attributes come first, so ours hold.
|
|
64
|
+
*/
|
|
65
|
+
function ImagePlaceholder({
|
|
66
|
+
alt,
|
|
67
|
+
note,
|
|
68
|
+
onRetry,
|
|
69
|
+
attributes = {},
|
|
70
|
+
}: {
|
|
71
|
+
alt?: string;
|
|
72
|
+
note: string;
|
|
73
|
+
onRetry?: () => void;
|
|
74
|
+
attributes?: HTMLAttributes<HTMLElement>;
|
|
75
|
+
}) {
|
|
76
|
+
const label = alt ? `${alt}. ${note}` : note;
|
|
77
|
+
const body = (
|
|
78
|
+
<>
|
|
79
|
+
<ImageOff size={14} aria-hidden="true" className="shrink-0" />
|
|
80
|
+
<span className="min-w-0 break-words">
|
|
81
|
+
{alt ? <span className="text-ink">{alt} </span> : null}
|
|
82
|
+
{note}
|
|
83
|
+
{onRetry ? <span className="ml-1.5 text-accent">Retry</span> : null}
|
|
84
|
+
</span>
|
|
85
|
+
</>
|
|
86
|
+
);
|
|
87
|
+
if (onRetry) {
|
|
88
|
+
return (
|
|
89
|
+
<button
|
|
90
|
+
{...attributes}
|
|
91
|
+
type="button"
|
|
92
|
+
onClick={onRetry}
|
|
93
|
+
aria-label={`${label}. Retry`}
|
|
94
|
+
title="Try loading the image again"
|
|
95
|
+
className={`${PLACEHOLDER_CLASS} cursor-pointer hover:text-ink`}
|
|
96
|
+
>
|
|
97
|
+
{body}
|
|
98
|
+
</button>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
return (
|
|
102
|
+
<span {...attributes} role="img" aria-label={label} title={note} className={PLACEHOLDER_CLASS}>
|
|
103
|
+
{body}
|
|
104
|
+
</span>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The six inputs an image can arrive with, and what each renders:
|
|
110
|
+
*
|
|
111
|
+
* src resolver → rendered
|
|
112
|
+
* ───────────────────────── ─────────── ──────────────────────────────────────────
|
|
113
|
+
* http(s)://… or //… any <img src as-is>
|
|
114
|
+
* '' (stripped: was data:) any placeholder: no usable source
|
|
115
|
+
* ./assets/x.png none <img src as-is> (the embed, as before)
|
|
116
|
+
* ./assets/x.png {src, path} <img src=raw-file URL>; on error the
|
|
117
|
+
* placeholder "Couldn't load image: <path>",
|
|
118
|
+
* with Retry
|
|
119
|
+
* ./assets/x.png {src: null} placeholder with the resolver's note
|
|
120
|
+
* ./assets/x.png null placeholder "Couldn't load image: <src>"
|
|
121
|
+
*
|
|
122
|
+
* The sanitizer removes a `data:` src before this runs, so the empty-src case
|
|
123
|
+
* cannot know the cause and says what to do instead. A native `<img>` error
|
|
124
|
+
* carries no HTTP status, so a failure says "couldn't load", never "not found".
|
|
125
|
+
*
|
|
126
|
+
* The failure state is keyed by the resolved src: an author who fixes the
|
|
127
|
+
* link, or a teammate who uploads the missing file (which bumps the revision
|
|
128
|
+
* in the URL), sees the image without a reload; the same URL is tried again
|
|
129
|
+
* on request. Every attribute the sanitizer let through reaches the element
|
|
130
|
+
* (`id`, `align`, `aria-*`; `srcset` and `class` never survive it), and a
|
|
131
|
+
* placeholder keeps the ones that place the image in the document (see
|
|
132
|
+
* `inheritedAttributes`). Every
|
|
133
|
+
* `<img>` carries `loading="lazy"` (thirty screenshots on a Loop export must
|
|
134
|
+
* not all fetch at once) and `referrerPolicy="no-referrer"` (an external image
|
|
135
|
+
* host learns nothing about which page of the knowledge base cited it).
|
|
136
|
+
*/
|
|
137
|
+
export function KbImage({
|
|
138
|
+
src,
|
|
139
|
+
alt,
|
|
140
|
+
title,
|
|
141
|
+
resolve,
|
|
142
|
+
...rest
|
|
143
|
+
}: ImgHTMLAttributes<HTMLImageElement> & { resolve?: KbImageResolver }) {
|
|
144
|
+
const [failedSrc, setFailedSrc] = useState<string | null>(null);
|
|
145
|
+
const attributes = inheritedAttributes(rest);
|
|
146
|
+
if (!src) return <ImagePlaceholder alt={alt} note={NO_SOURCE_NOTE} attributes={attributes} />;
|
|
147
|
+
// Ours come after the author's, so they hold on every image.
|
|
148
|
+
const shared = {
|
|
149
|
+
...rest,
|
|
150
|
+
alt,
|
|
151
|
+
title,
|
|
152
|
+
loading: 'lazy' as const,
|
|
153
|
+
referrerPolicy: 'no-referrer' as const,
|
|
154
|
+
};
|
|
155
|
+
if (!resolve || isExternalHref(src)) return <img src={src} {...shared} />;
|
|
156
|
+
const resolved = resolve(src);
|
|
157
|
+
if (!resolved) {
|
|
158
|
+
return <ImagePlaceholder alt={alt} note={`Couldn't load image: ${src}`} attributes={attributes} />;
|
|
159
|
+
}
|
|
160
|
+
if (resolved.src === null) {
|
|
161
|
+
return (
|
|
162
|
+
<ImagePlaceholder
|
|
163
|
+
alt={alt}
|
|
164
|
+
note={`${resolved.note}: ${resolved.path}`}
|
|
165
|
+
attributes={attributes}
|
|
166
|
+
/>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
if (failedSrc === resolved.src) {
|
|
170
|
+
return (
|
|
171
|
+
<ImagePlaceholder
|
|
172
|
+
alt={alt}
|
|
173
|
+
note={`Couldn't load image: ${resolved.path}`}
|
|
174
|
+
onRetry={() => setFailedSrc(null)}
|
|
175
|
+
attributes={attributes}
|
|
176
|
+
/>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
return <img src={resolved.src} {...shared} onError={() => setFailedSrc(resolved.src)} />;
|
|
180
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useMemo, type Ref } from 'react';
|
|
2
|
-
import Markdown from 'react-markdown';
|
|
2
|
+
import Markdown, { defaultUrlTransform } from 'react-markdown';
|
|
3
3
|
import { parseFrontmatter, labelFor } from '../../utils/frontmatter';
|
|
4
4
|
import { escapeSpacesInLinkDestinations } from '../../../../shared/markdown/Markdown';
|
|
5
5
|
import {
|
|
6
6
|
KB_REMARK_PLUGINS,
|
|
7
7
|
KB_REHYPE_PLUGINS,
|
|
8
8
|
useKbMarkdownComponents,
|
|
9
|
+
type KbImageResolver,
|
|
9
10
|
} from './kbMarkdownPipeline';
|
|
10
11
|
|
|
11
12
|
// A frontmatter value that is a single markdown link, e.g.
|
|
@@ -20,6 +21,12 @@ const FRONTMATTER_LINK_RE = /^\[([^\]]+)\]\(<?([^)>]+)>?\)$/;
|
|
|
20
21
|
* `nodeType`) renders as a clickable link; everything else is plain text.
|
|
21
22
|
* `onOpenFile` receives the raw href — the caller decides how to resolve and
|
|
22
23
|
* open it (in-workspace navigation, or a new tab for the embed).
|
|
24
|
+
*
|
|
25
|
+
* The panel never goes through the markdown pipeline, so it applies the
|
|
26
|
+
* pipeline's URL policy itself: a destination react-markdown would refuse in
|
|
27
|
+
* the body (`javascript:`, or a bare `Notes: today.md`, which reads as a
|
|
28
|
+
* scheme; `./Notes: today.md` does not) is refused here too and the value
|
|
29
|
+
* stays text. One rule for a link, wherever it sits in the file.
|
|
23
30
|
*/
|
|
24
31
|
function FrontmatterValue({
|
|
25
32
|
value,
|
|
@@ -29,8 +36,9 @@ function FrontmatterValue({
|
|
|
29
36
|
onOpenFile: (href: string) => void;
|
|
30
37
|
}) {
|
|
31
38
|
const match = value.match(FRONTMATTER_LINK_RE);
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
const href = match ? defaultUrlTransform(match[2]) : '';
|
|
40
|
+
if (match && href) {
|
|
41
|
+
const label = match[1];
|
|
34
42
|
return (
|
|
35
43
|
<a
|
|
36
44
|
href={href}
|
|
@@ -100,6 +108,13 @@ interface KbMarkdownViewProps {
|
|
|
100
108
|
* rehype-slug anchor id. Omit it (e.g. in the embed) to hide the buttons.
|
|
101
109
|
*/
|
|
102
110
|
headingLink?: (slug: string) => string;
|
|
111
|
+
/**
|
|
112
|
+
* Resolves a workspace image `src` (`./assets/x.png`) to the URL that serves
|
|
113
|
+
* it, or to the reason it will not be shown. The caller knows the workspace
|
|
114
|
+
* and the file this document is; the view does not. Omit it (the embed) and
|
|
115
|
+
* images render as plain `<img>` tags. See `KbImage` in the pipeline.
|
|
116
|
+
*/
|
|
117
|
+
resolveImage?: KbImageResolver;
|
|
103
118
|
/** Optional container ref (used by the file viewer for deep-link scroll). */
|
|
104
119
|
containerRef?: Ref<HTMLDivElement>;
|
|
105
120
|
/**
|
|
@@ -124,14 +139,15 @@ interface KbMarkdownViewProps {
|
|
|
124
139
|
* frontmatter panel, with navigation injected via `onOpenFile` so it carries no
|
|
125
140
|
* dependency on workspace routing or context.
|
|
126
141
|
*/
|
|
127
|
-
export function KbMarkdownView({ source, onOpenFile, onOpenNodeId, headingLink, containerRef, scroll = true, className }: KbMarkdownViewProps) {
|
|
142
|
+
export function KbMarkdownView({ source, onOpenFile, onOpenNodeId, headingLink, resolveImage, containerRef, scroll = true, className }: KbMarkdownViewProps) {
|
|
128
143
|
const { data: frontmatter, body } = useMemo(() => parseFrontmatter(source), [source]);
|
|
129
144
|
// CommonMark rejects unescaped spaces in link destinations, so a KB link like
|
|
130
145
|
// `[Foo](Some File.md)` would render as plain text. Wrap space-bearing
|
|
131
|
-
// destinations in `<...>` so links to files with spaces resolve.
|
|
146
|
+
// destinations in `<...>` so links to files with spaces resolve. The same
|
|
147
|
+
// rule covers an image's `` tail.
|
|
132
148
|
const normalizedBody = useMemo(() => escapeSpacesInLinkDestinations(body), [body]);
|
|
133
149
|
|
|
134
|
-
const components = useKbMarkdownComponents({ onOpenFile, onOpenNodeId, headingLink });
|
|
150
|
+
const components = useKbMarkdownComponents({ onOpenFile, onOpenNodeId, headingLink, resolveImage });
|
|
135
151
|
|
|
136
152
|
return (
|
|
137
153
|
<div
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState, useCallback, useEffect, useRef } from 'react';
|
|
1
|
+
import { useState, useCallback, useContext, useEffect, useRef } from 'react';
|
|
2
2
|
import { useLocation } from 'react-router-dom';
|
|
3
3
|
import { KbMarkdownView } from './KbMarkdownView';
|
|
4
4
|
import { useAutoGrowTextarea } from '../../hooks/useAutoGrowTextarea';
|
|
@@ -6,9 +6,11 @@ import {
|
|
|
6
6
|
useFileNav,
|
|
7
7
|
useNodeIdNav,
|
|
8
8
|
useCanonicalFileUrl,
|
|
9
|
-
KB_ROUTE_PREFIX,
|
|
10
|
-
resolveRelativePath,
|
|
11
9
|
} from '../../routing/kb-routes';
|
|
10
|
+
import { useRendererWorkspaceId } from './rendererWorkspace';
|
|
11
|
+
import { WorkspaceContext } from '../../state/workspace.context';
|
|
12
|
+
import { markdownLinkForPaste } from '../../utils/pasteLink';
|
|
13
|
+
import { useWorkspaceImageResolver } from '../../hooks/useWorkspaceImageResolver';
|
|
12
14
|
import type { FileRendererProps, RendererSaveState } from './types';
|
|
13
15
|
|
|
14
16
|
/** Decode a URL hash (`#some%20slug`) to its bare slug, tolerating bad escapes. */
|
|
@@ -60,9 +62,9 @@ export function MarkdownRenderer({
|
|
|
60
62
|
onSaveStateChange,
|
|
61
63
|
readOnly = false,
|
|
62
64
|
}: FileRendererProps) {
|
|
63
|
-
//
|
|
65
|
+
// openLink here is the navigating version: clicking a markdown link to a file
|
|
64
66
|
// updates the URL so the route reflects what's on screen.
|
|
65
|
-
const {
|
|
67
|
+
const { openLink } = useFileNav();
|
|
66
68
|
// Shared id-link resolver (resolve-id → openFile, heading preserved) — same
|
|
67
69
|
// implementation the chat citation renderer uses.
|
|
68
70
|
const { openNodeId } = useNodeIdNav();
|
|
@@ -137,9 +139,6 @@ export function MarkdownRenderer({
|
|
|
137
139
|
return () => cancelAnimationFrame(raf);
|
|
138
140
|
}, [location.hash, filePath, value, readOnly]);
|
|
139
141
|
|
|
140
|
-
// Navigate to a workspace file referenced by a relative link. react-markdown
|
|
141
|
-
// percent-encodes spaces in hrefs (`Some%20File.md`), so decode before
|
|
142
|
-
// resolving or the path won't match a real file.
|
|
143
142
|
// Citation deep-link for a heading: the node's canonical URL (its id URL when
|
|
144
143
|
// it's a node, else the path URL) plus the heading's `#slug`. Matches the "copy
|
|
145
144
|
// link to this file" affordance, scoped to a section. Falls back to the current
|
|
@@ -151,23 +150,23 @@ export function MarkdownRenderer({
|
|
|
151
150
|
[canonicalFileUrl, location.pathname],
|
|
152
151
|
);
|
|
153
152
|
|
|
153
|
+
// A link out of the page, resolved against this file by `openLink`: decoded
|
|
154
|
+
// (react-markdown percent-encodes the spaces in `Some File.md`), absolute
|
|
155
|
+
// citation URLs keeping their own branch. The same grammar every other
|
|
156
|
+
// rendered-document surface uses.
|
|
154
157
|
const handleFileLink = useCallback(
|
|
155
|
-
(href: string) =>
|
|
156
|
-
|
|
157
|
-
// links the agent emits) carry their own branch and are resolved by
|
|
158
|
-
// `openFile` directly. Never run them through `resolveRelativePath` — that
|
|
159
|
-
// would treat them as relative to the current file and mangle the path.
|
|
160
|
-
if (href.startsWith(`${KB_ROUTE_PREFIX}/`)) {
|
|
161
|
-
openFile(href);
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
let decoded = href;
|
|
165
|
-
try { decoded = decodeURIComponent(href); } catch { /* leave as-is */ }
|
|
166
|
-
openFile(resolveRelativePath(filePath, decoded));
|
|
167
|
-
},
|
|
168
|
-
[openFile, filePath],
|
|
158
|
+
(href: string) => openLink(href, filePath),
|
|
159
|
+
[openLink, filePath],
|
|
169
160
|
);
|
|
170
161
|
|
|
162
|
+
// An image in the page: the same grammar, but the bytes come from this
|
|
163
|
+
// workspace's raw file route (a plain `<img>` authenticates through the
|
|
164
|
+
// bevel_token cookie), and the URL carries the workspace's image revision,
|
|
165
|
+
// which changes when a teammate replaces a file, so an open tab shows the
|
|
166
|
+
// new picture.
|
|
167
|
+
const workspaceId = useRendererWorkspaceId();
|
|
168
|
+
const resolveImage = useWorkspaceImageResolver(workspaceId, filePath);
|
|
169
|
+
|
|
171
170
|
const save = useCallback(async (): Promise<boolean> => {
|
|
172
171
|
if (readOnly || value === savedValue) return true;
|
|
173
172
|
setSaveState('saving');
|
|
@@ -193,6 +192,31 @@ export function MarkdownRenderer({
|
|
|
193
192
|
onValueChange?.(next);
|
|
194
193
|
}, [onValueChange]);
|
|
195
194
|
|
|
195
|
+
// Pasting a bare workspace path (what Copy path gives) or a URL makes a
|
|
196
|
+
// link, so nobody has to know `[]()` to link a page. Anything else pastes
|
|
197
|
+
// as it always did. Read optionally, so paste adds no workspace-provider
|
|
198
|
+
// requirement of its own; without a `kbDirName` a path pastes as text.
|
|
199
|
+
const kbDirName = useContext(WorkspaceContext)?.kbDirName ?? null;
|
|
200
|
+
const handlePaste = useCallback((e: React.ClipboardEvent<HTMLTextAreaElement>) => {
|
|
201
|
+
const el = e.currentTarget;
|
|
202
|
+
const { selectionStart: start, selectionEnd: end } = el;
|
|
203
|
+
const link = markdownLinkForPaste(
|
|
204
|
+
e.clipboardData.getData('text/plain'),
|
|
205
|
+
kbDirName,
|
|
206
|
+
el.value.slice(start, end),
|
|
207
|
+
);
|
|
208
|
+
if (link === null) return;
|
|
209
|
+
e.preventDefault();
|
|
210
|
+
// `insertText` keeps the paste on the browser's undo stack and fires the
|
|
211
|
+
// usual change; where it is unavailable, splice the buffer directly.
|
|
212
|
+
if (typeof document.execCommand === 'function' && document.execCommand('insertText', false, link)) return;
|
|
213
|
+
const next = el.value.slice(0, start) + link + el.value.slice(end);
|
|
214
|
+
setValue(next);
|
|
215
|
+
onValueChange?.(next);
|
|
216
|
+
const caret = start + link.length;
|
|
217
|
+
requestAnimationFrame(() => textareaRef.current?.setSelectionRange(caret, caret));
|
|
218
|
+
}, [kbDirName, onValueChange]);
|
|
219
|
+
|
|
196
220
|
const handleKeyDown = useCallback((e: React.KeyboardEvent) => {
|
|
197
221
|
if ((e.ctrlKey || e.metaKey) && e.key === 's') {
|
|
198
222
|
e.preventDefault();
|
|
@@ -241,6 +265,7 @@ export function MarkdownRenderer({
|
|
|
241
265
|
onOpenFile={handleFileLink}
|
|
242
266
|
onOpenNodeId={openNodeId}
|
|
243
267
|
headingLink={headingLink}
|
|
268
|
+
resolveImage={resolveImage}
|
|
244
269
|
containerRef={scrollContainerRef}
|
|
245
270
|
// The document column scrolls; this view does not. See the prop's
|
|
246
271
|
// docstring — the embed and the library dialog keep the default.
|
|
@@ -256,6 +281,7 @@ export function MarkdownRenderer({
|
|
|
256
281
|
value={value}
|
|
257
282
|
onChange={handleChange}
|
|
258
283
|
onKeyDown={handleKeyDown}
|
|
284
|
+
onPaste={handlePaste}
|
|
259
285
|
spellCheck={false}
|
|
260
286
|
autoFocus
|
|
261
287
|
/>
|
|
@@ -4,8 +4,9 @@ import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist';
|
|
|
4
4
|
import type { PDFDocumentLoadingTask, PDFDocumentProxy, PDFPageProxy } from 'pdfjs-dist';
|
|
5
5
|
import pdfWorkerUrl from 'pdfjs-dist/build/pdf.worker.min.mjs?url';
|
|
6
6
|
import { Button } from '../../../../shared/components';
|
|
7
|
-
import {
|
|
7
|
+
import { useRendererWorkspaceId } from './rendererWorkspace';
|
|
8
8
|
import { authFetch } from '../../../../lib/api';
|
|
9
|
+
import { rawFileUrl } from '../../services/workspace.api';
|
|
9
10
|
import { DownloadFileButton } from './DownloadFileButton';
|
|
10
11
|
import type { FileRendererProps } from './types';
|
|
11
12
|
|
|
@@ -35,7 +36,7 @@ GlobalWorkerOptions.workerSrc = pdfWorkerUrl;
|
|
|
35
36
|
* `onSave` / `onValueChange` / `readOnly`.
|
|
36
37
|
*/
|
|
37
38
|
export function PdfRenderer({ filePath }: FileRendererProps) {
|
|
38
|
-
const
|
|
39
|
+
const workspaceId = useRendererWorkspaceId();
|
|
39
40
|
const [doc, setDoc] = useState<PDFDocumentProxy | null>(null);
|
|
40
41
|
const [pageNumber, setPageNumber] = useState(1);
|
|
41
42
|
const [error, setError] = useState<string | null>(null);
|
|
@@ -76,9 +77,7 @@ export function PdfRenderer({ filePath }: FileRendererProps) {
|
|
|
76
77
|
let loadingTask: PDFDocumentLoadingTask | null = null;
|
|
77
78
|
(async () => {
|
|
78
79
|
try {
|
|
79
|
-
const res = await authFetch(
|
|
80
|
-
`/api/workspace/${workspaceId}/file/raw?path=${encodeURIComponent(filePath)}`,
|
|
81
|
-
);
|
|
80
|
+
const res = await authFetch(rawFileUrl(workspaceId, filePath));
|
|
82
81
|
if (cancelled) return;
|
|
83
82
|
if (!res.ok) {
|
|
84
83
|
setError(`Failed to load PDF (HTTP ${res.status})`);
|