@cueloop/client 0.1.0-alpha.10 → 0.1.0-alpha.101
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/native/build-pty.sh +51 -0
- package/native/build.sh +82 -0
- package/native/darwin-arm64/libcuelooppty.dylib +0 -0
- package/native/darwin-arm64/libcueloopvt.dylib +0 -0
- package/native/src/pty.zig +193 -0
- package/native/src/shim.zig +114 -0
- package/package.json +42 -34
- package/src/annotations/annotation-palette.ts +62 -0
- package/src/annotations/components/AnnotationCards.stories.tsx +86 -0
- package/src/annotations/components/AnnotationCards.test.tsx +42 -0
- package/src/annotations/components/AnnotationCards.tsx +369 -0
- package/src/annotations/components/DiscussionMarkerRail.stories.tsx +54 -0
- package/src/annotations/components/DiscussionMarkerRail.tsx +186 -0
- package/src/annotations/discussions.ts +77 -0
- package/src/annotations/thread-selection.test.ts +210 -0
- package/src/annotations/thread-selection.ts +242 -0
- package/src/annotations/use-annotation-surface.tsx +1243 -0
- package/src/app/App.appearance.test.tsx +53 -0
- package/src/{App.autoclose.test.tsx → app/App.autoclose.test.tsx} +77 -51
- package/src/app/App.deleted-scroll.test.tsx +187 -0
- package/src/app/App.diff.test.tsx +313 -0
- package/src/app/App.export.test.tsx +105 -0
- package/src/app/App.focus.test.ts +89 -0
- package/src/app/App.identity.test.tsx +84 -0
- package/src/app/App.plan-render.test.tsx +209 -0
- package/src/app/App.plan-review.test.tsx +428 -0
- package/src/app/App.prototype-markdown.test.tsx +128 -0
- package/src/app/App.prototype.test.tsx +176 -0
- package/src/app/App.readonly.test.tsx +210 -0
- package/src/app/App.regression.test.tsx +99 -0
- package/src/app/App.rendering.test.tsx +134 -0
- package/src/app/App.share-dialog.test.tsx +177 -0
- package/src/app/App.submit-confirm.test.tsx +267 -0
- package/src/app/App.test.tsx +496 -0
- package/src/app/App.thread-agent.test.ts +20 -0
- package/src/app/App.toast.test.tsx +124 -0
- package/src/app/App.tsx +1667 -0
- package/src/app/App.visual.test.tsx +59 -0
- package/src/app/App.walk.test.tsx +299 -0
- package/src/app/App.workbench.test.tsx +1149 -0
- package/src/app/app-key-state.ts +61 -0
- package/src/app/app-screens.tsx +606 -0
- package/src/app/app-view-model.ts +168 -0
- package/src/app/components/AppHeader.stories.tsx +50 -0
- package/src/app/components/AppHeader.tsx +81 -0
- package/src/app/components/AppShell.brand.test.tsx +58 -0
- package/src/app/components/AppShell.extensions.test.tsx +191 -0
- package/src/app/components/AppShell.stories.tsx +89 -0
- package/src/app/components/AppShell.tsx +358 -0
- package/src/app/components/AppShell.zoom.test.tsx +149 -0
- package/src/app/components/Breadcrumb.stories.tsx +19 -0
- package/src/app/components/Breadcrumb.tsx +45 -0
- package/src/app/components/MenuBar.stories.tsx +28 -0
- package/src/app/components/MenuBar.tsx +44 -0
- package/src/app/components/PaneGrid.stories.tsx +84 -0
- package/src/app/components/PaneGrid.tsx +128 -0
- package/src/app/components/PanelColumn.stories.tsx +25 -0
- package/src/app/components/PanelColumn.tsx +93 -0
- package/src/app/components/ShellHeader.stories.tsx +50 -0
- package/src/app/components/ShellHeader.tsx +137 -0
- package/src/app/components/WorkspacePanels.stories.tsx +36 -0
- package/src/app/components/WorkspacePanels.tsx +120 -0
- package/src/app/components/pages/Workspace.stories.tsx +181 -0
- package/src/app/intent-dispatch.test.ts +728 -0
- package/src/app/intent-dispatch.ts +687 -0
- package/src/app/launch-layout.test.ts +78 -0
- package/src/app/launch-layout.ts +57 -0
- package/src/app/ready-signal.test.ts +85 -0
- package/src/app/ready-signal.ts +52 -0
- package/src/app/run.ts +109 -0
- package/src/{serve.test.ts → app/serve.test.ts} +24 -12
- package/src/app/serve.ts +111 -0
- package/src/app/version.ts +5 -0
- package/src/appearance/components/theme-context.stories.tsx +46 -0
- package/src/appearance/components/theme-context.tsx +37 -0
- package/src/appearance/theme-presets.test.ts +51 -0
- package/src/appearance/theme-presets.ts +219 -0
- package/src/appearance/theme.ts +112 -0
- package/src/appearance/visual/contrast.test.ts +35 -0
- package/src/appearance/visual/contrast.ts +33 -0
- package/src/diff/components/AnnotatableFileView.stories.tsx +42 -0
- package/src/diff/components/AnnotatableFileView.test.tsx +157 -0
- package/src/diff/components/AnnotatableFileView.tsx +141 -0
- package/src/diff/components/BareWorkbenchFileView.stories.tsx +27 -0
- package/src/diff/components/BareWorkbenchFileView.tsx +63 -0
- package/src/diff/components/DiffContentView.scroll.test.tsx +434 -0
- package/src/diff/components/DiffContentView.split.test.tsx +140 -0
- package/src/diff/components/DiffContentView.stories.tsx +80 -0
- package/src/diff/components/DiffContentView.syntax.test.tsx +82 -0
- package/src/diff/components/DiffContentView.tsx +1055 -0
- package/src/diff/components/WalkWizard.stories.tsx +100 -0
- package/src/diff/components/WalkWizard.tsx +146 -0
- package/src/diff/components/diff-content-view-layout.test.ts +198 -0
- package/src/diff/components/diff-content-view-layout.ts +84 -0
- package/src/diff/diff-fold.test.ts +78 -0
- package/src/diff/diff-fold.ts +126 -0
- package/src/diff/diff-hunk-curate.test.ts +315 -0
- package/src/diff/diff-hunk-curate.ts +152 -0
- package/src/diff/diff-intraline.test.ts +239 -0
- package/src/diff/diff-intraline.ts +238 -0
- package/src/diff/diff-syntax.test.ts +125 -0
- package/src/diff/diff-syntax.ts +186 -0
- package/src/diff/split-diff.test.ts +110 -0
- package/src/diff/split-diff.ts +144 -0
- package/src/diff/view-diff.test.ts +325 -0
- package/src/diff/view-diff.ts +522 -0
- package/src/diff/walk.test.ts +121 -0
- package/src/diff/walk.ts +73 -0
- package/src/index.ts +31 -2
- package/src/integrations/attribution.test.ts +31 -0
- package/src/integrations/attribution.ts +42 -0
- package/src/integrations/client-extension-registry.test.tsx +61 -0
- package/src/integrations/client-extension-registry.ts +159 -0
- package/src/integrations/clipboard.test.ts +23 -0
- package/src/integrations/clipboard.ts +33 -0
- package/src/integrations/components/ExtensionZone.stories.tsx +28 -0
- package/src/integrations/components/ExtensionZone.tsx +145 -0
- package/src/integrations/components/ShareDialog.agent.test.tsx +50 -0
- package/src/integrations/components/ShareDialog.stories.tsx +121 -0
- package/src/integrations/components/ShareDialog.tsx +574 -0
- package/src/integrations/components/share-dialog-store.ts +59 -0
- package/src/integrations/editor.test.ts +149 -0
- package/src/integrations/editor.ts +160 -0
- package/src/integrations/github-identity.test.ts +58 -0
- package/src/integrations/github-identity.ts +41 -0
- package/src/integrations/herdr.test.ts +43 -0
- package/src/integrations/herdr.ts +38 -0
- package/src/integrations/integrations.test.ts +41 -0
- package/src/integrations/integrations.ts +32 -0
- package/src/integrations/pasted-image.test.ts +67 -0
- package/src/integrations/pasted-image.ts +60 -0
- package/src/integrations/share.ts +238 -0
- package/src/keyboard/components/CompletionOverlay.stories.tsx +37 -0
- package/src/keyboard/components/CompletionOverlay.tsx +75 -0
- package/src/keyboard/components/HandleChipsInput.stories.tsx +24 -0
- package/src/keyboard/components/HandleChipsInput.test.tsx +35 -0
- package/src/keyboard/components/HandleChipsInput.tsx +143 -0
- package/src/keyboard/components/KeybindsDialog.stories.tsx +31 -0
- package/src/keyboard/components/KeybindsDialog.tsx +103 -0
- package/src/keyboard/components/NavModeHint.stories.tsx +40 -0
- package/src/keyboard/components/NavModeHint.tsx +31 -0
- package/src/keyboard/components/SlashComposer.stories.tsx +37 -0
- package/src/keyboard/components/SlashComposer.tsx +87 -0
- package/src/keyboard/key-bindings.test.ts +156 -0
- package/src/keyboard/key-bindings.ts +459 -0
- package/src/keyboard/keymap.test.ts +611 -0
- package/src/keyboard/keymap.ts +395 -0
- package/src/keyboard/skills.test.ts +74 -0
- package/src/keyboard/skills.ts +75 -0
- package/src/keyboard/slash-palette.test.ts +103 -0
- package/src/keyboard/slash-palette.ts +129 -0
- package/src/keyboard/thread-chords.test.ts +79 -0
- package/src/keyboard/thread-chords.ts +163 -0
- package/src/keyboard/use-shared-keyboard.ts +55 -0
- package/src/markdown/__snapshots__/view-plan.regression.test.ts.snap +100 -0
- package/src/markdown/components/MarkdownGridBlock.stories.tsx +33 -0
- package/src/markdown/components/MarkdownGridBlock.tsx +72 -0
- package/src/markdown/components/MarkdownThreadEditor.stories.tsx +15 -0
- package/src/markdown/components/MarkdownThreadEditor.test.tsx +98 -0
- package/src/markdown/components/MarkdownThreadEditor.tsx +160 -0
- package/src/markdown/components/ThreadView.selection.test.tsx +951 -0
- package/src/markdown/components/ThreadView.slash.test.tsx +146 -0
- package/src/markdown/components/ThreadView.stories.tsx +26 -0
- package/src/markdown/components/ThreadView.tsx +560 -0
- package/src/markdown/mark-runs.ts +121 -0
- package/src/markdown/markdown-editor-syntax-style.ts +50 -0
- package/src/markdown/markdown-grid.test.ts +101 -0
- package/src/markdown/markdown-grid.ts +203 -0
- package/src/markdown/markdown-highlight.test.ts +61 -0
- package/src/markdown/markdown-highlight.ts +124 -0
- package/src/markdown/thread-code-syntax.ts +45 -0
- package/src/markdown/use-thread-body-editing.tsx +54 -0
- package/src/markdown/view-plan.regression.test.ts +60 -0
- package/src/markdown/view-plan.test.ts +545 -0
- package/src/markdown/view-plan.ts +1009 -0
- package/src/performance/otlp-trace.test.ts +119 -0
- package/src/performance/otlp-trace.ts +134 -0
- package/src/performance/perf-report.ts +18 -0
- package/src/performance/perf-timings.test.ts +18 -0
- package/src/performance/perf-timings.ts +39 -0
- package/src/prototype/components/PrototypeContentView.stories.tsx +19 -0
- package/src/prototype/components/PrototypeContentView.tsx +442 -0
- package/src/prototype/prototype-browser.test.ts +81 -0
- package/src/prototype/prototype-browser.ts +321 -0
- package/src/prototype/prototype-pixels.tsx +35 -0
- package/src/settings/components/SettingsDialog.stories.tsx +117 -0
- package/src/settings/components/SettingsDialog.tsx +183 -0
- package/src/settings/components/SettingsRows.stories.tsx +18 -0
- package/src/settings/components/SettingsRows.tsx +112 -0
- package/src/settings/components/quick-actions-editor.stories.tsx +58 -0
- package/src/settings/components/quick-actions-editor.test.tsx +120 -0
- package/src/settings/components/quick-actions-editor.tsx +222 -0
- package/src/settings/config-identity.test.ts +78 -0
- package/src/settings/config.test.ts +676 -0
- package/src/settings/config.ts +628 -0
- package/src/settings/use-settings-dialog.tsx +351 -0
- package/src/stories/__snapshots__/stories.test.tsx.snap +2358 -0
- package/src/stories/stories-app.tsx +196 -0
- package/src/stories/stories.test.tsx +74 -0
- package/src/stories/story-fixtures.ts +102 -0
- package/src/stories/story-tree.test.ts +108 -0
- package/src/stories/story.ts +154 -0
- package/src/terminal/ansi-screen.test.ts +28 -0
- package/src/terminal/ansi-screen.ts +72 -0
- package/src/terminal/components/AnsiScreen.stories.tsx +12 -0
- package/src/terminal/components/AnsiScreen.tsx +28 -0
- package/src/terminal/components/terminal-pane.test.tsx +40 -0
- package/src/terminal/components/terminal-pane.ts +196 -0
- package/src/terminal/ghostty-terminal.test.ts +85 -0
- package/src/terminal/ghostty-terminal.ts +197 -0
- package/src/terminal/kitty-image.test.ts +66 -0
- package/src/terminal/kitty-image.ts +137 -0
- package/src/terminal/pty.test.ts +81 -0
- package/src/terminal/pty.ts +246 -0
- package/src/testing/test-support.test.ts +264 -0
- package/src/testing/test-support.ts +367 -0
- package/src/thread/agent-continuation.test.ts +32 -0
- package/src/thread/agent-continuation.ts +13 -0
- package/src/thread/agent-transcript.test.ts +161 -0
- package/src/thread/agent-transcript.ts +336 -0
- package/src/thread/components/AgentConfigControls.stories.tsx +39 -0
- package/src/thread/components/AgentConfigControls.test.tsx +112 -0
- package/src/thread/components/AgentConfigControls.tsx +114 -0
- package/src/thread/components/AgentThreadPane.stories.tsx +105 -0
- package/src/thread/components/AgentThreadPane.test.tsx +935 -0
- package/src/thread/components/AgentThreadPane.tsx +377 -0
- package/src/thread/components/ThreadFooter.stories.tsx +30 -0
- package/src/thread/components/ThreadFooter.test.tsx +49 -0
- package/src/thread/components/ThreadFooter.tsx +77 -0
- package/src/thread/components/ThreadTree.stories.tsx +46 -0
- package/src/thread/components/ThreadTree.test.tsx +41 -0
- package/src/thread/components/ThreadTree.tsx +267 -0
- package/src/thread/components/thread-tree.test.ts +137 -0
- package/src/thread/components/thread-tree.ts +112 -0
- package/src/thread/thread-controller.curate.test.ts +502 -0
- package/src/thread/thread-controller.derivation.test.ts +62 -0
- package/src/thread/thread-controller.live-diff.test.ts +357 -0
- package/src/thread/thread-controller.optimistic.test.ts +69 -0
- package/src/thread/thread-controller.share.test.ts +573 -0
- package/src/thread/thread-controller.switch-cache.test.ts +174 -0
- package/src/thread/thread-controller.tree.test.ts +263 -0
- package/src/thread/thread-controller.ts +2026 -0
- package/src/thread/tree-view.test.ts +128 -0
- package/src/thread/tree-view.ts +146 -0
- package/src/thread/use-thread-agent.test.tsx +208 -0
- package/src/thread/use-thread-agent.ts +117 -0
- package/src/ui/components/CodeBlock.stories.tsx +42 -0
- package/src/ui/components/CodeBlock.tsx +80 -0
- package/src/ui/components/ConfirmCard.stories.tsx +37 -0
- package/src/ui/components/ConfirmCard.tsx +151 -0
- package/src/ui/components/ConfirmDialog.stories.tsx +21 -0
- package/src/ui/components/ConfirmDialog.tsx +72 -0
- package/src/ui/components/OverlayScrollbar.stories.tsx +33 -0
- package/src/ui/components/OverlayScrollbar.test.tsx +139 -0
- package/src/ui/components/OverlayScrollbar.tsx +129 -0
- package/src/ui/components/PromptDialog.stories.tsx +36 -0
- package/src/ui/components/PromptDialog.test.tsx +65 -0
- package/src/ui/components/PromptDialog.tsx +99 -0
- package/src/ui/components/RootOverlay.stories.tsx +45 -0
- package/src/ui/components/RootOverlay.tsx +49 -0
- package/src/ui/components/ScrollArea.stories.tsx +20 -0
- package/src/ui/components/ScrollArea.tsx +61 -0
- package/src/ui/components/Toast.stories.tsx +19 -0
- package/src/ui/components/Toast.tsx +54 -0
- package/src/ui/components/Tooltip.stories.tsx +26 -0
- package/src/ui/components/Tooltip.tsx +72 -0
- package/src/ui/components/menu-control.stories.tsx +35 -0
- package/src/ui/components/menu-control.tsx +43 -0
- package/src/ui/components/primitives/Button.stories.tsx +32 -0
- package/src/ui/components/primitives/Button.tsx +57 -0
- package/src/ui/components/primitives/Card.stories.tsx +25 -0
- package/src/ui/components/primitives/Card.tsx +62 -0
- package/src/ui/components/primitives/Dialog.stories.tsx +24 -0
- package/src/ui/components/primitives/Dialog.test.tsx +38 -0
- package/src/ui/components/primitives/Dialog.tsx +69 -0
- package/src/ui/components/primitives/DialogActions.stories.tsx +20 -0
- package/src/ui/components/primitives/DialogActions.tsx +39 -0
- package/src/ui/components/primitives/IconButton.stories.tsx +36 -0
- package/src/ui/components/primitives/IconButton.tsx +58 -0
- package/src/ui/components/primitives/StatusBar.stories.tsx +11 -0
- package/src/ui/components/primitives/StatusBar.tsx +23 -0
- package/src/ui/components/primitives/Switch.stories.tsx +17 -0
- package/src/ui/components/primitives/Switch.tsx +32 -0
- package/src/ui/components/primitives/Tabs.stories.tsx +29 -0
- package/src/ui/components/primitives/Tabs.tsx +101 -0
- package/src/ui/components/primitives/Toolbar.stories.tsx +17 -0
- package/src/ui/components/primitives/Toolbar.tsx +14 -0
- package/src/ui/components/primitives/Tree.stories.tsx +124 -0
- package/src/ui/components/primitives/Tree.tsx +133 -0
- package/src/ui/components/primitives/frame.test.ts +12 -0
- package/src/ui/components/primitives/frame.ts +17 -0
- package/src/ui/components/primitives/icons.ts +61 -0
- package/src/ui/components/primitives/tree-model.test.ts +99 -0
- package/src/ui/components/primitives/tree-model.ts +137 -0
- package/src/ui/components/syntax-highlight.ts +133 -0
- package/src/ui/components/truncate-text.ts +7 -0
- package/src/ui/components/truncate-title.test.ts +31 -0
- package/src/ui/components/truncate-title.ts +15 -0
- package/src/ui/use-frame-measure.ts +74 -0
- package/src/ui/use-terminal-virtualizer.ts +259 -0
- package/src/workbench/components/ChangesColumn.stories.tsx +44 -0
- package/src/workbench/components/ChangesColumn.tsx +203 -0
- package/src/workbench/components/ChangesFileTree.test.tsx +181 -0
- package/src/workbench/components/EditorGrid.split.test.tsx +118 -0
- package/src/workbench/components/EditorGrid.stories.tsx +86 -0
- package/src/workbench/components/EditorGrid.tabs.test.tsx +118 -0
- package/src/workbench/components/EditorGrid.tsx +544 -0
- package/src/workbench/components/EditorGrid.zoom.test.tsx +132 -0
- package/src/workbench/components/FileContentsView.stories.tsx +16 -0
- package/src/workbench/components/FileContentsView.test.tsx +29 -0
- package/src/workbench/components/FileContentsView.tsx +100 -0
- package/src/workbench/components/GridTabContent.actions.test.tsx +151 -0
- package/src/workbench/components/GridTabContent.stories.tsx +59 -0
- package/src/workbench/components/GridTabContent.tsx +193 -0
- package/src/workbench/components/ProjectTreeView.stories.tsx +25 -0
- package/src/workbench/components/ProjectTreeView.test.tsx +236 -0
- package/src/workbench/components/ProjectTreeView.tsx +151 -0
- package/src/workbench/components/TreePane.stories.tsx +106 -0
- package/src/workbench/components/TreePane.tsx +155 -0
- package/src/workbench/components/WelcomePlayground.stories.tsx +12 -0
- package/src/workbench/components/WelcomePlayground.test.tsx +83 -0
- package/src/workbench/components/WelcomePlayground.tsx +138 -0
- package/src/workbench/components/editor-grid.test.ts +184 -0
- package/src/workbench/components/editor-grid.ts +281 -0
- package/src/workbench/components/file-tree.test.ts +60 -0
- package/src/workbench/components/file-tree.ts +112 -0
- package/src/workbench/use-changes-workbench.ts +205 -0
- package/src/workbench/use-remember-layout.ts +31 -0
- package/src/workbench/use-repo-changes.ts +91 -0
- package/src/workbench/workbench-snapshot.test.ts +99 -0
- package/src/workbench/workbench-snapshot.ts +59 -0
- package/src/App.diff.test.tsx +0 -99
- package/src/App.export.test.tsx +0 -88
- package/src/App.plan-review.test.tsx +0 -259
- package/src/App.readonly.test.tsx +0 -148
- package/src/App.rendering.test.tsx +0 -108
- package/src/App.submit-confirm.test.tsx +0 -183
- package/src/App.test.tsx +0 -218
- package/src/App.tsx +0 -1249
- package/src/config.test.ts +0 -116
- package/src/config.ts +0 -150
- package/src/editor.ts +0 -34
- package/src/herdr.test.ts +0 -68
- package/src/herdr.ts +0 -34
- package/src/keymap.test.ts +0 -270
- package/src/keymap.ts +0 -173
- package/src/run.ts +0 -30
- package/src/serve.ts +0 -75
- package/src/session-controller.ts +0 -398
- package/src/syntax.test.ts +0 -41
- package/src/syntax.ts +0 -88
- package/src/theme.ts +0 -46
- package/src/view-diff.test.ts +0 -55
- package/src/view-diff.ts +0 -86
- package/src/view.test.ts +0 -157
- package/src/view.ts +0 -364
|
@@ -0,0 +1,687 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The intent reducer: one effectful handler per keymap Intent, lifted out of
|
|
3
|
+
* the App component so the 30-case grammar can be read and tested on its own.
|
|
4
|
+
* keymap.ts turns keys into Intents (pure); this turns an Intent into the
|
|
5
|
+
* matching controller call or view-state update. App builds the dependency
|
|
6
|
+
* bag once per render and hands it here; nothing in this module reaches back
|
|
7
|
+
* into React beyond the setters it is given.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Dispatch, MutableRefObject, SetStateAction } from "react";
|
|
11
|
+
import { isAddressed, MESSAGE_OUTCOMES, type Thread, type MessageOutcome } from "@cueloop/schema";
|
|
12
|
+
import {
|
|
13
|
+
displayText,
|
|
14
|
+
spanKey,
|
|
15
|
+
startSpan,
|
|
16
|
+
type DisplayBlock,
|
|
17
|
+
type SpanState,
|
|
18
|
+
} from "../markdown/view-plan";
|
|
19
|
+
import type { DiffRow } from "../diff/view-diff";
|
|
20
|
+
import type { ReviewController } from "../thread/thread-controller";
|
|
21
|
+
import type { Intent } from "../keyboard/keymap";
|
|
22
|
+
import type { TreeRow } from "../thread/tree-view";
|
|
23
|
+
import { quickActionBody, type QuickAction } from "../settings/config";
|
|
24
|
+
|
|
25
|
+
/** Which pane of the session tree / review the keyboard grammar is aimed at. */
|
|
26
|
+
export type RailTab = "review" | "tree";
|
|
27
|
+
|
|
28
|
+
/** The one overlay/mode the TUI is in; every compose/submit/edit flow is a variant. */
|
|
29
|
+
export type Mode =
|
|
30
|
+
| { type: "normal" }
|
|
31
|
+
| { type: "span"; span: SpanState }
|
|
32
|
+
| { type: "spanActions"; span: SpanState; index: number }
|
|
33
|
+
| {
|
|
34
|
+
type: "compose";
|
|
35
|
+
kind: "comment";
|
|
36
|
+
displayIndex: number;
|
|
37
|
+
start: number;
|
|
38
|
+
end: number;
|
|
39
|
+
text: string;
|
|
40
|
+
}
|
|
41
|
+
| { type: "railEdit"; id: string; text: string }
|
|
42
|
+
| { type: "submit"; message: MessageOutcome; summary: string }
|
|
43
|
+
| { type: "confirmDelete"; sessionId: string; title: string }
|
|
44
|
+
| { type: "rename"; authorId: string; text: string }
|
|
45
|
+
| { type: "renameThread"; sessionId: string; text: string }
|
|
46
|
+
| { type: "nameSelf"; text: string }
|
|
47
|
+
| { type: "renameSelf"; text: string }
|
|
48
|
+
| { type: "treePrompt"; ask: TreeAsk; entryId?: string; text: string };
|
|
49
|
+
|
|
50
|
+
/** What a tree prompt asks for: a branch name, a checkpoint name, or the summary a move back leaves. */
|
|
51
|
+
export type TreeAsk = "branch" | "label" | "navigate";
|
|
52
|
+
|
|
53
|
+
/** The marked span for span mode and its quick-actions sub-mode; null otherwise. */
|
|
54
|
+
export function activeSpanState(mode: Mode): SpanState | null {
|
|
55
|
+
return mode.type === "span" || mode.type === "spanActions" ? mode.span : null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Everything the reducer reads or writes, supplied fresh each render: the
|
|
60
|
+
* controller and exit hook, the derived reads (view rows, cursor, mode,
|
|
61
|
+
* session), the refs it pokes, the state setters, and the three App-owned
|
|
62
|
+
* selection helpers it composes.
|
|
63
|
+
*/
|
|
64
|
+
export interface IntentDispatchDeps {
|
|
65
|
+
controller: ReviewController;
|
|
66
|
+
onExit?: (code: number) => void;
|
|
67
|
+
|
|
68
|
+
isDiff: boolean;
|
|
69
|
+
display: DisplayBlock[];
|
|
70
|
+
rows: DiffRow[];
|
|
71
|
+
cursor: number;
|
|
72
|
+
inbox: Thread[] | null;
|
|
73
|
+
inboxCursor: number;
|
|
74
|
+
mode: Mode;
|
|
75
|
+
session: Thread | null;
|
|
76
|
+
defaultMessage: MessageOutcome;
|
|
77
|
+
focusedAnnotationId: string | undefined;
|
|
78
|
+
selectedCurationId: string | undefined;
|
|
79
|
+
railTab: RailTab;
|
|
80
|
+
selectedEntryId: string | undefined;
|
|
81
|
+
authorNames: Record<string, string>;
|
|
82
|
+
quickActions: QuickAction[];
|
|
83
|
+
renameAuthor: (id: string, name: string) => void;
|
|
84
|
+
renameThread: (id: string, title: string) => void;
|
|
85
|
+
setLocalIdentityName: (name: string) => void;
|
|
86
|
+
|
|
87
|
+
liveInput: MutableRefObject<string>;
|
|
88
|
+
|
|
89
|
+
setCursor: Dispatch<SetStateAction<number>>;
|
|
90
|
+
setInboxCursor: Dispatch<SetStateAction<number>>;
|
|
91
|
+
setMode: Dispatch<SetStateAction<Mode>>;
|
|
92
|
+
setRailTab: Dispatch<SetStateAction<RailTab>>;
|
|
93
|
+
setSelectedEntryId: Dispatch<SetStateAction<string | undefined>>;
|
|
94
|
+
setFocusedAnnotationId: Dispatch<SetStateAction<string | undefined>>;
|
|
95
|
+
setSelectedCurationId: Dispatch<SetStateAction<string | undefined>>;
|
|
96
|
+
setPulsedAnnotationId: Dispatch<SetStateAction<string | null>>;
|
|
97
|
+
|
|
98
|
+
selectCardFromDocument: (annotationId: string) => void;
|
|
99
|
+
openBodyEditor: () => void;
|
|
100
|
+
openCardEdit: (annotationId: string) => void;
|
|
101
|
+
toggleDiffView: () => void;
|
|
102
|
+
openShareDialog: () => void;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
type IntentOfType<Kind extends Intent["type"]> = Extract<Intent, { type: Kind }>;
|
|
106
|
+
|
|
107
|
+
function handleExit(_intent: IntentOfType<"exit">, deps: IntentDispatchDeps): void {
|
|
108
|
+
deps.onExit?.(0);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function handleStatus(intent: IntentOfType<"status">, deps: IntentDispatchDeps): void {
|
|
112
|
+
deps.controller.setStatus(intent.message);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** A diff cursor rests on code lines only; file and hunk headers are structural dividers. */
|
|
116
|
+
function isCodeRow(row: DiffRow | undefined): boolean {
|
|
117
|
+
return row?.kind === "ctx" || row?.kind === "add" || row?.kind === "del";
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* A landable diff row: any code line, plus a collapsed file's band (a file row with
|
|
122
|
+
* no body before the next file or the end) so the cursor can reach it to expand it.
|
|
123
|
+
*/
|
|
124
|
+
function isLandableRow(rows: DiffRow[], index: number): boolean {
|
|
125
|
+
const row = rows[index];
|
|
126
|
+
|
|
127
|
+
if (isCodeRow(row)) return true;
|
|
128
|
+
if (row?.kind !== "file") return false;
|
|
129
|
+
const next = rows[index + 1];
|
|
130
|
+
|
|
131
|
+
return next === undefined || next.kind === "file";
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The next landable index in the move direction, skipping expanded headers; stays put at an edge. */
|
|
135
|
+
function nextCodeRowIndex(rows: DiffRow[], from: number, to: IntentOfType<"move">["to"]): number {
|
|
136
|
+
if (to === "top") {
|
|
137
|
+
for (let index = 0; index < rows.length; index++) if (isLandableRow(rows, index)) return index;
|
|
138
|
+
|
|
139
|
+
return from;
|
|
140
|
+
}
|
|
141
|
+
if (to === "bottom") {
|
|
142
|
+
for (let index = rows.length - 1; index >= 0; index--) {
|
|
143
|
+
if (isLandableRow(rows, index)) return index;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return from;
|
|
147
|
+
}
|
|
148
|
+
const step = to === "down" ? 1 : -1;
|
|
149
|
+
|
|
150
|
+
for (let index = from + step; index >= 0 && index < rows.length; index += step) {
|
|
151
|
+
if (isLandableRow(rows, index)) return index;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return from;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function handleMove(intent: IntentOfType<"move">, deps: IntentDispatchDeps): void {
|
|
158
|
+
if (deps.isDiff) {
|
|
159
|
+
deps.setCursor((current) => nextCodeRowIndex(deps.rows, current, intent.to));
|
|
160
|
+
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const navigableCount = deps.display.length;
|
|
164
|
+
|
|
165
|
+
if (intent.to === "down") deps.setCursor((current) => Math.min(navigableCount - 1, current + 1));
|
|
166
|
+
else if (intent.to === "up") deps.setCursor((current) => Math.max(0, current - 1));
|
|
167
|
+
else if (intent.to === "top") deps.setCursor(0);
|
|
168
|
+
else deps.setCursor(navigableCount - 1);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function handleInboxMove(intent: IntentOfType<"inboxMove">, deps: IntentDispatchDeps): void {
|
|
172
|
+
const navigableCount = deps.inbox?.length ?? 0;
|
|
173
|
+
|
|
174
|
+
deps.setInboxCursor((current) =>
|
|
175
|
+
intent.to === "down" ? Math.min(navigableCount - 1, current + 1) : Math.max(0, current - 1),
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function handleOpenSession(_intent: IntentOfType<"openSession">, deps: IntentDispatchDeps): void {
|
|
180
|
+
const selected = deps.inbox?.[deps.inboxCursor];
|
|
181
|
+
|
|
182
|
+
if (selected) deps.controller.open(selected.id);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function handleRequestDeleteSession(
|
|
186
|
+
_intent: IntentOfType<"requestDeleteSession">,
|
|
187
|
+
deps: IntentDispatchDeps,
|
|
188
|
+
): void {
|
|
189
|
+
const selected = deps.inbox?.[deps.inboxCursor];
|
|
190
|
+
|
|
191
|
+
if (selected)
|
|
192
|
+
deps.setMode({
|
|
193
|
+
type: "confirmDelete",
|
|
194
|
+
sessionId: selected.id,
|
|
195
|
+
title: selected.artifact.meta.title ?? selected.id,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function handleOpenRename(_intent: IntentOfType<"openRename">, deps: IntentDispatchDeps): void {
|
|
200
|
+
const focused = deps.session?.annotations.find(
|
|
201
|
+
(annotation) => annotation.id === deps.focusedAnnotationId,
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
if (!focused?.author) {
|
|
205
|
+
deps.controller.setStatus("that is your own note - nothing to rename");
|
|
206
|
+
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
deps.setMode({
|
|
210
|
+
type: "rename",
|
|
211
|
+
authorId: focused.author,
|
|
212
|
+
text: deps.authorNames[focused.author] ?? "",
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function handleConfirmDialog(
|
|
217
|
+
_intent: IntentOfType<"confirmDialog">,
|
|
218
|
+
deps: IntentDispatchDeps,
|
|
219
|
+
): void {
|
|
220
|
+
const { mode, controller } = deps;
|
|
221
|
+
|
|
222
|
+
if (mode.type === "confirmDelete") controller.deleteSession(mode.sessionId);
|
|
223
|
+
else if (mode.type === "rename") deps.renameAuthor(mode.authorId, mode.text.trim());
|
|
224
|
+
else if (mode.type === "renameThread") deps.renameThread(mode.sessionId, mode.text.trim());
|
|
225
|
+
else if (mode.type === "nameSelf") controller.setSelfName(mode.text.trim());
|
|
226
|
+
else if (mode.type === "renameSelf") deps.setLocalIdentityName(mode.text.trim());
|
|
227
|
+
else if (mode.type === "treePrompt") confirmTreePrompt(mode, deps);
|
|
228
|
+
deps.setMode({ type: "normal" });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function handleStartSpan(_intent: IntentOfType<"startSpan">, deps: IntentDispatchDeps): void {
|
|
232
|
+
const block = deps.display[deps.cursor];
|
|
233
|
+
|
|
234
|
+
if (!block?.work) return;
|
|
235
|
+
const span = startSpan(deps.cursor, displayText(block));
|
|
236
|
+
|
|
237
|
+
if (span) deps.setMode({ type: "span", span });
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function handleSpanKey(intent: IntentOfType<"spanKey">, deps: IntentDispatchDeps): void {
|
|
241
|
+
const { mode } = deps;
|
|
242
|
+
|
|
243
|
+
if (mode.type === "span") {
|
|
244
|
+
const span = spanKey(
|
|
245
|
+
mode.span,
|
|
246
|
+
intent.name,
|
|
247
|
+
displayText(deps.display[mode.span.displayIndex]!),
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
deps.setMode({ type: "span", span });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function handleSpanCut(_intent: IntentOfType<"spanCut">, deps: IntentDispatchDeps): void {
|
|
255
|
+
const { mode } = deps;
|
|
256
|
+
|
|
257
|
+
if (mode.type === "span") {
|
|
258
|
+
deps.controller.cut(mode.span.displayIndex, mode.span.start, mode.span.end);
|
|
259
|
+
deps.setMode({ type: "normal" });
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function handleOpenSpanActions(
|
|
264
|
+
_intent: IntentOfType<"openSpanActions">,
|
|
265
|
+
deps: IntentDispatchDeps,
|
|
266
|
+
): void {
|
|
267
|
+
const { mode } = deps;
|
|
268
|
+
|
|
269
|
+
if (mode.type === "span") deps.setMode({ type: "spanActions", span: mode.span, index: 0 });
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function handleMoveSpanAction(
|
|
273
|
+
intent: IntentOfType<"moveSpanAction">,
|
|
274
|
+
deps: IntentDispatchDeps,
|
|
275
|
+
): void {
|
|
276
|
+
const { mode } = deps;
|
|
277
|
+
|
|
278
|
+
if (mode.type === "spanActions") {
|
|
279
|
+
const index = Math.max(
|
|
280
|
+
0,
|
|
281
|
+
Math.min(deps.quickActions.length - 1, mode.index + intent.direction),
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
deps.setMode({ ...mode, index });
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function handleCloseSpanActions(
|
|
289
|
+
_intent: IntentOfType<"closeSpanActions">,
|
|
290
|
+
deps: IntentDispatchDeps,
|
|
291
|
+
): void {
|
|
292
|
+
const { mode } = deps;
|
|
293
|
+
|
|
294
|
+
if (mode.type === "spanActions") deps.setMode({ type: "span", span: mode.span });
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function handlePickSpanAction(
|
|
298
|
+
intent: IntentOfType<"pickSpanAction">,
|
|
299
|
+
deps: IntentDispatchDeps,
|
|
300
|
+
): void {
|
|
301
|
+
const { mode, session, controller } = deps;
|
|
302
|
+
|
|
303
|
+
if (mode.type !== "spanActions") return;
|
|
304
|
+
const action = deps.quickActions[intent.index ?? mode.index];
|
|
305
|
+
|
|
306
|
+
if (session && action) {
|
|
307
|
+
const body = quickActionBody(action);
|
|
308
|
+
const annotationId = controller.annotate(
|
|
309
|
+
"comment",
|
|
310
|
+
mode.span.displayIndex,
|
|
311
|
+
mode.span.start,
|
|
312
|
+
mode.span.end,
|
|
313
|
+
body,
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
if (annotationId) deps.setFocusedAnnotationId(annotationId);
|
|
317
|
+
}
|
|
318
|
+
deps.setMode({ type: "normal" });
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function handleOpenCompose(intent: IntentOfType<"openCompose">, deps: IntentDispatchDeps): void {
|
|
322
|
+
const { mode } = deps;
|
|
323
|
+
|
|
324
|
+
deps.liveInput.current = "";
|
|
325
|
+
if (intent.from === "span" && mode.type === "span") {
|
|
326
|
+
deps.setMode({
|
|
327
|
+
type: "compose",
|
|
328
|
+
kind: intent.kind,
|
|
329
|
+
displayIndex: mode.span.displayIndex,
|
|
330
|
+
start: mode.span.start,
|
|
331
|
+
end: mode.span.end,
|
|
332
|
+
text: "",
|
|
333
|
+
});
|
|
334
|
+
} else if (deps.isDiff) {
|
|
335
|
+
const row = deps.rows[deps.cursor];
|
|
336
|
+
|
|
337
|
+
if (row)
|
|
338
|
+
deps.setMode({
|
|
339
|
+
type: "compose",
|
|
340
|
+
kind: intent.kind,
|
|
341
|
+
displayIndex: deps.cursor,
|
|
342
|
+
start: 0,
|
|
343
|
+
end: row.text.length,
|
|
344
|
+
text: "",
|
|
345
|
+
});
|
|
346
|
+
} else {
|
|
347
|
+
const block = deps.display[deps.cursor];
|
|
348
|
+
|
|
349
|
+
if (block)
|
|
350
|
+
deps.setMode({
|
|
351
|
+
type: "compose",
|
|
352
|
+
kind: intent.kind,
|
|
353
|
+
displayIndex: deps.cursor,
|
|
354
|
+
start: 0,
|
|
355
|
+
end: displayText(block).length,
|
|
356
|
+
text: "",
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function handleOpenSubmit(_intent: IntentOfType<"openSubmit">, deps: IntentDispatchDeps): void {
|
|
362
|
+
const { session } = deps;
|
|
363
|
+
|
|
364
|
+
if (!session) return;
|
|
365
|
+
deps.liveInput.current = "";
|
|
366
|
+
deps.setMode({ type: "submit", message: deps.defaultMessage, summary: "" });
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// share opens the share dialog; it owns its own keys, links list, and publish wizard
|
|
370
|
+
function handleShare(_intent: IntentOfType<"share">, deps: IntentDispatchDeps): void {
|
|
371
|
+
deps.openShareDialog();
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function handleCut(_intent: IntentOfType<"cut">, deps: IntentDispatchDeps): void {
|
|
375
|
+
deps.controller.cut(deps.cursor);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function handleRejectHunk(_intent: IntentOfType<"rejectHunk">, deps: IntentDispatchDeps): void {
|
|
379
|
+
deps.controller.toggleRejectHunk(deps.cursor);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function handleRejectChange(_intent: IntentOfType<"rejectChange">, deps: IntentDispatchDeps): void {
|
|
383
|
+
deps.controller.toggleRejectChange(deps.cursor);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function handleFoldFile(_intent: IntentOfType<"foldFile">, deps: IntentDispatchDeps): void {
|
|
387
|
+
const file = deps.rows[deps.cursor]?.file;
|
|
388
|
+
|
|
389
|
+
if (!file || deps.controller.isFileCollapsed(file)) return;
|
|
390
|
+
deps.controller.setFileCollapsed(file, true);
|
|
391
|
+
// the file band is unchanged in index by its own collapse, so land the cursor on it
|
|
392
|
+
const headerIndex = deps.controller
|
|
393
|
+
.rows()
|
|
394
|
+
.findIndex((row) => row.kind === "file" && row.file === file);
|
|
395
|
+
|
|
396
|
+
if (headerIndex >= 0) deps.setCursor(headerIndex);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function handleUnfoldFile(_intent: IntentOfType<"unfoldFile">, deps: IntentDispatchDeps): void {
|
|
400
|
+
const file = deps.rows[deps.cursor]?.file;
|
|
401
|
+
|
|
402
|
+
if (!file || !deps.controller.isFileCollapsed(file)) return;
|
|
403
|
+
deps.controller.setFileCollapsed(file, false);
|
|
404
|
+
// drop the cursor onto the file's first code line now that its body is back
|
|
405
|
+
const firstCode = deps.controller.rows().findIndex((row) => row.file === file && isCodeRow(row));
|
|
406
|
+
|
|
407
|
+
if (firstCode >= 0) deps.setCursor(firstCode);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function handleToggleDiffView(
|
|
411
|
+
_intent: IntentOfType<"toggleDiffView">,
|
|
412
|
+
deps: IntentDispatchDeps,
|
|
413
|
+
): void {
|
|
414
|
+
deps.toggleDiffView();
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function handleRestoreCuration(
|
|
418
|
+
_intent: IntentOfType<"restoreCuration">,
|
|
419
|
+
deps: IntentDispatchDeps,
|
|
420
|
+
): void {
|
|
421
|
+
// undo the selected curated-out item, or the last rejected when none is
|
|
422
|
+
// selected, so a bare `u` reads as "undo my last curation"
|
|
423
|
+
const items = deps.controller.curationItems();
|
|
424
|
+
|
|
425
|
+
if (!items.length) return;
|
|
426
|
+
const targetId = deps.selectedCurationId ?? items[items.length - 1]!.id;
|
|
427
|
+
|
|
428
|
+
deps.controller.restoreCuration(targetId);
|
|
429
|
+
deps.setSelectedCurationId(undefined);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function handleEdit(_intent: IntentOfType<"edit">, deps: IntentDispatchDeps): void {
|
|
433
|
+
deps.openBodyEditor();
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function handleEditCard(_intent: IntentOfType<"editCard">, deps: IntentDispatchDeps): void {
|
|
437
|
+
if (deps.focusedAnnotationId) deps.openCardEdit(deps.focusedAnnotationId);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function handleAnnotationCycle(
|
|
441
|
+
intent: IntentOfType<"nextAnnotation" | "prevAnnotation">,
|
|
442
|
+
deps: IntentDispatchDeps,
|
|
443
|
+
): void {
|
|
444
|
+
// cycle open cards only - addressed ones are out of the rail
|
|
445
|
+
const annotations = (deps.session?.annotations ?? []).filter(
|
|
446
|
+
(annotation) => !isAddressed(annotation),
|
|
447
|
+
);
|
|
448
|
+
|
|
449
|
+
if (!annotations.length) return;
|
|
450
|
+
const focusedIndex = annotations.findIndex(
|
|
451
|
+
(annotation) => annotation.id === deps.focusedAnnotationId,
|
|
452
|
+
);
|
|
453
|
+
const nextIndex =
|
|
454
|
+
focusedIndex === -1
|
|
455
|
+
? 0
|
|
456
|
+
: (focusedIndex + (intent.type === "nextAnnotation" ? 1 : -1) + annotations.length) %
|
|
457
|
+
annotations.length;
|
|
458
|
+
|
|
459
|
+
deps.selectCardFromDocument(annotations[nextIndex]!.id);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function handleWalkStart(_intent: IntentOfType<"walkStart">, deps: IntentDispatchDeps): void {
|
|
463
|
+
deps.controller.walkStart();
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function handleWalkForward(_intent: IntentOfType<"walkForward">, deps: IntentDispatchDeps): void {
|
|
467
|
+
deps.controller.walkForward();
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function handleWalkBack(_intent: IntentOfType<"walkBack">, deps: IntentDispatchDeps): void {
|
|
471
|
+
deps.controller.walkBack();
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function handleWalkLeave(_intent: IntentOfType<"walkLeave">, deps: IntentDispatchDeps): void {
|
|
475
|
+
deps.controller.walkLeave();
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function handleRemoveAnnotation(
|
|
479
|
+
_intent: IntentOfType<"removeAnnotation">,
|
|
480
|
+
deps: IntentDispatchDeps,
|
|
481
|
+
): void {
|
|
482
|
+
if (deps.focusedAnnotationId) {
|
|
483
|
+
deps.controller.removeAnnotation(deps.focusedAnnotationId);
|
|
484
|
+
deps.setFocusedAnnotationId(undefined);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function handleDeselect(_intent: IntentOfType<"deselect">, deps: IntentDispatchDeps): void {
|
|
489
|
+
deps.setFocusedAnnotationId(undefined);
|
|
490
|
+
deps.setPulsedAnnotationId(null);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function handleCloseOverlay(_intent: IntentOfType<"closeOverlay">, deps: IntentDispatchDeps): void {
|
|
494
|
+
deps.setMode({ type: "normal" });
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function handleSaveCompose(_intent: IntentOfType<"saveCompose">, deps: IntentDispatchDeps): void {
|
|
498
|
+
const { mode, session, controller } = deps;
|
|
499
|
+
const body = deps.liveInput.current.trim();
|
|
500
|
+
|
|
501
|
+
if (mode.type === "railEdit") {
|
|
502
|
+
if (session && body) controller.updateAnnotation(mode.id, body);
|
|
503
|
+
deps.setMode({ type: "normal" });
|
|
504
|
+
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
if (mode.type !== "compose") return;
|
|
508
|
+
if (session && body) {
|
|
509
|
+
const annotationId = controller.annotate(
|
|
510
|
+
mode.kind,
|
|
511
|
+
mode.displayIndex,
|
|
512
|
+
mode.start,
|
|
513
|
+
mode.end,
|
|
514
|
+
body,
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
if (annotationId) deps.setFocusedAnnotationId(annotationId);
|
|
518
|
+
}
|
|
519
|
+
deps.setMode({ type: "normal" });
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function handleSubmitMessage(
|
|
523
|
+
_intent: IntentOfType<"submitMessage">,
|
|
524
|
+
deps: IntentDispatchDeps,
|
|
525
|
+
): void {
|
|
526
|
+
const { mode } = deps;
|
|
527
|
+
|
|
528
|
+
if (mode.type === "submit") deps.controller.submit(mode.message, deps.liveInput.current);
|
|
529
|
+
deps.setMode({ type: "normal" });
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function handleCycleMessage(intent: IntentOfType<"cycleMessage">, deps: IntentDispatchDeps): void {
|
|
533
|
+
const { mode } = deps;
|
|
534
|
+
|
|
535
|
+
if (mode.type !== "submit") return;
|
|
536
|
+
const messageIndex =
|
|
537
|
+
(MESSAGE_OUTCOMES.indexOf(mode.message) + intent.direction + MESSAGE_OUTCOMES.length) %
|
|
538
|
+
MESSAGE_OUTCOMES.length;
|
|
539
|
+
|
|
540
|
+
deps.setMode({ ...mode, message: MESSAGE_OUTCOMES[messageIndex]! });
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function handleFinishReview(_intent: IntentOfType<"finishReview">, deps: IntentDispatchDeps): void {
|
|
544
|
+
deps.controller.finishReview();
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function handleOptInAutoClose(
|
|
548
|
+
_intent: IntentOfType<"optInAutoClose">,
|
|
549
|
+
deps: IntentDispatchDeps,
|
|
550
|
+
): void {
|
|
551
|
+
deps.controller.optInAutoClose();
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function handleDismissCompletion(
|
|
555
|
+
_intent: IntentOfType<"dismissCompletion">,
|
|
556
|
+
deps: IntentDispatchDeps,
|
|
557
|
+
): void {
|
|
558
|
+
deps.controller.dismissCompletion();
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function confirmTreePrompt(
|
|
562
|
+
mode: Extract<Mode, { type: "treePrompt" }>,
|
|
563
|
+
deps: IntentDispatchDeps,
|
|
564
|
+
): void {
|
|
565
|
+
if (mode.ask === "branch") deps.controller.branch(mode.text);
|
|
566
|
+
else if (mode.ask === "label") deps.controller.labelTip(mode.text);
|
|
567
|
+
else if (mode.entryId !== undefined) deps.controller.goToEntry(mode.entryId, mode.text.trim());
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function handleToggleTree(_intent: IntentOfType<"toggleTree">, deps: IntentDispatchDeps): void {
|
|
571
|
+
deps.setRailTab(deps.railTab === "tree" ? "review" : "tree");
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/** The tree rows in drawing order; the selection falls back to the current tip. */
|
|
575
|
+
function selectedTreeIndex(deps: IntentDispatchDeps, rows: TreeRow[]): number {
|
|
576
|
+
const byId = rows.findIndex((row) => row.entryId === deps.selectedEntryId);
|
|
577
|
+
|
|
578
|
+
return byId === -1 ? rows.findIndex((row) => row.isCurrentTip) : byId;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function handleTreeMove(intent: IntentOfType<"treeMove">, deps: IntentDispatchDeps): void {
|
|
582
|
+
const rows = deps.controller.treeRows();
|
|
583
|
+
|
|
584
|
+
if (rows.length === 0) return;
|
|
585
|
+
const current = selectedTreeIndex(deps, rows);
|
|
586
|
+
const next = Math.min(rows.length - 1, Math.max(0, current + intent.direction));
|
|
587
|
+
|
|
588
|
+
deps.setSelectedEntryId(rows[next]!.entryId);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
function handleTreeGo(_intent: IntentOfType<"treeGo">, deps: IntentDispatchDeps): void {
|
|
592
|
+
const rows = deps.controller.treeRows();
|
|
593
|
+
const row = rows[selectedTreeIndex(deps, rows)];
|
|
594
|
+
|
|
595
|
+
if (!row) return deps.controller.setStatus("select an entry in the tree first");
|
|
596
|
+
if (row.isCurrentTip) return deps.controller.setStatus("already at the tip");
|
|
597
|
+
// a switch needs no summary; a move back may leave one, so it asks
|
|
598
|
+
if (row.tips.length > 0) return deps.controller.goToEntry(row.entryId);
|
|
599
|
+
deps.setMode({ type: "treePrompt", ask: "navigate", entryId: row.entryId, text: "" });
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function handleTreeBranch(_intent: IntentOfType<"treeBranch">, deps: IntentDispatchDeps): void {
|
|
603
|
+
deps.setMode({ type: "treePrompt", ask: "branch", text: "" });
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function handleTreeLabel(_intent: IntentOfType<"treeLabel">, deps: IntentDispatchDeps): void {
|
|
607
|
+
deps.setMode({ type: "treePrompt", ask: "label", text: "" });
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
function handleTreeFork(_intent: IntentOfType<"treeFork">, deps: IntentDispatchDeps): void {
|
|
611
|
+
deps.controller.fork();
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function handleTreeForkShare(
|
|
615
|
+
_intent: IntentOfType<"treeForkShare">,
|
|
616
|
+
deps: IntentDispatchDeps,
|
|
617
|
+
): void {
|
|
618
|
+
deps.controller.forkAndShare();
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
type IntentHandlers = {
|
|
622
|
+
[Kind in Intent["type"]]: (intent: IntentOfType<Kind>, deps: IntentDispatchDeps) => void;
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
const intentHandlers: IntentHandlers = {
|
|
626
|
+
exit: handleExit,
|
|
627
|
+
status: handleStatus,
|
|
628
|
+
move: handleMove,
|
|
629
|
+
inboxMove: handleInboxMove,
|
|
630
|
+
openSession: handleOpenSession,
|
|
631
|
+
requestDeleteSession: handleRequestDeleteSession,
|
|
632
|
+
openRename: handleOpenRename,
|
|
633
|
+
confirmDialog: handleConfirmDialog,
|
|
634
|
+
startSpan: handleStartSpan,
|
|
635
|
+
spanKey: handleSpanKey,
|
|
636
|
+
spanCut: handleSpanCut,
|
|
637
|
+
openSpanActions: handleOpenSpanActions,
|
|
638
|
+
moveSpanAction: handleMoveSpanAction,
|
|
639
|
+
closeSpanActions: handleCloseSpanActions,
|
|
640
|
+
pickSpanAction: handlePickSpanAction,
|
|
641
|
+
openCompose: handleOpenCompose,
|
|
642
|
+
openSubmit: handleOpenSubmit,
|
|
643
|
+
share: handleShare,
|
|
644
|
+
cut: handleCut,
|
|
645
|
+
rejectHunk: handleRejectHunk,
|
|
646
|
+
rejectChange: handleRejectChange,
|
|
647
|
+
foldFile: handleFoldFile,
|
|
648
|
+
unfoldFile: handleUnfoldFile,
|
|
649
|
+
toggleDiffView: handleToggleDiffView,
|
|
650
|
+
restoreCuration: handleRestoreCuration,
|
|
651
|
+
edit: handleEdit,
|
|
652
|
+
editCard: handleEditCard,
|
|
653
|
+
nextAnnotation: handleAnnotationCycle,
|
|
654
|
+
prevAnnotation: handleAnnotationCycle,
|
|
655
|
+
walkStart: handleWalkStart,
|
|
656
|
+
walkForward: handleWalkForward,
|
|
657
|
+
walkBack: handleWalkBack,
|
|
658
|
+
walkLeave: handleWalkLeave,
|
|
659
|
+
removeAnnotation: handleRemoveAnnotation,
|
|
660
|
+
deselect: handleDeselect,
|
|
661
|
+
closeOverlay: handleCloseOverlay,
|
|
662
|
+
saveCompose: handleSaveCompose,
|
|
663
|
+
submitMessage: handleSubmitMessage,
|
|
664
|
+
cycleMessage: handleCycleMessage,
|
|
665
|
+
finishReview: handleFinishReview,
|
|
666
|
+
optInAutoClose: handleOptInAutoClose,
|
|
667
|
+
dismissCompletion: handleDismissCompletion,
|
|
668
|
+
toggleTree: handleToggleTree,
|
|
669
|
+
treeMove: handleTreeMove,
|
|
670
|
+
treeGo: handleTreeGo,
|
|
671
|
+
treeBranch: handleTreeBranch,
|
|
672
|
+
treeLabel: handleTreeLabel,
|
|
673
|
+
treeFork: handleTreeFork,
|
|
674
|
+
treeForkShare: handleTreeForkShare,
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
function dispatchIntent<Kind extends Intent["type"]>(
|
|
678
|
+
intent: IntentOfType<Kind>,
|
|
679
|
+
deps: IntentDispatchDeps,
|
|
680
|
+
): void {
|
|
681
|
+
intentHandlers[intent.type](intent, deps);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/** Build the intent handler for one render from its dependency bag. */
|
|
685
|
+
export function createIntentDispatch(deps: IntentDispatchDeps): (intent: Intent) => void {
|
|
686
|
+
return (intent: Intent): void => dispatchIntent(intent, deps);
|
|
687
|
+
}
|