@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,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Which editor theme is live, and how a change reaches an open editor.
|
|
8
|
+
*
|
|
9
|
+
* The setting is visual, so it has to apply to the editor on screen — not on the
|
|
10
|
+
* next reload. `appSettings` is a prop captured at boot, so reading it once
|
|
11
|
+
* would leave an already-mounted editor on the previous palette; this follows
|
|
12
|
+
* the editor FONT's shape (`hooks/editor/font.ts`): the picker writes the
|
|
13
|
+
* setting and announces it, and every editor subscribes.
|
|
14
|
+
*
|
|
15
|
+
* A theme's module is fetched the first time it is SELECTED (`theme-loader.ts`),
|
|
16
|
+
* so an install that never opens the picker downloads none of them.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { useEffect, useState } from 'preact/hooks';
|
|
20
|
+
import { readKabmoSetting } from '@/shared/lib/settings/client';
|
|
21
|
+
import {
|
|
22
|
+
EDITOR_AUTO_THEME_ID,
|
|
23
|
+
EDITOR_DEFAULT_THEME_ID,
|
|
24
|
+
editorShikiThemes,
|
|
25
|
+
editorThemeVars,
|
|
26
|
+
resolveEditorTheme,
|
|
27
|
+
type EditorTheme,
|
|
28
|
+
} from '@/shared/lib/code/editor/themes';
|
|
29
|
+
import { loadEditorTheme } from '@/shared/lib/code/editor/theme-loader';
|
|
30
|
+
|
|
31
|
+
/** Broadcast on every editor-theme write. Detail is the new theme id. */
|
|
32
|
+
export const EDITOR_THEME_CHANGED_EVENT = 'omp:editor-theme-changed';
|
|
33
|
+
|
|
34
|
+
/** The theme id currently stored, falling back to `auto`. */
|
|
35
|
+
export function currentEditorThemeId(): string {
|
|
36
|
+
if (typeof window === 'undefined') return EDITOR_DEFAULT_THEME_ID;
|
|
37
|
+
return readKabmoSetting<string>('editorTheme') ?? EDITOR_DEFAULT_THEME_ID;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Everything a code surface needs to paint with the live editor theme. */
|
|
41
|
+
export interface EditorThemeState {
|
|
42
|
+
/** The theme itself, or `null` for `auto` (the app palette). */
|
|
43
|
+
theme: EditorTheme | null;
|
|
44
|
+
/** CSS custom properties for the surface host; empty for `auto`. */
|
|
45
|
+
vars: Record<string, string>;
|
|
46
|
+
/** The two Shiki theme names to tokenize with. */
|
|
47
|
+
themes: { light: string; dark: string };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const AUTO_STATE: EditorThemeState = { theme: null, vars: {}, themes: editorShikiThemes(null) };
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The live editor theme, kept in step with writes.
|
|
54
|
+
*
|
|
55
|
+
* One hook rather than three, because a surface needs all three values and
|
|
56
|
+
* three subscriptions to one event would be three re-render paths that can
|
|
57
|
+
* disagree for a frame.
|
|
58
|
+
*/
|
|
59
|
+
export function useEditorTheme(): EditorThemeState {
|
|
60
|
+
const [id, setId] = useState<string>(currentEditorThemeId);
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
const onChange = (event: Event) => {
|
|
64
|
+
const detail = (event as CustomEvent<string>).detail;
|
|
65
|
+
setId(detail || currentEditorThemeId());
|
|
66
|
+
};
|
|
67
|
+
window.addEventListener(EDITOR_THEME_CHANGED_EVENT, onChange);
|
|
68
|
+
return () => window.removeEventListener(EDITOR_THEME_CHANGED_EVENT, onChange);
|
|
69
|
+
}, []);
|
|
70
|
+
|
|
71
|
+
// Fetch the module the first time this theme is live, so the tokenizer can
|
|
72
|
+
// colour with it. A no-op for `auto` and for an id already registered.
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
void loadEditorTheme(id);
|
|
75
|
+
}, [id]);
|
|
76
|
+
|
|
77
|
+
// `auto` is the shipped state, and it allocates nothing new per render.
|
|
78
|
+
if (id === EDITOR_AUTO_THEME_ID) return AUTO_STATE;
|
|
79
|
+
|
|
80
|
+
const theme = resolveEditorTheme(id);
|
|
81
|
+
return { theme, vars: editorThemeVars(theme), themes: editorShikiThemes(id) };
|
|
82
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The typing settings.
|
|
8
|
+
*
|
|
9
|
+
* Both default ON — that is what every editor does, and a user who never opens Settings
|
|
10
|
+
* must not get an editor whose typing behaves unlike every other. Each key falls back
|
|
11
|
+
* INDEPENDENTLY, so a stored `autocomplete: false` does not also disable auto-close.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { afterAll, afterEach, describe, expect, test } from 'bun:test';
|
|
15
|
+
import { Window } from 'happy-dom';
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
DEFAULT_EDITOR_TYPING,
|
|
19
|
+
EDITOR_TYPING_CHANGED_EVENT,
|
|
20
|
+
currentEditorTyping,
|
|
21
|
+
} from '@/client/hooks/editor/typing-settings';
|
|
22
|
+
import { primeKabmoSettings } from '@/shared/lib/settings/client';
|
|
23
|
+
|
|
24
|
+
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Event', 'CustomEvent'] as const;
|
|
25
|
+
const native: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
26
|
+
const win = new Window({ url: 'http://localhost' });
|
|
27
|
+
for (const key of DOM_GLOBALS) {
|
|
28
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
29
|
+
native[key] = target[key];
|
|
30
|
+
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
afterAll(() => {
|
|
34
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
35
|
+
for (const key of DOM_GLOBALS) target[key] = native[key];
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
afterEach(() => {
|
|
39
|
+
primeKabmoSettings({});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('currentEditorTyping', () => {
|
|
43
|
+
test('both default ON', () => {
|
|
44
|
+
expect(currentEditorTyping()).toEqual(DEFAULT_EDITOR_TYPING);
|
|
45
|
+
expect(DEFAULT_EDITOR_TYPING).toEqual({ autoCloseBrackets: true, autocomplete: true });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('each key falls back on its own', () => {
|
|
49
|
+
primeKabmoSettings({ kabmo_settings: { editorAutocomplete: false } });
|
|
50
|
+
// Turning the completer off must not also turn auto-close off: they are two
|
|
51
|
+
// decisions, and a shared fallback would couple them.
|
|
52
|
+
expect(currentEditorTyping()).toEqual({ autoCloseBrackets: true, autocomplete: false });
|
|
53
|
+
|
|
54
|
+
primeKabmoSettings({ kabmo_settings: { editorAutoCloseBrackets: false } });
|
|
55
|
+
expect(currentEditorTyping()).toEqual({ autoCloseBrackets: false, autocomplete: true });
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('a non-boolean value falls back rather than being coerced', () => {
|
|
59
|
+
primeKabmoSettings({ kabmo_settings: { editorAutocomplete: 'no', editorAutoCloseBrackets: 0 } });
|
|
60
|
+
expect(currentEditorTyping()).toEqual(DEFAULT_EDITOR_TYPING);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('an explicit false is honoured, which is the whole point of the setting', () => {
|
|
64
|
+
primeKabmoSettings({ kabmo_settings: { editorAutocomplete: false, editorAutoCloseBrackets: false } });
|
|
65
|
+
expect(currentEditorTyping()).toEqual({ autoCloseBrackets: false, autocomplete: false });
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('the live event', () => {
|
|
70
|
+
test('the name is the one the editor subscribes to', () => {
|
|
71
|
+
expect(EDITOR_TYPING_CHANGED_EVENT).toBe('omp:editor-typing-changed');
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The two BEHAVIOUR settings for the editor: auto-close brackets, and the
|
|
8
|
+
* document-words completer.
|
|
9
|
+
*
|
|
10
|
+
* They are settings rather than always-on because both change what TYPING does. A view
|
|
11
|
+
* preference can be ignored by a user who does not like it; an auto-inserted `}` cannot.
|
|
12
|
+
* Both default ON, because that is what every editor does and a user who has never seen
|
|
13
|
+
* the setting would otherwise wonder why typing is different here.
|
|
14
|
+
*
|
|
15
|
+
* ## The completer is not LSP
|
|
16
|
+
*
|
|
17
|
+
* It suggests words that already appear near the caret. That works in every language with
|
|
18
|
+
* no server, which is the same reason the surface has no grammar — and it is bounded to a
|
|
19
|
+
* window around the caret, because a whole-document scan per keystroke is exactly the cost
|
|
20
|
+
* the CodeMirror migration removed.
|
|
21
|
+
*
|
|
22
|
+
* ## Reaching an open editor
|
|
23
|
+
*
|
|
24
|
+
* Through `omp:editor-typing-changed`, the same shape the font, theme and indent settings
|
|
25
|
+
* use: `appSettings` is a boot-time prop, so a value read once would not reach the editor
|
|
26
|
+
* already on screen.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { useEffect, useState } from 'preact/hooks';
|
|
30
|
+
import { readKabmoSetting } from '@/shared/lib/settings/client';
|
|
31
|
+
|
|
32
|
+
import type { EditorTypingOptions } from '@/client/components/common/code-surface/typing';
|
|
33
|
+
|
|
34
|
+
/** Broadcast on every typing-setting write. Detail is the resolved pair. */
|
|
35
|
+
export const EDITOR_TYPING_CHANGED_EVENT = 'omp:editor-typing-changed';
|
|
36
|
+
|
|
37
|
+
/** Both ON: what every editor does, and what a user who never opens Settings expects. */
|
|
38
|
+
export const DEFAULT_EDITOR_TYPING: EditorTypingOptions = { autoCloseBrackets: true, autocomplete: true };
|
|
39
|
+
|
|
40
|
+
/** The stored pair, falling back per key so one unset does not disable the other. */
|
|
41
|
+
export function currentEditorTyping(): EditorTypingOptions {
|
|
42
|
+
if (typeof window === 'undefined') return DEFAULT_EDITOR_TYPING;
|
|
43
|
+
const close = readKabmoSetting<boolean>('editorAutoCloseBrackets');
|
|
44
|
+
const complete = readKabmoSetting<boolean>('editorAutocomplete');
|
|
45
|
+
return {
|
|
46
|
+
autoCloseBrackets: typeof close === 'boolean' ? close : DEFAULT_EDITOR_TYPING.autoCloseBrackets,
|
|
47
|
+
autocomplete: typeof complete === 'boolean' ? complete : DEFAULT_EDITOR_TYPING.autocomplete,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The stored pair, kept in step with writes from the settings modal. */
|
|
52
|
+
export function useEditorTyping(): EditorTypingOptions {
|
|
53
|
+
const [typing, setTyping] = useState<EditorTypingOptions>(currentEditorTyping);
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
const onChange = (event: Event) => {
|
|
57
|
+
const detail = (event as CustomEvent<EditorTypingOptions>).detail;
|
|
58
|
+
setTyping(detail ?? currentEditorTyping());
|
|
59
|
+
};
|
|
60
|
+
window.addEventListener(EDITOR_TYPING_CHANGED_EVENT, onChange);
|
|
61
|
+
return () => window.removeEventListener(EDITOR_TYPING_CHANGED_EVENT, onChange);
|
|
62
|
+
}, []);
|
|
63
|
+
|
|
64
|
+
return typing;
|
|
65
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The close guard, as one hook.
|
|
8
|
+
*
|
|
9
|
+
* The panel owns three things here and each needs the others: the dirty set the
|
|
10
|
+
* editor publishes, the tab a close was asked for, and the buffer that has to be
|
|
11
|
+
* written if the answer is "Save & close". Keeping them in the panel pushed that
|
|
12
|
+
* file past the repository's line ceiling, and the cluster is self-contained —
|
|
13
|
+
* one state, one dialog, one decision.
|
|
14
|
+
*
|
|
15
|
+
* ## Why only DIRTY tabs ask
|
|
16
|
+
*
|
|
17
|
+
* A confirm on every close is one people learn to dismiss without reading, which
|
|
18
|
+
* is worse than none. A clean tab closes instantly; the dialog appears only where
|
|
19
|
+
* there is something to lose.
|
|
20
|
+
*
|
|
21
|
+
* ## Why `saveNow` is not enough on its own
|
|
22
|
+
*
|
|
23
|
+
* `saveNow` writes the ACTIVE file. A background tab is saved by activating it
|
|
24
|
+
* first, which is what the panel's `onSelectFile` does — and the activation has
|
|
25
|
+
* to happen BEFORE the save call, because the hook reads its target from the
|
|
26
|
+
* render it was built in.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { useCallback, useState } from 'preact/hooks';
|
|
30
|
+
|
|
31
|
+
import { isTabDirty } from '@/client/lib/editor-dirty-tabs';
|
|
32
|
+
import { useUnloadGuard, type DirtyCloseAnswer } from '@/client/hooks/editor/use-unload-guard';
|
|
33
|
+
import type { OpenedFile } from '@/shared/types/fs';
|
|
34
|
+
|
|
35
|
+
interface UseCloseGuardOptions {
|
|
36
|
+
openedFiles: OpenedFile[];
|
|
37
|
+
activeFileId: number | string | null;
|
|
38
|
+
onSelectFile: (id: number | string) => void;
|
|
39
|
+
onCloseFile: (id: number | string) => void;
|
|
40
|
+
/** Writes the ACTIVE buffer; the caller activates the tab first. */
|
|
41
|
+
saveNow: () => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface CloseGuard {
|
|
45
|
+
/** Close a tab, asking first when it holds edits that are not on disk. */
|
|
46
|
+
requestClose: (id: number | string) => void;
|
|
47
|
+
/** The tab the dialog is asking about, or null. */
|
|
48
|
+
pending: OpenedFile | null;
|
|
49
|
+
/** The dialog's answer. */
|
|
50
|
+
answer: (answer: DirtyCloseAnswer) => void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function useCloseGuard({
|
|
54
|
+
openedFiles,
|
|
55
|
+
activeFileId,
|
|
56
|
+
onSelectFile,
|
|
57
|
+
onCloseFile,
|
|
58
|
+
saveNow,
|
|
59
|
+
}: UseCloseGuardOptions): CloseGuard {
|
|
60
|
+
const [pending, setPending] = useState<OpenedFile | null>(null);
|
|
61
|
+
// Armed only while something is dirty — see the hook's own note.
|
|
62
|
+
useUnloadGuard();
|
|
63
|
+
|
|
64
|
+
const requestClose = useCallback(
|
|
65
|
+
(id: number | string) => {
|
|
66
|
+
const file = openedFiles.find((entry) => entry.id === id);
|
|
67
|
+
if (file && isTabDirty(id)) {
|
|
68
|
+
setPending(file);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
onCloseFile(id);
|
|
72
|
+
},
|
|
73
|
+
[openedFiles, onCloseFile],
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const answer = useCallback(
|
|
77
|
+
(decision: DirtyCloseAnswer) => {
|
|
78
|
+
const file = pending;
|
|
79
|
+
if (!file) return;
|
|
80
|
+
if (decision === 'cancel') {
|
|
81
|
+
setPending(null);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (decision === 'save') {
|
|
85
|
+
// `saveNow` writes the ACTIVE file, so a background tab is activated
|
|
86
|
+
// first. The dialog closes with the tab either way; a failed write is
|
|
87
|
+
// reported by the toolbar's own status, not here.
|
|
88
|
+
if (file.id !== activeFileId) onSelectFile(file.id);
|
|
89
|
+
saveNow();
|
|
90
|
+
}
|
|
91
|
+
setPending(null);
|
|
92
|
+
onCloseFile(file.id);
|
|
93
|
+
},
|
|
94
|
+
[pending, activeFileId, onSelectFile, saveNow, onCloseFile],
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return { requestClose, pending, answer };
|
|
98
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The editor drop target's OVERLAY state.
|
|
8
|
+
*
|
|
9
|
+
* Every case here was a way the overlay could stay lit with the pointer nowhere
|
|
10
|
+
* near the panel, which is what a user reports as "the drop target is stuck":
|
|
11
|
+
*
|
|
12
|
+
* - `dragenter` fires for every nested child the pointer crosses, so the counter
|
|
13
|
+
* this replaced rose with each crossing while a `dragleave` to a node still
|
|
14
|
+
* inside was ignored. Measured in Chromium against the real app: five child
|
|
15
|
+
* crossings inside the chat left the counter at 5 after one exit, and the
|
|
16
|
+
* "Drop a file to open it" overlay stayed drawn.
|
|
17
|
+
* - A drag cancelled with Escape (or released outside the window) delivers NO
|
|
18
|
+
* `dragleave` and NO `dragend` for an OS file drag — measured — so only the
|
|
19
|
+
* pointer can report that the gesture is over.
|
|
20
|
+
*
|
|
21
|
+
* Split from `use-editor-drop.test.ts` for the per-file ceiling.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
25
|
+
import { Window } from 'happy-dom';
|
|
26
|
+
import { h, render } from 'preact';
|
|
27
|
+
import { act } from 'preact/test-utils';
|
|
28
|
+
import { useEditorDrop, type UseEditorDropResult } from '@/client/hooks/editor/use-editor-drop';
|
|
29
|
+
|
|
30
|
+
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent', 'fetch'] as const;
|
|
31
|
+
const nativeGlobals: Partial<Record<(typeof DOM_GLOBALS)[number], unknown>> = {};
|
|
32
|
+
|
|
33
|
+
beforeAll(() => {
|
|
34
|
+
const win = new Window({ url: 'http://localhost' });
|
|
35
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
36
|
+
for (const key of DOM_GLOBALS) {
|
|
37
|
+
nativeGlobals[key] = target[key];
|
|
38
|
+
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
39
|
+
}
|
|
40
|
+
globalThis.fetch = (async () => ({ ok: true, status: 200, json: async () => ({}) })) as unknown as typeof globalThis.fetch;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
afterAll(() => {
|
|
44
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
45
|
+
for (const key of DOM_GLOBALS) {
|
|
46
|
+
if (nativeGlobals[key] === undefined) delete target[key];
|
|
47
|
+
else target[key] = nativeGlobals[key];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/** A `DataTransfer` carrying one `text/uri-list` reference, as a Finder drop does. */
|
|
52
|
+
function fileTransfer(reference: string): DataTransfer {
|
|
53
|
+
return {
|
|
54
|
+
types: ['text/uri-list'],
|
|
55
|
+
files: [],
|
|
56
|
+
getData: (type: string) => (type.toLowerCase() === 'text/uri-list' ? reference : ''),
|
|
57
|
+
} as unknown as DataTransfer;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface Harness {
|
|
61
|
+
api: () => UseEditorDropResult;
|
|
62
|
+
/** A node INSIDE the bound target, for the between-children case. */
|
|
63
|
+
child: Node;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let container: HTMLElement;
|
|
67
|
+
|
|
68
|
+
async function mount(enabled = true): Promise<Harness> {
|
|
69
|
+
container = document.body.appendChild(document.createElement('div'));
|
|
70
|
+
const target = container.appendChild(document.createElement('div'));
|
|
71
|
+
const child = target.appendChild(document.createElement('div'));
|
|
72
|
+
|
|
73
|
+
let api: UseEditorDropResult | null = null;
|
|
74
|
+
const Probe = () => {
|
|
75
|
+
api = useEditorDrop({ enabled, onResult: () => {} });
|
|
76
|
+
return null;
|
|
77
|
+
};
|
|
78
|
+
await act(async () => {
|
|
79
|
+
render(h(Probe, {}), container);
|
|
80
|
+
});
|
|
81
|
+
return { api: () => api!, child };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A drag event as the DOM delivers it: `currentTarget` is the bound element. */
|
|
85
|
+
function dragEvent(transfer: DataTransfer, related: Node | null) {
|
|
86
|
+
const event = new window.Event('dragover', { bubbles: true, cancelable: true });
|
|
87
|
+
Object.defineProperty(event, 'dataTransfer', { value: transfer });
|
|
88
|
+
Object.defineProperty(event, 'currentTarget', { value: container.firstElementChild });
|
|
89
|
+
Object.defineProperty(event, 'relatedTarget', { value: related });
|
|
90
|
+
return event as never;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
beforeEach(() => {
|
|
94
|
+
container?.remove();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('useEditorDrop overlay', () => {
|
|
98
|
+
test('child crossings keep it lit and one real exit clears it', async () => {
|
|
99
|
+
const harness = await mount();
|
|
100
|
+
const transfer = fileTransfer('file:///repo/src/app.ts');
|
|
101
|
+
|
|
102
|
+
await act(async () => { harness.api().dropProps.onDragEnter(dragEvent(transfer, null)); });
|
|
103
|
+
expect(harness.api().isDragging).toBe(true);
|
|
104
|
+
|
|
105
|
+
// A sweep across nested children: the pointer never leaves the panel, so
|
|
106
|
+
// every leave names a node still inside it.
|
|
107
|
+
for (let pass = 0; pass < 5; pass += 1) {
|
|
108
|
+
await act(async () => { harness.api().dropProps.onDragOver(dragEvent(transfer, null)); });
|
|
109
|
+
await act(async () => { harness.api().dropProps.onDragLeave(dragEvent(transfer, harness.child)); });
|
|
110
|
+
}
|
|
111
|
+
expect(harness.api().isDragging).toBe(true);
|
|
112
|
+
|
|
113
|
+
await act(async () => { harness.api().dropProps.onDragLeave(dragEvent(transfer, null)); });
|
|
114
|
+
expect(harness.api().isDragging).toBe(false);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('a drag cancelled with no leave at all is cleared by a pointer move', async () => {
|
|
118
|
+
const harness = await mount();
|
|
119
|
+
await act(async () => { harness.api().dropProps.onDragEnter(dragEvent(fileTransfer('file:///repo/a.ts'), null)); });
|
|
120
|
+
expect(harness.api().isDragging).toBe(true);
|
|
121
|
+
|
|
122
|
+
// A held button is a gesture still in progress, so the overlay stays.
|
|
123
|
+
const move = (buttons: number) => {
|
|
124
|
+
const event = new window.PointerEvent('pointermove', { bubbles: true });
|
|
125
|
+
Object.defineProperty(event, 'buttons', { value: buttons });
|
|
126
|
+
window.dispatchEvent(event);
|
|
127
|
+
};
|
|
128
|
+
await act(async () => { move(1); });
|
|
129
|
+
expect(harness.api().isDragging).toBe(true);
|
|
130
|
+
|
|
131
|
+
await act(async () => { move(0); });
|
|
132
|
+
expect(harness.api().isDragging).toBe(false);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('a target with no workspace behind it never lights up', async () => {
|
|
136
|
+
// A drop there can only be refused, and an overlay that promises an open it
|
|
137
|
+
// will not perform is worse than one that stays dark.
|
|
138
|
+
const harness = await mount(false);
|
|
139
|
+
const transfer = fileTransfer('file:///repo/src/app.ts');
|
|
140
|
+
await act(async () => { harness.api().dropProps.onDragEnter(dragEvent(transfer, null)); });
|
|
141
|
+
await act(async () => { harness.api().dropProps.onDragOver(dragEvent(transfer, null)); });
|
|
142
|
+
expect(harness.api().isDragging).toBe(false);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('a drop clears it, so the overlay does not outlive the gesture', async () => {
|
|
146
|
+
const harness = await mount();
|
|
147
|
+
const transfer = fileTransfer('file:///repo/src/app.ts');
|
|
148
|
+
await act(async () => { harness.api().dropProps.onDragEnter(dragEvent(transfer, null)); });
|
|
149
|
+
expect(harness.api().isDragging).toBe(true);
|
|
150
|
+
|
|
151
|
+
await act(async () => {
|
|
152
|
+
harness.api().dropProps.onDrop(dragEvent(transfer, null));
|
|
153
|
+
});
|
|
154
|
+
for (let pass = 0; pass < 4; pass += 1) {
|
|
155
|
+
await act(async () => { await Promise.resolve(); });
|
|
156
|
+
}
|
|
157
|
+
expect(harness.api().isDragging).toBe(false);
|
|
158
|
+
});
|
|
159
|
+
});
|