@bevel-software/platform-core-frontend 0.4.1 → 0.5.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/package.json +5 -3
- package/src/core/CoreAppShell.tsx +195 -56
- package/src/core/__tests__/AppChrome.test.tsx +125 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +37 -2
- package/src/core/__tests__/bootstrap.test.ts +63 -0
- package/src/core/bootstrap.ts +73 -0
- package/src/core/events.ts +12 -0
- package/src/core/registry.ts +58 -9
- package/src/index.css +100 -11
- package/src/index.ts +24 -23
- package/src/lib/utils.ts +93 -117
- package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +281 -0
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +166 -1
- package/src/modules/access/api.ts +49 -0
- package/src/modules/access/components/ManageAccessDialog.tsx +786 -481
- package/src/modules/access/hooks/useFileAccess.ts +1 -1
- package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +86 -0
- package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +17 -1
- package/src/modules/admin/__tests__/admin.unread.test.tsx +61 -0
- package/src/modules/admin/components/AdminRolesPage.tsx +44 -38
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +11 -10
- package/src/modules/admin/components/UserAccountsPage.tsx +36 -28
- package/src/modules/admin/state/admin.context.tsx +15 -6
- package/src/modules/auth/components/AccountPage.tsx +11 -11
- package/src/modules/auth/components/LoginScreen.tsx +12 -12
- package/src/modules/auth/services/sso.ts +47 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +277 -0
- package/src/modules/change-requests/__tests__/author.test.ts +48 -0
- package/src/modules/change-requests/__tests__/conflict.test.ts +73 -0
- package/src/modules/change-requests/__tests__/diff.test.ts +134 -0
- package/src/modules/change-requests/__tests__/propose.test.ts +93 -0
- package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +72 -0
- package/src/modules/change-requests/change-requests.css +22 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +277 -0
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +713 -0
- package/src/modules/change-requests/components/ConflictHelp.tsx +47 -0
- package/src/modules/change-requests/components/CrFileTree.tsx +398 -0
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +168 -0
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +236 -0
- package/src/modules/change-requests/hooks/useCrFileDiffs.ts +79 -0
- package/src/modules/change-requests/hooks/useFileOnBranch.ts +80 -0
- package/src/modules/change-requests/services/change-requests.api.ts +45 -0
- package/src/modules/change-requests/services/propose.api.ts +162 -0
- package/src/modules/change-requests/utils/author.ts +47 -0
- package/src/modules/change-requests/utils/conflict.ts +38 -0
- package/src/modules/change-requests/utils/diff.ts +80 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +27 -18
- package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +36 -83
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +5 -5
- package/src/modules/git/__tests__/PullRequestsForMe.test.tsx +147 -0
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +2 -8
- package/src/modules/git/components/BranchSwitcher.tsx +68 -31
- package/src/modules/git/components/DiffView.tsx +4 -4
- package/src/modules/git/components/FileComparisonPanel.tsx +20 -20
- package/src/modules/git/components/FileHistoryPanel.tsx +71 -107
- package/src/modules/git/components/PullNeededBanner.tsx +6 -13
- package/src/modules/git/components/PullRequestsForMe.tsx +71 -36
- package/src/modules/git/components/UnifiedDiffView.tsx +4 -4
- package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +2 -2
- package/src/modules/git/hooks/useGitState.ts +15 -14
- package/src/modules/git/services/__tests__/error-messages.test.ts +4 -4
- package/src/modules/git/services/error-messages.ts +7 -7
- package/src/modules/git/services/git.api.ts +17 -11
- package/src/modules/git/services/pr-prompts.ts +2 -2
- package/src/modules/git/state/git.context.ts +10 -1
- package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +224 -0
- package/src/modules/layout/__tests__/SidebarToggle.test.tsx +242 -0
- package/src/modules/layout/__tests__/breakpoints.test.ts +56 -0
- package/src/modules/layout/breakpoints.ts +6 -0
- package/src/modules/layout/components/AppLayout.tsx +17 -5
- package/src/modules/layout/components/DemoBanner.tsx +10 -1
- package/src/modules/layout/components/MaintenanceOverlay.tsx +3 -3
- package/src/modules/layout/components/MobileChatLayout.tsx +31 -26
- package/src/modules/layout/components/ResizableThreePaneLayout.tsx +59 -24
- package/src/modules/layout/components/SidebarFrame.tsx +317 -0
- package/src/modules/layout/components/SidebarToggle.tsx +86 -0
- package/src/modules/layout/components/SlideOverlay.tsx +1 -1
- package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +40 -2
- package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +19 -3
- package/src/modules/layout/state/sidebar.ts +200 -0
- package/src/modules/library/__tests__/AddToGroupDialog.test.tsx +313 -0
- package/src/modules/library/__tests__/ChangeRequestDock.test.tsx +84 -0
- package/src/modules/library/__tests__/GroupJoinRequests.test.tsx +178 -0
- package/src/modules/library/__tests__/GroupPage.test.tsx +479 -0
- package/src/modules/library/__tests__/GroupsIndexPage.test.tsx +283 -0
- package/src/modules/library/__tests__/GroupsSidebar.contextmenu.test.tsx +175 -0
- package/src/modules/library/__tests__/GroupsSidebar.locked.test.tsx +96 -0
- package/src/modules/library/__tests__/GroupsSidebar.test.tsx +142 -0
- package/src/modules/library/__tests__/GroupsSidebarMenu.test.tsx +142 -0
- package/src/modules/library/__tests__/LibraryCard.test.tsx +149 -0
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +378 -0
- package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +347 -0
- package/src/modules/library/__tests__/LockedGroupView.test.tsx +203 -0
- package/src/modules/library/__tests__/NewGroupDialog.test.tsx +114 -0
- package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +177 -0
- package/src/modules/library/__tests__/SkillPage.test.tsx +1063 -0
- package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +259 -0
- package/src/modules/library/__tests__/ToolLogo.test.tsx +63 -0
- package/src/modules/library/__tests__/ToolPage.test.tsx +315 -0
- package/src/modules/library/__tests__/ToolSharePanel.test.tsx +36 -0
- package/src/modules/library/__tests__/ToolVarRow.test.tsx +260 -0
- package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +197 -0
- package/src/modules/library/__tests__/auth-harness.tsx +37 -0
- package/src/modules/library/__tests__/oauth-fragment.test.ts +48 -0
- package/src/modules/library/__tests__/status.test.ts +113 -20
- package/src/modules/library/__tests__/useSkillDetail.test.tsx +102 -0
- package/src/modules/library/__tests__/useToolPage.test.tsx +146 -0
- package/src/modules/library/components/AccessRequestsBanner.tsx +101 -0
- package/src/modules/library/components/AddToGroupDialog.tsx +115 -0
- package/src/modules/library/components/ChangeRequestDock.tsx +52 -28
- package/src/modules/library/components/DeleteGroupDialog.tsx +87 -0
- package/src/modules/library/components/GroupIndexRow.tsx +63 -0
- package/src/modules/library/components/GroupJoinRequests.tsx +56 -0
- package/src/modules/library/components/GroupPage.tsx +373 -0
- package/src/modules/library/components/GroupsIndexPage.tsx +222 -0
- package/src/modules/library/components/GroupsSidebar.tsx +338 -0
- package/src/modules/library/components/GroupsSidebarMenu.tsx +160 -0
- package/src/modules/library/components/LibraryCard.tsx +123 -102
- package/src/modules/library/components/LibraryLayout.tsx +344 -0
- package/src/modules/library/components/LibraryPage.tsx +111 -227
- package/src/modules/library/components/LockGlyph.tsx +31 -0
- package/src/modules/library/components/LockedGroupView.tsx +159 -0
- package/src/modules/library/components/ManagedGroupRequests.tsx +70 -0
- package/src/modules/library/components/NewGroupDialog.tsx +112 -0
- package/src/modules/library/components/NewSkillPanel.tsx +151 -0
- package/src/modules/library/components/PageActions.tsx +156 -0
- package/src/modules/library/components/PendingSkillReview.tsx +63 -0
- package/src/modules/library/components/PersonalAddDialog.tsx +88 -0
- package/src/modules/library/components/PersonalGroupPage.tsx +125 -0
- package/src/modules/library/components/StatusDot.tsx +25 -0
- package/src/modules/library/components/ToolLogo.tsx +171 -0
- package/src/modules/library/components/group-page-parts.tsx +419 -0
- package/src/modules/library/components/skill-page/SkillFileEditor.tsx +134 -0
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +117 -0
- package/src/modules/library/components/skill-page/SkillFileTabs.tsx +112 -0
- package/src/modules/library/components/skill-page/SkillPage.tsx +673 -0
- package/src/modules/library/components/skill-page/tab-ids.ts +33 -0
- package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +175 -0
- package/src/modules/library/components/tool-page/ToolPage.tsx +228 -0
- package/src/modules/library/components/tool-page/ToolSharePanel.tsx +45 -0
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +289 -0
- package/src/modules/library/hooks/useJoinRequests.ts +114 -0
- package/src/modules/library/hooks/useLibraryData.ts +134 -119
- package/src/modules/library/hooks/useSkillDetail.ts +119 -74
- package/src/modules/library/hooks/useToolPage.ts +145 -0
- package/src/modules/library/library.css +33 -245
- package/src/modules/library/routes/LibraryRoutes.tsx +134 -0
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +74 -0
- package/src/modules/library/routes/library-paths.ts +191 -0
- package/src/modules/library/services/groups.api.ts +189 -0
- package/src/modules/library/services/library.api.ts +291 -164
- package/src/modules/library/services/tools.api.ts +60 -0
- package/src/modules/library/state/library-context.ts +22 -0
- package/src/modules/library/state/library-data.tsx +223 -0
- package/src/modules/library/state/toast.context.ts +32 -0
- package/src/modules/library/state/toast.tsx +84 -42
- package/src/modules/library/utils/clipboard.ts +33 -0
- package/src/modules/library/utils/group-summary.ts +68 -0
- package/src/modules/library/utils/names.ts +30 -0
- package/src/modules/library/utils/navigate-external.ts +15 -0
- package/src/modules/library/utils/oauth-fragment.ts +32 -0
- package/src/modules/library/utils/personal-group.ts +36 -0
- package/src/modules/library/utils/status.ts +108 -25
- package/src/modules/library/utils/toast-duration.ts +16 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +533 -0
- package/src/modules/onboarding/agent-clients.ts +48 -0
- package/src/modules/onboarding/components/ConnectAgentPill.tsx +133 -0
- package/src/modules/onboarding/components/RootLanding.tsx +54 -0
- package/src/modules/onboarding/components/WelcomePage.tsx +364 -0
- package/src/modules/onboarding/paths.ts +9 -0
- package/src/modules/onboarding/state/onboarding.ts +191 -0
- package/src/modules/pr/components/OpenChangeRequestDialog.tsx +10 -10
- package/src/modules/pr/services/pr-approvals.api.ts +19 -0
- package/src/modules/pr/services/pr-cancel.api.ts +11 -0
- package/src/modules/review/components/BinaryChangePlaceholder.tsx +3 -3
- package/src/modules/review/components/DiffViewer.tsx +4 -4
- package/src/modules/review/components/MarkdownDiffViewer.tsx +84 -26
- package/src/modules/review/components/ReviewFileRow.tsx +10 -10
- package/src/modules/review/components/ReviewPanel.tsx +49 -17
- package/src/modules/review/components/ReviewPanelSurface.tsx +1 -1
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +122 -0
- package/src/modules/review/hooks/__tests__/useReviewState.test.ts +1 -1
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +273 -171
- package/src/modules/secrets-vault/components/SecretsPage.tsx +147 -110
- package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +109 -92
- package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +35 -4
- package/src/modules/secrets-vault/services/connect.api.ts +24 -3
- package/src/modules/settings/components/DeploymentPage.tsx +90 -0
- package/src/modules/settings/components/SettingsLayout.tsx +135 -0
- package/src/modules/settings/components/SettingsNav.tsx +114 -0
- package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +110 -0
- package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +249 -0
- package/src/modules/settings/settings-nav-items.tsx +166 -0
- package/src/modules/setup/__tests__/setup.test.tsx +540 -0
- package/src/modules/setup/components/SetupGate.tsx +67 -0
- package/src/modules/setup/components/SetupScreen.tsx +573 -0
- package/src/modules/setup/services/setup.api.ts +106 -0
- package/src/modules/setup/utils/git-host.ts +34 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +38 -15
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +50 -50
- package/src/modules/toolbar/components/ProfileMenu.tsx +294 -0
- package/src/modules/toolbar/components/Toolbar.tsx +56 -54
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +176 -122
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +252 -77
- package/src/modules/tools/ToolsExplorerPage.tsx +45 -40
- package/src/modules/workspace/__tests__/design-system-parity.test.ts +133 -0
- package/src/modules/workspace/__tests__/testFixtures.ts +2 -0
- package/src/modules/workspace/components/EditorTabs.tsx +82 -50
- package/src/modules/workspace/components/FileExplorer.tsx +413 -189
- package/src/modules/workspace/components/FilePaneCard.tsx +53 -0
- package/src/modules/workspace/components/FileRoute.tsx +89 -84
- package/src/modules/workspace/components/FileViewer.tsx +700 -294
- package/src/modules/workspace/components/KbDocumentShell.tsx +138 -0
- package/src/modules/workspace/components/KbFileRail.tsx +128 -0
- package/src/modules/workspace/components/KbPageHeader.tsx +390 -0
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +87 -3
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +293 -39
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +1 -16
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +462 -44
- package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +84 -0
- package/src/modules/workspace/components/__tests__/KbFileRail.test.tsx +83 -0
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +192 -0
- package/src/modules/workspace/components/renderers/CopyAnchorButton.tsx +64 -0
- package/src/modules/workspace/components/renderers/CsvRenderer.tsx +8 -8
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +18 -9
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +14 -14
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +2 -2
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +31 -165
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +18 -5
- package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +27 -10
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +2 -2
- package/src/modules/workspace/components/renderers/TextRenderer.tsx +11 -5
- package/src/modules/workspace/components/renderers/ToolForm.tsx +24 -24
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +27 -27
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -11
- package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +66 -0
- package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +17 -1
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +1 -1
- package/src/modules/workspace/components/renderers/__tests__/MermaidDiagram.test.tsx +58 -0
- package/src/modules/workspace/components/renderers/__tests__/lazyRenderer.test.tsx +68 -0
- package/src/modules/workspace/components/renderers/__tests__/rendererLayout.test.ts +64 -0
- package/src/modules/workspace/components/renderers/__tests__/sanitizeDocxHtml.test.ts +0 -0
- package/src/modules/workspace/components/renderers/chunk-boundary.tsx +71 -0
- package/src/modules/workspace/components/renderers/index.ts +78 -2
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +241 -0
- package/src/modules/workspace/components/renderers/lazyRenderer.tsx +59 -0
- package/src/modules/workspace/components/renderers/sanitizeDocxHtml.ts +91 -0
- package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +59 -0
- package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +237 -0
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +185 -0
- package/src/modules/workspace/hooks/useAutoGrowTextarea.ts +30 -0
- package/src/modules/workspace/hooks/useLastCommit.ts +66 -0
- package/src/modules/workspace/hooks/useLinksOut.ts +56 -0
- package/src/modules/workspace/hooks/useOpenChangeRequests.ts +20 -0
- package/src/modules/workspace/hooks/useWorkspaceState.ts +123 -14
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +1 -1
- package/src/modules/workspace/services/workspace.api.ts +9 -2
- package/src/modules/workspace/state/open-change-requests.context.ts +35 -0
- package/src/modules/workspace/state/open-change-requests.tsx +185 -0
- package/src/modules/workspace/state/workspace.context.ts +9 -0
- package/src/modules/workspace/utils/__tests__/diff.test.ts +87 -0
- package/src/modules/workspace/utils/diff.ts +130 -53
- package/src/modules/workspace/utils/fileTree.ts +7 -4
- package/src/modules/workspace/workspace.css +28 -0
- package/src/shared/components/Badge.tsx +62 -0
- package/src/shared/components/Banner.tsx +58 -0
- package/src/shared/components/Button.tsx +90 -0
- package/src/shared/components/Dialog.tsx +6 -6
- package/src/shared/components/Field.tsx +45 -0
- package/src/shared/components/IconButton.tsx +74 -0
- package/src/shared/components/ListRow.tsx +96 -0
- package/src/shared/components/Menu.tsx +88 -0
- package/src/shared/components/PageShell.tsx +8 -5
- package/src/shared/components/Surface.tsx +86 -0
- package/src/shared/components/__tests__/primitives.test.tsx +333 -0
- package/src/shared/components/index.ts +48 -0
- package/src/shared/components/useDismissableMenu.ts +71 -0
- package/src/shared/theme/__tests__/accent-contrast.test.ts +84 -0
- package/src/shared/theme/index.css +12 -0
- package/src/shared/theme/measure.ts +64 -0
- package/src/shared/theme/shadows.css +34 -0
- package/src/shared/theme/tokens.css +193 -0
- package/src/test-setup.ts +9 -0
- package/src/modules/access/components/AccessRestrictedBanner.tsx +0 -31
- package/src/modules/access/components/NodeOwnersBanner.tsx +0 -30
- package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +0 -82
- package/src/modules/git/components/ProtectedBranchBanner.tsx +0 -42
- package/src/modules/library/__tests__/DetailDialog.test.tsx +0 -200
- package/src/modules/library/__tests__/diff.test.ts +0 -62
- package/src/modules/library/__tests__/loadout.test.tsx +0 -72
- package/src/modules/library/components/CompareView.tsx +0 -357
- package/src/modules/library/components/DetailDialog.tsx +0 -566
- package/src/modules/library/components/GearIcon.tsx +0 -12
- package/src/modules/library/components/LoadoutSidebar.tsx +0 -156
- package/src/modules/library/components/StatusGem.tsx +0 -21
- package/src/modules/library/components/SuggestChange.tsx +0 -171
- package/src/modules/library/components/particles.ts +0 -50
- package/src/modules/library/state/loadout.tsx +0 -129
- package/src/modules/library/utils/diff.ts +0 -102
- package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +0 -93
- package/src/modules/pr/__tests__/PrCancelButton.test.tsx +0 -158
- package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +0 -44
- package/src/modules/pr/__tests__/PrMergeButton.test.tsx +0 -360
- package/src/modules/pr/__tests__/bucketize-comments.test.ts +0 -85
- package/src/modules/pr/__tests__/parsePatch.test.ts +0 -104
- package/src/modules/pr/__tests__/usePrViewerState.test.ts +0 -72
- package/src/modules/pr/components/PrApprovalBadge.tsx +0 -80
- package/src/modules/pr/components/PrCancelButton.tsx +0 -99
- package/src/modules/pr/components/PrCancelConfirmDialog.tsx +0 -119
- package/src/modules/pr/components/PrCommentComposer.tsx +0 -92
- package/src/modules/pr/components/PrCommentThread.tsx +0 -168
- package/src/modules/pr/components/PrCommentsPanel.tsx +0 -143
- package/src/modules/pr/components/PrDiffPane.tsx +0 -425
- package/src/modules/pr/components/PrFileRow.tsx +0 -164
- package/src/modules/pr/components/PrFilesList.tsx +0 -53
- package/src/modules/pr/components/PrHeader.tsx +0 -45
- package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +0 -58
- package/src/modules/pr/components/PrMergeButton.tsx +0 -268
- package/src/modules/pr/components/PrMergeConfirmDialog.tsx +0 -112
- package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +0 -110
- package/src/modules/pr/components/PrViewer.tsx +0 -364
- package/src/modules/pr/hooks/usePrViewerState.ts +0 -150
- package/src/modules/pr/state/pr-viewer.context.ts +0 -34
- package/src/modules/pr/utils/bucketize-comments.ts +0 -55
- package/src/modules/pr/utils/parsePatch.ts +0 -57
- package/src/modules/toolbar/components/AdminMenu.tsx +0 -271
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { createRef } from 'react';
|
|
4
|
+
import { KbDocumentShell } from '../KbDocumentShell';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The shell's job is a measure and a scroll contract. Both are invisible to a
|
|
8
|
+
* headless DOM's layout engine, so these tests assert the STRUCTURE that
|
|
9
|
+
* produces them — which track the children land in, and which node the ref
|
|
10
|
+
* lands on — rather than computed pixels.
|
|
11
|
+
*/
|
|
12
|
+
describe('KbDocumentShell', () => {
|
|
13
|
+
it('renders children inside a centred, measured column', () => {
|
|
14
|
+
render(
|
|
15
|
+
<KbDocumentShell>
|
|
16
|
+
<p>The document</p>
|
|
17
|
+
</KbDocumentShell>,
|
|
18
|
+
);
|
|
19
|
+
const column = screen.getByText('The document').parentElement!;
|
|
20
|
+
expect(column.className).toContain('mx-auto');
|
|
21
|
+
expect(column.className).toContain('max-w-[880px]');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('opens a second track and widens the measure when a rail is given', () => {
|
|
25
|
+
render(
|
|
26
|
+
<KbDocumentShell rail={<p>About this file</p>}>
|
|
27
|
+
<p>The document</p>
|
|
28
|
+
</KbDocumentShell>,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
expect(screen.getByText('About this file')).toBeInTheDocument();
|
|
32
|
+
// The article and the rail are siblings in one grid, not nested.
|
|
33
|
+
const article = screen.getByText('The document').closest('article')!;
|
|
34
|
+
const aside = screen.getByText('About this file').closest('aside')!;
|
|
35
|
+
expect(article.parentElement).toBe(aside.parentElement);
|
|
36
|
+
expect(article.parentElement!.className).toContain('max-w-[980px]');
|
|
37
|
+
expect(article.parentElement!.className).toContain('grid');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('uses one narrow track when there is no rail', () => {
|
|
41
|
+
const { container } = render(
|
|
42
|
+
<KbDocumentShell>
|
|
43
|
+
<p>The document</p>
|
|
44
|
+
</KbDocumentShell>,
|
|
45
|
+
);
|
|
46
|
+
expect(container.querySelector('aside')).toBeNull();
|
|
47
|
+
expect(screen.getByText('The document').parentElement!.className).not.toContain('grid');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('drops the measure and the bottom rhythm in full-bleed', () => {
|
|
51
|
+
render(
|
|
52
|
+
<KbDocumentShell variant="full-bleed">
|
|
53
|
+
<p>A PDF</p>
|
|
54
|
+
</KbDocumentShell>,
|
|
55
|
+
);
|
|
56
|
+
const box = screen.getByText('A PDF').parentElement!;
|
|
57
|
+
expect(box.className).not.toContain('max-w-[880px]');
|
|
58
|
+
expect(box.className).not.toContain('pb-[110px]');
|
|
59
|
+
// A definite height instead, so an `h-full` iframe inside gets real pixels.
|
|
60
|
+
expect(box.className).toContain('h-full');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// The regression this file exists for. `editorContainerRef` carries a
|
|
64
|
+
// capture-phase scroll listener that is the file lock's ONLY activity signal
|
|
65
|
+
// for someone who is reading rather than typing. Scroll events do not
|
|
66
|
+
// bubble, so a ref on an element nested inside the scroller never fires —
|
|
67
|
+
// and nothing type-errors when that happens; locks just silently drop out
|
|
68
|
+
// from under readers after two minutes.
|
|
69
|
+
it.each(['prose', 'full-bleed'] as const)(
|
|
70
|
+
'lands scrollRef on the element that scrolls (%s)',
|
|
71
|
+
(variant) => {
|
|
72
|
+
const ref = createRef<HTMLDivElement>();
|
|
73
|
+
render(
|
|
74
|
+
<KbDocumentShell variant={variant} scrollRef={ref}>
|
|
75
|
+
<p>Body</p>
|
|
76
|
+
</KbDocumentShell>,
|
|
77
|
+
);
|
|
78
|
+
expect(ref.current).toBe(screen.getByTestId('kb-document-shell'));
|
|
79
|
+
expect(ref.current!.className).toContain('overflow-auto');
|
|
80
|
+
// And the body really is a descendant of it, so capture reaches the ref.
|
|
81
|
+
expect(ref.current!.contains(screen.getByText('Body'))).toBe(true);
|
|
82
|
+
},
|
|
83
|
+
);
|
|
84
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { KbFileRail, type KbFileRailProps } from '../KbFileRail';
|
|
5
|
+
|
|
6
|
+
const LONG_PATH =
|
|
7
|
+
'knowledge-base/Knowledge/Engineering/Architecture/Invariants/A-Very-Long-Node-Name-Indeed.md';
|
|
8
|
+
|
|
9
|
+
function renderRail(overrides: Partial<KbFileRailProps> = {}) {
|
|
10
|
+
const props: KbFileRailProps = {
|
|
11
|
+
path: 'knowledge-base/Knowledge/Invariant.md',
|
|
12
|
+
charCount: 4218,
|
|
13
|
+
lastCommit: { author: 'Ali', relative: '3d ago' },
|
|
14
|
+
owners: { roles: ['Architect'], users: [] },
|
|
15
|
+
linksOut: [{ label: 'NodeType.md', target: '../NodeTypes/NodeType.md' }],
|
|
16
|
+
onOpen: vi.fn(),
|
|
17
|
+
...overrides,
|
|
18
|
+
};
|
|
19
|
+
return { props, ...render(<KbFileRail {...props} />) };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('KbFileRail', () => {
|
|
23
|
+
it('states where the file is, who touched it and who it is for', () => {
|
|
24
|
+
renderRail();
|
|
25
|
+
expect(screen.getByText('Path')).toBeInTheDocument();
|
|
26
|
+
expect(screen.getByText('knowledge-base/Knowledge/Invariant.md')).toBeInTheDocument();
|
|
27
|
+
expect(screen.getByText('Edited')).toBeInTheDocument();
|
|
28
|
+
expect(screen.getByText(/3d ago by Ali/)).toBeInTheDocument();
|
|
29
|
+
expect(screen.getByText('Access')).toBeInTheDocument();
|
|
30
|
+
expect(screen.getByText('Architect')).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// The rail never shows a row it cannot fill. A metadata panel that prints
|
|
34
|
+
// "—" for half its rows teaches people to stop reading it.
|
|
35
|
+
it('omits the character count entirely when it is unknowable', () => {
|
|
36
|
+
renderRail({ charCount: null });
|
|
37
|
+
expect(screen.queryByText('Characters')).not.toBeInTheDocument();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// "Characters", not "Size": `openFileContent` is a string, so its length is
|
|
41
|
+
// UTF-16 code units, and the rail will not print a byte figure it cannot
|
|
42
|
+
// compute.
|
|
43
|
+
it('labels the count Characters and never claims a byte size', () => {
|
|
44
|
+
renderRail({ charCount: 4218 });
|
|
45
|
+
expect(screen.getByText('Characters')).toBeInTheDocument();
|
|
46
|
+
// Grouped through the runner's own locale, not a hard-coded `4,218`: the
|
|
47
|
+
// rail calls `toLocaleString()`, so an en-DE machine renders `4.218` and a
|
|
48
|
+
// literal would fail there while the component is perfectly correct.
|
|
49
|
+
expect(screen.getByText((4218).toLocaleString())).toBeInTheDocument();
|
|
50
|
+
expect(screen.queryByText('Size')).not.toBeInTheDocument();
|
|
51
|
+
expect(screen.queryByText(/KB/)).not.toBeInTheDocument();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('omits Edited when there is no commit to name', () => {
|
|
55
|
+
renderRail({ lastCommit: null });
|
|
56
|
+
expect(screen.queryByText('Edited')).not.toBeInTheDocument();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('omits Access when nobody owns the path', () => {
|
|
60
|
+
renderRail({ owners: { roles: [], users: [] } });
|
|
61
|
+
expect(screen.queryByText('Access')).not.toBeInTheDocument();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('renders no Links out section when the document links nowhere', () => {
|
|
65
|
+
renderRail({ linksOut: [] });
|
|
66
|
+
expect(screen.queryByText('Links out')).not.toBeInTheDocument();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('opens a link with the raw target the caller resolves', async () => {
|
|
70
|
+
const user = userEvent.setup();
|
|
71
|
+
const { props } = renderRail();
|
|
72
|
+
await user.click(screen.getByRole('button', { name: 'NodeType.md' }));
|
|
73
|
+
expect(props.onOpen).toHaveBeenCalledWith('../NodeTypes/NodeType.md');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// A truncated path is unusable for the one thing anyone copies a path for.
|
|
77
|
+
it('wraps a long path rather than truncating it', () => {
|
|
78
|
+
renderRail({ path: LONG_PATH });
|
|
79
|
+
const value = screen.getByText(LONG_PATH);
|
|
80
|
+
expect(value.className).toContain('break-all');
|
|
81
|
+
expect(value.className).not.toContain('truncate');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { render, screen, act, fireEvent } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { KbPageHeader, type KbPageHeaderProps } from '../KbPageHeader';
|
|
5
|
+
|
|
6
|
+
function renderHeader(overrides: Partial<KbPageHeaderProps> = {}) {
|
|
7
|
+
const props: KbPageHeaderProps = {
|
|
8
|
+
path: 'knowledge-base/Knowledge/Invariant.md',
|
|
9
|
+
canWrite: true,
|
|
10
|
+
editMode: false,
|
|
11
|
+
entering: false,
|
|
12
|
+
proposeMode: false,
|
|
13
|
+
proposalBusy: false,
|
|
14
|
+
onPropose: vi.fn(),
|
|
15
|
+
onSendProposal: vi.fn(),
|
|
16
|
+
onDiscardProposal: vi.fn(),
|
|
17
|
+
lockedBy: null,
|
|
18
|
+
historyAvailable: true,
|
|
19
|
+
isDirty: false,
|
|
20
|
+
waitingOnAgentUpdate: false,
|
|
21
|
+
isReviewingPending: false,
|
|
22
|
+
activeTab: 'content',
|
|
23
|
+
onEdit: vi.fn(),
|
|
24
|
+
onDone: vi.fn(),
|
|
25
|
+
onOpenHistory: vi.fn(),
|
|
26
|
+
onShare: vi.fn(),
|
|
27
|
+
onCopyPage: vi.fn(async () => true),
|
|
28
|
+
onCopyLink: vi.fn(async () => true),
|
|
29
|
+
...overrides,
|
|
30
|
+
};
|
|
31
|
+
return { props, ...render(<KbPageHeader {...props} />) };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe('KbPageHeader', () => {
|
|
35
|
+
it('leads with the basename, minus a known extension', () => {
|
|
36
|
+
renderHeader();
|
|
37
|
+
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Invariant');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('leaves an unknown extension alone', () => {
|
|
41
|
+
renderHeader({ path: 'Knowledge/roles.unknownext' });
|
|
42
|
+
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('roles.unknownext');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('shows the name verbatim for a file with no extension', () => {
|
|
46
|
+
renderHeader({ path: 'Knowledge/LICENSE' });
|
|
47
|
+
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('LICENSE');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('opens Manage access from Share, and offers the link behind the chevron', async () => {
|
|
51
|
+
const user = userEvent.setup();
|
|
52
|
+
const { props } = renderHeader();
|
|
53
|
+
|
|
54
|
+
await user.click(screen.getByRole('button', { name: 'Share' }));
|
|
55
|
+
expect(props.onShare).toHaveBeenCalled();
|
|
56
|
+
|
|
57
|
+
await user.click(screen.getByRole('button', { name: 'More sharing options' }));
|
|
58
|
+
expect(screen.getByRole('menuitem', { name: /Manage access/ })).toBeInTheDocument();
|
|
59
|
+
expect(screen.getByRole('menuitem', { name: /Copy link to this page/ })).toBeInTheDocument();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// This page shares ONE thing. "Share the whole folder" was one click from
|
|
63
|
+
// handing over everything in the folder, with nothing on screen showing what
|
|
64
|
+
// "everything" was; it lives on the folder's own tree row now.
|
|
65
|
+
it('does not offer to share the whole folder', async () => {
|
|
66
|
+
const user = userEvent.setup();
|
|
67
|
+
renderHeader();
|
|
68
|
+
await user.click(screen.getByRole('button', { name: 'More sharing options' }));
|
|
69
|
+
expect(screen.queryByRole('menuitem', { name: /whole folder/i })).not.toBeInTheDocument();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// `canWrite` is `boolean | null`, and null means "not known yet". Treating it
|
|
73
|
+
// as false would flicker the button out on every file open.
|
|
74
|
+
it('hides Edit only on a hard false. Null still renders it', () => {
|
|
75
|
+
const { unmount } = renderHeader({ canWrite: false });
|
|
76
|
+
expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument();
|
|
77
|
+
unmount();
|
|
78
|
+
|
|
79
|
+
renderHeader({ canWrite: null });
|
|
80
|
+
expect(screen.getByRole('button', { name: 'Edit' })).toBeInTheDocument();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('disables Edit while someone else holds the lock and names the holder', () => {
|
|
84
|
+
renderHeader({ lockedBy: 'Ali Raza' });
|
|
85
|
+
const edit = screen.getByRole('button', { name: 'Edit' });
|
|
86
|
+
expect(edit).toBeDisabled();
|
|
87
|
+
expect(edit).toHaveAttribute('title', 'Locked by Ali Raza');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('swaps Edit for Done in edit mode', () => {
|
|
91
|
+
renderHeader({ editMode: true });
|
|
92
|
+
expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument();
|
|
93
|
+
expect(screen.getByRole('button', { name: 'Done' })).toBeInTheDocument();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// The pairing FileViewer.test.tsx already asserts: the review badge and the
|
|
97
|
+
// button's absence in the same case.
|
|
98
|
+
it('renders the review badge and no Edit while a pending agent update is under review', () => {
|
|
99
|
+
renderHeader({ isReviewingPending: true });
|
|
100
|
+
expect(screen.getByText('Reviewing agent update')).toBeInTheDocument();
|
|
101
|
+
expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('renders the Unsaved and Agent-update badges independently', () => {
|
|
105
|
+
const { unmount } = renderHeader({ isDirty: true });
|
|
106
|
+
expect(screen.getByText('Unsaved')).toBeInTheDocument();
|
|
107
|
+
expect(screen.queryByText('Agent update waiting')).not.toBeInTheDocument();
|
|
108
|
+
unmount();
|
|
109
|
+
|
|
110
|
+
renderHeader({ waitingOnAgentUpdate: true });
|
|
111
|
+
expect(screen.getByText('Agent update waiting')).toBeInTheDocument();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('offers the whole overflow behind ⋯', async () => {
|
|
115
|
+
const user = userEvent.setup();
|
|
116
|
+
renderHeader();
|
|
117
|
+
await user.click(screen.getByRole('button', { name: 'More actions' }));
|
|
118
|
+
expect(screen.getByRole('menuitem', { name: /Version history/ })).toBeInTheDocument();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Copying a reference to this page is one errand, and Share owns it. Two
|
|
122
|
+
// menus offering near-identical copies is how someone pastes the wrong one.
|
|
123
|
+
it('does not repeat Copy path in the overflow. Share owns copying a reference', async () => {
|
|
124
|
+
const user = userEvent.setup();
|
|
125
|
+
renderHeader();
|
|
126
|
+
await user.click(screen.getByRole('button', { name: 'More actions' }));
|
|
127
|
+
expect(screen.queryByRole('menuitem', { name: /Copy path/i })).not.toBeInTheDocument();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Version history is the whole menu now, so git not being ready leaves
|
|
131
|
+
// nothing behind ⋯ — and the trigger goes with it rather than opening onto
|
|
132
|
+
// an empty panel.
|
|
133
|
+
it('drops the ⋯ trigger entirely when git is not ready', () => {
|
|
134
|
+
renderHeader({ historyAvailable: false });
|
|
135
|
+
expect(screen.queryByRole('button', { name: 'More actions' })).not.toBeInTheDocument();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// A copy that fails must say so — `navigator.clipboard` rejects outright on
|
|
139
|
+
// a non-secure origin, and a silent no-op is the worst possible answer.
|
|
140
|
+
it('confirms a copy on the control that was clicked', async () => {
|
|
141
|
+
const user = userEvent.setup();
|
|
142
|
+
renderHeader();
|
|
143
|
+
await user.click(screen.getByRole('button', { name: 'Copy page as Markdown' }));
|
|
144
|
+
expect(await screen.findByRole('button', { name: 'Copied' })).toBeInTheDocument();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('reports a failed copy rather than swallowing it', async () => {
|
|
148
|
+
const user = userEvent.setup();
|
|
149
|
+
renderHeader({ onCopyPage: vi.fn(async () => false) });
|
|
150
|
+
await user.click(screen.getByRole('button', { name: 'Copy page as Markdown' }));
|
|
151
|
+
expect(await screen.findByRole('button', { name: "Couldn't copy" })).toBeInTheDocument();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Copy link's confirmation is the ROW, and the row is inside the menu — so
|
|
155
|
+
// the menu has to outlive the copy. Closing it first would leave the one
|
|
156
|
+
// action on this page with no answer at all.
|
|
157
|
+
it('confirms a copied link on the row, before the menu goes away', async () => {
|
|
158
|
+
const user = userEvent.setup();
|
|
159
|
+
const { props } = renderHeader();
|
|
160
|
+
await user.click(screen.getByRole('button', { name: 'More sharing options' }));
|
|
161
|
+
await user.click(screen.getByRole('menuitem', { name: /Copy link to this page/ }));
|
|
162
|
+
expect(props.onCopyLink).toHaveBeenCalled();
|
|
163
|
+
expect(await screen.findByRole('menuitem', { name: /Copied/ })).toBeInTheDocument();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('says so on the row when copying the link fails', async () => {
|
|
167
|
+
const user = userEvent.setup();
|
|
168
|
+
renderHeader({ onCopyLink: vi.fn(async () => false) });
|
|
169
|
+
await user.click(screen.getByRole('button', { name: 'More sharing options' }));
|
|
170
|
+
await user.click(screen.getByRole('menuitem', { name: /Copy link to this page/ }));
|
|
171
|
+
expect(await screen.findByRole('menuitem', { name: /Couldn't copy/ })).toBeInTheDocument();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('omits Copy page entirely when there is no markdown to copy', () => {
|
|
175
|
+
renderHeader({ onCopyPage: undefined });
|
|
176
|
+
expect(screen.queryByRole('button', { name: /Copy page/ })).not.toBeInTheDocument();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('closes an open menu on Escape and returns focus to its trigger', async () => {
|
|
180
|
+
const user = userEvent.setup();
|
|
181
|
+
renderHeader();
|
|
182
|
+
const trigger = screen.getByRole('button', { name: 'More actions' });
|
|
183
|
+
await user.click(trigger);
|
|
184
|
+
expect(screen.getByRole('menu', { name: 'More actions' })).toBeInTheDocument();
|
|
185
|
+
|
|
186
|
+
await act(async () => {
|
|
187
|
+
fireEvent.keyDown(document, { key: 'Escape' });
|
|
188
|
+
});
|
|
189
|
+
expect(screen.queryByRole('menu', { name: 'More actions' })).not.toBeInTheDocument();
|
|
190
|
+
expect(document.activeElement).toBe(trigger);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { Link2, Check } from 'lucide-react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Copy text to the clipboard. Prefers the async Clipboard API; falls back to a
|
|
6
|
+
* hidden-textarea `execCommand('copy')` for contexts where the Clipboard API is
|
|
7
|
+
* blocked by Permissions Policy (e.g. some embedded iframes).
|
|
8
|
+
*/
|
|
9
|
+
async function copyToClipboard(text: string): Promise<boolean> {
|
|
10
|
+
try {
|
|
11
|
+
await navigator.clipboard.writeText(text);
|
|
12
|
+
return true;
|
|
13
|
+
} catch {
|
|
14
|
+
let ta: HTMLTextAreaElement | null = null;
|
|
15
|
+
try {
|
|
16
|
+
ta = document.createElement('textarea');
|
|
17
|
+
ta.value = text;
|
|
18
|
+
ta.style.position = 'fixed';
|
|
19
|
+
ta.style.opacity = '0';
|
|
20
|
+
document.body.appendChild(ta);
|
|
21
|
+
ta.select();
|
|
22
|
+
return document.execCommand('copy');
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
} finally {
|
|
26
|
+
// Always remove the textarea, even if select()/execCommand threw.
|
|
27
|
+
if (ta?.parentNode) document.body.removeChild(ta);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Hover-revealed "copy link to this heading" button — mirrors the FileViewer's
|
|
34
|
+
* "copy link to this file" affordance (same `Link2` icon + 1.5s copied state),
|
|
35
|
+
* but copies the heading's deep-link (URL + `#slug`) so a reader can cite a
|
|
36
|
+
* specific section.
|
|
37
|
+
*
|
|
38
|
+
* Lives in its own module because the heading renderer that mounts it moved to
|
|
39
|
+
* `kbMarkdownPipeline`, which is shared with the diff viewer.
|
|
40
|
+
*/
|
|
41
|
+
export function CopyAnchorButton({ url }: { url: string }) {
|
|
42
|
+
const [copied, setCopied] = useState(false);
|
|
43
|
+
return (
|
|
44
|
+
<button
|
|
45
|
+
type="button"
|
|
46
|
+
onClick={async (e) => {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
if (await copyToClipboard(url)) {
|
|
49
|
+
setCopied(true);
|
|
50
|
+
window.setTimeout(() => setCopied(false), 1500);
|
|
51
|
+
} else {
|
|
52
|
+
console.error('Failed to copy heading link');
|
|
53
|
+
}
|
|
54
|
+
}}
|
|
55
|
+
// `align-middle` keeps it on the heading baseline; hidden until the
|
|
56
|
+
// heading is hovered (or the button is focused for keyboard users).
|
|
57
|
+
className="ml-1.5 inline-flex align-middle p-0.5 rounded-xs text-ink-faint no-underline opacity-0 transition-opacity hover:bg-hover hover:text-ink focus:opacity-100 group-hover/anchor:opacity-100"
|
|
58
|
+
title={copied ? 'Link copied' : 'Copy link to this heading'}
|
|
59
|
+
aria-label="Copy link to this heading"
|
|
60
|
+
>
|
|
61
|
+
{copied ? <Check size={13} /> : <Link2 size={13} />}
|
|
62
|
+
</button>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -102,13 +102,13 @@ export function CsvRenderer({
|
|
|
102
102
|
return (
|
|
103
103
|
<div className="flex flex-col h-full">
|
|
104
104
|
{showStatusStrip && (
|
|
105
|
-
<div className="flex items-center gap-2 pb-2 mb-2 border-b border-
|
|
105
|
+
<div className="flex items-center gap-2 pb-2 mb-2 border-b border-line shrink-0">
|
|
106
106
|
{saveState === 'saving' && (
|
|
107
107
|
<span
|
|
108
108
|
role="status"
|
|
109
109
|
aria-live="polite"
|
|
110
110
|
aria-atomic="true"
|
|
111
|
-
className="text-xs text-
|
|
111
|
+
className="text-xs text-ink-muted"
|
|
112
112
|
>
|
|
113
113
|
Saving…
|
|
114
114
|
</span>
|
|
@@ -118,7 +118,7 @@ export function CsvRenderer({
|
|
|
118
118
|
role="alert"
|
|
119
119
|
aria-live="assertive"
|
|
120
120
|
aria-atomic="true"
|
|
121
|
-
className="text-xs text-
|
|
121
|
+
className="text-xs text-danger"
|
|
122
122
|
>
|
|
123
123
|
Couldn't save your changes. Try again in a moment.
|
|
124
124
|
</span>
|
|
@@ -129,7 +129,7 @@ export function CsvRenderer({
|
|
|
129
129
|
{readOnly ? (
|
|
130
130
|
<div className="flex-1 overflow-auto">
|
|
131
131
|
{rows.length === 0 || columnCount === 0 ? (
|
|
132
|
-
<div className="flex items-center justify-center h-full text-
|
|
132
|
+
<div className="flex items-center justify-center h-full text-ink-muted text-sm">
|
|
133
133
|
This file is empty.
|
|
134
134
|
</div>
|
|
135
135
|
) : (
|
|
@@ -143,10 +143,10 @@ export function CsvRenderer({
|
|
|
143
143
|
return (
|
|
144
144
|
<Tag
|
|
145
145
|
key={cIdx}
|
|
146
|
-
className={`border border-
|
|
146
|
+
className={`border border-line px-2 py-1 align-top whitespace-pre-wrap ${
|
|
147
147
|
rIdx === 0
|
|
148
|
-
? 'bg-
|
|
149
|
-
: 'text-
|
|
148
|
+
? 'bg-sunken text-ink font-medium text-left'
|
|
149
|
+
: 'text-ink'
|
|
150
150
|
}`}
|
|
151
151
|
>
|
|
152
152
|
{cell}
|
|
@@ -161,7 +161,7 @@ export function CsvRenderer({
|
|
|
161
161
|
</div>
|
|
162
162
|
) : (
|
|
163
163
|
<textarea
|
|
164
|
-
className="flex-1 w-full bg-transparent text-sm text-
|
|
164
|
+
className="flex-1 w-full bg-transparent text-sm text-ink font-mono whitespace-pre-wrap break-words leading-relaxed resize-none outline-none"
|
|
165
165
|
value={value}
|
|
166
166
|
onChange={handleChange}
|
|
167
167
|
onKeyDown={handleKeyDown}
|
|
@@ -8,15 +8,22 @@ import { useEffect, useState } from 'react';
|
|
|
8
8
|
import mammoth from 'mammoth/mammoth.browser.js';
|
|
9
9
|
import { useWorkspace } from '../../state/workspace.context';
|
|
10
10
|
import { authFetch } from '../../../../lib/api';
|
|
11
|
+
import { sanitizeDocxHtml } from './sanitizeDocxHtml';
|
|
11
12
|
import type { FileRendererProps } from './types';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Inline .docx viewer. Fetches the binary from `/api/workspace/:id/file/raw`,
|
|
15
|
-
* runs it through mammoth's browser bundle to convert OOXML → HTML,
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* runs it through mammoth's browser bundle to convert OOXML → HTML, and
|
|
17
|
+
* renders the result in a Tailwind `prose` block.
|
|
18
|
+
*
|
|
19
|
+
* The HTML goes through {@link sanitizeDocxHtml} first, and that step is
|
|
20
|
+
* load-bearing rather than belt-and-braces. mammoth is a CONVERTER, not a
|
|
21
|
+
* sanitizer: it emits no `<script>` only because OOXML has no such element,
|
|
22
|
+
* while a hyperlink's target is copied verbatim from the document — so a
|
|
23
|
+
* crafted `.docx` can carry `href="javascript:…"` into THIS origin, where a
|
|
24
|
+
* single click would run it with the reader's session. The document is
|
|
25
|
+
* attacker-controlled input (anyone who can write to a folder can upload
|
|
26
|
+
* one), so it is sanitized like any other. See the sanitizer for the rules.
|
|
20
27
|
*
|
|
21
28
|
* View-only: there is no edit mode for binary office formats. The renderer
|
|
22
29
|
* ignores `onSave` / `onValueChange` / `readOnly`.
|
|
@@ -48,7 +55,7 @@ export function DocxRenderer({ filePath }: FileRendererProps) {
|
|
|
48
55
|
value: string;
|
|
49
56
|
};
|
|
50
57
|
if (cancelled) return;
|
|
51
|
-
setHtml(result.value);
|
|
58
|
+
setHtml(sanitizeDocxHtml(result.value));
|
|
52
59
|
} catch (e) {
|
|
53
60
|
if (cancelled) return;
|
|
54
61
|
setError(e instanceof Error ? e.message : String(e));
|
|
@@ -62,7 +69,7 @@ export function DocxRenderer({ filePath }: FileRendererProps) {
|
|
|
62
69
|
|
|
63
70
|
if (error) {
|
|
64
71
|
return (
|
|
65
|
-
<div className="flex items-center justify-center h-
|
|
72
|
+
<div className="flex items-center justify-center min-h-40 text-danger text-sm">
|
|
66
73
|
{error}
|
|
67
74
|
</div>
|
|
68
75
|
);
|
|
@@ -70,14 +77,16 @@ export function DocxRenderer({ filePath }: FileRendererProps) {
|
|
|
70
77
|
|
|
71
78
|
if (html === null) {
|
|
72
79
|
return (
|
|
73
|
-
<div className="flex items-center justify-center h-
|
|
80
|
+
<div className="flex items-center justify-center min-h-40 text-ink-muted text-sm">
|
|
74
81
|
Loading Word document...
|
|
75
82
|
</div>
|
|
76
83
|
);
|
|
77
84
|
}
|
|
78
85
|
|
|
79
86
|
return (
|
|
80
|
-
|
|
87
|
+
// No scroller of its own: a Word document is a document, so it sits in
|
|
88
|
+
// `KbDocumentShell`'s prose column and the column scrolls.
|
|
89
|
+
<div className="min-w-0">
|
|
81
90
|
<div
|
|
82
91
|
className="prose prose-sm max-w-none"
|
|
83
92
|
dangerouslySetInnerHTML={{ __html: html }}
|
|
@@ -149,14 +149,14 @@ export function HtmlRenderer({
|
|
|
149
149
|
|
|
150
150
|
return (
|
|
151
151
|
<div className="flex flex-col h-full">
|
|
152
|
-
<div className="flex items-center gap-1 pb-3 border-b border-
|
|
152
|
+
<div className="flex items-center gap-1 pb-3 border-b border-line mb-3 shrink-0">
|
|
153
153
|
{!readOnly && (
|
|
154
154
|
<button
|
|
155
155
|
onClick={switchToEdit}
|
|
156
|
-
className={`flex items-center gap-1.5 px-2.5 py-1 rounded text-xs font-medium transition-colors ${
|
|
156
|
+
className={`flex items-center gap-1.5 px-2.5 py-1 rounded-xs text-xs font-medium transition-colors ${
|
|
157
157
|
mode === 'edit'
|
|
158
|
-
? 'bg-
|
|
159
|
-
: 'text-
|
|
158
|
+
? 'bg-line-strong text-ink'
|
|
159
|
+
: 'text-ink-muted hover:text-ink hover:bg-hover'
|
|
160
160
|
}`}
|
|
161
161
|
>
|
|
162
162
|
<Pencil size={12} />
|
|
@@ -165,10 +165,10 @@ export function HtmlRenderer({
|
|
|
165
165
|
)}
|
|
166
166
|
<button
|
|
167
167
|
onClick={switchToPreview}
|
|
168
|
-
className={`flex items-center gap-1.5 px-2.5 py-1 rounded text-xs font-medium transition-colors ${
|
|
168
|
+
className={`flex items-center gap-1.5 px-2.5 py-1 rounded-xs text-xs font-medium transition-colors ${
|
|
169
169
|
mode === 'preview'
|
|
170
|
-
? 'bg-
|
|
171
|
-
: 'text-
|
|
170
|
+
? 'bg-line-strong text-ink'
|
|
171
|
+
: 'text-ink-muted hover:text-ink hover:bg-hover'
|
|
172
172
|
}`}
|
|
173
173
|
>
|
|
174
174
|
<Eye size={12} />
|
|
@@ -177,7 +177,7 @@ export function HtmlRenderer({
|
|
|
177
177
|
{mode === 'preview' && (
|
|
178
178
|
<button
|
|
179
179
|
onClick={() => setReloadKey((k) => k + 1)}
|
|
180
|
-
className="flex items-center gap-1.5 px-2.5 py-1 rounded text-xs font-medium text-
|
|
180
|
+
className="flex items-center gap-1.5 px-2.5 py-1 rounded-xs text-xs font-medium text-ink-muted hover:text-ink hover:bg-hover transition-colors"
|
|
181
181
|
title="Reload preview"
|
|
182
182
|
>
|
|
183
183
|
<RotateCw size={12} />
|
|
@@ -185,10 +185,10 @@ export function HtmlRenderer({
|
|
|
185
185
|
</button>
|
|
186
186
|
)}
|
|
187
187
|
{saveState === 'saving' && (
|
|
188
|
-
<span className="ml-2 text-xs text-
|
|
188
|
+
<span className="ml-2 text-xs text-ink-muted">Saving…</span>
|
|
189
189
|
)}
|
|
190
190
|
{saveState === 'error' && saveError && (
|
|
191
|
-
<span className="ml-2 text-xs text-
|
|
191
|
+
<span className="ml-2 text-xs text-danger truncate" title={saveError}>
|
|
192
192
|
{saveError}
|
|
193
193
|
</span>
|
|
194
194
|
)}
|
|
@@ -196,7 +196,7 @@ export function HtmlRenderer({
|
|
|
196
196
|
|
|
197
197
|
{mode === 'edit' && !readOnly ? (
|
|
198
198
|
<textarea
|
|
199
|
-
className="flex-1 w-full bg-transparent text-sm text-
|
|
199
|
+
className="flex-1 w-full bg-transparent text-sm text-ink font-mono whitespace-pre-wrap break-words leading-relaxed resize-none outline-none"
|
|
200
200
|
value={value}
|
|
201
201
|
onChange={handleChange}
|
|
202
202
|
onKeyDown={handleKeyDown}
|
|
@@ -204,7 +204,7 @@ export function HtmlRenderer({
|
|
|
204
204
|
autoFocus
|
|
205
205
|
/>
|
|
206
206
|
) : previewError ? (
|
|
207
|
-
<div className="flex items-center justify-center h-full text-sm text-
|
|
207
|
+
<div className="flex items-center justify-center h-full text-sm text-danger px-4 text-center">
|
|
208
208
|
{previewError}
|
|
209
209
|
</div>
|
|
210
210
|
) : bundledSrcdoc ? (
|
|
@@ -219,10 +219,10 @@ export function HtmlRenderer({
|
|
|
219
219
|
// iframe cannot exfiltrate, navigate, popup, or fetch.
|
|
220
220
|
sandbox="allow-scripts"
|
|
221
221
|
referrerPolicy="no-referrer"
|
|
222
|
-
className="flex-1 w-full bg-white rounded border border-
|
|
222
|
+
className="flex-1 w-full bg-white rounded-xs border border-line"
|
|
223
223
|
/>
|
|
224
224
|
) : (
|
|
225
|
-
<div className="flex items-center justify-center h-full text-
|
|
225
|
+
<div className="flex items-center justify-center h-full text-ink-muted text-sm">
|
|
226
226
|
Loading preview…
|
|
227
227
|
</div>
|
|
228
228
|
)}
|
|
@@ -32,7 +32,7 @@ export function ImageRenderer({ filePath }: FileRendererProps) {
|
|
|
32
32
|
|
|
33
33
|
if (!objectUrl) {
|
|
34
34
|
return (
|
|
35
|
-
<div className="flex items-center justify-center h-full text-
|
|
35
|
+
<div className="flex items-center justify-center h-full text-ink-muted text-sm">
|
|
36
36
|
Loading image...
|
|
37
37
|
</div>
|
|
38
38
|
);
|
|
@@ -43,7 +43,7 @@ export function ImageRenderer({ filePath }: FileRendererProps) {
|
|
|
43
43
|
<img
|
|
44
44
|
src={objectUrl}
|
|
45
45
|
alt={filePath}
|
|
46
|
-
className="max-w-full max-h-full object-contain rounded"
|
|
46
|
+
className="max-w-full max-h-full object-contain rounded-xs"
|
|
47
47
|
/>
|
|
48
48
|
</div>
|
|
49
49
|
);
|