@kabmo-labs/kabmo 0.11.1 → 0.12.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/README.md +67 -421
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +426 -413
- package/dist/client/static/js/{index-amss8pge.js → index-0smc9gm2.js} +1123 -747
- package/dist/client/static/js/index-shexbk5f.css +1 -0
- package/marketplace/marketplace.json +13 -3
- package/marketplace/plugins/command-runner/package.json +4 -2
- package/marketplace/plugins/git-forge/README.md +219 -0
- package/marketplace/plugins/git-forge/icon.svg +20 -0
- package/marketplace/plugins/git-forge/package.json +56 -0
- package/marketplace/plugins/git-forge/src/app.tsx +82 -0
- package/marketplace/plugins/git-forge/src/command.test.ts +181 -0
- package/marketplace/plugins/git-forge/src/command.ts +119 -0
- package/marketplace/plugins/git-forge/src/header.tsx +87 -0
- package/marketplace/plugins/git-forge/src/panel/Badge.tsx +76 -0
- package/marketplace/plugins/git-forge/src/panel/Change.tsx +150 -0
- package/marketplace/plugins/git-forge/src/panel/CiBadge.tsx +51 -0
- package/marketplace/plugins/git-forge/src/panel/Credential.tsx +107 -0
- package/marketplace/plugins/git-forge/src/panel/Glyph.tsx +70 -0
- package/marketplace/plugins/git-forge/src/panel/Header.tsx +255 -0
- package/marketplace/plugins/git-forge/src/panel/ItemView.tsx +198 -0
- package/marketplace/plugins/git-forge/src/panel/List.tsx +89 -0
- package/marketplace/plugins/git-forge/src/panel/Row.tsx +68 -0
- package/marketplace/plugins/git-forge/src/panel/Sidebar.tsx +94 -0
- package/marketplace/plugins/git-forge/src/panel/Write.tsx +236 -0
- package/marketplace/plugins/git-forge/src/panel/format.ts +78 -0
- package/marketplace/plugins/git-forge/src/panel/index.test.tsx +344 -0
- package/marketplace/plugins/git-forge/src/panel/index.tsx +193 -0
- package/marketplace/plugins/git-forge/src/panel/use-forge.ts +250 -0
- package/marketplace/plugins/git-forge/src/panel/write.test.tsx +269 -0
- package/marketplace/plugins/git-forge/src/protocol.ts +308 -0
- package/marketplace/plugins/git-forge/src/server/adapters.test.ts +274 -0
- package/marketplace/plugins/git-forge/src/server/bitbucket.ts +307 -0
- package/marketplace/plugins/git-forge/src/server/capabilities.test.ts +116 -0
- package/marketplace/plugins/git-forge/src/server/capabilities.ts +105 -0
- package/marketplace/plugins/git-forge/src/server/ci.test.ts +88 -0
- package/marketplace/plugins/git-forge/src/server/ci.ts +118 -0
- package/marketplace/plugins/git-forge/src/server/context.ts +76 -0
- package/marketplace/plugins/git-forge/src/server/diff.test.ts +127 -0
- package/marketplace/plugins/git-forge/src/server/diff.ts +120 -0
- package/marketplace/plugins/git-forge/src/server/filters.test.ts +138 -0
- package/marketplace/plugins/git-forge/src/server/filters.ts +138 -0
- package/marketplace/plugins/git-forge/src/server/forges.test.ts +235 -0
- package/marketplace/plugins/git-forge/src/server/gitea.ts +296 -0
- package/marketplace/plugins/git-forge/src/server/github-extras.ts +92 -0
- package/marketplace/plugins/git-forge/src/server/github.ts +320 -0
- package/marketplace/plugins/git-forge/src/server/gitlab-detail.ts +207 -0
- package/marketplace/plugins/git-forge/src/server/gitlab.test.ts +195 -0
- package/marketplace/plugins/git-forge/src/server/gitlab.ts +176 -0
- package/marketplace/plugins/git-forge/src/server/http.test.ts +270 -0
- package/marketplace/plugins/git-forge/src/server/http.ts +329 -0
- package/marketplace/plugins/git-forge/src/server/map.ts +120 -0
- package/marketplace/plugins/git-forge/src/server/registry.ts +47 -0
- package/marketplace/plugins/git-forge/src/server/remote.test.ts +146 -0
- package/marketplace/plugins/git-forge/src/server/remote.ts +188 -0
- package/marketplace/plugins/git-forge/src/server/scope-probe.test.ts +98 -0
- package/marketplace/plugins/git-forge/src/server/scope-probe.ts +128 -0
- package/marketplace/plugins/git-forge/src/server/scope.ts +66 -0
- package/marketplace/plugins/git-forge/src/server/test-context.ts +67 -0
- package/marketplace/plugins/git-forge/src/server/test-host.ts +51 -0
- package/marketplace/plugins/git-forge/src/server/token.test.ts +107 -0
- package/marketplace/plugins/git-forge/src/server/token.ts +139 -0
- package/marketplace/plugins/git-forge/src/server/write-http.test.ts +127 -0
- package/marketplace/plugins/git-forge/src/server/write-http.ts +110 -0
- package/marketplace/plugins/git-forge/src/server/writes.test.ts +218 -0
- package/marketplace/plugins/git-forge/src/server/writes.ts +313 -0
- package/marketplace/plugins/git-forge/src/server.ts +284 -0
- package/marketplace/plugins/git-forge/tsconfig.json +16 -0
- package/marketplace/plugins/session-info/package.json +4 -2
- package/marketplace/plugins/stats/package.json +4 -2
- package/package.json +6 -1
- package/src/client/components/common/code-surface/blame-hover.ts +188 -0
- package/src/client/components/common/code-surface/blame-panel.test.ts +304 -0
- package/src/client/components/common/code-surface/blame-panel.ts +306 -0
- package/src/client/components/common/code-surface/blame.test.ts +303 -0
- package/src/client/components/common/code-surface/blame.ts +227 -0
- package/src/client/components/common/code-surface/conflict-markers.test.ts +135 -0
- package/src/client/components/common/code-surface/conflict-markers.ts +144 -0
- package/src/client/components/common/code-surface/documents.ts +48 -1
- package/src/client/components/common/code-surface/extensions.test.ts +4 -0
- package/src/client/components/common/code-surface/extensions.ts +44 -0
- package/src/client/components/common/code-surface/fold-stack.test.ts +4 -0
- package/src/client/components/common/code-surface/indent.test.ts +5 -0
- package/src/client/components/common/code-surface/index.tsx +16 -2
- package/src/client/components/common/code-surface/lint-parsers.test.ts +109 -0
- package/src/client/components/common/code-surface/lint-parsers.ts +134 -0
- package/src/client/components/common/code-surface/lint.test.ts +101 -0
- package/src/client/components/common/code-surface/lint.ts +85 -0
- package/src/client/components/common/code-surface/props.ts +17 -0
- package/src/client/components/common/code-surface/surface-failures.test.ts +132 -0
- package/src/client/components/common/code-surface/theme.ts +71 -0
- package/src/client/components/common/header-controls/index.test.tsx +1 -1
- package/src/client/components/common/header-controls/plugin-entry.test.tsx +1 -1
- package/src/client/components/common/header-controls/shell-chrome.test.tsx +1 -1
- package/src/client/components/common/provider-icon/Plate.tsx +88 -0
- package/src/client/components/common/provider-icon/index.tsx +55 -11
- package/src/client/components/layout/session-sidebar/SessionsView.tsx +5 -2
- package/src/client/components/mobile/SessionSidebar.tsx +2 -10
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +6 -0
- package/src/client/components/mobile/mobile-right-sidebar/StatusBar.tsx +8 -0
- package/src/client/components/settings/categories/AppearanceSettings.tsx +3 -0
- package/src/client/components/settings/categories/ProviderSettings.tsx +43 -41
- package/src/client/components/settings/categories/appearance-settings/EditorBlameSection.tsx +97 -0
- package/src/client/components/settings/categories/panel-plugins/AvailableList.tsx +106 -54
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.tsx +14 -1
- package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +39 -150
- package/src/client/components/settings/categories/panel-plugins/Meta.test.tsx +143 -0
- package/src/client/components/settings/categories/panel-plugins/Meta.tsx +157 -0
- package/src/client/components/settings/categories/panel-plugins/Placement.test.tsx +149 -0
- package/src/client/components/settings/categories/panel-plugins/Placement.tsx +99 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +270 -0
- package/src/client/components/settings/categories/panel-plugins/Section.tsx +11 -3
- package/src/client/components/settings/categories/provider-settings/AddModelModal.tsx +25 -0
- package/src/client/components/settings/categories/provider-settings/AuthSection.tsx +135 -80
- package/src/client/components/settings/categories/provider-settings/DeleteProviderModal.tsx +51 -21
- package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +175 -0
- package/src/client/components/settings/categories/provider-settings/EntryModal.tsx +275 -0
- package/src/client/components/settings/categories/provider-settings/Header.tsx +40 -9
- package/src/client/components/settings/categories/provider-settings/LoginModal.tsx +142 -160
- package/src/client/components/settings/categories/provider-settings/LogoutProviderModal.tsx +2 -2
- package/src/client/components/settings/categories/provider-settings/ModelCapabilitiesModal.tsx +84 -46
- package/src/client/components/settings/categories/provider-settings/ModelsList.tsx +217 -102
- package/src/client/components/settings/categories/provider-settings/PresetPicker.tsx +5 -2
- package/src/client/components/settings/categories/provider-settings/SidebarList.plugin.test.ts +3 -3
- package/src/client/components/settings/categories/provider-settings/SidebarList.tsx +158 -102
- package/src/client/components/settings/categories/provider-settings/auth-section.test.tsx +135 -0
- package/src/client/components/settings/categories/provider-settings/groups.test.ts +98 -0
- package/src/client/components/settings/categories/provider-settings/groups.ts +108 -0
- package/src/client/components/settings/categories/provider-settings/layout.test.tsx +325 -0
- package/src/client/components/settings/categories/provider-settings/model-dialogs.test.tsx +135 -0
- package/src/client/components/settings/categories/provider-settings/preset-picker.test.tsx +73 -0
- package/src/client/components/settings/categories/usage-settings/ProviderCard.tsx +22 -2
- package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +2 -0
- package/src/client/components/settings/categories/usage-settings/SidebarList.tsx +16 -6
- package/src/client/components/settings/categories/usage-settings/providers.ts +3 -0
- package/src/client/components/settings/categories/usage-settings/usage-and-picker.test.ts +19 -0
- package/src/client/components/settings/categories/usage-settings/usage-icons.test.tsx +143 -0
- package/src/client/components/workspace/chat-timeline/MinimapShortcuts.test.ts +2 -1
- package/src/client/components/workspace/chat-timeline/chat-input/GoalBanner.test.ts +23 -19
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.test.ts +23 -19
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +20 -18
- package/src/client/components/workspace/chat-timeline/chat-input/compact.test.tsx +19 -6
- package/src/client/components/workspace/chat-timeline/index.tsx +7 -16
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.missing.test.ts +100 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +3 -47
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +8 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/wait-test-util.ts +62 -0
- package/src/client/components/workspace/diff-panel/HunkStepper.tsx +62 -0
- package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +29 -0
- package/src/client/components/workspace/diff-panel/Toolbar.tsx +32 -1
- package/src/client/components/workspace/diff-panel/changes.ts +69 -0
- package/src/client/components/workspace/diff-panel/chunks.ts +85 -0
- package/src/client/components/workspace/diff-panel/index.tsx +21 -1
- package/src/client/components/workspace/diff-panel/merge.test.ts +145 -0
- package/src/client/components/workspace/diff-panel/merge.ts +63 -68
- package/src/client/components/workspace/editor/EditorDropOverlay.tsx +6 -1
- package/src/client/components/workspace/editor/FileDocument.tsx +51 -1
- package/src/client/components/workspace/editor/FilePane.tsx +25 -1
- package/src/client/components/workspace/editor/StatusBar.tsx +19 -0
- package/src/client/components/workspace/editor/Toolbar.tsx +29 -5
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +86 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +48 -16
- package/src/client/components/workspace/editor/viewers/bytes.ts +16 -0
- package/src/client/components/workspace/git-panel/index.test.ts +46 -1
- package/src/client/components/workspace/git-panel/index.tsx +11 -38
- package/src/client/components/workspace/model-dropdown/Item.plugin.test.ts +66 -0
- package/src/client/components/workspace/model-dropdown/Item.tsx +71 -62
- package/src/client/components/workspace/model-dropdown/Section.tsx +31 -14
- package/src/client/components/workspace/model-dropdown/collapsed.ts +72 -0
- package/src/client/components/workspace/model-dropdown/index.tsx +42 -19
- package/src/client/components/workspace/model-dropdown/refresh.test.tsx +260 -0
- package/src/client/components/workspace/model-dropdown/trigger.test.ts +34 -0
- package/src/client/components/workspace/model-dropdown/use-catalog.ts +13 -2
- package/src/client/components/workspace/usage-panel/ProviderSelect.tsx +19 -3
- package/src/client/hooks/chat/omp/folder-auto-expand.ts +113 -0
- package/src/client/hooks/chat/omp/index.ts +20 -0
- package/src/client/hooks/chat/omp/pending-rows.ts +21 -0
- package/src/client/hooks/chat/omp/pending-sessions.test.ts +16 -1
- package/src/client/hooks/chat/omp/session-sidebar-controller.test.ts +102 -0
- package/src/client/hooks/chat/omp/session-sidebar-controller.ts +21 -1
- package/src/client/hooks/chat/omp/stream.ts +8 -1
- package/src/client/hooks/chat/timeline/index.ts +1 -1
- package/src/client/hooks/chat/timeline/new-chat-open.ts +60 -0
- package/src/client/hooks/editor/blame-settings.ts +67 -0
- package/src/client/hooks/editor/blame.test.ts +272 -0
- package/src/client/hooks/editor/blame.ts +232 -0
- package/src/client/hooks/editor/file-editor-types.ts +23 -0
- package/src/client/hooks/editor/save-file.test.ts +20 -0
- package/src/client/hooks/editor/use-editor-drop.test-util.ts +198 -0
- package/src/client/hooks/editor/use-editor-drop.test.ts +70 -175
- package/src/client/hooks/editor/use-editor-drop.ts +19 -36
- package/src/client/hooks/editor/use-file-editor.ts +7 -1
- package/src/client/hooks/settings/providers/actions.ts +90 -194
- package/src/client/hooks/settings/providers/api.ts +7 -1
- package/src/client/hooks/settings/providers/index.ts +171 -59
- package/src/client/hooks/settings/providers/login.test.ts +79 -0
- package/src/client/hooks/settings/providers/login.ts +276 -0
- package/src/client/hooks/settings/providers/messages.ts +28 -0
- package/src/client/hooks/settings/providers/model-actions.ts +178 -0
- package/src/client/hooks/ui/editor-error-toast.ts +47 -0
- package/src/client/hooks/ui/open-file.ts +7 -0
- package/src/client/hooks/ui/toasts.ts +7 -0
- package/src/client/hooks/workspace/file-tabs.ts +4 -1
- package/src/client/hooks/workspace/folder-expansion.test.ts +62 -0
- package/src/client/hooks/workspace/folder-expansion.ts +33 -0
- package/src/client/hooks/workspace/git-action-outcome.ts +86 -0
- package/src/client/hooks/workspace/git-actions.ts +29 -2
- package/src/client/hooks/workspace/plugin-contributions.test.ts +117 -0
- package/src/client/hooks/workspace/plugin-contributions.ts +146 -0
- package/src/client/lib/editor-errors.test.ts +85 -0
- package/src/client/lib/editor-errors.ts +71 -0
- package/src/client/lib/fs/resolve-open.test.ts +125 -0
- package/src/client/lib/fs/resolve-open.ts +90 -0
- package/src/client/lib/git/action-message.test.ts +82 -0
- package/src/client/lib/git/action-message.ts +160 -0
- package/src/client/lib/launch/device-files.test.ts +160 -0
- package/src/client/lib/launch/device-files.ts +197 -0
- package/src/client/lib/native/open-paths.test.ts +140 -0
- package/src/client/lib/native/open-paths.ts +157 -0
- package/src/client/lib/plugins/bootstrap.test.ts +1 -1
- package/src/client/main.tsx +20 -0
- package/src/server/db.server.test.ts +39 -0
- package/src/server/db.server.ts +21 -2
- package/src/server/lib/db/schema.ts +2 -0
- package/src/server/lib/fs/external-roots.test.ts +100 -0
- package/src/server/lib/fs/external-roots.ts +101 -0
- package/src/server/lib/fs/git-actions-branch.ts +15 -2
- package/src/server/lib/fs/git-actions-shared.ts +24 -0
- package/src/server/lib/fs/git-actions-sync.test.ts +18 -7
- package/src/server/lib/fs/git-actions-worktree.ts +5 -1
- package/src/server/lib/fs/git-blame.test.ts +206 -0
- package/src/server/lib/fs/git-blame.ts +189 -0
- package/src/server/lib/fs/root.ts +14 -0
- package/src/server/lib/http/same-origin.ts +28 -7
- package/src/server/lib/models/catalog.server.ts +230 -0
- package/src/server/lib/models/catalog.test.ts +83 -0
- package/src/server/lib/models/credential-origin.server.ts +108 -0
- package/src/server/lib/models/credential-origin.test.ts +132 -0
- package/src/server/lib/models/provider-icon-fetch.ts +115 -0
- package/src/server/lib/models/provider-icon-parse.test.ts +134 -0
- package/src/server/lib/models/provider-icon-parse.ts +139 -0
- package/src/server/lib/models/provider-icon-store.server.ts +118 -0
- package/src/server/lib/models/provider-icon-store.test.ts +107 -0
- package/src/server/lib/models/provider-icon.server.ts +209 -0
- package/src/server/lib/models/provider-items.server.ts +211 -37
- package/src/server/lib/models/provider-items.test.ts +201 -0
- package/src/server/lib/models/provider-registry.server.test.ts +27 -9
- package/src/server/lib/models/provider-registry.server.ts +160 -67
- package/src/server/lib/models/registry.server.test.ts +3 -3
- package/src/server/lib/models/registry.server.ts +8 -0
- package/src/server/lib/omp/config/definitions.test.ts +5 -4
- package/src/server/lib/omp/config/models-config.ts +42 -0
- package/src/server/lib/omp/config/provider-entry.test.ts +205 -0
- package/src/server/lib/omp/config/provider-entry.ts +197 -0
- package/src/server/lib/omp/config/provider-seeds.ts +10 -0
- package/src/server/lib/omp/core/models-json.ts +69 -0
- package/src/server/lib/omp/session/messages.ts +17 -3
- package/src/server/lib/omp/session/sidebar-data.canonical.test.ts +13 -3
- package/src/server/lib/panels/bundled-catalog.server.ts +7 -0
- package/src/server/lib/panels/catalog-offers.server.ts +68 -0
- package/src/server/lib/panels/git-update.server.test.ts +14 -0
- package/src/server/lib/panels/git-update.server.ts +63 -1
- package/src/server/lib/panels/manifest.test.ts +65 -0
- package/src/server/lib/panels/manifest.ts +55 -1
- package/src/server/lib/panels/offers.server.test.ts +191 -0
- package/src/server/lib/panels/offers.server.ts +108 -0
- package/src/server/lib/panels/registry.server.test.ts +35 -1
- package/src/server/lib/panels/registry.server.ts +51 -142
- package/src/server/lib/panels/scan.server.ts +162 -0
- package/src/server/lib/route-adapter.ts +13 -2
- package/src/server/lib/tray/tray.test.ts +2 -1
- package/src/server/lib/usage/providers.server.ts +4 -1
- package/src/server/routes/chat/session.ts +7 -1
- package/src/server/routes/fs/git-blame-loader.test.ts +146 -0
- package/src/server/routes/fs/git.ts +17 -0
- package/src/server/routes/fs/grant.test.ts +135 -0
- package/src/server/routes/fs/grant.ts +79 -0
- package/src/server/routes/fs/index.ts +2 -0
- package/src/server/routes/fs/scope.ts +34 -17
- package/src/server/routes/omp/login.ts +41 -14
- package/src/server/routes/omp/routes.test.ts +23 -10
- package/src/server/routes/settings/index.ts +8 -0
- package/src/server/routes/settings/provider-entry.ts +108 -0
- package/src/server/routes/settings/provider-icon.ts +99 -0
- package/src/server/routes/settings/provider-model.ts +4 -1
- package/src/server/routes/settings/provider-refresh.ts +87 -0
- package/src/server/routes/settings/providers.ts +31 -2
- package/src/shared/lib/chat/omp/fold.test.ts +34 -0
- package/src/shared/lib/chat/omp/tool-frames.test.ts +20 -0
- package/src/shared/lib/chat/omp/tool-frames.ts +5 -1
- package/src/shared/lib/chat/omp/tool-results.ts +29 -3
- package/src/shared/lib/chat/tool/wait-facts.ts +4 -0
- package/src/shared/lib/fs/git-blame.test.ts +266 -0
- package/src/shared/lib/fs/git-blame.ts +246 -0
- package/src/shared/lib/git/url.ts +18 -0
- package/src/shared/lib/markdown/sanitize.test.ts +57 -0
- package/src/shared/lib/markdown/sanitize.ts +30 -7
- package/src/shared/lib/models/provider/connection.ts +135 -0
- package/src/shared/lib/models/provider/dialect.test.ts +4 -2
- package/src/shared/lib/models/provider/dialect.ts +76 -6
- package/src/shared/lib/models/provider/models.ts +2 -0
- package/src/shared/lib/models/provider/origin.ts +94 -0
- package/src/shared/lib/models/provider/provider-ui.test.ts +7 -0
- package/src/shared/lib/models/server-cache.ts +8 -3
- package/src/shared/lib/omp/session/messages-map-pending.test.ts +110 -0
- package/src/shared/lib/omp/session/messages-map.ts +34 -2
- package/src/shared/lib/omp/session/prewarm-misc.test.ts +7 -90
- package/src/shared/lib/omp/session/prewarm.test.ts +133 -0
- package/src/shared/lib/omp/session/prewarm.ts +23 -1
- package/src/shared/lib/omp/session/wait.test.ts +28 -0
- package/src/shared/lib/omp/session/wait.ts +38 -3
- package/src/shared/lib/panels/slot-labels.test.ts +61 -0
- package/src/shared/lib/panels/slot-labels.ts +133 -0
- package/src/shared/lib/workspace/panel-ids.ts +11 -0
- package/src/shared/types/fs.ts +6 -0
- package/src/shared/types/index.ts +1 -0
- package/src/shared/types/models.ts +12 -0
- package/src/shared/types/panels-registry.ts +277 -0
- package/src/shared/types/panels.ts +46 -213
- package/src/shared/types/settings/provider.ts +58 -0
- package/src/shared/types/settings/usage.ts +10 -0
- package/src/test-support/pristine-globals.ts +7 -0
- package/dist/client/static/js/index-bq6qeayr.css +0 -1
- package/src/client/components/settings/categories/provider-settings/ReconnectModal.tsx +0 -184
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The blame card's six states, and what each one SAYS.
|
|
8
|
+
*
|
|
9
|
+
* The sentences are the product here: a card that renders the right shape with
|
|
10
|
+
* the wrong words still passes a DOM assertion, and the wrong words are exactly
|
|
11
|
+
* what the first cut of this feature produced — "Blame failed" over a file that
|
|
12
|
+
* was merely untracked, and a blank author line for a line that is not
|
|
13
|
+
* committed yet.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
17
|
+
import { Window } from 'happy-dom';
|
|
18
|
+
|
|
19
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
20
|
+
import type { BlamePayload } from '@/shared/lib/fs/git-blame';
|
|
21
|
+
import type { BlameSnapshot, BlameHistoryResult, FileBlame } from '@/client/hooks/editor/blame';
|
|
22
|
+
import { blamePanelNote, createBlamePanel } from '@/client/components/common/code-surface/blame-panel';
|
|
23
|
+
|
|
24
|
+
const SHA = 'a'.repeat(40);
|
|
25
|
+
const OLD = 'b'.repeat(40);
|
|
26
|
+
|
|
27
|
+
const PAYLOAD: BlamePayload = {
|
|
28
|
+
available: true,
|
|
29
|
+
head: SHA,
|
|
30
|
+
lines: 12,
|
|
31
|
+
runs: [
|
|
32
|
+
{ from: 1, to: 3, sha: OLD },
|
|
33
|
+
{ from: 4, to: 12, sha: SHA },
|
|
34
|
+
],
|
|
35
|
+
commits: {
|
|
36
|
+
[SHA]: { sha: SHA, author: 'Ada Lovelace', mail: 'ada@example.com', time: 1_700_000_000, summary: 'feat: open the file' },
|
|
37
|
+
[OLD]: { sha: OLD, author: 'Grace Hopper', mail: 'grace@example.com', time: 1_690_000_000, summary: 'fix: the bug' },
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** A controller whose answer the test sets, and whose history it can hold open. */
|
|
42
|
+
function fakeController(snapshot: BlameSnapshot, options: { stale?: boolean; history?: BlameHistoryResult } = {}): FileBlame & {
|
|
43
|
+
readonly reloads: number;
|
|
44
|
+
} {
|
|
45
|
+
const listeners = new Set<() => void>();
|
|
46
|
+
const state = { reloads: 0 };
|
|
47
|
+
const controller: FileBlame & { readonly reloads: number } = {
|
|
48
|
+
ensure: () => {},
|
|
49
|
+
reload: () => {
|
|
50
|
+
state.reloads += 1;
|
|
51
|
+
for (const listener of listeners) listener();
|
|
52
|
+
},
|
|
53
|
+
history: async () => options.history ?? { entries: [], truncated: false },
|
|
54
|
+
snapshot: () => snapshot,
|
|
55
|
+
stale: () => options.stale === true,
|
|
56
|
+
subscribe: (listener) => {
|
|
57
|
+
listeners.add(listener);
|
|
58
|
+
return () => listeners.delete(listener);
|
|
59
|
+
},
|
|
60
|
+
get reloads() {
|
|
61
|
+
return state.reloads;
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
return controller;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The four fields `place` reads, as the DOM's own rect type. */
|
|
68
|
+
function rect(left: number, top: number, width: number, height: number): DOMRect {
|
|
69
|
+
return { left, top, width, height, right: left + width, bottom: top + height } as DOMRect;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function text(element: Element): string {
|
|
73
|
+
return (element.textContent ?? '').replace(/\s+/g, ' ').trim();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
beforeAll(() => {
|
|
77
|
+
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
afterAll(() => {
|
|
81
|
+
restoreDomGlobals();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
let body: HTMLElement;
|
|
85
|
+
beforeEach(() => {
|
|
86
|
+
body = document.createElement('div');
|
|
87
|
+
document.body.append(body);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('blamePanelNote', () => {
|
|
91
|
+
const base = { line: 5, stale: false, history: null, historyOpen: false, historyLoading: false };
|
|
92
|
+
|
|
93
|
+
test('an error is the only state that names a failure', () => {
|
|
94
|
+
const note = blamePanelNote({
|
|
95
|
+
...base,
|
|
96
|
+
status: 'error',
|
|
97
|
+
payload: null,
|
|
98
|
+
message: 'fatal: bad object',
|
|
99
|
+
});
|
|
100
|
+
expect(note).toEqual({ title: 'Blame failed', body: 'fatal: bad object' });
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('an untracked file is an answer, and does not claim a failure', () => {
|
|
104
|
+
const note = blamePanelNote({
|
|
105
|
+
...base,
|
|
106
|
+
status: 'unavailable',
|
|
107
|
+
payload: { available: false, head: null, lines: 0, runs: [], commits: {}, reason: 'untracked' },
|
|
108
|
+
message: "fatal: no such path 'x' in HEAD",
|
|
109
|
+
});
|
|
110
|
+
expect(note?.title).toBe('Not tracked');
|
|
111
|
+
expect(note?.body).toContain('never been committed');
|
|
112
|
+
expect(note?.title).not.toContain('failed');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('a folder that is not a repository says which reason', () => {
|
|
116
|
+
const note = blamePanelNote({
|
|
117
|
+
...base,
|
|
118
|
+
status: 'unavailable',
|
|
119
|
+
payload: { available: false, head: null, lines: 0, runs: [], commits: {}, reason: 'not-repo' },
|
|
120
|
+
message: null,
|
|
121
|
+
});
|
|
122
|
+
expect(note?.title).toBe('No history');
|
|
123
|
+
expect(note?.body).toContain('not a git repository');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('a dirty buffer explains the edit rather than the file', () => {
|
|
127
|
+
const note = blamePanelNote({ ...base, status: 'ready', payload: PAYLOAD, message: null, stale: true });
|
|
128
|
+
expect(note?.title).toBe('Not committed yet');
|
|
129
|
+
expect(note?.body).toContain('changed in the editor');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('a line past the end of HEAD names the file’s own length', () => {
|
|
133
|
+
const note = blamePanelNote({ ...base, line: 99, status: 'ready', payload: PAYLOAD, message: null });
|
|
134
|
+
expect(note?.body).toContain('Line 99');
|
|
135
|
+
expect(note?.body).toContain('12 lines');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('a line the payload cannot place says so instead of drawing blanks', () => {
|
|
139
|
+
const note = blamePanelNote({ ...base, line: 6, status: 'ready', payload: { ...PAYLOAD, runs: [] }, message: null });
|
|
140
|
+
expect(note?.title).toBe('Not committed yet');
|
|
141
|
+
expect(note?.body).toContain('no attribution for line 6');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('a line whose commit is the all-zero sha is not attributed to a person', () => {
|
|
145
|
+
const uncommitted = '0'.repeat(40);
|
|
146
|
+
const note = blamePanelNote({
|
|
147
|
+
...base,
|
|
148
|
+
status: 'ready',
|
|
149
|
+
message: null,
|
|
150
|
+
payload: {
|
|
151
|
+
...PAYLOAD,
|
|
152
|
+
runs: [{ from: 5, to: 5, sha: uncommitted }],
|
|
153
|
+
commits: { [uncommitted]: { sha: uncommitted, author: 'Not Committed Yet', mail: '', time: 0, summary: '' } },
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
expect(note?.title).toBe('Not committed yet');
|
|
157
|
+
expect(note?.body).toBe('This line differs from the last commit.');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('an attributable line has no note at all', () => {
|
|
161
|
+
expect(blamePanelNote({ ...base, status: 'ready', payload: PAYLOAD, message: null })).toBeNull();
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe('createBlamePanel', () => {
|
|
166
|
+
test('draws the author, the subject, the sha and the date', () => {
|
|
167
|
+
const controller = fakeController({ status: 'ready', payload: PAYLOAD, message: null });
|
|
168
|
+
const panel = createBlamePanel(5, controller, () => {});
|
|
169
|
+
body.append(panel.element);
|
|
170
|
+
|
|
171
|
+
const content = text(panel.element);
|
|
172
|
+
expect(content).toContain('Ada Lovelace');
|
|
173
|
+
expect(content).toContain('feat: open the file');
|
|
174
|
+
expect(content).toContain(SHA.slice(0, 7));
|
|
175
|
+
expect(content).toContain('Line history');
|
|
176
|
+
// The card is a dialog to a screen reader, and it is named.
|
|
177
|
+
expect(panel.element.getAttribute('role')).toBe('dialog');
|
|
178
|
+
expect(panel.element.getAttribute('aria-label')).toBe('Line blame');
|
|
179
|
+
panel.destroy();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('the history toggle loads once and marks the oldest entry as the birth', async () => {
|
|
183
|
+
const history: BlameHistoryResult = {
|
|
184
|
+
entries: [
|
|
185
|
+
{ sha: SHA, author: 'Ada Lovelace', time: 1_700_000_000, summary: 'feat: x' },
|
|
186
|
+
{ sha: OLD, author: 'Grace Hopper', time: 1_690_000_000, summary: 'fix: y' },
|
|
187
|
+
],
|
|
188
|
+
truncated: false,
|
|
189
|
+
};
|
|
190
|
+
const controller = fakeController({ status: 'ready', payload: PAYLOAD, message: null }, { history });
|
|
191
|
+
const panel = createBlamePanel(5, controller, () => {});
|
|
192
|
+
body.append(panel.element);
|
|
193
|
+
|
|
194
|
+
expect(text(panel.element)).not.toContain('Grace Hopper');
|
|
195
|
+
panel.element.querySelector<HTMLButtonElement>('button[aria-expanded]')!.click();
|
|
196
|
+
// The read is async; one microtask turn settles the stubbed promise.
|
|
197
|
+
await Promise.resolve();
|
|
198
|
+
await Promise.resolve();
|
|
199
|
+
await Promise.resolve();
|
|
200
|
+
|
|
201
|
+
const rows = panel.element.querySelectorAll('ol li');
|
|
202
|
+
expect(rows).toHaveLength(2);
|
|
203
|
+
expect(text(rows[0])).toContain('edit');
|
|
204
|
+
expect(text(rows[1])).toContain('new');
|
|
205
|
+
expect(panel.element.querySelector('button[aria-expanded]')!.getAttribute('aria-expanded')).toBe('true');
|
|
206
|
+
panel.destroy();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('a truncated history says the rest is not shown', async () => {
|
|
210
|
+
const controller = fakeController(
|
|
211
|
+
{ status: 'ready', payload: PAYLOAD, message: null },
|
|
212
|
+
{ history: { entries: [{ sha: SHA, author: 'Ada', time: 1_700_000_000, summary: 'x' }], truncated: true } },
|
|
213
|
+
);
|
|
214
|
+
const panel = createBlamePanel(5, controller, () => {});
|
|
215
|
+
body.append(panel.element);
|
|
216
|
+
panel.element.querySelector<HTMLButtonElement>('button[aria-expanded]')!.click();
|
|
217
|
+
await Promise.resolve();
|
|
218
|
+
await Promise.resolve();
|
|
219
|
+
await Promise.resolve();
|
|
220
|
+
expect(text(panel.element)).toContain('Older commits are not shown.');
|
|
221
|
+
panel.destroy();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test('an empty history is a sentence, not an empty box', async () => {
|
|
225
|
+
const controller = fakeController({ status: 'ready', payload: PAYLOAD, message: null });
|
|
226
|
+
const panel = createBlamePanel(5, controller, () => {});
|
|
227
|
+
body.append(panel.element);
|
|
228
|
+
panel.element.querySelector<HTMLButtonElement>('button[aria-expanded]')!.click();
|
|
229
|
+
await Promise.resolve();
|
|
230
|
+
await Promise.resolve();
|
|
231
|
+
await Promise.resolve();
|
|
232
|
+
expect(text(panel.element)).toContain('No commits touched this line.');
|
|
233
|
+
panel.destroy();
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test('the error state offers Try again, which asks its owner to re-read', () => {
|
|
237
|
+
const controller = fakeController({ status: 'error', payload: null, message: 'fatal: bad object' });
|
|
238
|
+
let retries = 0;
|
|
239
|
+
const panel = createBlamePanel(5, controller, () => {
|
|
240
|
+
retries += 1;
|
|
241
|
+
});
|
|
242
|
+
body.append(panel.element);
|
|
243
|
+
|
|
244
|
+
expect(text(panel.element)).toContain('Blame failed');
|
|
245
|
+
expect(text(panel.element)).toContain('fatal: bad object');
|
|
246
|
+
panel.element.querySelector<HTMLButtonElement>('[aria-label="Read the blame again"]')!.click();
|
|
247
|
+
// The CARD never reloads itself: it reports the press, and the surface that
|
|
248
|
+
// owns the controller decides what a retry means.
|
|
249
|
+
expect(retries).toBe(1);
|
|
250
|
+
expect(controller.reloads).toBe(0);
|
|
251
|
+
panel.destroy();
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('a loading card says it is reading rather than showing a blank', () => {
|
|
255
|
+
const controller = fakeController({ status: 'loading', payload: null, message: null });
|
|
256
|
+
const panel = createBlamePanel(5, controller, () => {});
|
|
257
|
+
body.append(panel.element);
|
|
258
|
+
// The beat between a hover and the file's blame landing: the card is on
|
|
259
|
+
// screen with nothing to say yet, and an empty box reads as broken.
|
|
260
|
+
expect(text(panel.element)).toBe('Reading blame…');
|
|
261
|
+
panel.destroy();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test('place() keeps the card inside the viewport and flips it above near the bottom', () => {
|
|
265
|
+
const controller = fakeController({ status: 'ready', payload: PAYLOAD, message: null });
|
|
266
|
+
const panel = createBlamePanel(5, controller, () => {});
|
|
267
|
+
body.append(panel.element);
|
|
268
|
+
|
|
269
|
+
// happy-dom reports 0 for every box, so the card's own fallback size is what
|
|
270
|
+
// decides the placement — which is the path a hidden pane takes.
|
|
271
|
+
panel.place(rect(10, 10, 40, 16));
|
|
272
|
+
expect(panel.element.style.left).toBe('10px');
|
|
273
|
+
expect(panel.element.style.top).toBe('32px');
|
|
274
|
+
|
|
275
|
+
// Past the bottom edge it flips above the anchor instead of being clipped.
|
|
276
|
+
panel.place(rect(10, window.innerHeight - 10, 40, 16));
|
|
277
|
+
expect(Number.parseFloat(panel.element.style.top)).toBeLessThan(window.innerHeight - 10);
|
|
278
|
+
panel.destroy();
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test('a press inside the card does not reach the document', () => {
|
|
282
|
+
const controller = fakeController({ status: 'ready', payload: PAYLOAD, message: null });
|
|
283
|
+
const panel = createBlamePanel(5, controller, () => {});
|
|
284
|
+
body.append(panel.element);
|
|
285
|
+
|
|
286
|
+
let reached = false;
|
|
287
|
+
document.addEventListener('mousedown', () => {
|
|
288
|
+
reached = true;
|
|
289
|
+
});
|
|
290
|
+
panel.element.dispatchEvent(new window.MouseEvent('mousedown', { bubbles: true }));
|
|
291
|
+
expect(reached).toBe(false);
|
|
292
|
+
panel.destroy();
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test('destroy unsubscribes, so a later change cannot repaint a removed card', () => {
|
|
296
|
+
const controller = fakeController({ status: 'ready', payload: PAYLOAD, message: null });
|
|
297
|
+
const panel = createBlamePanel(5, controller, () => {});
|
|
298
|
+
body.append(panel.element);
|
|
299
|
+
panel.destroy();
|
|
300
|
+
expect(panel.element.isConnected).toBe(false);
|
|
301
|
+
// A reload after destroy must not throw on a detached element.
|
|
302
|
+
controller.reload();
|
|
303
|
+
});
|
|
304
|
+
});
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The blame card: the commit that last touched a line, and — on request — every
|
|
8
|
+
* commit that touched it.
|
|
9
|
+
*
|
|
10
|
+
* Built from DOM rather than from Preact because it lives inside the editor's
|
|
11
|
+
* own subtree, which is not the Preact tree: a portal would need the component
|
|
12
|
+
* to re-render on every hover, and the editor is the one place the app already
|
|
13
|
+
* keeps its DOM imperative (see `theme.ts`, `marks.ts`).
|
|
14
|
+
*
|
|
15
|
+
* ## Six states, and only ONE of them is an error
|
|
16
|
+
*
|
|
17
|
+
* A dirty buffer, a line past the end of HEAD, an untracked file and a folder
|
|
18
|
+
* that is not a repository are all ANSWERS — the reader asked who wrote this
|
|
19
|
+
* and the honest reply is "nobody yet". Painting them red would make an
|
|
20
|
+
* ordinary state look like a failure and would teach the reader to distrust the
|
|
21
|
+
* one case that IS one.
|
|
22
|
+
*
|
|
23
|
+
* ## The card stays open while the pointer is over it
|
|
24
|
+
*
|
|
25
|
+
* That is what makes its text selectable, which is the only way to copy a sha
|
|
26
|
+
* out of it. Closing is the owner's job (see `blame.ts`): Escape, an outside
|
|
27
|
+
* press, a document change, and a pointer that left both the editor and the
|
|
28
|
+
* card.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { blameUnavailableText, formatBlameAge, isUncommittedSha } from '@/shared/lib/fs/git-blame';
|
|
32
|
+
import type { BlamePayload } from '@/shared/lib/fs/git-blame';
|
|
33
|
+
import type { BlameHistoryResult, BlameStatus, FileBlame } from '@/client/hooks/editor/blame';
|
|
34
|
+
|
|
35
|
+
export interface BlamePanelState {
|
|
36
|
+
line: number;
|
|
37
|
+
status: BlameStatus;
|
|
38
|
+
payload: BlamePayload | null;
|
|
39
|
+
message: string | null;
|
|
40
|
+
stale: boolean;
|
|
41
|
+
history: BlameHistoryResult | null;
|
|
42
|
+
historyOpen: boolean;
|
|
43
|
+
historyLoading: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const PANEL_CLASS =
|
|
47
|
+
'fixed z-50 w-[min(340px,92vw)] rounded-xl border border-ink/20 bg-paper p-3 shadow-xl font-sans text-xs text-ink';
|
|
48
|
+
|
|
49
|
+
const HEAD_CLASS = 'flex items-baseline justify-between gap-2';
|
|
50
|
+
const AUTHOR_CLASS = 'truncate text-xs font-semibold text-ink';
|
|
51
|
+
const AGE_CLASS = 'shrink-0 font-mono text-[10px] text-ink/40';
|
|
52
|
+
const SUBJECT_CLASS = 'mt-1 line-clamp-2 text-[11px] leading-snug text-ink/80';
|
|
53
|
+
const RULE_CLASS = 'mt-2 border-t border-ink/10 pt-2';
|
|
54
|
+
const META_CLASS = 'flex items-center gap-2 font-mono text-[9px] text-ink/40';
|
|
55
|
+
const NOTE_CLASS = 'mt-1 text-[10px] leading-snug text-ink/50';
|
|
56
|
+
const HISTORY_BUTTON_CLASS =
|
|
57
|
+
'mt-2 flex w-full items-center gap-1.5 text-left text-[10px] text-ink/50 hover:text-ink cursor-pointer';
|
|
58
|
+
const HISTORY_LIST_CLASS = 'mt-1.5 space-y-1 border-t border-ink/10 pt-1.5';
|
|
59
|
+
const HISTORY_ROW_CLASS = 'flex items-center gap-1.5 font-mono text-[10px]';
|
|
60
|
+
|
|
61
|
+
function el<K extends keyof HTMLElementTagNameMap>(
|
|
62
|
+
tag: K,
|
|
63
|
+
className: string,
|
|
64
|
+
text?: string,
|
|
65
|
+
): HTMLElementTagNameMap[K] {
|
|
66
|
+
const node = document.createElement(tag);
|
|
67
|
+
node.className = className;
|
|
68
|
+
if (text !== undefined) node.textContent = text;
|
|
69
|
+
return node;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** `14 Nov 2023`, from the commit's own clock. */
|
|
73
|
+
function commitDate(epochSeconds: number): string {
|
|
74
|
+
return new Date(epochSeconds * 1000).toLocaleDateString(undefined, {
|
|
75
|
+
day: 'numeric',
|
|
76
|
+
month: 'short',
|
|
77
|
+
year: 'numeric',
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* What the card says for a state, as a title and a body.
|
|
83
|
+
*
|
|
84
|
+
* Exported because the sentence is the whole product here: a test that only
|
|
85
|
+
* checked the DOM's shape would pass on a card that said the wrong thing about
|
|
86
|
+
* an unsaved line.
|
|
87
|
+
*/
|
|
88
|
+
export function blamePanelNote(state: BlamePanelState): { title: string; body: string } | null {
|
|
89
|
+
const payload = state.payload;
|
|
90
|
+
if (state.status === 'error') {
|
|
91
|
+
return { title: 'Blame failed', body: state.message ?? 'git could not read this file.' };
|
|
92
|
+
}
|
|
93
|
+
if (state.status === 'unavailable') {
|
|
94
|
+
return {
|
|
95
|
+
title: payload?.reason === 'untracked' ? 'Not tracked' : 'No history',
|
|
96
|
+
body: blameUnavailableText(payload?.reason ?? 'error', state.message ?? undefined),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (!payload) return null;
|
|
100
|
+
if (state.stale) {
|
|
101
|
+
return {
|
|
102
|
+
title: 'Not committed yet',
|
|
103
|
+
body: 'This line changed in the editor. Save the file to see its blame.',
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
if (state.line > payload.lines) {
|
|
107
|
+
return {
|
|
108
|
+
title: 'Not committed yet',
|
|
109
|
+
body: `Line ${state.line} is past the end of the file at HEAD (${payload.lines} lines).`,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const commit = payload.runs.length > 0 ? commitAt(payload, state.line) : null;
|
|
113
|
+
if (!commit) {
|
|
114
|
+
return { title: 'Not committed yet', body: `git has no attribution for line ${state.line}.` };
|
|
115
|
+
}
|
|
116
|
+
if (isUncommittedSha(commit.sha)) {
|
|
117
|
+
return { title: 'Not committed yet', body: 'This line differs from the last commit.' };
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function commitAt(payload: BlamePayload, line: number) {
|
|
123
|
+
for (const run of payload.runs) {
|
|
124
|
+
if (line >= run.from && line <= run.to) return payload.commits[run.sha] ?? null;
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** The card's own markup, rebuilt whole on every change. */
|
|
130
|
+
function renderInto(root: HTMLElement, state: BlamePanelState): void {
|
|
131
|
+
root.replaceChildren();
|
|
132
|
+
root.className = PANEL_CLASS;
|
|
133
|
+
|
|
134
|
+
const note = blamePanelNote(state);
|
|
135
|
+
if (note) {
|
|
136
|
+
const head = el('div', HEAD_CLASS);
|
|
137
|
+
head.append(el('span', AUTHOR_CLASS, note.title));
|
|
138
|
+
if (state.status === 'error' && state.message) {
|
|
139
|
+
const retry = el('button', 'shrink-0 cursor-pointer text-[10px] text-ink/50 hover:text-ink', 'Try again');
|
|
140
|
+
retry.type = 'button';
|
|
141
|
+
retry.setAttribute('aria-label', 'Read the blame again');
|
|
142
|
+
head.append(retry);
|
|
143
|
+
}
|
|
144
|
+
root.append(head, el('p', NOTE_CLASS, note.body));
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const payload = state.payload;
|
|
149
|
+
if (!payload) {
|
|
150
|
+
// The read has not landed yet. A card with nothing in it reads as broken, so
|
|
151
|
+
// it says what it is waiting for.
|
|
152
|
+
root.append(el('p', NOTE_CLASS, 'Reading blame…'));
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const commit = commitAt(payload, state.line)!;
|
|
156
|
+
|
|
157
|
+
const head = el('div', HEAD_CLASS);
|
|
158
|
+
head.append(el('span', AUTHOR_CLASS, commit.author.trim() || 'Unknown'), el('span', AGE_CLASS, formatBlameAge(commit.time)));
|
|
159
|
+
root.append(head);
|
|
160
|
+
|
|
161
|
+
if (commit.summary) root.append(el('p', SUBJECT_CLASS, commit.summary));
|
|
162
|
+
|
|
163
|
+
const meta = el('div', `${META_CLASS} ${RULE_CLASS}`);
|
|
164
|
+
meta.append(el('code', 'truncate', commit.sha.slice(0, 7)), el('span', '', commitDate(commit.time)));
|
|
165
|
+
if (commit.mail) {
|
|
166
|
+
const mail = el('span', 'truncate', commit.mail);
|
|
167
|
+
mail.title = commit.mail;
|
|
168
|
+
meta.append(mail);
|
|
169
|
+
}
|
|
170
|
+
root.append(meta);
|
|
171
|
+
|
|
172
|
+
const toggle = el('button', HISTORY_BUTTON_CLASS);
|
|
173
|
+
toggle.type = 'button';
|
|
174
|
+
toggle.setAttribute('aria-expanded', state.historyOpen ? 'true' : 'false');
|
|
175
|
+
toggle.textContent = `${state.historyOpen ? '▾' : '▸'} Line history`;
|
|
176
|
+
root.append(toggle);
|
|
177
|
+
|
|
178
|
+
if (!state.historyOpen) return;
|
|
179
|
+
|
|
180
|
+
const list = el('ol', HISTORY_LIST_CLASS);
|
|
181
|
+
if (state.historyLoading) {
|
|
182
|
+
list.append(el('li', `${HISTORY_ROW_CLASS} text-ink/40`, 'Reading history…'));
|
|
183
|
+
} else if (!state.history || state.history.entries.length === 0) {
|
|
184
|
+
list.append(el('li', `${HISTORY_ROW_CLASS} text-ink/40`, 'No commits touched this line.'));
|
|
185
|
+
} else {
|
|
186
|
+
const entries = state.history.entries;
|
|
187
|
+
entries.forEach((entry, index) => {
|
|
188
|
+
const row = el('li', HISTORY_ROW_CLASS);
|
|
189
|
+
// The LAST entry is where the line was born: `log -L` walks backwards
|
|
190
|
+
// from the newest commit that touched it.
|
|
191
|
+
const kind = index === entries.length - 1 ? 'new' : 'edit';
|
|
192
|
+
row.append(
|
|
193
|
+
el('span', 'text-ink/40', index === 0 ? '●' : '○'),
|
|
194
|
+
el('code', 'text-ink/60', entry.sha.slice(0, 7)),
|
|
195
|
+
el('span', 'truncate text-ink/80', entry.author.trim() || 'Unknown'),
|
|
196
|
+
el('span', 'ml-auto shrink-0 text-ink/40', formatBlameAge(entry.time)),
|
|
197
|
+
el(
|
|
198
|
+
'span',
|
|
199
|
+
'shrink-0 rounded bg-ink/5 px-1 text-[8.5px] uppercase tracking-wider text-ink/45',
|
|
200
|
+
kind,
|
|
201
|
+
),
|
|
202
|
+
);
|
|
203
|
+
list.append(row);
|
|
204
|
+
});
|
|
205
|
+
if (state.history.truncated) {
|
|
206
|
+
list.append(el('li', `${HISTORY_ROW_CLASS} text-ink/40`, 'Older commits are not shown.'));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
root.append(list);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export interface BlamePanel {
|
|
213
|
+
element: HTMLElement;
|
|
214
|
+
/** Re-place the card under `anchor` without rebuilding it. */
|
|
215
|
+
place(anchor: { left: number; top: number; bottom: number }): void;
|
|
216
|
+
destroy(): void;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Build a card for `line`, live-updating it as the answer arrives.
|
|
221
|
+
*
|
|
222
|
+
* The controller is subscribed rather than read once: a hover that lands before
|
|
223
|
+
* the file's blame has been read shows the skeleton, and the card has to fill
|
|
224
|
+
* itself in — a snapshot taken at open time would leave "Reading blame…" on
|
|
225
|
+
* screen forever.
|
|
226
|
+
*/
|
|
227
|
+
export function createBlamePanel(line: number, controller: FileBlame, onRetry: () => void): BlamePanel {
|
|
228
|
+
const element = el('div', PANEL_CLASS);
|
|
229
|
+
element.setAttribute('role', 'dialog');
|
|
230
|
+
element.setAttribute('aria-label', 'Line blame');
|
|
231
|
+
// A press inside the card is the reader selecting its text, so the owner must
|
|
232
|
+
// not treat it as an outside click.
|
|
233
|
+
element.addEventListener('mousedown', (event) => event.stopPropagation());
|
|
234
|
+
|
|
235
|
+
let history: BlameHistoryResult | null = null;
|
|
236
|
+
let historyOpen = false;
|
|
237
|
+
let historyLoading = false;
|
|
238
|
+
|
|
239
|
+
const state = (): BlamePanelState => {
|
|
240
|
+
const snapshot = controller.snapshot();
|
|
241
|
+
return {
|
|
242
|
+
line,
|
|
243
|
+
status: snapshot.status,
|
|
244
|
+
payload: snapshot.payload,
|
|
245
|
+
message: snapshot.message,
|
|
246
|
+
stale: controller.stale(),
|
|
247
|
+
history,
|
|
248
|
+
historyOpen,
|
|
249
|
+
historyLoading,
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const paint = () => {
|
|
254
|
+
renderInto(element, state());
|
|
255
|
+
const retry = element.querySelector<HTMLButtonElement>('[aria-label="Read the blame again"]');
|
|
256
|
+
if (retry) {
|
|
257
|
+
retry.addEventListener('click', (event) => {
|
|
258
|
+
event.stopPropagation();
|
|
259
|
+
onRetry();
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
element.querySelector<HTMLButtonElement>('button[aria-expanded]')?.addEventListener('click', (event) => {
|
|
263
|
+
event.stopPropagation();
|
|
264
|
+
historyOpen = !historyOpen;
|
|
265
|
+
paint();
|
|
266
|
+
if (!historyOpen || history || historyLoading) return;
|
|
267
|
+
historyLoading = true;
|
|
268
|
+
paint();
|
|
269
|
+
void controller.history(line).then((result) => {
|
|
270
|
+
history = result;
|
|
271
|
+
historyLoading = false;
|
|
272
|
+
paint();
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
paint();
|
|
278
|
+
const unsubscribe = controller.subscribe(paint);
|
|
279
|
+
|
|
280
|
+
return {
|
|
281
|
+
element,
|
|
282
|
+
place(anchor) {
|
|
283
|
+
// Measured after the paint, so the card's own height decides whether it
|
|
284
|
+
// flips above the line. The viewport comes from the card's OWN window
|
|
285
|
+
// rather than a bare `window` global: the card is mounted in whatever
|
|
286
|
+
// document the editor belongs to, and a module that assumes the top-level
|
|
287
|
+
// one cannot be mounted in a test window or an iframe.
|
|
288
|
+
const win = element.ownerDocument.defaultView;
|
|
289
|
+
const viewportWidth = win?.innerWidth ?? 1024;
|
|
290
|
+
const viewportHeight = win?.innerHeight ?? 768;
|
|
291
|
+
const width = element.offsetWidth || 340;
|
|
292
|
+
const height = element.offsetHeight || 120;
|
|
293
|
+
const margin = 8;
|
|
294
|
+
const left = Math.max(margin, Math.min(anchor.left, viewportWidth - width - margin));
|
|
295
|
+
const below = anchor.bottom + 6;
|
|
296
|
+
const above = anchor.top - height - 6;
|
|
297
|
+
const top = below + height > viewportHeight - margin && above > margin ? above : below;
|
|
298
|
+
element.style.left = `${left}px`;
|
|
299
|
+
element.style.top = `${Math.max(margin, top)}px`;
|
|
300
|
+
},
|
|
301
|
+
destroy() {
|
|
302
|
+
unsubscribe();
|
|
303
|
+
element.remove();
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
}
|