@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,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The editor's blame controller: one read per open file, and one history read
|
|
8
|
+
* per line the reader asks about.
|
|
9
|
+
*
|
|
10
|
+
* ## The identity is STABLE, and the state is read through it
|
|
11
|
+
*
|
|
12
|
+
* The controller is handed to a CodeMirror extension, which is built once per
|
|
13
|
+
* document state. A controller that changed identity per render would have to
|
|
14
|
+
* be threaded through a compartment reconfigure on every keystroke — and a
|
|
15
|
+
* reconfigure rebuilds the plugin, closing the panel the reader has open. So
|
|
16
|
+
* the controller is built once and exposes `snapshot()` / `subscribe()`; the
|
|
17
|
+
* component re-renders from the same subscription, and the surface reads the
|
|
18
|
+
* same answer without either of them owning it.
|
|
19
|
+
*
|
|
20
|
+
* ## Three guards, each a bug first
|
|
21
|
+
*
|
|
22
|
+
* - **A LATE answer for another file is dropped** (a sequence number). The
|
|
23
|
+
* panel re-renders on a tab switch while the previous file's read is in
|
|
24
|
+
* flight, and adopting it would label the new file with the old authors.
|
|
25
|
+
* - **A payload is only reported for the key it was read for.** The snapshot
|
|
26
|
+
* carries its own key, so the frame between a tab switch and its read shows
|
|
27
|
+
* `idle` rather than the previous file's blame.
|
|
28
|
+
* - **A DIRTY buffer keeps the last payload but marks it stale.** The bytes on
|
|
29
|
+
* disk and the bytes on screen are different documents, so every line number
|
|
30
|
+
* after an edit may name the wrong line. The surface hides the labels and the
|
|
31
|
+
* panel says so; discarding the payload instead would flash the panel back to
|
|
32
|
+
* a skeleton on every keystroke.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
|
36
|
+
|
|
37
|
+
import type { BlameHistoryEntry, BlamePayload } from '@/shared/lib/fs/git-blame';
|
|
38
|
+
import type { FileEditorTarget } from '@/client/hooks/editor/file-editor-types';
|
|
39
|
+
|
|
40
|
+
export type BlameStatus = 'idle' | 'loading' | 'ready' | 'unavailable' | 'error';
|
|
41
|
+
|
|
42
|
+
export interface BlameSnapshot {
|
|
43
|
+
status: BlameStatus;
|
|
44
|
+
payload: BlamePayload | null;
|
|
45
|
+
message: string | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface BlameHistoryResult {
|
|
49
|
+
entries: BlameHistoryEntry[];
|
|
50
|
+
truncated: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface FileBlame {
|
|
54
|
+
/** Read the file's blame unless it is already known or in flight. */
|
|
55
|
+
ensure(): void;
|
|
56
|
+
/** Forget the answer and read it again (the panel's Try again). */
|
|
57
|
+
reload(): void;
|
|
58
|
+
/** The commits that touched `line`, newest first. Cached per line. */
|
|
59
|
+
history(line: number): Promise<BlameHistoryResult>;
|
|
60
|
+
/** The answer for the file on screen now; `idle` while a read is in flight. */
|
|
61
|
+
snapshot(): BlameSnapshot;
|
|
62
|
+
/** True while the buffer holds bytes the blame does not describe. */
|
|
63
|
+
stale(): boolean;
|
|
64
|
+
/** Fires when the answer, its staleness or the file changes. */
|
|
65
|
+
subscribe(listener: () => void): () => void;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const IDLE: BlameSnapshot = { status: 'idle', payload: null, message: null };
|
|
69
|
+
|
|
70
|
+
/** The request's own identity: two workspaces can hold the same relative path. */
|
|
71
|
+
function scopeKey(target: FileEditorTarget | null): string {
|
|
72
|
+
if (!target?.path) return '';
|
|
73
|
+
return `${target.root ?? ''}\u0000${target.repo ?? ''}\u0000${target.path}`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function useFileBlame(
|
|
77
|
+
target: FileEditorTarget | null,
|
|
78
|
+
options: { enabled?: boolean; dirty?: boolean } = {},
|
|
79
|
+
): FileBlame {
|
|
80
|
+
const enabled = options.enabled !== false && Boolean(target?.path) && target?.deviceFile !== true;
|
|
81
|
+
const dirty = options.dirty === true;
|
|
82
|
+
const key = scopeKey(target);
|
|
83
|
+
|
|
84
|
+
const [snapshot, setSnapshot] = useState<{ key: string; value: BlameSnapshot }>({ key: '', value: IDLE });
|
|
85
|
+
|
|
86
|
+
const targetRef = useRef(target);
|
|
87
|
+
targetRef.current = target;
|
|
88
|
+
const keyRef = useRef(key);
|
|
89
|
+
keyRef.current = key;
|
|
90
|
+
const enabledRef = useRef(enabled);
|
|
91
|
+
enabledRef.current = enabled;
|
|
92
|
+
const dirtyRef = useRef(dirty);
|
|
93
|
+
dirtyRef.current = dirty;
|
|
94
|
+
const snapshotRef = useRef(snapshot);
|
|
95
|
+
snapshotRef.current = snapshot;
|
|
96
|
+
|
|
97
|
+
/** The request sequence, so a late answer for another file is dropped. */
|
|
98
|
+
const seqRef = useRef(0);
|
|
99
|
+
/** The key of the read in flight, so `ensure` cannot start a second one. */
|
|
100
|
+
const inflightRef = useRef('');
|
|
101
|
+
const historyRef = useRef<Map<number, BlameHistoryResult>>(new Map());
|
|
102
|
+
const listenersRef = useRef(new Set<() => void>());
|
|
103
|
+
|
|
104
|
+
const load = useCallback(async (): Promise<void> => {
|
|
105
|
+
const file = targetRef.current;
|
|
106
|
+
if (!file?.path) return;
|
|
107
|
+
const forKey = scopeKey(file);
|
|
108
|
+
const seq = ++seqRef.current;
|
|
109
|
+
inflightRef.current = forKey;
|
|
110
|
+
setSnapshot((prev) => ({
|
|
111
|
+
key: forKey,
|
|
112
|
+
// The previous payload stays while a refresh runs: a reload should not
|
|
113
|
+
// blank the panel it is refreshing.
|
|
114
|
+
value: { status: 'loading', payload: prev.key === forKey ? prev.value.payload : null, message: null },
|
|
115
|
+
}));
|
|
116
|
+
|
|
117
|
+
const params = new URLSearchParams({ blame: '1', file: file.path, repo: file.repo || '.' });
|
|
118
|
+
if (file.root) params.set('root', file.root);
|
|
119
|
+
try {
|
|
120
|
+
const response = await fetch(`/api/fs/git?${params.toString()}`);
|
|
121
|
+
const data = (await response.json().catch(() => null)) as (BlamePayload & { error?: string }) | null;
|
|
122
|
+
if (seq !== seqRef.current) return;
|
|
123
|
+
if (!response.ok || !data) {
|
|
124
|
+
setSnapshot({
|
|
125
|
+
key: forKey,
|
|
126
|
+
value: {
|
|
127
|
+
status: 'error',
|
|
128
|
+
payload: null,
|
|
129
|
+
message: data?.error ?? `Blame request failed (HTTP ${response.status})`,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
setSnapshot({
|
|
135
|
+
key: forKey,
|
|
136
|
+
value: data.available
|
|
137
|
+
? { status: 'ready', payload: data, message: null }
|
|
138
|
+
: { status: 'unavailable', payload: data, message: data.message ?? null },
|
|
139
|
+
});
|
|
140
|
+
} catch (error: unknown) {
|
|
141
|
+
if (seq !== seqRef.current) return;
|
|
142
|
+
setSnapshot({
|
|
143
|
+
key: forKey,
|
|
144
|
+
value: { status: 'error', payload: null, message: error instanceof Error ? error.message : 'Blame failed' },
|
|
145
|
+
});
|
|
146
|
+
} finally {
|
|
147
|
+
if (inflightRef.current === forKey) inflightRef.current = '';
|
|
148
|
+
}
|
|
149
|
+
}, []);
|
|
150
|
+
|
|
151
|
+
const readHistory = useCallback(async (line: number): Promise<BlameHistoryResult> => {
|
|
152
|
+
const cached = historyRef.current.get(line);
|
|
153
|
+
if (cached) return cached;
|
|
154
|
+
const file = targetRef.current;
|
|
155
|
+
if (!file?.path) return { entries: [], truncated: false };
|
|
156
|
+
const params = new URLSearchParams({
|
|
157
|
+
blameHistory: '1',
|
|
158
|
+
file: file.path,
|
|
159
|
+
line: String(line),
|
|
160
|
+
repo: file.repo || '.',
|
|
161
|
+
});
|
|
162
|
+
if (file.root) params.set('root', file.root);
|
|
163
|
+
try {
|
|
164
|
+
const response = await fetch(`/api/fs/git?${params.toString()}`);
|
|
165
|
+
const data = (await response.json().catch(() => null)) as Partial<BlameHistoryResult> | null;
|
|
166
|
+
const result: BlameHistoryResult = {
|
|
167
|
+
entries: Array.isArray(data?.entries) ? data.entries : [],
|
|
168
|
+
truncated: data?.truncated === true,
|
|
169
|
+
};
|
|
170
|
+
historyRef.current.set(line, result);
|
|
171
|
+
return result;
|
|
172
|
+
} catch {
|
|
173
|
+
// A failed history read is an empty list, not a broken panel: the blame
|
|
174
|
+
// above it is already the answer to "who touched this line last".
|
|
175
|
+
return { entries: [], truncated: false };
|
|
176
|
+
}
|
|
177
|
+
}, []);
|
|
178
|
+
|
|
179
|
+
const controllerRef = useRef<FileBlame | null>(null);
|
|
180
|
+
if (!controllerRef.current) {
|
|
181
|
+
controllerRef.current = {
|
|
182
|
+
ensure: () => {
|
|
183
|
+
if (!enabledRef.current || dirtyRef.current) return;
|
|
184
|
+
const current = snapshotRef.current;
|
|
185
|
+
if (current.key === keyRef.current && current.value.status !== 'idle') return;
|
|
186
|
+
if (inflightRef.current === keyRef.current) return;
|
|
187
|
+
void load();
|
|
188
|
+
},
|
|
189
|
+
reload: () => {
|
|
190
|
+
historyRef.current.clear();
|
|
191
|
+
void load();
|
|
192
|
+
},
|
|
193
|
+
history: readHistory,
|
|
194
|
+
snapshot: () => {
|
|
195
|
+
const current = snapshotRef.current;
|
|
196
|
+
return current.key === keyRef.current ? current.value : IDLE;
|
|
197
|
+
},
|
|
198
|
+
stale: () => dirtyRef.current,
|
|
199
|
+
subscribe: (listener) => {
|
|
200
|
+
listenersRef.current.add(listener);
|
|
201
|
+
return () => {
|
|
202
|
+
listenersRef.current.delete(listener);
|
|
203
|
+
};
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Read on mount and after every save: a dirty buffer has no blame to show,
|
|
209
|
+
// and the save is what makes one exist again.
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
if (!enabled || dirty || !key) return;
|
|
212
|
+
historyRef.current.clear();
|
|
213
|
+
void load();
|
|
214
|
+
}, [enabled, dirty, key, load]);
|
|
215
|
+
|
|
216
|
+
// One notification per real change. `dirty` is compared rather than depended
|
|
217
|
+
// on, because it moves on every keystroke and the listeners only care when it
|
|
218
|
+
// FLIPS.
|
|
219
|
+
const lastDirty = useRef(dirty);
|
|
220
|
+
useEffect(() => {
|
|
221
|
+
if (lastDirty.current === dirty) return;
|
|
222
|
+
lastDirty.current = dirty;
|
|
223
|
+
for (const listener of listenersRef.current) listener();
|
|
224
|
+
}, [dirty]);
|
|
225
|
+
|
|
226
|
+
useEffect(() => {
|
|
227
|
+
for (const listener of listenersRef.current) listener();
|
|
228
|
+
}, [snapshot]);
|
|
229
|
+
|
|
230
|
+
const controller = controllerRef.current;
|
|
231
|
+
return controller;
|
|
232
|
+
}
|
|
@@ -28,6 +28,12 @@ export interface FileEditorTarget {
|
|
|
28
28
|
repo?: string;
|
|
29
29
|
/** The live handle a PWA launch opened this file through, when there is one. */
|
|
30
30
|
handleId?: string;
|
|
31
|
+
/**
|
|
32
|
+
* True when the bytes came from the DEVICE (a document the phone handed over).
|
|
33
|
+
* The tab renders and is READ-ONLY: there is no path the server can reach and
|
|
34
|
+
* no writable handle, so a Save has nothing to write to.
|
|
35
|
+
*/
|
|
36
|
+
deviceFile?: boolean;
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
export interface UseFileEditorOptions {
|
|
@@ -116,6 +122,23 @@ export interface UseFileEditorResult {
|
|
|
116
122
|
* instead of showing a button that silently fails.
|
|
117
123
|
*/
|
|
118
124
|
handleMissing: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* A tab whose bytes the DEVICE supplied (a document a phone opened).
|
|
127
|
+
*
|
|
128
|
+
* Distinct from `handleMissing`, and the distinction is the message: a missing
|
|
129
|
+
* handle means the permission ENDED (reopening restores it), while a
|
|
130
|
+
* device-backed tab never had anywhere to write — telling a phone user to
|
|
131
|
+
* reopen the file for write access would promise what reopening cannot give.
|
|
132
|
+
*/
|
|
133
|
+
deviceBacked: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* A device-backed tab whose BYTES are gone — the page reloaded, and a phone's
|
|
136
|
+
* file cannot be re-read (the URI grant belonged to the native intent).
|
|
137
|
+
*
|
|
138
|
+
* Its own flag because the two states need different words: "read-only, copy
|
|
139
|
+
* it into a workspace" is wrong for a tab with nothing left to copy.
|
|
140
|
+
*/
|
|
141
|
+
deviceMissing: boolean;
|
|
119
142
|
/** True for raster images: the surface renders `imageUrl`, not `content`. */
|
|
120
143
|
isImage: boolean;
|
|
121
144
|
/** Raw-byte URL of the active image (cache-busted per revision), else null. */
|
|
@@ -69,6 +69,26 @@ function stubWrite(answer: { ok: boolean; status?: number; body?: unknown; throw
|
|
|
69
69
|
return writes;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
describe('saveEditorFile — a tab with no writable handle', () => {
|
|
73
|
+
test('a handle whose registration is gone writes NOTHING to the server', async () => {
|
|
74
|
+
// The device path: a document a PHONE handed over carries a `handleId` that
|
|
75
|
+
// names an in-page byte registry, and its `path` is only a display name. If
|
|
76
|
+
// this fell through to `/api/fs/action`, the server would resolve that name
|
|
77
|
+
// against the default root and write an unrelated file — the same failure a
|
|
78
|
+
// reloaded PWA launch had.
|
|
79
|
+
const writes = stubWrite({ ok: true, body: { success: true } });
|
|
80
|
+
const outcome = await saveEditorFile(
|
|
81
|
+
{ path: 'report.md', handleId: 'device-never-registered' },
|
|
82
|
+
'edited\n',
|
|
83
|
+
'lf',
|
|
84
|
+
{ interactive: true },
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
expect(outcome).toEqual({ status: 'failed' });
|
|
88
|
+
expect(writes).toEqual([]);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
72
92
|
describe('saveEditorFile — the request it builds', () => {
|
|
73
93
|
test('posts the buffer with the path and the ending as its own field', async () => {
|
|
74
94
|
const writes = stubWrite({ ok: true, body: { success: true } });
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The harness the editor-drop suite drives: a happy-dom window, a stubbed
|
|
8
|
+
* `fetch`, and the `DataTransfer` shapes each kind of drag actually presents.
|
|
9
|
+
*
|
|
10
|
+
* Split out because the suite is at the repository's per-file ceiling and this
|
|
11
|
+
* half is INFRASTRUCTURE — nothing here asserts anything. The builders are the
|
|
12
|
+
* load-bearing part: each one is a shape measured from a real browser, and a
|
|
13
|
+
* drop test written against a convenient fake would pass while the product
|
|
14
|
+
* failed (which is exactly how the "Finder drop carries no path" bug shipped).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Window } from 'happy-dom';
|
|
18
|
+
import { h, render } from 'preact';
|
|
19
|
+
import { act } from 'preact/test-utils';
|
|
20
|
+
import { useEditorDrop, type UseEditorDropResult } from '@/client/hooks/editor/use-editor-drop';
|
|
21
|
+
|
|
22
|
+
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent', 'MouseEvent', 'KeyboardEvent', 'fetch'] as const;
|
|
23
|
+
const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
24
|
+
|
|
25
|
+
/** What the stubbed `fetch` answers with. */
|
|
26
|
+
export interface ScopeAnswer {
|
|
27
|
+
ok: boolean;
|
|
28
|
+
status: number;
|
|
29
|
+
body: unknown;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let scopeResponse: ScopeAnswer = { ok: true, status: 200, body: {} };
|
|
33
|
+
/**
|
|
34
|
+
* A scripted sequence, shifted before `scopeResponse` — the shape a drop needs
|
|
35
|
+
* when the first answer is a REFUSAL that earns a retry (a file outside every
|
|
36
|
+
* workspace is granted, then resolved).
|
|
37
|
+
*/
|
|
38
|
+
let scopeSequence: ScopeAnswer[] = [];
|
|
39
|
+
let fetchCalls: string[] = [];
|
|
40
|
+
let opened: unknown[] = [];
|
|
41
|
+
|
|
42
|
+
/** Install the DOM, the fetch stub and the open-file recorder. */
|
|
43
|
+
export function installDropHarness(): void {
|
|
44
|
+
const win = new Window({ url: 'http://localhost' });
|
|
45
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
46
|
+
for (const key of DOM_GLOBALS) {
|
|
47
|
+
nativeGlobals[key] = target[key];
|
|
48
|
+
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
49
|
+
}
|
|
50
|
+
globalThis.fetch = (async (url: string) => {
|
|
51
|
+
fetchCalls.push(String(url));
|
|
52
|
+
const { ok, status, body } = scopeSequence.shift() ?? scopeResponse;
|
|
53
|
+
return { ok, status, json: async () => body };
|
|
54
|
+
}) as unknown as typeof globalThis.fetch;
|
|
55
|
+
// The open path is a window event; recording it here is what proves the file
|
|
56
|
+
// was handed to the editor rather than merely resolved.
|
|
57
|
+
win.addEventListener('omp:open-file', (event) => {
|
|
58
|
+
opened.push((event as unknown as CustomEvent).detail);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Put the process back the way it was found. */
|
|
63
|
+
export function restoreDropHarness(): void {
|
|
64
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
65
|
+
for (const key of DOM_GLOBALS) {
|
|
66
|
+
if (nativeGlobals[key] === undefined) delete target[key];
|
|
67
|
+
else target[key] = nativeGlobals[key];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** One answer for every request. */
|
|
72
|
+
export function setScopeResponse(answer: ScopeAnswer): void {
|
|
73
|
+
scopeResponse = answer;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** A sequence, consumed one answer per request. */
|
|
77
|
+
export function queueScopeResponses(answers: ScopeAnswer[]): void {
|
|
78
|
+
scopeSequence = answers;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Every URL the hook asked for, in order. */
|
|
82
|
+
export function scopeFetchCalls(): string[] {
|
|
83
|
+
return fetchCalls;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Every `omp:open-file` detail the hook dispatched, in order. */
|
|
87
|
+
export function openedFiles(): unknown[] {
|
|
88
|
+
return opened;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Forget everything between cases. */
|
|
92
|
+
export function resetDropHarness(): void {
|
|
93
|
+
scopeResponse = { ok: true, status: 200, body: {} };
|
|
94
|
+
scopeSequence = [];
|
|
95
|
+
fetchCalls = [];
|
|
96
|
+
opened = [];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** A `DataTransfer` carrying one `text/uri-list` reference, as a browser drag does. */
|
|
100
|
+
export function fileTransfer(reference: string): DataTransfer {
|
|
101
|
+
return {
|
|
102
|
+
types: ['text/uri-list'],
|
|
103
|
+
files: [],
|
|
104
|
+
getData: (type: string) => (type.toLowerCase() === 'text/uri-list' ? reference : ''),
|
|
105
|
+
} as unknown as DataTransfer;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** A `DataTransfer` with real bytes and no path — the composer's territory. */
|
|
109
|
+
export function bytesTransfer(): DataTransfer {
|
|
110
|
+
return {
|
|
111
|
+
types: ['Files'],
|
|
112
|
+
files: [{ name: 'photo.png', size: 100 }],
|
|
113
|
+
getData: () => '',
|
|
114
|
+
} as unknown as DataTransfer;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* A `DataTransfer` shaped exactly as Chrome for macOS presents a Finder drag:
|
|
119
|
+
* `types: ["Files"]`, one `file` item with a handle, and NO path anywhere.
|
|
120
|
+
*/
|
|
121
|
+
export function finderTransfer(handle: FileSystemFileHandle): DataTransfer {
|
|
122
|
+
return {
|
|
123
|
+
types: ['Files'],
|
|
124
|
+
files: [],
|
|
125
|
+
getData: () => '',
|
|
126
|
+
items: [
|
|
127
|
+
{
|
|
128
|
+
kind: 'file',
|
|
129
|
+
type: 'application/octet-stream',
|
|
130
|
+
getAsFileSystemHandle: async () => handle,
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
} as unknown as DataTransfer;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** A handle over `text`, recording writes so a save can be observed. */
|
|
137
|
+
export function fakeHandle(name: string, text: string) {
|
|
138
|
+
const writes: string[] = [];
|
|
139
|
+
const handle = {
|
|
140
|
+
name,
|
|
141
|
+
kind: 'file',
|
|
142
|
+
async getFile() {
|
|
143
|
+
return new File([new TextEncoder().encode(text)], name);
|
|
144
|
+
},
|
|
145
|
+
async createWritable() {
|
|
146
|
+
return {
|
|
147
|
+
async write(data: string) {
|
|
148
|
+
writes.push(data);
|
|
149
|
+
},
|
|
150
|
+
async close() {},
|
|
151
|
+
};
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
return { handle: handle as unknown as FileSystemFileHandle, writes };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface Harness {
|
|
158
|
+
drop: (transfer: DataTransfer) => Promise<void>;
|
|
159
|
+
dragging: () => boolean;
|
|
160
|
+
results: { ok: boolean; message: string }[];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Mount the hook and hand back the gestures a case drives. */
|
|
164
|
+
export async function mountEditorDrop(enabled = true): Promise<Harness> {
|
|
165
|
+
const results: { ok: boolean; message: string }[] = [];
|
|
166
|
+
const container = document.createElement('div');
|
|
167
|
+
document.body.appendChild(container);
|
|
168
|
+
|
|
169
|
+
let api: UseEditorDropResult | null = null;
|
|
170
|
+
const Probe = () => {
|
|
171
|
+
api = useEditorDrop({ enabled, onResult: (r) => results.push(r) });
|
|
172
|
+
return null;
|
|
173
|
+
};
|
|
174
|
+
await act(async () => {
|
|
175
|
+
render(h(Probe, {}), container);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
drop: async (transfer) => {
|
|
180
|
+
const event = new window.Event('drop', { bubbles: true, cancelable: true });
|
|
181
|
+
Object.defineProperty(event, 'dataTransfer', { value: transfer });
|
|
182
|
+
Object.defineProperty(event, 'stopPropagation', { value: () => {} });
|
|
183
|
+
Object.defineProperty(event, 'preventDefault', { value: () => {} });
|
|
184
|
+
await act(async () => {
|
|
185
|
+
api?.dropProps.onDrop(event as never);
|
|
186
|
+
});
|
|
187
|
+
// The handler resolves the reference over `fetch` and then `res.json()`,
|
|
188
|
+
// so the assertion needs that chain drained before it runs.
|
|
189
|
+
for (let pass = 0; pass < 4; pass += 1) {
|
|
190
|
+
await act(async () => {
|
|
191
|
+
await Promise.resolve();
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
dragging: () => api?.isDragging ?? false,
|
|
196
|
+
results,
|
|
197
|
+
};
|
|
198
|
+
}
|