@kabmo-labs/kabmo 0.8.0 → 0.10.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 +52 -0
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +336 -336
- package/dist/client/static/js/index-18xe7655.css +1 -0
- package/dist/client/static/js/{index-qwpvd9fv.js → index-nxpe7835.js} +933 -898
- package/package.json +11 -1
- package/src/client/components/common/code-surface/bracket-guide.test.ts +249 -0
- package/src/client/components/common/code-surface/bracket-guide.ts +131 -0
- package/src/client/components/common/code-surface/documents.test.ts +122 -0
- package/src/client/components/common/code-surface/documents.ts +286 -0
- package/src/client/components/common/code-surface/extensions.test.ts +115 -0
- package/src/client/components/common/code-surface/extensions.ts +295 -0
- package/src/client/components/common/code-surface/fold-stack.test.ts +218 -0
- package/src/client/components/common/code-surface/fold.test.ts +148 -0
- package/src/client/components/common/code-surface/fold.ts +118 -0
- package/src/client/components/common/code-surface/handle.ts +102 -0
- package/src/client/components/common/code-surface/indent-guide.ts +104 -0
- package/src/client/components/common/code-surface/indent.test.ts +239 -0
- package/src/client/components/common/code-surface/indent.ts +124 -0
- package/src/client/components/common/code-surface/index.tsx +283 -314
- package/src/client/components/common/code-surface/keymap.test.ts +133 -0
- package/src/client/components/common/code-surface/keymap.ts +256 -0
- package/src/client/components/common/code-surface/line-commands.test.ts +90 -0
- package/src/client/components/common/code-surface/line-commands.ts +103 -0
- package/src/client/components/common/code-surface/marks.ts +74 -0
- package/src/client/components/common/code-surface/props.ts +87 -0
- package/src/client/components/common/code-surface/shiki.ts +234 -0
- package/src/client/components/common/code-surface/stream-language.test.ts +118 -0
- package/src/client/components/common/code-surface/stream-language.ts +123 -0
- package/src/client/components/common/code-surface/sync.test.ts +185 -0
- package/src/client/components/common/code-surface/sync.ts +58 -0
- package/src/client/components/common/code-surface/theme.test.ts +237 -0
- package/src/client/components/common/code-surface/theme.ts +224 -0
- package/src/client/components/common/code-surface/typing.test.ts +97 -0
- package/src/client/components/common/code-surface/typing.ts +111 -0
- package/src/client/components/common/editor-view-buttons/index.test.tsx +148 -0
- package/src/client/components/common/editor-view-buttons/index.tsx +109 -0
- package/src/client/components/common/shell-update-button/Modal.tsx +163 -0
- package/src/client/components/common/shell-update-button/index.test.tsx +251 -0
- package/src/client/components/common/shell-update-button/index.tsx +125 -0
- package/src/client/components/common/toolbar-row/index.test.tsx +215 -0
- package/src/client/components/common/toolbar-row/index.tsx +260 -0
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +58 -78
- package/src/client/components/layout/desktop-layout/index.tsx +65 -67
- package/src/client/components/layout/desktop-layout/resizer/index.tsx +6 -3
- package/src/client/components/layout/session-sidebar/Footer.tsx +8 -15
- package/src/client/components/mobile/LayoutWrapper.tsx +1 -0
- package/src/client/components/mobile/mobile-right-sidebar/FullDiff.tsx +3 -0
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +98 -71
- package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +20 -1
- package/src/client/components/mobile/mobile-right-sidebar/OutlineButton.test.tsx +137 -0
- package/src/client/components/mobile/mobile-right-sidebar/OutlineButton.tsx +14 -3
- package/src/client/components/mobile/mobile-right-sidebar/editor-props.ts +25 -0
- package/src/client/components/mobile/mobile-session-sidebar/Footer.tsx +9 -21
- package/src/client/components/settings/Modal.tsx +8 -0
- package/src/client/components/settings/categories/AppearanceSettings.tsx +9 -0
- package/src/client/components/settings/categories/appearance-settings/EditorIndentSection.tsx +87 -0
- package/src/client/components/settings/categories/appearance-settings/EditorThemeSection.test.tsx +167 -0
- package/src/client/components/settings/categories/appearance-settings/EditorThemeSection.tsx +184 -0
- package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +99 -0
- package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +8 -2
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +16 -8
- package/src/client/components/workspace/chat-timeline/SystemNotice.tsx +9 -4
- package/src/client/components/workspace/chat-timeline/TaskResultContent.tsx +9 -7
- package/src/client/components/workspace/chat-timeline/chat-input/expansion.ts +9 -4
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +15 -11
- package/src/client/components/workspace/chat-timeline/chat-input/stretch-send.test.tsx +165 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.test.tsx +132 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +120 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.test.tsx +319 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +285 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.test.ts +2 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/hashline-patch/index.tsx +34 -29
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/AstEdit.tsx +11 -9
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +10 -7
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Edit.tsx +25 -8
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Eval.tsx +8 -11
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/FileMatches.test.ts +114 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/FileMatches.tsx +111 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +7 -7
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/SearchTool.tsx +9 -59
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactBody.tsx +2 -7
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.test.ts +43 -30
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.tsx +49 -32
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ExcerptCode.tsx +8 -8
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/HighlightedCode.tsx +35 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/JsonCodeBlock.tsx +4 -4
- package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +179 -0
- package/src/client/components/workspace/diff-panel/ThemedMergeDiffView.tsx +24 -0
- package/src/client/components/workspace/diff-panel/Toolbar.tsx +224 -186
- package/src/client/components/workspace/diff-panel/ToolbarSegments.tsx +98 -0
- package/src/client/components/workspace/diff-panel/index.tsx +76 -145
- package/src/client/components/workspace/diff-panel/merge.ts +315 -0
- package/src/client/components/workspace/editor/Body.tsx +28 -7
- package/src/client/components/workspace/editor/CommandPalette.tsx +6 -6
- package/src/client/components/workspace/editor/ConflictStrip.tsx +77 -0
- package/src/client/components/workspace/editor/Dialogs.tsx +53 -0
- package/src/client/components/workspace/editor/EmptyEditor.tsx +23 -0
- package/src/client/components/workspace/editor/ExternalChangeStrip.tsx +61 -0
- package/src/client/components/workspace/editor/FileDocument.tsx +146 -63
- package/src/client/components/workspace/editor/FilePane.tsx +47 -7
- package/src/client/components/workspace/editor/FindWidget.test.ts +9 -5
- package/src/client/components/workspace/editor/FindWidget.tsx +36 -2
- package/src/client/components/workspace/editor/GoToLineModal.tsx +123 -0
- package/src/client/components/workspace/editor/Notices.tsx +71 -0
- package/src/client/components/workspace/editor/Pane.tsx +118 -0
- package/src/client/components/workspace/editor/PluginColumn.tsx +32 -0
- package/src/client/components/workspace/editor/QuickOpenModal.tsx +146 -0
- package/src/client/components/workspace/editor/SaveAsModal.tsx +175 -0
- package/src/client/components/workspace/editor/SplitColumn.tsx +98 -0
- package/src/client/components/workspace/editor/SplitPane.tsx +57 -0
- package/src/client/components/workspace/editor/StatusBar.tsx +106 -0
- package/src/client/components/workspace/editor/TabContextMenu.tsx +75 -0
- package/src/client/components/workspace/editor/Tabs.tsx +195 -18
- package/src/client/components/workspace/editor/Toolbar.tsx +110 -140
- package/src/client/components/workspace/editor/index.tsx +201 -193
- package/src/client/components/workspace/editor/props.ts +64 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +300 -0
- package/src/client/components/workspace/file-explorer/Modals.tsx +14 -1
- package/src/client/components/workspace/file-explorer/OutlineSection.test.tsx +18 -0
- package/src/client/components/workspace/file-explorer/OutlineSection.tsx +10 -3
- package/src/client/components/workspace/file-explorer/TreeItem.tsx +2 -1
- package/src/client/components/workspace/file-explorer/clipboard.test.ts +3 -1
- package/src/client/components/workspace/file-explorer/index.test.ts +61 -0
- package/src/client/components/workspace/file-explorer/index.tsx +10 -48
- package/src/client/components/workspace/file-explorer/local-edit.test.ts +8 -3
- package/src/client/components/workspace/search-panel/Body.tsx +7 -2
- package/src/client/components/workspace/worktree-modal/index.test.tsx +118 -0
- package/src/client/hooks/chat/composer/file-drop.ts +22 -37
- package/src/client/hooks/chat/composer/pipeline.test.ts +76 -0
- package/src/client/hooks/chat/composer/pipeline.ts +12 -1
- package/src/client/hooks/chat/omp/reconnect.test.ts +338 -0
- package/src/client/hooks/chat/omp/reconnect.ts +187 -0
- package/src/client/hooks/chat/omp/run-liveness.test.ts +71 -0
- package/src/client/hooks/chat/omp/run-liveness.ts +65 -0
- package/src/client/hooks/chat/omp/session-list.activity.test.ts +114 -0
- package/src/client/hooks/chat/omp/session-list.test-util.ts +164 -0
- package/src/client/hooks/chat/omp/session-list.test.ts +30 -150
- package/src/client/hooks/chat/omp/session-list.tsx +69 -9
- package/src/client/hooks/chat/timeline/generating.ts +19 -2
- package/src/client/hooks/chat/timeline/index.ts +19 -24
- package/src/client/hooks/chat/timeline/lost-run.test.ts +329 -0
- package/src/client/hooks/chat/timeline/lost-run.ts +177 -0
- package/src/client/hooks/chat/timeline/session-load.test-util.ts +205 -0
- package/src/client/hooks/chat/timeline/session-load.test.ts +61 -162
- package/src/client/hooks/chat/timeline/session-load.ts +69 -37
- package/src/client/hooks/chat/timeline/session-switch.test.ts +65 -0
- package/src/client/hooks/chat/timeline/session-switch.ts +63 -0
- package/src/client/hooks/code/deferred-highlight.test.ts +182 -0
- package/src/client/hooks/code/deferred-highlight.ts +129 -0
- package/src/client/hooks/editor/caret-position.test.ts +58 -0
- package/src/client/hooks/editor/caret-position.ts +48 -0
- package/src/client/hooks/editor/file-editor-types.ts +200 -0
- package/src/client/hooks/editor/find-history.test.ts +132 -0
- package/src/client/hooks/editor/find-history.ts +46 -0
- package/src/client/hooks/editor/find-selection-range.test.ts +100 -0
- package/src/client/hooks/editor/find-selection-range.ts +49 -0
- package/src/client/hooks/editor/find-state.ts +14 -1
- package/src/client/hooks/editor/font.test.ts +0 -93
- package/src/client/hooks/editor/indent-settings.test.ts +104 -0
- package/src/client/hooks/editor/indent-settings.ts +88 -0
- package/src/client/hooks/editor/quick-open.test.ts +141 -0
- package/src/client/hooks/editor/quick-open.ts +127 -0
- package/src/client/hooks/editor/save-as.test.ts +156 -0
- package/src/client/hooks/editor/save-as.ts +122 -0
- package/src/client/hooks/editor/save-file.test.ts +179 -0
- package/src/client/hooks/editor/save-file.ts +73 -28
- package/src/client/hooks/editor/theme.test.ts +206 -0
- package/src/client/hooks/editor/theme.ts +82 -0
- package/src/client/hooks/editor/typing-settings.test.ts +73 -0
- package/src/client/hooks/editor/typing-settings.ts +65 -0
- package/src/client/hooks/editor/use-close-guard.ts +98 -0
- package/src/client/hooks/editor/use-editor-drop-overlay.test.ts +159 -0
- package/src/client/hooks/editor/use-editor-drop.shell.test.ts +224 -0
- package/src/client/hooks/editor/use-editor-drop.test.ts +101 -0
- package/src/client/hooks/editor/use-editor-drop.ts +120 -77
- package/src/client/hooks/editor/use-editor-find.test.ts +2 -2
- package/src/client/hooks/editor/use-editor-find.ts +45 -10
- package/src/client/hooks/editor/use-editor-panel-keys.ts +152 -0
- package/src/client/hooks/editor/use-editor-tab-state.ts +71 -0
- package/src/client/hooks/editor/use-external-change-notice.ts +71 -0
- package/src/client/hooks/editor/use-external-change.test.ts +88 -0
- package/src/client/hooks/editor/use-external-change.ts +146 -0
- package/src/client/hooks/editor/use-file-editor.ts +83 -116
- package/src/client/hooks/editor/use-file-read.ts +16 -8
- package/src/client/hooks/editor/use-file-writes.ts +28 -3
- package/src/client/hooks/editor/use-mobile-editor-find.ts +69 -0
- package/src/client/hooks/editor/use-mobile-reveal.ts +53 -0
- package/src/client/hooks/editor/use-outline-view.test.ts +182 -0
- package/src/client/hooks/editor/use-outline-view.ts +94 -7
- package/src/client/hooks/editor/use-scroll-restore.test.ts +55 -2
- package/src/client/hooks/editor/use-scroll-restore.ts +124 -4
- package/src/client/hooks/editor/use-search-reveal-jump.ts +57 -0
- package/src/client/hooks/editor/use-search-reveal.ts +1 -1
- package/src/client/hooks/editor/use-split-editor.test.tsx +169 -0
- package/src/client/hooks/editor/use-split-editor.ts +91 -0
- package/src/client/hooks/editor/use-unload-guard.tsx +117 -0
- package/src/client/hooks/editor/use-write-conflict.test.ts +164 -0
- package/src/client/hooks/editor/use-write-conflict.ts +152 -0
- package/src/client/hooks/editor/wheel-zoom.test.ts +141 -0
- package/src/client/hooks/editor/wheel-zoom.ts +96 -0
- package/src/client/hooks/ui/drag-presence.test.ts +193 -0
- package/src/client/hooks/ui/drag-presence.ts +108 -0
- package/src/client/hooks/ui/settings-modal.test.ts +115 -0
- package/src/client/hooks/ui/settings-modal.ts +56 -0
- package/src/client/hooks/ui/updates/shell-download.test.ts +2 -0
- package/src/client/hooks/ui/updates/shell-download.ts +55 -14
- package/src/client/hooks/ui/updates/shell-offer.test.ts +26 -0
- package/src/client/hooks/ui/updates/shell-update.test.ts +140 -0
- package/src/client/hooks/ui/updates/shell-update.ts +119 -0
- package/src/client/hooks/workspace/diff-file.ts +29 -10
- package/src/client/hooks/workspace/diff-git-actions.ts +147 -0
- package/src/client/hooks/workspace/editor-view.ts +61 -0
- package/src/client/hooks/workspace/file-listing.ts +36 -24
- package/src/client/hooks/workspace/file-tabs.test.ts +152 -5
- package/src/client/hooks/workspace/file-tabs.ts +70 -11
- package/src/client/hooks/workspace/file-tree-edits.ts +103 -0
- package/src/client/hooks/workspace/navbar-session-actions.ts +72 -0
- package/src/client/hooks/workspace/worktree/index.ts +20 -5
- package/src/client/lib/desktop/bridge.ts +45 -0
- package/src/client/lib/desktop/dropped-paths.ts +83 -0
- package/src/client/lib/editor/tab-menu.test.ts +127 -0
- package/src/client/lib/editor/tab-menu.ts +127 -0
- package/src/client/lib/editor-dirty-tabs.test.ts +102 -0
- package/src/client/lib/editor-dirty-tabs.ts +103 -0
- package/src/client/lib/native/resume.test.ts +66 -0
- package/src/client/lib/native/resume.ts +42 -0
- package/src/client/lib/search-reveal.ts +1 -1
- package/src/client/main.tsx +13 -1
- package/src/client/tailwind.css +75 -8
- package/src/server/lib/auth/guard.test.ts +28 -0
- package/src/server/lib/auth/guard.ts +10 -0
- package/src/server/lib/bundler/css.test.ts +31 -0
- package/src/server/lib/fs/listing.test.ts +81 -16
- package/src/server/lib/fs/listing.ts +72 -5
- package/src/server/lib/fs/worktree/create.ts +2 -3
- package/src/server/lib/fs/worktree/list.ts +13 -0
- package/src/server/lib/fs/worktree/remove.ts +3 -3
- package/src/server/lib/fs/write-conflict.test.ts +68 -0
- package/src/server/lib/fs/write-conflict.ts +84 -0
- package/src/server/lib/lifecycle/claim-port.test.ts +156 -0
- package/src/server/lib/lifecycle/port-guard.test.ts +20 -164
- package/src/server/lib/lifecycle/port-guard.ts +39 -7
- package/src/server/lib/lifecycle/probe-health.test.ts +166 -0
- package/src/server/lib/lifecycle/probe.test.ts +77 -164
- package/src/server/lib/lifecycle/probe.ts +121 -13
- package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +112 -0
- package/src/server/lib/omp/rpc/frame-fold.ts +10 -5
- package/src/server/lib/omp/session/sidebar-activity.server.test.ts +162 -0
- package/src/server/lib/omp/session/sidebar-activity.server.ts +70 -0
- package/src/server/lib/omp/session/telemetry/compute.ts +13 -1
- package/src/server/lib/omp/session/telemetry.test.ts +33 -0
- package/src/server/lib/realtime/signals.server.ts +10 -0
- package/src/server/lib/realtime/topics/catalog.server.ts +4 -1
- package/src/server/lib/realtime/topics.server.ts +16 -0
- package/src/server/lib/updates/shell-assets.ts +94 -3
- package/src/server/lib/updates/shell-cache.ts +105 -0
- package/src/server/lib/updates/shell-pages.test.ts +33 -2
- package/src/server/lib/updates/shell-pages.ts +17 -5
- package/src/server/lib/updates/shell-release-desktop.test.ts +166 -0
- package/src/server/lib/updates/shell-release.test.ts +10 -27
- package/src/server/lib/updates/shell-release.ts +107 -111
- package/src/server/routes/fs/action-save-as.test.ts +82 -0
- package/src/server/routes/fs/action.test.ts +82 -0
- package/src/server/routes/fs/action.ts +54 -1
- package/src/server/routes/fs/exists.ts +11 -1
- package/src/server/routes/fs/git-merge.test.ts +11 -1
- package/src/server/routes/fs/read.test.ts +24 -7
- package/src/server/routes/fs/read.ts +6 -1
- package/src/server/routes/fs/scope.test.ts +15 -10
- package/src/server/routes/fs/scope.ts +3 -14
- package/src/server/routes/updates/android.ts +6 -1
- package/src/server/routes/updates/desktop.ts +29 -7
- package/src/server/routes/updates/ios.ts +5 -1
- package/src/server/routes/worktrees/list.ts +11 -1
- package/src/server/routes/worktrees/routes.test.ts +17 -0
- package/src/shared/lib/chat/timeline/omp-callbacks.test.ts +36 -0
- package/src/shared/lib/chat/timeline/omp-callbacks.ts +18 -0
- package/src/shared/lib/chat/timeline/run-signals.test.ts +2 -0
- package/src/shared/lib/code/editor/comment-syntax.test.ts +37 -0
- package/src/shared/lib/code/editor/comment-syntax.ts +55 -0
- package/src/shared/lib/code/editor/find-replace.test.ts +134 -0
- package/src/shared/lib/code/editor/{find.ts → find-replace.ts} +23 -107
- package/src/shared/lib/code/editor/{find.test.ts → find-scan.test.ts} +20 -74
- package/src/shared/lib/code/editor/find-scan.ts +198 -0
- package/src/shared/lib/code/editor/find-selection.test.ts +56 -0
- package/src/shared/lib/code/editor/indent-guide-rule.test.ts +65 -0
- package/src/shared/lib/code/editor/indent-guide-rule.ts +47 -0
- package/src/shared/lib/code/editor/indent-rules.test.ts +219 -0
- package/src/shared/lib/code/editor/indent-rules.ts +198 -0
- package/src/shared/lib/code/editor/keymap.test.ts +23 -0
- package/src/shared/lib/code/editor/keymap.ts +43 -6
- package/src/shared/lib/code/editor/lines.test.ts +7 -55
- package/src/shared/lib/code/editor/lines.ts +8 -48
- package/src/shared/lib/code/editor/marks.test.ts +4 -5
- package/src/shared/lib/code/editor/marks.ts +13 -25
- package/src/shared/lib/code/editor/palette.test.ts +25 -2
- package/src/shared/lib/code/editor/palette.ts +10 -0
- package/src/shared/lib/code/editor/stream-modes.ts +225 -0
- package/src/shared/lib/code/editor/theme-loader.ts +97 -0
- package/src/shared/lib/code/editor/themes.generated.ts +156 -0
- package/src/shared/lib/code/editor/themes.test.ts +165 -0
- package/src/shared/lib/code/editor/themes.ts +165 -0
- package/src/shared/lib/code/highlight-memo.test.ts +103 -0
- package/src/shared/lib/code/highlight-memo.ts +149 -0
- package/src/shared/lib/code/highlighter-warmup.ts +112 -0
- package/src/shared/lib/code/highlighter.ts +3 -1
- package/src/shared/lib/code/idle.ts +37 -0
- package/src/shared/lib/code/outline/rows.test.ts +96 -0
- package/src/shared/lib/code/outline/rows.ts +94 -0
- package/src/shared/lib/code/syntax-highlight.test.ts +2 -80
- package/src/shared/lib/code/syntax-highlight.ts +2 -3
- package/src/shared/lib/fs/file-kind-classify.test.ts +25 -11
- package/src/shared/lib/fs/file-kind.ts +47 -13
- package/src/shared/lib/fs/file-tree.test.ts +41 -0
- package/src/shared/lib/fs/file-tree.ts +126 -34
- package/src/shared/lib/fs/file-url.test.ts +52 -0
- package/src/shared/lib/fs/file-url.ts +37 -0
- package/src/shared/lib/fs/folder-chain.test.ts +87 -0
- package/src/shared/lib/fs/folder-chain.ts +91 -0
- package/src/shared/lib/fs/fs-helpers.test.ts +4 -50
- package/src/shared/lib/fs/patch-sides.test.ts +114 -0
- package/src/shared/lib/fs/patch-sides.ts +139 -0
- package/src/shared/lib/realtime/connection.test.ts +5 -1
- package/src/shared/lib/realtime/connection.ts +25 -119
- package/src/shared/lib/realtime/frozen-recovery.test.ts +93 -0
- package/src/shared/lib/realtime/protocol.ts +16 -0
- package/src/shared/lib/realtime/resume.ts +223 -0
- package/src/shared/lib/realtime/state.ts +22 -0
- package/src/shared/lib/realtime/watchdog-wiring.test.ts +224 -0
- package/src/shared/lib/realtime/watchdog.test.ts +99 -0
- package/src/shared/lib/realtime/watchdog.ts +72 -0
- package/src/shared/lib/ui/toolbar-overflow.test.ts +83 -0
- package/src/shared/lib/ui/toolbar-overflow.ts +86 -0
- package/src/shared/lib/updates/shell-arch.ts +54 -0
- package/src/shared/lib/updates/shell-ua.ts +4 -4
- package/src/shared/lib/workspace/editor-view-mode.test.ts +70 -0
- package/src/shared/lib/workspace/editor-view-mode.ts +48 -0
- package/src/shared/lib/workspace/panel-widths.test.ts +30 -0
- package/src/shared/lib/workspace/panel-widths.ts +25 -5
- package/src/shared/lib/workspace/session-state/cache.ts +159 -0
- package/src/shared/lib/workspace/session-state/harness.test-util.ts +55 -0
- package/src/shared/lib/workspace/session-state/merge.ts +100 -0
- package/src/shared/lib/workspace/session-state/store-load.test.ts +206 -0
- package/src/shared/lib/workspace/session-state/store.test.ts +17 -139
- package/src/shared/lib/workspace/session-state/store.ts +92 -130
- package/src/shared/lib/workspace/split-editor.test.ts +104 -0
- package/src/shared/lib/workspace/split-editor.ts +129 -0
- package/src/shared/lib/workspace/workspace-panel-widths.ts +124 -0
- package/src/shared/types/realtime.ts +29 -0
- package/src/shared/types/settings/state.ts +10 -0
- package/src/test-support/file-explorer-disk.test-util.ts +30 -3
- package/src/test-support/loopback.ts +183 -0
- package/src/test-support/pristine-globals.ts +7 -0
- package/dist/client/static/js/index-gtbpewr7.css +0 -1
- package/src/client/components/common/code-editor/handler.test.ts +0 -274
- package/src/client/components/common/code-editor/handler.ts +0 -175
- package/src/client/components/common/code-editor/index.tsx +0 -314
- package/src/client/components/common/code-surface/measure.ts +0 -148
- package/src/client/components/workspace/chat-timeline/target-picker/index.test.tsx +0 -227
- package/src/client/components/workspace/chat-timeline/target-picker/index.tsx +0 -260
- package/src/client/components/workspace/diff-panel/SplitView.tsx +0 -209
- package/src/client/components/workspace/diff-panel/UnifiedView.tsx +0 -150
- package/src/client/hooks/editor/scroll-container.test.ts +0 -102
- package/src/client/hooks/editor/scroll-container.ts +0 -26
- package/src/client/hooks/editor/use-code-window.ts +0 -100
- package/src/client/hooks/editor/use-editor-history.test.ts +0 -216
- package/src/client/hooks/editor/use-editor-history.ts +0 -134
- package/src/client/hooks/editor/use-occurrences.test.ts +0 -236
- package/src/client/hooks/editor/use-occurrences.ts +0 -98
- package/src/shared/lib/code/editor/commands.test.ts +0 -155
- package/src/shared/lib/code/editor/commands.ts +0 -260
- package/src/shared/lib/code/editor/edits.test.ts +0 -100
- package/src/shared/lib/code/editor/edits.ts +0 -122
- package/src/shared/lib/code/editor/history.test.ts +0 -118
- package/src/shared/lib/code/editor/history.ts +0 -101
- package/src/shared/lib/code/editor/layers.test.ts +0 -77
- package/src/shared/lib/code/editor/layers.ts +0 -67
- package/src/shared/lib/code/editor/line-edits.test.ts +0 -131
- package/src/shared/lib/code/editor/line-edits.ts +0 -159
- package/src/shared/lib/code/editor/occurrences.test.ts +0 -117
- package/src/shared/lib/code/editor/occurrences.ts +0 -111
- package/src/shared/lib/code/editor/reset-css.test.ts +0 -35
- package/src/shared/lib/code/editor/reset-css.ts +0 -32
- package/src/shared/lib/code/editor/text-commands.test.ts +0 -178
- package/src/shared/lib/code/editor/text-commands.ts +0 -154
- package/src/shared/lib/code/lazy-window.test.ts +0 -161
- package/src/shared/lib/code/lazy-window.ts +0 -156
- package/src/shared/lib/code/windowed-highlight.ts +0 -114
- package/src/shared/lib/fs/diff-parser.test.ts +0 -116
- package/src/shared/lib/fs/diff-parser.ts +0 -213
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The desktop shell's drop path, which is the only route a WebKit webview has.
|
|
8
|
+
*
|
|
9
|
+
* Measured on macOS 27 against a real `NSFilenamesPboardType` + `public.file-url`
|
|
10
|
+
* pasteboard delivered into a `WKWebView`:
|
|
11
|
+
*
|
|
12
|
+
* drop: types ["Files"], files [File], getData('text/uri-list') ''
|
|
13
|
+
* getData('text/plain') '', File.path undefined
|
|
14
|
+
* DataTransferItem.getAsFileSystemHandle undefined
|
|
15
|
+
*
|
|
16
|
+
* So both routes the hook already had are dead there: there is no handle to
|
|
17
|
+
* open (WebKit implements no File System Access API) and no URI list to resolve
|
|
18
|
+
* (WebKit stopped adding local filenames as URLs to a file drag). Every Finder
|
|
19
|
+
* drop on the macOS shell was refused with "that drop carried no readable file"
|
|
20
|
+
* — the composer still worked, because it only needs the bytes.
|
|
21
|
+
*
|
|
22
|
+
* The shell reads its own pasteboard before the DOM event and answers
|
|
23
|
+
* `dropped_paths`. These cases pin the three properties of that answer: it is
|
|
24
|
+
* used when present, it does not displace a handle, and it is refused when it
|
|
25
|
+
* is stale.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
29
|
+
import { Window } from 'happy-dom';
|
|
30
|
+
import { h, render } from 'preact';
|
|
31
|
+
import { act } from 'preact/test-utils';
|
|
32
|
+
import { useEditorDrop, type UseEditorDropResult } from '@/client/hooks/editor/use-editor-drop';
|
|
33
|
+
import { readShellDroppedPaths, SHELL_DROP_TTL_MS } from '@/client/lib/desktop/dropped-paths';
|
|
34
|
+
|
|
35
|
+
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent', 'MouseEvent', 'KeyboardEvent', 'fetch'] as const;
|
|
36
|
+
const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
37
|
+
|
|
38
|
+
let scopeResponse: { ok: boolean; status: number; body: unknown } = { ok: true, status: 200, body: {} };
|
|
39
|
+
let fetchCalls: string[] = [];
|
|
40
|
+
let opened: unknown[] = [];
|
|
41
|
+
let bridgeCalls: string[] = [];
|
|
42
|
+
/** What the shell answers for `dropped_paths`, per case. */
|
|
43
|
+
let bridgeAnswer: unknown = null;
|
|
44
|
+
|
|
45
|
+
beforeAll(() => {
|
|
46
|
+
const win = new Window({ url: 'http://localhost' });
|
|
47
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
48
|
+
for (const key of DOM_GLOBALS) {
|
|
49
|
+
nativeGlobals[key] = target[key];
|
|
50
|
+
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
51
|
+
}
|
|
52
|
+
globalThis.fetch = (async (url: string) => {
|
|
53
|
+
fetchCalls.push(String(url));
|
|
54
|
+
const { ok, status, body } = scopeResponse;
|
|
55
|
+
return { ok, status, json: async () => body };
|
|
56
|
+
}) as unknown as typeof globalThis.fetch;
|
|
57
|
+
win.addEventListener('omp:open-file', (event) => {
|
|
58
|
+
opened.push((event as unknown as CustomEvent).detail);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
afterAll(() => {
|
|
63
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
64
|
+
for (const key of DOM_GLOBALS) {
|
|
65
|
+
if (nativeGlobals[key] === undefined) delete target[key];
|
|
66
|
+
else target[key] = nativeGlobals[key];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/** A `DataTransfer` shaped exactly as a Finder drag arrives on WebKit. */
|
|
71
|
+
function webkitFinderTransfer(): DataTransfer {
|
|
72
|
+
return {
|
|
73
|
+
types: ['Files'],
|
|
74
|
+
files: [{ name: 'from-finder.ts', size: 12 }],
|
|
75
|
+
getData: () => '',
|
|
76
|
+
items: [{ kind: 'file', type: '', getAsFile: () => null }],
|
|
77
|
+
} as unknown as DataTransfer;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A `DataTransfer` that offers a handle — the Chromium shape. */
|
|
81
|
+
function handleTransfer(handle: FileSystemFileHandle): DataTransfer {
|
|
82
|
+
return {
|
|
83
|
+
types: ['Files'],
|
|
84
|
+
files: [],
|
|
85
|
+
getData: () => '',
|
|
86
|
+
items: [{ kind: 'file', type: '', getAsFileSystemHandle: async () => handle }],
|
|
87
|
+
} as unknown as DataTransfer;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function mount(enabled = true): Promise<UseEditorDropResult> {
|
|
91
|
+
const container = document.createElement('div');
|
|
92
|
+
document.body.appendChild(container);
|
|
93
|
+
let api: UseEditorDropResult | null = null;
|
|
94
|
+
const Probe = () => {
|
|
95
|
+
api = useEditorDrop({ enabled, onResult: () => {} });
|
|
96
|
+
return null;
|
|
97
|
+
};
|
|
98
|
+
await act(async () => {
|
|
99
|
+
render(h(Probe, {}), container);
|
|
100
|
+
});
|
|
101
|
+
if (!api) throw new Error('the hook did not mount');
|
|
102
|
+
return api;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Deliver a drop and drain the handler's awaits (fetch, bridge, handle). */
|
|
106
|
+
async function drop(api: UseEditorDropResult, transfer: DataTransfer): Promise<void> {
|
|
107
|
+
const event = {
|
|
108
|
+
dataTransfer: transfer,
|
|
109
|
+
defaultPrevented: false,
|
|
110
|
+
target: document.body,
|
|
111
|
+
preventDefault: () => {},
|
|
112
|
+
stopPropagation: () => {},
|
|
113
|
+
};
|
|
114
|
+
await act(async () => {
|
|
115
|
+
api.dropProps.onDrop(event as never);
|
|
116
|
+
});
|
|
117
|
+
for (let pass = 0; pass < 6; pass += 1) {
|
|
118
|
+
await act(async () => {
|
|
119
|
+
await Promise.resolve();
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
describe('a WebKit drop with no payload path', () => {
|
|
125
|
+
beforeEach(() => {
|
|
126
|
+
scopeResponse = {
|
|
127
|
+
ok: true,
|
|
128
|
+
status: 200,
|
|
129
|
+
body: { root: '/repo', path: 'src/from-finder.ts', name: 'from-finder.ts', kind: 'text' },
|
|
130
|
+
};
|
|
131
|
+
fetchCalls = [];
|
|
132
|
+
opened = [];
|
|
133
|
+
bridgeCalls = [];
|
|
134
|
+
bridgeAnswer = { paths: ['/repo/src/from-finder.ts'], at: Date.now() };
|
|
135
|
+
window.__kabmoCall = async (method: string) => {
|
|
136
|
+
bridgeCalls.push(method);
|
|
137
|
+
return bridgeAnswer;
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('the shell’s path is what opens the file', async () => {
|
|
142
|
+
const api = await mount();
|
|
143
|
+
await drop(api, webkitFinderTransfer());
|
|
144
|
+
|
|
145
|
+
// The bridge was asked, and the answer went through the same resolver every
|
|
146
|
+
// other drop uses — the shell's path is a path, not a second code path.
|
|
147
|
+
expect(bridgeCalls).toEqual(['dropped_paths']);
|
|
148
|
+
expect(fetchCalls[0]).toContain('/api/fs/scope?path=');
|
|
149
|
+
expect(decodeURIComponent(fetchCalls[0])).toContain('/repo/src/from-finder.ts');
|
|
150
|
+
expect(opened).toHaveLength(1);
|
|
151
|
+
expect(opened[0]).toEqual({ path: 'src/from-finder.ts', name: 'from-finder.ts', root: '/repo' });
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('a handle still wins over the shell’s path', async () => {
|
|
155
|
+
const writes: string[] = [];
|
|
156
|
+
const handle = {
|
|
157
|
+
name: 'by-handle.ts',
|
|
158
|
+
kind: 'file',
|
|
159
|
+
async getFile() {
|
|
160
|
+
return new File([new TextEncoder().encode('const a = 1;\n')], 'by-handle.ts');
|
|
161
|
+
},
|
|
162
|
+
async createWritable() {
|
|
163
|
+
return {
|
|
164
|
+
async write(data: string) {
|
|
165
|
+
writes.push(data);
|
|
166
|
+
},
|
|
167
|
+
async close() {},
|
|
168
|
+
};
|
|
169
|
+
},
|
|
170
|
+
} as unknown as FileSystemFileHandle;
|
|
171
|
+
|
|
172
|
+
const api = await mount();
|
|
173
|
+
await drop(api, handleTransfer(handle));
|
|
174
|
+
|
|
175
|
+
// The handle is the shape that carries write access, so it must not be
|
|
176
|
+
// displaced by a path the shell also happened to capture.
|
|
177
|
+
expect(bridgeCalls).toEqual([]);
|
|
178
|
+
expect(fetchCalls).toHaveLength(0);
|
|
179
|
+
expect(opened).toHaveLength(1);
|
|
180
|
+
expect((opened[0] as { handleId?: string }).handleId).toBeTruthy();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('an in-page drag with no path is still reported, not swallowed', async () => {
|
|
184
|
+
bridgeAnswer = null;
|
|
185
|
+
const api = await mount();
|
|
186
|
+
await drop(api, webkitFinderTransfer());
|
|
187
|
+
|
|
188
|
+
expect(fetchCalls).toHaveLength(0);
|
|
189
|
+
expect(opened).toHaveLength(0);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
describe('readShellDroppedPaths', () => {
|
|
194
|
+
beforeEach(() => {
|
|
195
|
+
bridgeCalls = [];
|
|
196
|
+
bridgeAnswer = { paths: ['/repo/a.ts'], at: 1_000 };
|
|
197
|
+
window.__kabmoCall = async (method: string) => {
|
|
198
|
+
bridgeCalls.push(method);
|
|
199
|
+
return bridgeAnswer;
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('a stale answer is refused', async () => {
|
|
204
|
+
// The page asks in the drop's own turn; anything older is a leftover from a
|
|
205
|
+
// drag released where no target claimed it.
|
|
206
|
+
expect(await readShellDroppedPaths(1_000 + SHELL_DROP_TTL_MS + 1)).toEqual([]);
|
|
207
|
+
expect(await readShellDroppedPaths(1_000 + SHELL_DROP_TTL_MS - 1)).toEqual(['/repo/a.ts']);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test('an empty or malformed answer reads as no help', async () => {
|
|
211
|
+
bridgeAnswer = { paths: [], at: 1_000 };
|
|
212
|
+
expect(await readShellDroppedPaths(1_000)).toEqual([]);
|
|
213
|
+
bridgeAnswer = { paths: ['', ' '], at: 1_000 };
|
|
214
|
+
expect(await readShellDroppedPaths(1_000)).toEqual([]);
|
|
215
|
+
bridgeAnswer = { paths: 'nope', at: 1_000 };
|
|
216
|
+
expect(await readShellDroppedPaths(1_000)).toEqual([]);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('a browser never asks the bridge', async () => {
|
|
220
|
+
delete window.__kabmoCall;
|
|
221
|
+
expect(await readShellDroppedPaths(1_000)).toEqual([]);
|
|
222
|
+
expect(bridgeCalls).toHaveLength(0);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
@@ -243,3 +243,104 @@ describe('useEditorDrop', () => {
|
|
|
243
243
|
expect(harness.results).toHaveLength(0);
|
|
244
244
|
});
|
|
245
245
|
});
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* The capture-phase claim, which exists because CodeMirror handles `drop`
|
|
249
|
+
* itself: for a drag carrying files it reads each file's TEXT and inserts it
|
|
250
|
+
* into the document, then calls `preventDefault`, so the panel's own handler saw
|
|
251
|
+
* `defaultPrevented` and stood down. Measured in the browser: dropping `b.ts` on
|
|
252
|
+
* an open `a.ts` put `b.ts`'s text at the top of the buffer, and the autosave
|
|
253
|
+
* wrote it to disk.
|
|
254
|
+
*
|
|
255
|
+
* The claim is scoped to a code surface, so a drop on the composer is still the
|
|
256
|
+
* composer's.
|
|
257
|
+
*/
|
|
258
|
+
describe('useEditorDrop capture claim', () => {
|
|
259
|
+
/** A drop event whose target is `element`, recording the calls it received. */
|
|
260
|
+
function captureEvent(target: Node, transfer: DataTransfer) {
|
|
261
|
+
const calls: string[] = [];
|
|
262
|
+
const event = {
|
|
263
|
+
target,
|
|
264
|
+
dataTransfer: transfer,
|
|
265
|
+
preventDefault: () => calls.push('preventDefault'),
|
|
266
|
+
stopPropagation: () => calls.push('stopPropagation'),
|
|
267
|
+
};
|
|
268
|
+
return { event: event as never, calls };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async function capture(api: UseEditorDropResult | null, event: unknown): Promise<void> {
|
|
272
|
+
await act(async () => {
|
|
273
|
+
api?.captureDropProps.onDropCapture(event as never);
|
|
274
|
+
});
|
|
275
|
+
for (let pass = 0; pass < 4; pass += 1) {
|
|
276
|
+
await act(async () => {
|
|
277
|
+
await Promise.resolve();
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** Mount the hook and hand back the API plus a node for each target shape. */
|
|
283
|
+
async function mountWithTargets() {
|
|
284
|
+
const results: { ok: boolean; message: string }[] = [];
|
|
285
|
+
const container = document.createElement('div');
|
|
286
|
+
document.body.appendChild(container);
|
|
287
|
+
const surface = document.createElement('div');
|
|
288
|
+
surface.setAttribute('data-code-surface', '');
|
|
289
|
+
const inner = document.createElement('div');
|
|
290
|
+
surface.appendChild(inner);
|
|
291
|
+
const composer = document.createElement('div');
|
|
292
|
+
container.append(surface, composer);
|
|
293
|
+
|
|
294
|
+
let api: UseEditorDropResult | null = null;
|
|
295
|
+
const Probe = () => {
|
|
296
|
+
api = useEditorDrop({ enabled: true, onResult: (r) => results.push(r) });
|
|
297
|
+
return null;
|
|
298
|
+
};
|
|
299
|
+
await act(async () => {
|
|
300
|
+
render(h(Probe, {}), container);
|
|
301
|
+
});
|
|
302
|
+
return { api: () => api, inner, composer, results };
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
beforeEach(() => {
|
|
306
|
+
scopeResponse = { ok: true, status: 200, body: {} };
|
|
307
|
+
fetchCalls = [];
|
|
308
|
+
opened = [];
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
test('claims a file drop aimed at a code surface, and opens the file', async () => {
|
|
312
|
+
scopeResponse = {
|
|
313
|
+
ok: true,
|
|
314
|
+
status: 200,
|
|
315
|
+
body: { root: '/repo', path: 'src/b.ts', name: 'b.ts', kind: 'text' },
|
|
316
|
+
};
|
|
317
|
+
const { api, inner } = await mountWithTargets();
|
|
318
|
+
const { event, calls } = captureEvent(inner, fileTransfer('file:///repo/src/b.ts'));
|
|
319
|
+
|
|
320
|
+
await capture(api(), event);
|
|
321
|
+
|
|
322
|
+
// Claimed BEFORE the surface's own handler could insert the file's text.
|
|
323
|
+
expect(calls).toEqual(['preventDefault', 'stopPropagation']);
|
|
324
|
+
expect(opened).toHaveLength(1);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
test('leaves a drop aimed anywhere else to the bubble handler', async () => {
|
|
328
|
+
const { api, composer } = await mountWithTargets();
|
|
329
|
+
const { event, calls } = captureEvent(composer, fileTransfer('file:///repo/src/b.ts'));
|
|
330
|
+
|
|
331
|
+
await capture(api(), event);
|
|
332
|
+
|
|
333
|
+
expect(calls).toEqual([]);
|
|
334
|
+
expect(opened).toHaveLength(0);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test('ignores a text drag, which CodeMirror should still insert', async () => {
|
|
338
|
+
const { api, inner } = await mountWithTargets();
|
|
339
|
+
const textDrag = { types: ['text/plain'], files: [], getData: () => 'copied text' } as unknown as DataTransfer;
|
|
340
|
+
const { event, calls } = captureEvent(inner, textDrag);
|
|
341
|
+
|
|
342
|
+
await capture(api(), event);
|
|
343
|
+
|
|
344
|
+
expect(calls).toEqual([]);
|
|
345
|
+
});
|
|
346
|
+
});
|
|
@@ -18,20 +18,31 @@
|
|
|
18
18
|
* `text/uri-list` / `text/plain`. That resolves through `/api/fs/scope`,
|
|
19
19
|
* because a path can be written back through the server.
|
|
20
20
|
*
|
|
21
|
+
* 3. **A Finder drag onto a DESKTOP SHELL's webview.** Neither of the above
|
|
22
|
+
* exists there: WebKit implements no `getAsFileSystemHandle` (WebKit bug
|
|
23
|
+
* 257792) and puts no path on the pasteboard the page can read, so a drop
|
|
24
|
+
* carried bytes and nothing else and the editor refused it. The shell reads
|
|
25
|
+
* the pasteboard itself and hands the paths over — see
|
|
26
|
+
* `client/lib/desktop/dropped-paths`.
|
|
27
|
+
*
|
|
21
28
|
* Handles are tried FIRST: they are the shape that carries write access, and a
|
|
22
29
|
* host that offers both (a Finder drag onto a page that also set a URI list)
|
|
23
|
-
* should keep it.
|
|
30
|
+
* should keep it. The shell's paths come next — they resolve to a real path,
|
|
31
|
+
* which is what the editor saves through.
|
|
24
32
|
*
|
|
25
|
-
* The overlay's state is a depth
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
33
|
+
* The overlay's state is `useDragPresence`, NOT a depth counter: `dragenter`
|
|
34
|
+
* fires for every nested child the pointer crosses, so a counter rose with each
|
|
35
|
+
* crossing and only a full exit lowered it — measured in Chromium, five child
|
|
36
|
+
* crossings inside the chat left the counter at 5 after the pointer had left, and
|
|
37
|
+
* the overlay stayed on. `relatedTarget` answers the same question symmetrically.
|
|
29
38
|
*/
|
|
30
39
|
|
|
31
|
-
import { useCallback,
|
|
40
|
+
import { useCallback, useRef } from 'preact/hooks';
|
|
32
41
|
import type { TargetedDragEvent } from 'preact';
|
|
33
42
|
import { collectDroppedFileUris, hasDraggedFiles } from '@/client/hooks/chat/composer/drop-payload';
|
|
43
|
+
import { useDragPresence } from '@/client/hooks/ui/drag-presence';
|
|
34
44
|
import { openHandleAsTab } from '@/client/lib/launch/file-handlers';
|
|
45
|
+
import { readShellDroppedPaths } from '@/client/lib/desktop/dropped-paths';
|
|
35
46
|
import { openFileInEditor } from '@/client/hooks/ui/open-file';
|
|
36
47
|
|
|
37
48
|
/** What `/api/fs/scope` answers with. */
|
|
@@ -62,9 +73,34 @@ export interface EditorDropProps {
|
|
|
62
73
|
onDrop: (e: TargetedDragEvent<HTMLElement>) => void;
|
|
63
74
|
}
|
|
64
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Handlers that must run BEFORE a code surface sees the drag.
|
|
78
|
+
*
|
|
79
|
+
* CodeMirror handles `drop` itself, on its own `contentDOM`: for a drag carrying
|
|
80
|
+
* FILES it reads each file's text and INSERTS it into the document, then calls
|
|
81
|
+
* `preventDefault` — so the panel's own drop handler saw `defaultPrevented` and
|
|
82
|
+
* stood down. Measured in the browser: dropping `b.ts` on an open `a.ts` put
|
|
83
|
+
* `DROPPED_CONTENT` at the top of the buffer (and the autosave then wrote it to
|
|
84
|
+
* disk), while the overlay had promised "Drop a file to open it".
|
|
85
|
+
*
|
|
86
|
+
* A capture-phase listener on the panel is what wins that race, because capture
|
|
87
|
+
* runs from the outermost element inward — the surface's own handler has not run
|
|
88
|
+
* yet. It claims ONLY a drag that is over a code surface (`[data-code-surface]`,
|
|
89
|
+
* set by `CodeSurface`), so a drop on the composer still belongs to the composer
|
|
90
|
+
* and a drop on the chat's own chrome still reaches `onDrop` as before.
|
|
91
|
+
*/
|
|
92
|
+
export interface EditorDropCaptureProps {
|
|
93
|
+
onDropCapture: (e: TargetedDragEvent<HTMLElement>) => void;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The attribute a code surface marks itself with, for the capture handler. */
|
|
97
|
+
export const CODE_SURFACE_ATTRIBUTE = 'data-code-surface';
|
|
98
|
+
|
|
65
99
|
export interface UseEditorDropResult {
|
|
66
100
|
isDragging: boolean;
|
|
67
101
|
dropProps: EditorDropProps;
|
|
102
|
+
/** Spread on the same element as `dropProps`. */
|
|
103
|
+
captureDropProps: EditorDropCaptureProps;
|
|
68
104
|
}
|
|
69
105
|
|
|
70
106
|
/**
|
|
@@ -153,47 +189,24 @@ async function openDroppedHandle(
|
|
|
153
189
|
}
|
|
154
190
|
|
|
155
191
|
export function useEditorDrop({ enabled = true, onResult }: UseEditorDropOptions = {}): UseEditorDropResult {
|
|
156
|
-
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
const
|
|
192
|
+
// `relatedTarget`-based, not a counter: see `useDragPresence`. The counter that
|
|
193
|
+
// used to live here is what left the overlay stuck after a gesture the element
|
|
194
|
+
// never saw the end of.
|
|
195
|
+
const presence = useDragPresence();
|
|
160
196
|
const enabledRef = useRef(enabled);
|
|
161
197
|
enabledRef.current = enabled;
|
|
162
198
|
const onResultRef = useRef(onResult);
|
|
163
199
|
onResultRef.current = onResult;
|
|
164
200
|
|
|
165
|
-
const reset = useCallback(() => {
|
|
166
|
-
depthRef.current = 0;
|
|
167
|
-
setIsDragging(false);
|
|
168
|
-
}, []);
|
|
169
|
-
|
|
170
|
-
// A drag can end without reaching this element again — released over another
|
|
171
|
-
// window, cancelled with Escape, or its source node unmounted mid-drag. The
|
|
172
|
-
// element's own handlers have already run by the time these fire, so this only
|
|
173
|
-
// clears state the drop handler did not. Without it a counter left above zero
|
|
174
|
-
// made the next drag's overlay look stuck on, and a counter left BELOW zero
|
|
175
|
-
// (see `onDragLeave`) made the next one never appear.
|
|
176
|
-
useEffect(() => {
|
|
177
|
-
window.addEventListener('dragend', reset);
|
|
178
|
-
window.addEventListener('drop', reset);
|
|
179
|
-
return () => {
|
|
180
|
-
window.removeEventListener('dragend', reset);
|
|
181
|
-
window.removeEventListener('drop', reset);
|
|
182
|
-
};
|
|
183
|
-
}, [reset]);
|
|
184
|
-
|
|
185
201
|
const onDragEnter = useCallback((e: TargetedDragEvent<HTMLElement>) => {
|
|
186
202
|
// A descendant already claimed this drag — the composer, whose own handler
|
|
187
|
-
// runs first because it is deeper in the tree.
|
|
188
|
-
// is safe ONLY because `onDragLeave` counts symmetrically; the two must
|
|
189
|
-
// agree or the counter drifts negative and the overlay stops appearing.
|
|
203
|
+
// runs first because it is deeper in the tree.
|
|
190
204
|
if (e.defaultPrevented) return;
|
|
191
205
|
if (!isOpenableDrag(e.dataTransfer)) return;
|
|
192
206
|
e.preventDefault();
|
|
193
207
|
if (!enabledRef.current) return;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}, []);
|
|
208
|
+
presence.enter();
|
|
209
|
+
}, [presence]);
|
|
197
210
|
|
|
198
211
|
const onDragOver = useCallback((e: TargetedDragEvent<HTMLElement>) => {
|
|
199
212
|
// A descendant claimed the drag — the composer, whose own handler runs first
|
|
@@ -203,7 +216,7 @@ export function useEditorDrop({ enabled = true, onResult }: UseEditorDropOptions
|
|
|
203
216
|
// of them. The counter is left alone, so moving back off the composer
|
|
204
217
|
// restores this overlay.
|
|
205
218
|
if (e.defaultPrevented) {
|
|
206
|
-
|
|
219
|
+
presence.clear();
|
|
207
220
|
return;
|
|
208
221
|
}
|
|
209
222
|
if (!isOpenableDrag(e.dataTransfer)) return;
|
|
@@ -212,53 +225,46 @@ export function useEditorDrop({ enabled = true, onResult }: UseEditorDropOptions
|
|
|
212
225
|
// window-level guard, which runs later in the bubble.
|
|
213
226
|
e.preventDefault();
|
|
214
227
|
e.stopPropagation();
|
|
215
|
-
|
|
228
|
+
// Every `dragover` on this element is proof the pointer is inside it — a
|
|
229
|
+
// child crossing fires the pair in between, and this is what re-asserts the
|
|
230
|
+
// overlay without counting anything. Gated on `enabled` for the same reason
|
|
231
|
+
// `onDragEnter` is: a target with no workspace behind it must stay dark
|
|
232
|
+
// rather than light up to refuse.
|
|
233
|
+
if (enabledRef.current) presence.enter();
|
|
216
234
|
if (!e.dataTransfer) return;
|
|
217
235
|
e.dataTransfer.dropEffect = enabledRef.current ? 'copy' : 'none';
|
|
218
|
-
}, []);
|
|
236
|
+
}, [presence]);
|
|
219
237
|
|
|
220
238
|
/**
|
|
221
239
|
* A `dragleave` that stays INSIDE the element is a move between children, not
|
|
222
|
-
* an exit —
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* The failure, measured: entering the workspace increments the counter, moving
|
|
226
|
-
* onto the composer is claimed by the composer (`defaultPrevented`, so the
|
|
227
|
-
* workspace does NOT increment), and moving back off the composer fires a
|
|
228
|
-
* `dragleave` that bubbles up and DECREMENTS — the counter returns to zero and
|
|
229
|
-
* the overlay turns off even though the pointer never left the workspace.
|
|
230
|
-
*
|
|
231
|
-
* `relatedTarget` is the element being entered, so `contains` is the exact
|
|
232
|
-
* test. It can be null (a drag leaving the window), which the counter still
|
|
233
|
-
* handles; the clamp at zero keeps a stray leave from going negative, because
|
|
234
|
-
* a negative counter makes every later drag's `=== 0` test miss and the
|
|
235
|
-
* overlay never appears again.
|
|
240
|
+
* an exit — `useDragPresence.leave` is the only rule here, because the counter
|
|
241
|
+
* this replaced is what made the overlay stay lit (or vanish) for the wrong
|
|
242
|
+
* reason.
|
|
236
243
|
*/
|
|
237
244
|
const onDragLeave = useCallback((e: TargetedDragEvent<HTMLElement>) => {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
depthRef.current -= 1;
|
|
241
|
-
if (depthRef.current === 0) setIsDragging(false);
|
|
242
|
-
}, []);
|
|
245
|
+
presence.leave(e);
|
|
246
|
+
}, [presence]);
|
|
243
247
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
//
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
reset();
|
|
253
|
-
if (!enabledRef.current || !e.dataTransfer) return;
|
|
254
|
-
|
|
255
|
-
const dt = e.dataTransfer;
|
|
248
|
+
/** Open what a drop carries — shared by the bubble and the capture paths. */
|
|
249
|
+
const openDropped = useCallback((dt: DataTransfer | null) => {
|
|
250
|
+
if (!dt) return;
|
|
251
|
+
// The payload is read in THIS tick, before any await. A drop's data store is
|
|
252
|
+
// released when the handler returns, so a `getData` issued after an IPC
|
|
253
|
+
// round trip reads an empty string — measured on the shell's `dropped_paths`
|
|
254
|
+
// call, which is exactly such a round trip.
|
|
255
|
+
const references = collectDroppedFileUris(dt);
|
|
256
256
|
// Handles first: they are the only shape that carries write access, and a
|
|
257
|
-
// Finder drag has nothing else.
|
|
258
|
-
void openDroppedHandle(dt, onResultRef.current).then((opened) => {
|
|
257
|
+
// Finder drag on a Chromium webview has nothing else.
|
|
258
|
+
void openDroppedHandle(dt, onResultRef.current).then(async (opened) => {
|
|
259
259
|
if (opened) return;
|
|
260
|
-
|
|
261
|
-
|
|
260
|
+
// Then the shell's own read of the pasteboard, which is the ONLY route a
|
|
261
|
+
// WebKit webview offers: it has no file-system handle and no URI list, so
|
|
262
|
+
// a Finder drop there carries bytes the editor cannot save. Asked only
|
|
263
|
+
// when no handle won, and consumed by the shell, so one drop opens one
|
|
264
|
+
// file.
|
|
265
|
+
const shellPaths = await readShellDroppedPaths();
|
|
266
|
+
const first = shellPaths[0] ?? references[0];
|
|
267
|
+
if (!first) {
|
|
262
268
|
onResultRef.current?.({
|
|
263
269
|
ok: false,
|
|
264
270
|
message: 'That drop carried no readable file — drop it on the composer to attach it instead.',
|
|
@@ -267,9 +273,46 @@ export function useEditorDrop({ enabled = true, onResult }: UseEditorDropOptions
|
|
|
267
273
|
}
|
|
268
274
|
// One open per gesture: the editor has a single active tab, so opening
|
|
269
275
|
// several would leave the user on whichever resolved last.
|
|
270
|
-
|
|
276
|
+
await openDroppedReference(first, onResultRef.current);
|
|
271
277
|
});
|
|
272
|
-
}, [
|
|
278
|
+
}, []);
|
|
279
|
+
|
|
280
|
+
const onDrop = useCallback((e: TargetedDragEvent<HTMLElement>) => {
|
|
281
|
+
// The composer claimed it: one gesture must not both open the file and
|
|
282
|
+
// queue it as an attachment. `defaultPrevented` is the platform's own
|
|
283
|
+
// signal for "someone deeper already handled this".
|
|
284
|
+
if (e.defaultPrevented) return;
|
|
285
|
+
if (!isOpenableDrag(e.dataTransfer)) return;
|
|
286
|
+
e.preventDefault();
|
|
287
|
+
e.stopPropagation();
|
|
288
|
+
presence.clear();
|
|
289
|
+
if (!enabledRef.current || !e.dataTransfer) return;
|
|
290
|
+
openDropped(e.dataTransfer);
|
|
291
|
+
}, [openDropped, presence]);
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Claim a file drop that is about to land on a code surface.
|
|
295
|
+
*
|
|
296
|
+
* Capture phase, so it runs before CodeMirror's own `drop` handler on the
|
|
297
|
+
* `contentDOM` — that one reads a dropped file's TEXT and inserts it into the
|
|
298
|
+
* document, which would silently rewrite the open file on the next autosave.
|
|
299
|
+
* Scoped to `[data-code-surface]` so a drop anywhere else keeps the existing
|
|
300
|
+
* behaviour, the composer's included.
|
|
301
|
+
*/
|
|
302
|
+
const onDropCapture = useCallback((e: TargetedDragEvent<HTMLElement>) => {
|
|
303
|
+
if (!isOpenableDrag(e.dataTransfer)) return;
|
|
304
|
+
const target = e.target;
|
|
305
|
+
if (!(target instanceof Element) || !target.closest(`[${CODE_SURFACE_ATTRIBUTE}]`)) return;
|
|
306
|
+
e.preventDefault();
|
|
307
|
+
e.stopPropagation();
|
|
308
|
+
presence.clear();
|
|
309
|
+
if (!enabledRef.current || !e.dataTransfer) return;
|
|
310
|
+
openDropped(e.dataTransfer);
|
|
311
|
+
}, [openDropped, presence]);
|
|
273
312
|
|
|
274
|
-
return {
|
|
313
|
+
return {
|
|
314
|
+
isDragging: presence.active,
|
|
315
|
+
dropProps: { onDragEnter, onDragOver, onDragLeave, onDrop },
|
|
316
|
+
captureDropProps: { onDropCapture },
|
|
317
|
+
};
|
|
275
318
|
}
|
|
@@ -135,7 +135,7 @@ describe('useEditorFind revealMatch', () => {
|
|
|
135
135
|
test('aims the caret at the first match on the given line and focuses it', async () => {
|
|
136
136
|
// `alpha beta alpha` — line 1 holds the first match; the request names it.
|
|
137
137
|
await harness.act(async () => {
|
|
138
|
-
harness.find?.revealMatch({ query: 'beta', options: { matchCase: false, wholeWord: false, isRegex: false }, line: 1 });
|
|
138
|
+
harness.find?.revealMatch({ query: 'beta', options: { matchCase: false, wholeWord: false, isRegex: false, inSelection: false }, line: 1 });
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
expect(harness.find?.query).toBe('beta');
|
|
@@ -148,7 +148,7 @@ describe('useEditorFind revealMatch', () => {
|
|
|
148
148
|
|
|
149
149
|
test('does not open the bar — the jump must not cover the line it shows', async () => {
|
|
150
150
|
await harness.act(async () => {
|
|
151
|
-
harness.find?.revealMatch({ query: 'alpha', options: { matchCase: false, wholeWord: false, isRegex: false }, line: 1 });
|
|
151
|
+
harness.find?.revealMatch({ query: 'alpha', options: { matchCase: false, wholeWord: false, isRegex: false, inSelection: false }, line: 1 });
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
expect(harness.find?.open).toBe(false);
|