@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,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The DOM harness both `wait` panel suites mount through.
|
|
8
|
+
*
|
|
9
|
+
* Two files share it because the panel's two halves are different questions —
|
|
10
|
+
* a live/settled call (clock, bar, jobs) and a call with NO result (the reload
|
|
11
|
+
* shape) — and each suite is at the repo's per-file ceiling on its own.
|
|
12
|
+
*
|
|
13
|
+
* `happy-dom` is installed as globals here rather than in the suites so the two
|
|
14
|
+
* cannot drift on which globals a mounted panel needs; `render` runs inside
|
|
15
|
+
* `act` because the stopwatch schedules a `setInterval` on mount.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { Window } from 'happy-dom';
|
|
19
|
+
import { h, render } from 'preact';
|
|
20
|
+
import { act } from 'preact/test-utils';
|
|
21
|
+
import { Wait } from '@/client/components/workspace/chat-timeline/tool-renderers/panels/Wait';
|
|
22
|
+
import type { ToolCallData } from '@/shared/types';
|
|
23
|
+
|
|
24
|
+
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'HTMLInputElement', 'Event', 'MouseEvent', 'KeyboardEvent'] as const;
|
|
25
|
+
const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
26
|
+
|
|
27
|
+
/** Install the browser globals; call from `beforeAll`. */
|
|
28
|
+
export function installWaitDom(): void {
|
|
29
|
+
const win = new Window({ url: 'http://localhost' });
|
|
30
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
31
|
+
for (const key of DOM_GLOBALS) {
|
|
32
|
+
nativeGlobals[key] = target[key];
|
|
33
|
+
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Put the previous globals back; call from `afterAll`. */
|
|
38
|
+
export function restoreWaitDom(): void {
|
|
39
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
40
|
+
for (const key of DOM_GLOBALS) {
|
|
41
|
+
if (nativeGlobals[key] === undefined) delete target[key];
|
|
42
|
+
else target[key] = nativeGlobals[key];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Mount the panel for one call and return its container. */
|
|
47
|
+
export async function mountWait(
|
|
48
|
+
partial: Partial<ToolCallData> & Pick<ToolCallData, 'type'>,
|
|
49
|
+
): Promise<HTMLElement> {
|
|
50
|
+
const tool = { id: 'c1', name: partial.type, title: partial.type, ...partial } as ToolCallData;
|
|
51
|
+
const container = document.createElement('div');
|
|
52
|
+
document.body.appendChild(container);
|
|
53
|
+
await act(async () => {
|
|
54
|
+
render(h(Wait, { tool }), container);
|
|
55
|
+
});
|
|
56
|
+
return container;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The panel's progress track, if it drew one. */
|
|
60
|
+
export function waitBar(el: HTMLElement): HTMLElement | null {
|
|
61
|
+
return el.querySelector('[role="progressbar"]');
|
|
62
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The diff toolbar's hunk stepper: `‹ 2/5 ›`.
|
|
8
|
+
*
|
|
9
|
+
* Its own file for the per-file ceiling, and because it is the one cluster with
|
|
10
|
+
* state to read — the others are toggles over a prop. The index is 0-based in
|
|
11
|
+
* the view and 1-based on screen: "3 of 7" is what a reader counts, and `-1`
|
|
12
|
+
* (the caret outside every chunk) prints an en dash rather than `0`.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { ChevronDown, ChevronUp } from 'lucide-preact';
|
|
16
|
+
|
|
17
|
+
const ACTION_CLASS =
|
|
18
|
+
'flex items-center justify-center p-1.5 rounded transition-colors cursor-pointer disabled:cursor-default disabled:opacity-40 disabled:hover:bg-transparent disabled:hover:text-ink/50';
|
|
19
|
+
|
|
20
|
+
interface HunkStepperProps {
|
|
21
|
+
/** 0-based, or -1 when the caret is not inside a chunk. */
|
|
22
|
+
index: number;
|
|
23
|
+
count: number;
|
|
24
|
+
/** A git write or a reload is in flight; stepping a stale pair is misleading. */
|
|
25
|
+
locked: boolean;
|
|
26
|
+
onStep: (direction: 1 | -1) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function HunkStepper({ index, count, locked, onStep }: HunkStepperProps) {
|
|
30
|
+
const position = index >= 0 ? index + 1 : '–';
|
|
31
|
+
return (
|
|
32
|
+
<div className="flex items-center gap-0.5">
|
|
33
|
+
<button
|
|
34
|
+
type="button"
|
|
35
|
+
onClick={() => onStep(-1)}
|
|
36
|
+
disabled={locked}
|
|
37
|
+
className={`${ACTION_CLASS} text-ink/50 hover:text-ink hover:bg-ink/5`}
|
|
38
|
+
title="Previous change"
|
|
39
|
+
aria-label="Previous change"
|
|
40
|
+
>
|
|
41
|
+
<ChevronUp size={13} />
|
|
42
|
+
</button>
|
|
43
|
+
<span
|
|
44
|
+
className="text-[10px] font-mono tabular-nums text-ink/50 px-0.5 min-w-[3.5ch] text-center"
|
|
45
|
+
title={`Changed hunk ${position} of ${count}`}
|
|
46
|
+
aria-live="polite"
|
|
47
|
+
>
|
|
48
|
+
{position}/{count}
|
|
49
|
+
</span>
|
|
50
|
+
<button
|
|
51
|
+
type="button"
|
|
52
|
+
onClick={() => onStep(1)}
|
|
53
|
+
disabled={locked}
|
|
54
|
+
className={`${ACTION_CLASS} text-ink/50 hover:text-ink hover:bg-ink/5`}
|
|
55
|
+
title="Next change"
|
|
56
|
+
aria-label="Next change"
|
|
57
|
+
>
|
|
58
|
+
<ChevronDown size={13} />
|
|
59
|
+
</button>
|
|
60
|
+
</div>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
@@ -23,6 +23,8 @@ import { EDITOR_LINE_HEIGHT } from '@/shared/lib/code/editor/typography';
|
|
|
23
23
|
import {
|
|
24
24
|
countChanges,
|
|
25
25
|
foldWhitespaceOnly,
|
|
26
|
+
} from '@/client/components/workspace/diff-panel/changes';
|
|
27
|
+
import {
|
|
26
28
|
mountSplitDiff,
|
|
27
29
|
mountUnifiedDiff,
|
|
28
30
|
type DiffViewHandle,
|
|
@@ -46,6 +48,22 @@ interface MergeDiffViewProps {
|
|
|
46
48
|
* that draws its own badge from the patch (the chat's tool card).
|
|
47
49
|
*/
|
|
48
50
|
onCounts?: (counts: { additions: number; deletions: number }) => void;
|
|
51
|
+
/**
|
|
52
|
+
* The changed chunks in the pair on screen, and which one holds the caret.
|
|
53
|
+
*
|
|
54
|
+
* Reported rather than owned: the toolbar that draws "2 of 5" and the two
|
|
55
|
+
* chevrons lives in the panel above, and it must read the same numbers the
|
|
56
|
+
* view is stepping through.
|
|
57
|
+
*/
|
|
58
|
+
onChunkPosition?: (position: { index: number; count: number }) => void;
|
|
59
|
+
/**
|
|
60
|
+
* The step command, handed UP so the toolbar can call it.
|
|
61
|
+
*
|
|
62
|
+
* A callback rather than a ref because the handle is created in an effect
|
|
63
|
+
* that the toolbar's render cannot see; this runs after mount, once the view
|
|
64
|
+
* exists, and is a no-op before that.
|
|
65
|
+
*/
|
|
66
|
+
onStepChunk?: (step: (direction: 1 | -1) => void) => void;
|
|
49
67
|
/** Nothing to compare (both sides empty). */
|
|
50
68
|
empty: boolean;
|
|
51
69
|
fontFamily: string;
|
|
@@ -66,6 +84,8 @@ export function MergeDiffView({
|
|
|
66
84
|
ignoreWhitespace,
|
|
67
85
|
tabKey,
|
|
68
86
|
onCounts,
|
|
87
|
+
onChunkPosition,
|
|
88
|
+
onStepChunk,
|
|
69
89
|
empty,
|
|
70
90
|
fontFamily,
|
|
71
91
|
fontSize,
|
|
@@ -105,6 +125,7 @@ export function MergeDiffView({
|
|
|
105
125
|
themes,
|
|
106
126
|
scrollTestId: 'diff-scroller',
|
|
107
127
|
onScroller: setScroller,
|
|
128
|
+
onChunkPosition,
|
|
108
129
|
} as const;
|
|
109
130
|
const handle =
|
|
110
131
|
viewMode === 'split' ? mountSplitDiff(host, { ...options }) : mountUnifiedDiff(host, { ...options });
|
|
@@ -140,6 +161,14 @@ export function MergeDiffView({
|
|
|
140
161
|
handleRef.current?.setWordWrap(wordWrap);
|
|
141
162
|
}, [wordWrap]);
|
|
142
163
|
|
|
164
|
+
// The step command, published once the view exists. `stepChunk` reads the live
|
|
165
|
+
// handle, so a callback held across a re-mount still steps the current view.
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
onStepChunk?.((direction) => {
|
|
168
|
+
handleRef.current?.stepChunk(direction);
|
|
169
|
+
});
|
|
170
|
+
}, [onStepChunk]);
|
|
171
|
+
|
|
143
172
|
// Counts describe the pair ON SCREEN, so the badge cannot disagree with the
|
|
144
173
|
// rows under it (git's own `+n/-n` still counts a hidden whitespace change).
|
|
145
174
|
useEffect(() => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { AlignJustify, Check, Code2, Columns, Copy, Diff, FileCode, Minus, Plus, RefreshCw, Space, Undo2, WrapText } from 'lucide-preact';
|
|
1
|
+
import { AlignJustify, Check, ChevronDown, ChevronUp, Code2, Columns, Copy, Diff, FileCode, Minus, Plus, RefreshCw, Space, Undo2, WrapText } from 'lucide-preact';
|
|
2
2
|
import { FileIcon } from '@/client/components/common/file-icon';
|
|
3
3
|
import { EditorViewButtons, useEditorViewActions } from '@/client/components/common/editor-view-buttons';
|
|
4
4
|
import { getGitStatusInfo } from '@/shared/lib/fs/git-status';
|
|
5
5
|
import { ToolbarRow, type ToolbarCluster } from '@/client/components/common/toolbar-row';
|
|
6
6
|
import { DiffContentModeSegments, DiffViewModeSegments } from '@/client/components/workspace/diff-panel/ToolbarSegments';
|
|
7
|
+
import { HunkStepper } from '@/client/components/workspace/diff-panel/HunkStepper';
|
|
7
8
|
|
|
8
9
|
export type DiffViewMode = 'unified' | 'split';
|
|
9
10
|
|
|
@@ -25,6 +26,11 @@ interface DiffToolbarProps {
|
|
|
25
26
|
ignoreWhitespace: boolean;
|
|
26
27
|
additions: number;
|
|
27
28
|
deletions: number;
|
|
29
|
+
/** The chunk the caret is in (0-based, -1 for none), and how many there are. */
|
|
30
|
+
chunkIndex?: number;
|
|
31
|
+
chunkCount?: number;
|
|
32
|
+
/** Step to the next (`1`) or previous (`-1`) changed chunk. */
|
|
33
|
+
onStepChunk?: (direction: 1 | -1) => void;
|
|
28
34
|
isLoading: boolean;
|
|
29
35
|
isCopied: boolean;
|
|
30
36
|
/** A stage/unstage/discard write is in flight; the toolbar locks its actions. */
|
|
@@ -59,6 +65,9 @@ export function DiffToolbar({
|
|
|
59
65
|
ignoreWhitespace,
|
|
60
66
|
additions,
|
|
61
67
|
deletions,
|
|
68
|
+
chunkIndex = -1,
|
|
69
|
+
chunkCount = 0,
|
|
70
|
+
onStepChunk,
|
|
62
71
|
isLoading,
|
|
63
72
|
isCopied,
|
|
64
73
|
isBusy = false,
|
|
@@ -135,6 +144,28 @@ export function DiffToolbar({
|
|
|
135
144
|
children: <DiffContentModeSegments contentMode={contentMode} onSetContentMode={onSetContentMode} />,
|
|
136
145
|
});
|
|
137
146
|
|
|
147
|
+
if (onStepChunk && chunkCount > 0) {
|
|
148
|
+
// NOT pinned, and pushed AFTER the two mode segments — both facts are the
|
|
149
|
+
// measured answer to a row that cannot hold everything. Pinned clusters are
|
|
150
|
+
// placed in full before anything else, and at the panel's 320px floor the
|
|
151
|
+
// five pinned clusters (counts, view modes, stage, edit) already claim
|
|
152
|
+
// 260px of a 296px row; the 76px stepper left 2px for the 76px
|
|
153
|
+
// Unified/Split pair, which therefore never reached the row. Unpinned
|
|
154
|
+
// placement follows ROW ORDER, so sitting beside the counts cluster would
|
|
155
|
+
// still have won the budget ahead of the shape control. Here it takes the
|
|
156
|
+
// row as soon as the row can hold it — measured on the row at a 637px panel
|
|
157
|
+
// (457px of row), in `⋯` at the 320px floor — and stays one click away
|
|
158
|
+
// below that, as the same two actions it draws.
|
|
159
|
+
clusters.push({
|
|
160
|
+
id: 'hunks',
|
|
161
|
+
actions: [
|
|
162
|
+
{ label: 'Previous change', icon: ChevronUp, onSelect: () => onStepChunk(-1), disabled: locked },
|
|
163
|
+
{ label: 'Next change', icon: ChevronDown, onSelect: () => onStepChunk(1), disabled: locked },
|
|
164
|
+
],
|
|
165
|
+
children: <HunkStepper index={chunkIndex} count={chunkCount} locked={locked} onStep={onStepChunk} />,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
138
169
|
clusters.push({
|
|
139
170
|
id: 'wrap',
|
|
140
171
|
actions: [{ label: wrapLabel, icon: WrapText, onSelect: onToggleWordWrap, active: wordWrap }],
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What the diff toolbar's badge counts, and what the whitespace toggle folds.
|
|
8
|
+
*
|
|
9
|
+
* Split out of `merge.ts` for the per-file ceiling, and the two belong together:
|
|
10
|
+
* both answer "what counts as a change" and they must answer it the SAME way.
|
|
11
|
+
* A badge that counted a whitespace change the toggle had hidden would be a
|
|
12
|
+
* number describing rows that are not on screen.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { Chunk, diff } from '@codemirror/merge';
|
|
16
|
+
import { Text } from '@codemirror/state';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Additions and deletions, counted from the SAME line-level diff the view draws.
|
|
20
|
+
*
|
|
21
|
+
* `Chunk.build` is the merge view's own chunking — a line-level diff, which is
|
|
22
|
+
* what its rows are. `diff()` would be the wrong source here: it is a
|
|
23
|
+
* CHARACTER diff, so changing `line 5` into `line 5 changed` reports one
|
|
24
|
+
* insertion of `" changed"` and no deletion at all, and the badge would claim
|
|
25
|
+
* two additions for two edited lines.
|
|
26
|
+
*/
|
|
27
|
+
export function countChanges(original: string, next: string): { additions: number; deletions: number } {
|
|
28
|
+
const a = Text.of(original.split('\n'));
|
|
29
|
+
const b = Text.of(next.split('\n'));
|
|
30
|
+
let additions = 0;
|
|
31
|
+
let deletions = 0;
|
|
32
|
+
for (const chunk of Chunk.build(a, b)) {
|
|
33
|
+
// `endA`/`endB` are the end of the chunk's last line, and equal the start
|
|
34
|
+
// when the chunk covers no lines on that side (a pure insertion/deletion).
|
|
35
|
+
if (chunk.endA > chunk.fromA) deletions += a.lineAt(chunk.endA).number - a.lineAt(chunk.fromA).number + 1;
|
|
36
|
+
if (chunk.endB > chunk.fromB) additions += b.lineAt(chunk.endB).number - b.lineAt(chunk.fromB).number + 1;
|
|
37
|
+
}
|
|
38
|
+
return { additions, deletions };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* `original` with every whitespace-only change replaced by the new text.
|
|
43
|
+
*
|
|
44
|
+
* The toolbar's whitespace toggle means "do not show me formatting noise", and
|
|
45
|
+
* the merge view compares DOCUMENTS — so the way to honour it is to make the two
|
|
46
|
+
* sides agree there. The old table parser folded a `-`/`+` pair whose trimmed
|
|
47
|
+
* text matched back into a context row; this does the same at the source, which
|
|
48
|
+
* is why the toggle changes the CHUNKS rather than only their colour.
|
|
49
|
+
*
|
|
50
|
+
* Only line-for-line changes are folded: an inserted or deleted line is a real
|
|
51
|
+
* change even when it is blank, and hiding it would make the file's line count
|
|
52
|
+
* disagree with what is on screen.
|
|
53
|
+
*/
|
|
54
|
+
export function foldWhitespaceOnly(original: string, next: string): string {
|
|
55
|
+
const changes = diff(original, next);
|
|
56
|
+
let folded = original;
|
|
57
|
+
// Back to front: an earlier splice would move every later offset.
|
|
58
|
+
for (let index = changes.length - 1; index >= 0; index--) {
|
|
59
|
+
const change = changes[index];
|
|
60
|
+
const before = original.slice(change.fromA, change.toA);
|
|
61
|
+
const after = next.slice(change.fromB, change.toB);
|
|
62
|
+
const beforeLines = before.split('\n');
|
|
63
|
+
const afterLines = after.split('\n');
|
|
64
|
+
if (beforeLines.length !== afterLines.length) continue;
|
|
65
|
+
if (!beforeLines.every((line, lineIndex) => line.trim() === afterLines[lineIndex].trim())) continue;
|
|
66
|
+
folded = folded.slice(0, change.fromA) + after + folded.slice(change.toA);
|
|
67
|
+
}
|
|
68
|
+
return folded;
|
|
69
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Stepping through a diff's changed chunks.
|
|
8
|
+
*
|
|
9
|
+
* Split out of `merge.ts` for the per-file ceiling, and it earns the boundary:
|
|
10
|
+
* everything here is a question about a LIVE view's selection, while `merge.ts`
|
|
11
|
+
* owns mounting and reconfiguring the two shapes.
|
|
12
|
+
*
|
|
13
|
+
* Three facts are load-bearing, and none is guessable:
|
|
14
|
+
*
|
|
15
|
+
* - `getChunks` is a FUNCTION on the state and answers `null` for a state with
|
|
16
|
+
* no merge extension. `state.field(getChunks)` throws "Field is not present
|
|
17
|
+
* in this state", and a null treated as "no changes" reads as an empty diff.
|
|
18
|
+
* - The side matters. A split view's B editor is the working file and reports
|
|
19
|
+
* `side: 'b'`; a unified view also reports `'b'` (it renders the new
|
|
20
|
+
* document). Reading `fromA` on a `'b'` view measures the wrong document.
|
|
21
|
+
* - The package's own `goToNextChunk` moves the SELECTION and scrolls through
|
|
22
|
+
* `scrollIntoView` on the range — which is not enough on a read-only reader,
|
|
23
|
+
* so the row is centred again after the move.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import type { Extension } from '@codemirror/state';
|
|
27
|
+
import { EditorView } from '@codemirror/view';
|
|
28
|
+
import { goToNextChunk, goToPreviousChunk, getChunks } from '@codemirror/merge';
|
|
29
|
+
|
|
30
|
+
/** The chunk the selection is in (`index` 0-based, or -1), and how many exist. */
|
|
31
|
+
export interface ChunkPosition {
|
|
32
|
+
index: number;
|
|
33
|
+
count: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** `StateCommand`'s shape as this module invokes it (see `keymap.ts`). */
|
|
37
|
+
type ViewCommand = (view: EditorView) => boolean;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The chunk the selection is in, and how many there are.
|
|
41
|
+
*
|
|
42
|
+
* A pair rather than two calls because they are read in one render: a caller
|
|
43
|
+
* that fetched them separately could print "3 of 2" after a document swap.
|
|
44
|
+
*/
|
|
45
|
+
export function chunkPositionOf(view: EditorView): ChunkPosition {
|
|
46
|
+
const field = getChunks(view.state);
|
|
47
|
+
if (!field || field.chunks.length === 0) return { index: -1, count: 0 };
|
|
48
|
+
const head = view.state.selection.main.head;
|
|
49
|
+
const index = field.chunks.findIndex((chunk) =>
|
|
50
|
+
field.side === 'a'
|
|
51
|
+
? head >= chunk.fromA && head <= chunk.toA
|
|
52
|
+
: head >= chunk.fromB && head <= chunk.toB,
|
|
53
|
+
);
|
|
54
|
+
return { index, count: field.chunks.length };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Step to the next/previous chunk and bring it into view.
|
|
59
|
+
*
|
|
60
|
+
* False when there is nowhere to go — no chunks at all, or the caret already
|
|
61
|
+
* inside the only one — so a caller can leave a control inert.
|
|
62
|
+
*/
|
|
63
|
+
export function stepChunkIn(view: EditorView, direction: 1 | -1): boolean {
|
|
64
|
+
const command = (direction === 1 ? goToNextChunk : goToPreviousChunk) as unknown as ViewCommand;
|
|
65
|
+
const moved = command(view);
|
|
66
|
+
if (moved) {
|
|
67
|
+
const head = view.state.selection.main.head;
|
|
68
|
+
view.dispatch({ effects: EditorView.scrollIntoView(head, { y: 'center' }) });
|
|
69
|
+
}
|
|
70
|
+
return moved;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Report the selection's chunk on every update that moves it.
|
|
75
|
+
*
|
|
76
|
+
* Attached to ONE view per shape (the B side of a split, the single view of a
|
|
77
|
+
* unified diff): both sides of a split carry the chunk field, and two reporters
|
|
78
|
+
* would race for the same toolbar label.
|
|
79
|
+
*/
|
|
80
|
+
export function chunkReporter(report: (position: ChunkPosition) => void): Extension {
|
|
81
|
+
return EditorView.updateListener.of((update) => {
|
|
82
|
+
if (!update.docChanged && !update.selectionSet) return;
|
|
83
|
+
report(chunkPositionOf(update.view));
|
|
84
|
+
});
|
|
85
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState } from 'preact/hooks';
|
|
1
|
+
import { useCallback, useRef, useState } from 'preact/hooks';
|
|
2
2
|
import { useSessionUiState } from '@/client/hooks/workspace/session-state';
|
|
3
3
|
import { isUnmergedCode } from '@/shared/lib/fs/git-unmerged';
|
|
4
4
|
import { useFileDiff } from '@/client/hooks/workspace/diff-file';
|
|
@@ -58,6 +58,21 @@ export function DiffPanel({
|
|
|
58
58
|
const [showDiscardConfirm, setShowDiscardConfirm] = useState<boolean>(false);
|
|
59
59
|
/** Additions/deletions of the pair on screen, reported by the merge view. */
|
|
60
60
|
const [counts, setCounts] = useState<{ additions: number; deletions: number }>({ additions: 0, deletions: 0 });
|
|
61
|
+
/**
|
|
62
|
+
* Which changed hunk the caret is in, reported by the merge view.
|
|
63
|
+
*
|
|
64
|
+
* The step command is held in a ref rather than state: it is a function the
|
|
65
|
+
* toolbar calls, and putting it in state would re-render the panel every time
|
|
66
|
+
* the view re-mounts (a shape switch) for a value nothing displays.
|
|
67
|
+
*/
|
|
68
|
+
const [chunkPosition, setChunkPosition] = useState<{ index: number; count: number }>({ index: -1, count: 0 });
|
|
69
|
+
const stepChunkRef = useRef<((direction: 1 | -1) => void) | null>(null);
|
|
70
|
+
const handleStepChunk = useCallback((direction: 1 | -1) => {
|
|
71
|
+
stepChunkRef.current?.(direction);
|
|
72
|
+
}, []);
|
|
73
|
+
const handleChunkCommand = useCallback((step: (direction: 1 | -1) => void) => {
|
|
74
|
+
stepChunkRef.current = step;
|
|
75
|
+
}, []);
|
|
61
76
|
const editorFontFamily = useEditorFontStack();
|
|
62
77
|
|
|
63
78
|
const {
|
|
@@ -146,6 +161,9 @@ export function DiffPanel({
|
|
|
146
161
|
ignoreWhitespace={ignoreWhitespace}
|
|
147
162
|
additions={counts.additions}
|
|
148
163
|
deletions={counts.deletions}
|
|
164
|
+
chunkIndex={chunkPosition.index}
|
|
165
|
+
chunkCount={chunkPosition.count}
|
|
166
|
+
onStepChunk={handleStepChunk}
|
|
149
167
|
isLoading={isLoading}
|
|
150
168
|
isCopied={isCopied}
|
|
151
169
|
isBusy={isBusy}
|
|
@@ -230,6 +248,8 @@ export function DiffPanel({
|
|
|
230
248
|
ignoreWhitespace={ignoreWhitespace}
|
|
231
249
|
tabKey={tabKey}
|
|
232
250
|
onCounts={setCounts}
|
|
251
|
+
onChunkPosition={setChunkPosition}
|
|
252
|
+
onStepChunk={handleChunkCommand}
|
|
233
253
|
empty={!rawDiff || !rawDiff.trim()}
|
|
234
254
|
fontFamily={editorFontFamily}
|
|
235
255
|
fontSize={EDITOR_DEFAULT_FONT_SIZE}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The diff's hunk stepper: the two numbers the toolbar prints, and the move
|
|
8
|
+
* behind the two chevrons.
|
|
9
|
+
*
|
|
10
|
+
* Every way this fails is silent. `getChunks` is a FUNCTION on the state and
|
|
11
|
+
* answers `null` without a merge extension, so a wrong call reads as "no
|
|
12
|
+
* changes" — and the merge package's own `goToNextChunk` moves the SELECTION
|
|
13
|
+
* without scrolling, which on a read-only reader means the row changes somewhere
|
|
14
|
+
* off screen. Both cases mount a real view.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
|
18
|
+
import { Window } from 'happy-dom';
|
|
19
|
+
|
|
20
|
+
import { mountSplitDiff, mountUnifiedDiff, type DiffViewHandle } from '@/client/components/workspace/diff-panel/merge';
|
|
21
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
22
|
+
|
|
23
|
+
const EXTRA_GLOBALS = ['MutationObserver', 'requestAnimationFrame', 'cancelAnimationFrame', 'ResizeObserver'] as const;
|
|
24
|
+
const native: Partial<Record<(typeof EXTRA_GLOBALS)[number], unknown>> = {};
|
|
25
|
+
|
|
26
|
+
let host: HTMLElement;
|
|
27
|
+
|
|
28
|
+
beforeAll(() => {
|
|
29
|
+
const win = new Window({ url: 'http://localhost' });
|
|
30
|
+
installDomGlobals(win);
|
|
31
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
32
|
+
for (const key of EXTRA_GLOBALS) {
|
|
33
|
+
native[key] = target[key];
|
|
34
|
+
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
35
|
+
}
|
|
36
|
+
host = document.body.appendChild(document.createElement('div'));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterAll(() => {
|
|
40
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
41
|
+
for (const key of EXTRA_GLOBALS) {
|
|
42
|
+
if (native[key] === undefined) delete target[key];
|
|
43
|
+
else target[key] = native[key];
|
|
44
|
+
}
|
|
45
|
+
restoreDomGlobals();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const ORIGINAL = ['one', 'two', 'three', 'four', 'five', 'six'].join('\n');
|
|
49
|
+
// Two separate changes, far enough apart that the diff keeps them as two chunks.
|
|
50
|
+
const NEXT = ['one', 'TWO', 'three', 'four', 'FIVE', 'six'].join('\n');
|
|
51
|
+
|
|
52
|
+
interface Mounted {
|
|
53
|
+
handle: DiffViewHandle;
|
|
54
|
+
positions: Array<{ index: number; count: number }>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function mount(kind: 'unified' | 'split', original = ORIGINAL, next = NEXT): Mounted {
|
|
58
|
+
const parent = document.createElement('div');
|
|
59
|
+
host.appendChild(parent);
|
|
60
|
+
const positions: Array<{ index: number; count: number }> = [];
|
|
61
|
+
const options = {
|
|
62
|
+
original,
|
|
63
|
+
next,
|
|
64
|
+
language: 'text',
|
|
65
|
+
wordWrap: false,
|
|
66
|
+
collapse: 'diff' as const,
|
|
67
|
+
scrollTestId: 'diff-scroller',
|
|
68
|
+
onScroller: () => {},
|
|
69
|
+
onChunkPosition: (position: { index: number; count: number }) => positions.push(position),
|
|
70
|
+
};
|
|
71
|
+
const handle = kind === 'split' ? mountSplitDiff(parent, options) : mountUnifiedDiff(parent, options);
|
|
72
|
+
return { handle, positions };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
describe('chunk position', () => {
|
|
76
|
+
test('a changed pair reports its chunks on mount', () => {
|
|
77
|
+
for (const kind of ['unified', 'split'] as const) {
|
|
78
|
+
const { handle } = mount(kind);
|
|
79
|
+
const position = handle.chunkPosition();
|
|
80
|
+
expect(position.count).toBe(2);
|
|
81
|
+
// The selection starts at the top, which is not inside a chunk.
|
|
82
|
+
expect(position.index).toBe(-1);
|
|
83
|
+
handle.destroy();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('an identical pair reports no chunks', () => {
|
|
88
|
+
const { handle } = mount('unified', ORIGINAL, ORIGINAL);
|
|
89
|
+
expect(handle.chunkPosition()).toEqual({ index: -1, count: 0 });
|
|
90
|
+
// Nothing to step to, so the toolbar must be able to tell.
|
|
91
|
+
expect(handle.stepChunk(1)).toBe(false);
|
|
92
|
+
handle.destroy();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('the mount reports the seed position, so the badge is not "0 of 0"', () => {
|
|
96
|
+
const { handle, positions } = mount('unified');
|
|
97
|
+
expect(positions[0]).toEqual({ index: -1, count: 2 });
|
|
98
|
+
handle.destroy();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('stepChunk', () => {
|
|
103
|
+
test('steps forward through every chunk and wraps', () => {
|
|
104
|
+
const { handle } = mount('unified');
|
|
105
|
+
expect(handle.stepChunk(1)).toBe(true);
|
|
106
|
+
expect(handle.chunkPosition().index).toBe(0);
|
|
107
|
+
expect(handle.stepChunk(1)).toBe(true);
|
|
108
|
+
expect(handle.chunkPosition().index).toBe(1);
|
|
109
|
+
// Past the last one is the first one again: the package's own wrap.
|
|
110
|
+
expect(handle.stepChunk(1)).toBe(true);
|
|
111
|
+
expect(handle.chunkPosition().index).toBe(0);
|
|
112
|
+
handle.destroy();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('steps backward and wraps the other way', () => {
|
|
116
|
+
const { handle } = mount('unified');
|
|
117
|
+
expect(handle.stepChunk(-1)).toBe(true);
|
|
118
|
+
expect(handle.chunkPosition().index).toBe(1);
|
|
119
|
+
expect(handle.stepChunk(-1)).toBe(true);
|
|
120
|
+
expect(handle.chunkPosition().index).toBe(0);
|
|
121
|
+
handle.destroy();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('the split shape steps the B side, which is the working file', () => {
|
|
125
|
+
const { handle } = mount('split');
|
|
126
|
+
expect(handle.stepChunk(1)).toBe(true);
|
|
127
|
+
expect(handle.chunkPosition().index).toBe(0);
|
|
128
|
+
expect(handle.stepChunk(1)).toBe(true);
|
|
129
|
+
expect(handle.chunkPosition().index).toBe(1);
|
|
130
|
+
handle.destroy();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('a single chunk is entered once and then refuses to move', () => {
|
|
134
|
+
// Measured: the package only refuses when the caret is ALREADY inside the
|
|
135
|
+
// one chunk. From outside it, the first step is the useful one — it puts the
|
|
136
|
+
// caret on the change — and every step after that returns false rather than
|
|
137
|
+
// re-selecting the same row.
|
|
138
|
+
const { handle } = mount('unified', 'a\nb\nc', 'a\nB\nc');
|
|
139
|
+
expect(handle.chunkPosition().count).toBe(1);
|
|
140
|
+
expect(handle.stepChunk(1)).toBe(true);
|
|
141
|
+
expect(handle.chunkPosition().index).toBe(0);
|
|
142
|
+
expect(handle.stepChunk(1)).toBe(false);
|
|
143
|
+
handle.destroy();
|
|
144
|
+
});
|
|
145
|
+
});
|