@cueloop/client 0.1.0-alpha.65 → 0.1.0-alpha.67
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/package.json +6 -5
- package/src/App.autoclose.test.tsx +2 -2
- package/src/App.diff.test.tsx +79 -112
- package/src/App.plan-review.test.tsx +23 -205
- package/src/App.prototype.test.tsx +1 -8
- package/src/App.readonly.test.tsx +9 -27
- package/src/App.submit-confirm.test.tsx +19 -72
- package/src/App.test.tsx +136 -31
- package/src/App.tsx +491 -322
- package/src/App.walk.test.tsx +15 -16
- package/src/App.workbench.test.tsx +390 -0
- package/src/__snapshots__/view-plan.regression.test.ts.snap +1 -1
- package/src/annotation-palette.ts +61 -0
- package/src/app-screens.tsx +197 -77
- package/src/app-view-model.ts +9 -69
- package/src/components/AnnotationCard.stories.tsx +1 -1
- package/src/components/AnnotationCard.tsx +1 -1
- package/src/components/AnnotationCards.stories.tsx +87 -0
- package/src/components/AnnotationCards.tsx +303 -0
- package/src/components/AppHeader.stories.tsx +50 -0
- package/src/components/AppHeader.tsx +83 -0
- package/src/components/AppShell.stories.tsx +89 -0
- package/src/components/AppShell.tsx +239 -0
- package/src/components/AppShell.zoom.test.tsx +94 -0
- package/src/components/Breadcrumb.stories.tsx +1 -1
- package/src/components/ChangesColumn.stories.tsx +39 -0
- package/src/components/ChangesColumn.tsx +170 -0
- package/src/components/CodeBlock.stories.tsx +1 -1
- package/src/components/CompletionOverlay.stories.tsx +1 -1
- package/src/components/ConfirmCard.stories.tsx +1 -1
- package/src/components/ConfirmCard.tsx +3 -4
- package/src/components/ConfirmDialog.stories.tsx +1 -1
- package/src/components/DiffSheet.scroll.test.tsx +38 -55
- package/src/components/DiffSheet.split.test.tsx +140 -0
- package/src/components/DiffSheet.stories.tsx +56 -54
- package/src/components/DiffSheet.syntax.test.tsx +24 -7
- package/src/components/DiffSheet.tsx +607 -276
- package/src/components/DiscussionMarkerRail.stories.tsx +54 -0
- package/src/components/DiscussionMarkerRail.tsx +181 -0
- package/src/components/EditorGrid.stories.tsx +59 -0
- package/src/components/EditorGrid.tabs.test.tsx +105 -0
- package/src/components/EditorGrid.tsx +338 -0
- package/src/components/EditorGrid.zoom.test.tsx +68 -0
- package/src/components/FileContentsView.stories.tsx +16 -0
- package/src/components/FileContentsView.test.tsx +29 -0
- package/src/components/FileContentsView.tsx +78 -0
- package/src/components/InboxList.stories.tsx +23 -8
- package/src/components/InboxList.tsx +188 -33
- package/src/components/KeybindsDialog.stories.tsx +1 -1
- package/src/components/MarkerPopover.stories.tsx +1 -1
- package/src/components/MenuBar.stories.tsx +3 -12
- package/src/components/MenuBar.tsx +25 -56
- package/src/components/PaneGrid.stories.tsx +84 -0
- package/src/components/PaneGrid.tsx +128 -0
- package/src/components/PanelColumn.stories.tsx +25 -0
- package/src/components/PanelColumn.tsx +95 -0
- package/src/components/ProjectTreeView.stories.tsx +25 -0
- package/src/components/ProjectTreeView.test.tsx +32 -0
- package/src/components/ProjectTreeView.tsx +82 -0
- package/src/components/PromptDialog.stories.tsx +1 -1
- package/src/components/PromptDialog.tsx +8 -1
- package/src/components/PrototypeSheet.stories.tsx +1 -1
- package/src/components/RootOverlay.stories.tsx +44 -0
- package/src/components/RootOverlay.tsx +35 -0
- package/src/components/SettingsDialog.stories.tsx +7 -1
- package/src/components/SettingsDialog.tsx +114 -67
- package/src/components/SettingsRows.stories.tsx +1 -1
- package/src/components/ShellHeader.stories.tsx +50 -0
- package/src/components/ShellHeader.tsx +137 -0
- package/src/components/SurfaceScrollbar.stories.tsx +34 -0
- package/src/components/SurfaceScrollbar.test.tsx +111 -0
- package/src/components/SurfaceScrollbar.tsx +93 -0
- package/src/components/ThreadFooter.stories.tsx +30 -0
- package/src/components/ThreadFooter.test.tsx +31 -0
- package/src/components/ThreadFooter.tsx +54 -0
- package/src/components/ThreadView.slash.test.tsx +113 -0
- package/src/components/ThreadView.stories.tsx +1 -1
- package/src/components/ThreadView.tsx +62 -1352
- package/src/components/ThreadsSidebar.stories.tsx +36 -0
- package/src/components/ThreadsSidebar.tsx +70 -0
- package/src/components/Toast.stories.tsx +1 -1
- package/src/components/Tooltip.stories.tsx +26 -0
- package/src/components/Tooltip.tsx +72 -0
- package/src/components/TreePane.stories.tsx +1 -1
- package/src/components/WalkWizard.stories.tsx +1 -1
- package/src/components/WelcomeSurface.stories.tsx +12 -0
- package/src/components/WelcomeSurface.tsx +52 -0
- package/src/components/__snapshots__/stories.test.tsx.snap +732 -572
- package/src/components/agent-launcher.stories.tsx +1 -1
- package/src/components/diff-sheet-layout.test.ts +125 -55
- package/src/components/diff-sheet-layout.ts +3 -103
- package/src/components/editor-grid.test.ts +86 -0
- package/src/components/editor-grid.ts +138 -0
- package/src/components/fade-title.test.ts +49 -0
- package/src/components/fade-title.ts +61 -0
- package/src/components/file-tree.test.ts +60 -0
- package/src/components/file-tree.ts +112 -0
- package/src/components/pages/Workspace.stories.tsx +181 -0
- package/src/components/primitives/Button.stories.tsx +1 -1
- package/src/components/primitives/Card.stories.tsx +1 -1
- package/src/components/primitives/Dialog.stories.tsx +1 -1
- package/src/components/primitives/IconButton.stories.tsx +36 -0
- package/src/components/primitives/IconButton.tsx +62 -0
- package/src/components/primitives/StatusBar.stories.tsx +1 -1
- package/src/components/primitives/Tabs.stories.tsx +1 -1
- package/src/components/primitives/Toolbar.stories.tsx +1 -1
- package/src/components/primitives/Tree.stories.tsx +124 -0
- package/src/components/primitives/Tree.tsx +96 -0
- package/src/components/primitives/icons.ts +61 -0
- package/src/components/primitives/tree-model.test.ts +99 -0
- package/src/components/primitives/tree-model.ts +137 -0
- package/src/components/quick-actions-editor.stories.tsx +1 -1
- package/src/components/session-tree.test.ts +134 -0
- package/src/components/session-tree.ts +108 -0
- package/src/components/stories-app.tsx +142 -82
- package/src/components/story-tree.test.ts +100 -0
- package/src/components/story.ts +55 -0
- package/src/components/theme-context.stories.tsx +1 -1
- package/src/config.test.ts +20 -49
- package/src/config.ts +26 -28
- package/src/diff-fold.test.ts +78 -0
- package/src/diff-fold.ts +126 -0
- package/src/diff-syntax.test.ts +16 -0
- package/src/diff-syntax.ts +6 -3
- package/src/discussions.ts +79 -0
- package/src/intent-dispatch.test.ts +31 -11
- package/src/intent-dispatch.ts +93 -48
- package/src/key-bindings.test.ts +1 -1
- package/src/keymap.test.ts +3 -25
- package/src/keymap.ts +17 -18
- package/src/mark-runs.ts +120 -0
- package/src/pty.ts +10 -2
- package/src/run.ts +17 -7
- package/src/serve.test.ts +4 -8
- package/src/session-controller.curate.test.ts +75 -0
- package/src/session-controller.share.test.ts +1 -0
- package/src/session-controller.tree.test.ts +26 -0
- package/src/session-controller.ts +160 -31
- package/src/slash-palette.ts +83 -0
- package/src/split-diff.test.ts +110 -0
- package/src/split-diff.ts +149 -0
- package/src/test-support.test.ts +3 -3
- package/src/test-support.ts +39 -8
- package/src/theme.ts +4 -4
- package/src/thread-chords.test.ts +25 -9
- package/src/thread-chords.ts +33 -8
- package/src/use-annotation-surface.tsx +837 -0
- package/src/use-changes-workbench.ts +151 -0
- package/src/use-frame-measure.ts +38 -0
- package/src/use-settings-dialog.tsx +23 -24
- package/src/use-terminal-virtualizer.ts +233 -0
- package/src/view-diff.ts +114 -0
- package/src/App.review-panel.test.tsx +0 -140
- package/src/App.tree.test.tsx +0 -224
- package/src/components/ReviewPanel.stories.tsx +0 -100
- package/src/components/ReviewPanel.tsx +0 -103
- package/src/components/ReviewRail.stories.tsx +0 -232
- package/src/components/ReviewRail.tsx +0 -327
- package/src/review-panel.test.ts +0 -113
- package/src/review-panel.ts +0 -83
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// The Changes/Project right-region state machine: the Project pane is the right sidebar and is always
|
|
2
|
+
// present when the region is on, the Changes editor rides on it and never stands alone, and the two
|
|
3
|
+
// toggles are mutually-exclusive file-tree modes. Owns the editor grid (tabs and splits) too.
|
|
4
|
+
|
|
5
|
+
import { useRef, useState } from "react";
|
|
6
|
+
import type { ProjectPanelMode } from "./components/AppShell";
|
|
7
|
+
import {
|
|
8
|
+
activateTab,
|
|
9
|
+
addTab,
|
|
10
|
+
changesTab,
|
|
11
|
+
closeTab,
|
|
12
|
+
containsGroup,
|
|
13
|
+
fileTab,
|
|
14
|
+
firstGroupId,
|
|
15
|
+
makeGroup,
|
|
16
|
+
splitGroup,
|
|
17
|
+
welcomeTab,
|
|
18
|
+
type EditorNode,
|
|
19
|
+
type SplitDirection,
|
|
20
|
+
} from "./components/editor-grid";
|
|
21
|
+
|
|
22
|
+
/** Seed the workbench for a bare launch: the region opens on a disposable Welcome tab. */
|
|
23
|
+
export interface ChangesWorkbenchOptions {
|
|
24
|
+
seed?: "changes" | "welcome";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ChangesWorkbench {
|
|
28
|
+
projectOpen: boolean;
|
|
29
|
+
changesOpen: boolean;
|
|
30
|
+
projectMode: ProjectPanelMode;
|
|
31
|
+
zoomed: boolean;
|
|
32
|
+
grid: EditorNode;
|
|
33
|
+
activeGroup: string;
|
|
34
|
+
toggleRight: () => void;
|
|
35
|
+
toggleChanges: () => void;
|
|
36
|
+
toggleProject: () => void;
|
|
37
|
+
toggleZoom: () => void;
|
|
38
|
+
focusGroup: (groupId: string) => void;
|
|
39
|
+
activate: (groupId: string, tabId: string) => void;
|
|
40
|
+
close: (groupId: string, tabId: string) => void;
|
|
41
|
+
split: (groupId: string, direction: SplitDirection) => void;
|
|
42
|
+
openFile: (path: string, fileView: "diff" | "contents") => void;
|
|
43
|
+
/** Re-open defaults when the session changes: a diff opens the region in changed-files mode. */
|
|
44
|
+
syncSession: (sessionId: string | undefined, isDiff: boolean) => void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function useChangesWorkbench(options?: ChangesWorkbenchOptions): ChangesWorkbench {
|
|
48
|
+
const welcomeSeed = options?.seed === "welcome";
|
|
49
|
+
const [projectOpen, setProjectOpen] = useState(welcomeSeed);
|
|
50
|
+
const [changesOpen, setChangesOpen] = useState(welcomeSeed);
|
|
51
|
+
const [projectMode, setProjectMode] = useState<ProjectPanelMode>("changes");
|
|
52
|
+
const [zoomed, setZoomed] = useState(false);
|
|
53
|
+
const [grid, setGrid] = useState<EditorNode>(() =>
|
|
54
|
+
makeGroup([welcomeSeed ? welcomeTab() : changesTab()]),
|
|
55
|
+
);
|
|
56
|
+
const [focusedGroup, setFocusedGroup] = useState<string | null>(null);
|
|
57
|
+
const rememberedChanges = useRef(welcomeSeed);
|
|
58
|
+
const seenSession = useRef<string | undefined>(undefined);
|
|
59
|
+
|
|
60
|
+
const syncSession = (sessionId: string | undefined, isDiff: boolean): void => {
|
|
61
|
+
if (sessionId === undefined || sessionId === seenSession.current) return;
|
|
62
|
+
seenSession.current = sessionId;
|
|
63
|
+
setProjectOpen(isDiff);
|
|
64
|
+
setChangesOpen(isDiff);
|
|
65
|
+
setProjectMode(isDiff ? "changes" : "tree");
|
|
66
|
+
rememberedChanges.current = isDiff;
|
|
67
|
+
setGrid(makeGroup([changesTab()]));
|
|
68
|
+
setFocusedGroup(null);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const toggleRight = (): void => {
|
|
72
|
+
if (projectOpen) {
|
|
73
|
+
rememberedChanges.current = changesOpen;
|
|
74
|
+
setChangesOpen(false);
|
|
75
|
+
setProjectOpen(false);
|
|
76
|
+
// zoom focuses the Changes editor; collapsing the region returns the Thread pane full width
|
|
77
|
+
setZoomed(false);
|
|
78
|
+
} else {
|
|
79
|
+
setProjectOpen(true);
|
|
80
|
+
setChangesOpen(rememberedChanges.current);
|
|
81
|
+
setProjectMode(rememberedChanges.current ? "changes" : "tree");
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const toggleChanges = (): void => {
|
|
85
|
+
if (projectMode === "changes") {
|
|
86
|
+
setChangesOpen(false);
|
|
87
|
+
setProjectMode("tree");
|
|
88
|
+
// never leave zoom on with the Changes editor gone - the Thread pane would stay hidden
|
|
89
|
+
setZoomed(false);
|
|
90
|
+
} else {
|
|
91
|
+
setChangesOpen(true);
|
|
92
|
+
setProjectOpen(true);
|
|
93
|
+
setProjectMode("changes");
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const toggleProject = (): void => {
|
|
97
|
+
setProjectOpen(true);
|
|
98
|
+
setProjectMode("tree");
|
|
99
|
+
};
|
|
100
|
+
const close = (groupId: string, tabId: string): void => {
|
|
101
|
+
setGrid((tree) => {
|
|
102
|
+
const pruned = closeTab(tree, groupId, tabId);
|
|
103
|
+
if (pruned === null) {
|
|
104
|
+
setChangesOpen(false);
|
|
105
|
+
setProjectMode("tree");
|
|
106
|
+
// leaving zoom on would hide the Thread pane with no editor to fill the gap
|
|
107
|
+
setZoomed(false);
|
|
108
|
+
return makeGroup([changesTab()]);
|
|
109
|
+
}
|
|
110
|
+
// re-home focus when the closed group was pruned away, so the next open has a live target
|
|
111
|
+
setFocusedGroup((current) =>
|
|
112
|
+
current !== null && containsGroup(pruned, current) ? current : firstGroupId(pruned),
|
|
113
|
+
);
|
|
114
|
+
return pruned;
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
const split = (groupId: string, direction: SplitDirection): void => {
|
|
118
|
+
setGrid((tree) => {
|
|
119
|
+
const result = splitGroup(tree, groupId, direction);
|
|
120
|
+
setFocusedGroup(result.focusGroupId);
|
|
121
|
+
return result.tree;
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
const openFile = (path: string, fileView: "diff" | "contents"): void => {
|
|
125
|
+
setProjectOpen(true);
|
|
126
|
+
setChangesOpen(true);
|
|
127
|
+
const label = path.split("/").pop() ?? path;
|
|
128
|
+
setGrid((tree) =>
|
|
129
|
+
addTab(tree, focusedGroup ?? firstGroupId(tree), fileTab(label, path, fileView)),
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
projectOpen,
|
|
135
|
+
changesOpen,
|
|
136
|
+
projectMode,
|
|
137
|
+
zoomed,
|
|
138
|
+
grid,
|
|
139
|
+
activeGroup: focusedGroup ?? firstGroupId(grid),
|
|
140
|
+
toggleRight,
|
|
141
|
+
toggleChanges,
|
|
142
|
+
toggleProject,
|
|
143
|
+
toggleZoom: () => setZoomed((value) => !value),
|
|
144
|
+
focusGroup: setFocusedGroup,
|
|
145
|
+
activate: (groupId, tabId) => setGrid((tree) => activateTab(tree, groupId, tabId)),
|
|
146
|
+
close,
|
|
147
|
+
split,
|
|
148
|
+
openFile,
|
|
149
|
+
syncSession,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a layout-dependent value after every rendered frame (and resize),
|
|
3
|
+
* committing only on change. Layout lands after the commit, so a timer
|
|
4
|
+
* would race the visual-idle wait; measuring on the frame event converges
|
|
5
|
+
* deterministically within a frame or two.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { useEffect, useState } from "react";
|
|
9
|
+
import { useRenderer } from "@opentui/react";
|
|
10
|
+
|
|
11
|
+
export function useFrameMeasure<T>(
|
|
12
|
+
read: () => T,
|
|
13
|
+
isEqual: (left: T, right: T) => boolean,
|
|
14
|
+
initial: T,
|
|
15
|
+
): T {
|
|
16
|
+
const renderer = useRenderer();
|
|
17
|
+
const [value, setValue] = useState(initial);
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const measure = (): void => {
|
|
21
|
+
const next = read();
|
|
22
|
+
|
|
23
|
+
setValue((current) => (isEqual(current, next) ? current : next));
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
measure();
|
|
27
|
+
renderer?.on("frame", measure);
|
|
28
|
+
renderer?.on("resize", measure);
|
|
29
|
+
|
|
30
|
+
return () => {
|
|
31
|
+
renderer?.off("frame", measure);
|
|
32
|
+
renderer?.off("resize", measure);
|
|
33
|
+
};
|
|
34
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
|
+
}, [renderer]);
|
|
36
|
+
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
@@ -3,8 +3,10 @@ import {
|
|
|
3
3
|
DEFAULT_QUICK_ACTIONS,
|
|
4
4
|
persistActions,
|
|
5
5
|
persistAutoClose,
|
|
6
|
+
persistDiffView,
|
|
6
7
|
persistTheme,
|
|
7
8
|
type AutoClose,
|
|
9
|
+
type DiffViewMode,
|
|
8
10
|
type QuickAction,
|
|
9
11
|
} from "./config";
|
|
10
12
|
import {
|
|
@@ -15,10 +17,8 @@ import {
|
|
|
15
17
|
type ThemeName,
|
|
16
18
|
} from "./theme-presets";
|
|
17
19
|
import type { Theme } from "./theme";
|
|
18
|
-
import type { ReviewPanelMode } from "./review-panel";
|
|
19
20
|
import type { SettingsCategory } from "./components/SettingsDialog";
|
|
20
21
|
import { QuickActionsEditor } from "./components/quick-actions-editor";
|
|
21
|
-
import type { ReviewController } from "./session-controller";
|
|
22
22
|
|
|
23
23
|
export interface SettingsNav {
|
|
24
24
|
categoryId: string;
|
|
@@ -74,15 +74,14 @@ export function useSettingsDialog(params: {
|
|
|
74
74
|
appearance: Appearance;
|
|
75
75
|
autoClose: AutoClose;
|
|
76
76
|
setAutoClose: Dispatch<SetStateAction<AutoClose>>;
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
diffView: DiffViewMode;
|
|
78
|
+
setDiffView: Dispatch<SetStateAction<DiffViewMode>>;
|
|
79
79
|
themeName: ThemeName;
|
|
80
80
|
setThemeName: Dispatch<SetStateAction<ThemeName>>;
|
|
81
81
|
themeOverrides: Partial<Theme>;
|
|
82
82
|
setTheme: Dispatch<SetStateAction<Theme>>;
|
|
83
83
|
quickActions: QuickAction[];
|
|
84
84
|
setQuickActions: Dispatch<SetStateAction<QuickAction[]>>;
|
|
85
|
-
controller: ReviewController;
|
|
86
85
|
setMenuDialog: Dispatch<SetStateAction<"keybinds" | "settings" | null>>;
|
|
87
86
|
}): SettingsDialogModel {
|
|
88
87
|
const {
|
|
@@ -90,15 +89,14 @@ export function useSettingsDialog(params: {
|
|
|
90
89
|
appearance,
|
|
91
90
|
autoClose,
|
|
92
91
|
setAutoClose,
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
diffView,
|
|
93
|
+
setDiffView,
|
|
95
94
|
themeName,
|
|
96
95
|
setThemeName,
|
|
97
96
|
themeOverrides,
|
|
98
97
|
setTheme,
|
|
99
98
|
quickActions,
|
|
100
99
|
setQuickActions,
|
|
101
|
-
controller,
|
|
102
100
|
setMenuDialog,
|
|
103
101
|
} = params;
|
|
104
102
|
|
|
@@ -142,18 +140,11 @@ export function useSettingsDialog(params: {
|
|
|
142
140
|
kind: "cycle",
|
|
143
141
|
options: ["off", "3s", "10s"],
|
|
144
142
|
},
|
|
145
|
-
],
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
id: "display",
|
|
149
|
-
name: "Display",
|
|
150
|
-
description: "the review panel",
|
|
151
|
-
rows: [
|
|
152
143
|
{
|
|
153
|
-
key: "
|
|
154
|
-
label: "
|
|
144
|
+
key: "diffView",
|
|
145
|
+
label: "Diff view (when zoomed)",
|
|
155
146
|
kind: "cycle",
|
|
156
|
-
options: ["
|
|
147
|
+
options: ["Unified", "Split"],
|
|
157
148
|
},
|
|
158
149
|
],
|
|
159
150
|
},
|
|
@@ -191,10 +182,16 @@ export function useSettingsDialog(params: {
|
|
|
191
182
|
/>
|
|
192
183
|
),
|
|
193
184
|
},
|
|
185
|
+
{
|
|
186
|
+
id: "keybinds",
|
|
187
|
+
name: "Keybinds",
|
|
188
|
+
description: "keyboard reference",
|
|
189
|
+
rows: [],
|
|
190
|
+
},
|
|
194
191
|
];
|
|
195
192
|
const settingsValues = {
|
|
196
193
|
autoClose: autoClose === "off" ? "off" : `${autoClose}s`,
|
|
197
|
-
|
|
194
|
+
diffView: diffView === "split" ? "Split" : "Unified",
|
|
198
195
|
theme: THEME_LABELS[themeName],
|
|
199
196
|
};
|
|
200
197
|
const cycleSetting = (rowKey: string): void => {
|
|
@@ -203,12 +200,11 @@ export function useSettingsDialog(params: {
|
|
|
203
200
|
|
|
204
201
|
setAutoClose(next);
|
|
205
202
|
persistAutoClose(next);
|
|
206
|
-
} else if (rowKey === "
|
|
207
|
-
const
|
|
208
|
-
const next = order[(order.indexOf(reviewMode) + 1) % order.length]!;
|
|
203
|
+
} else if (rowKey === "diffView") {
|
|
204
|
+
const next: DiffViewMode = diffView === "unified" ? "split" : "unified";
|
|
209
205
|
|
|
210
|
-
|
|
211
|
-
|
|
206
|
+
setDiffView(next);
|
|
207
|
+
persistDiffView(next);
|
|
212
208
|
} else if (rowKey === "theme") {
|
|
213
209
|
const next = THEME_NAMES[(THEME_NAMES.indexOf(themeName) + 1) % THEME_NAMES.length]!;
|
|
214
210
|
|
|
@@ -219,6 +215,9 @@ export function useSettingsDialog(params: {
|
|
|
219
215
|
};
|
|
220
216
|
|
|
221
217
|
const onCategorySelect = (categoryId: string): void => {
|
|
218
|
+
// the nav tree carries a synthetic Settings group folder; clicking it must
|
|
219
|
+
// not become the active category, or the key handler dereferences nothing
|
|
220
|
+
if (!settingsCategories.some((category) => category.id === categoryId)) return;
|
|
222
221
|
setActionsExpandedIndex(null);
|
|
223
222
|
setSettingsNav({ categoryId, rowIndex: 0, zone: "body" });
|
|
224
223
|
};
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Row virtualization for an OpenTUI scrollbox, driven by @tanstack/virtual-core.
|
|
3
|
+
* The core is DOM-free at heart: it only reaches the scroll container through the
|
|
4
|
+
* observe/scroll callbacks given here, so a terminal scrollbox stands in for the
|
|
5
|
+
* element - offsets and sizes are terminal rows, the "scroll event" is the
|
|
6
|
+
* renderer's frame event, and a mounted row's height is read off its renderable.
|
|
7
|
+
* Callers render `items` with a spacer of `items[0].start` rows above and
|
|
8
|
+
* `totalSize - last.end` below, and hand each row's box to `measureRef(index)`.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { useEffect, useLayoutEffect, useRef, useState, type RefObject } from "react";
|
|
12
|
+
import type { BoxRenderable, ScrollBoxRenderable } from "@opentui/core";
|
|
13
|
+
import { useRenderer } from "@opentui/react";
|
|
14
|
+
import { Virtualizer, type VirtualItem } from "@tanstack/virtual-core";
|
|
15
|
+
|
|
16
|
+
export interface TerminalVirtualizerOptions {
|
|
17
|
+
scrollbox: RefObject<ScrollBoxRenderable | null>;
|
|
18
|
+
count: number;
|
|
19
|
+
/** Rows an item occupies before it is measured (its wrapped visual lines). */
|
|
20
|
+
estimateSize: (index: number) => number;
|
|
21
|
+
/** Items this many rows beyond the viewport stay mounted, so a scroll step never shows a gap. */
|
|
22
|
+
overscan: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface TerminalVirtualizer {
|
|
26
|
+
items: VirtualItem[];
|
|
27
|
+
totalSize: number;
|
|
28
|
+
/** Ref callback for an item's row box, so its real height (cards included) replaces the estimate. */
|
|
29
|
+
measureRef: (index: number) => (renderable: BoxRenderable | null) => void | (() => void);
|
|
30
|
+
/** Scroll the item into view; "auto" only scrolls when it is off screen. */
|
|
31
|
+
scrollToIndex: (index: number, align?: "auto" | "start" | "center" | "end") => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The scroll container as the core reads it: the offset and the extents it clamps a scroll
|
|
36
|
+
* target with. These are the `Element` members of the same names, so the view passes as one.
|
|
37
|
+
*/
|
|
38
|
+
interface ScrollContainerView {
|
|
39
|
+
readonly scrollTop: number;
|
|
40
|
+
readonly scrollHeight: number;
|
|
41
|
+
readonly clientHeight: number;
|
|
42
|
+
readonly scrollWidth: number;
|
|
43
|
+
readonly clientWidth: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A mounted row as the core measures it: its height under the `Element` member name. */
|
|
47
|
+
interface RowView {
|
|
48
|
+
readonly clientHeight: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type CoreVirtualizer = Virtualizer<Element, Element>;
|
|
52
|
+
|
|
53
|
+
function scrollContainerView(scrollbox: ScrollBoxRenderable): ScrollContainerView {
|
|
54
|
+
return {
|
|
55
|
+
get scrollTop() {
|
|
56
|
+
return scrollbox.scrollTop;
|
|
57
|
+
},
|
|
58
|
+
get scrollHeight() {
|
|
59
|
+
return scrollbox.scrollHeight;
|
|
60
|
+
},
|
|
61
|
+
get clientHeight() {
|
|
62
|
+
return scrollbox.viewport.height;
|
|
63
|
+
},
|
|
64
|
+
get scrollWidth() {
|
|
65
|
+
return scrollbox.scrollWidth;
|
|
66
|
+
},
|
|
67
|
+
get clientWidth() {
|
|
68
|
+
return scrollbox.viewport.width;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function rowView(renderable: BoxRenderable): RowView {
|
|
74
|
+
return {
|
|
75
|
+
get clientHeight() {
|
|
76
|
+
return renderable.height;
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The core's element generics are DOM-typed, but every way it touches the container or a row
|
|
83
|
+
* (rect, offset, scroll, measurement, index lookup) is replaced here with a renderable-aware
|
|
84
|
+
* callback, so a view exposing just the members it reads stands in for the element.
|
|
85
|
+
*/
|
|
86
|
+
function asElement(view: ScrollContainerView | RowView): Element {
|
|
87
|
+
// SAFETY: the core never calls DOM methods on this value; its DOM defaults are all overridden.
|
|
88
|
+
return view as Element;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function useTerminalVirtualizer(options: TerminalVirtualizerOptions): TerminalVirtualizer {
|
|
92
|
+
const renderer = useRenderer();
|
|
93
|
+
const [, setRevision] = useState(0);
|
|
94
|
+
// one stable view per mounted row box, so the core's element cache keeps its identity
|
|
95
|
+
const viewOfRenderable = useRef(new WeakMap<BoxRenderable, Element>());
|
|
96
|
+
const indexOfView = useRef(new WeakMap<Element, number>());
|
|
97
|
+
const container = useRef<{ scrollbox: ScrollBoxRenderable; view: Element } | null>(null);
|
|
98
|
+
|
|
99
|
+
const scrollContainer = (): Element | null => {
|
|
100
|
+
const scrollbox = options.scrollbox.current;
|
|
101
|
+
|
|
102
|
+
if (!scrollbox) return null;
|
|
103
|
+
if (container.current?.scrollbox !== scrollbox) {
|
|
104
|
+
container.current = { scrollbox, view: asElement(scrollContainerView(scrollbox)) };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return container.current.view;
|
|
108
|
+
};
|
|
109
|
+
const viewFor = (renderable: BoxRenderable): Element => {
|
|
110
|
+
const known = viewOfRenderable.current.get(renderable);
|
|
111
|
+
|
|
112
|
+
if (known) return known;
|
|
113
|
+
const view = asElement(rowView(renderable));
|
|
114
|
+
|
|
115
|
+
viewOfRenderable.current.set(renderable, view);
|
|
116
|
+
|
|
117
|
+
return view;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// the offset reporter the core registered, so a scroll the core asks for reports at once
|
|
121
|
+
const reportOffset = useRef<(() => void) | null>(null);
|
|
122
|
+
|
|
123
|
+
// a frame-event poll stands in for scroll and resize events: the renderer fires it after every
|
|
124
|
+
// render, and the callbacks only fire the core when the value actually changed
|
|
125
|
+
const onFrame = (read: () => void): (() => void) => {
|
|
126
|
+
read();
|
|
127
|
+
renderer?.on("frame", read);
|
|
128
|
+
|
|
129
|
+
return () => renderer?.off("frame", read);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const coreOptions = () => ({
|
|
133
|
+
count: options.count,
|
|
134
|
+
overscan: options.overscan,
|
|
135
|
+
estimateSize: options.estimateSize,
|
|
136
|
+
getScrollElement: scrollContainer,
|
|
137
|
+
observeElementRect: (
|
|
138
|
+
_instance: CoreVirtualizer,
|
|
139
|
+
callback: (rect: { width: number; height: number }) => void,
|
|
140
|
+
) => {
|
|
141
|
+
let last = { width: -1, height: -1 };
|
|
142
|
+
|
|
143
|
+
return onFrame(() => {
|
|
144
|
+
const scrollbox = options.scrollbox.current;
|
|
145
|
+
|
|
146
|
+
if (!scrollbox) return;
|
|
147
|
+
const next = { width: scrollbox.viewport.width, height: scrollbox.viewport.height };
|
|
148
|
+
|
|
149
|
+
if (next.width === last.width && next.height === last.height) return;
|
|
150
|
+
last = next;
|
|
151
|
+
callback(next);
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
observeElementOffset: (
|
|
155
|
+
_instance: CoreVirtualizer,
|
|
156
|
+
callback: (offset: number, isScrolling: boolean) => void,
|
|
157
|
+
) => {
|
|
158
|
+
let last = -1;
|
|
159
|
+
const report = (): void => {
|
|
160
|
+
const scrollbox = options.scrollbox.current;
|
|
161
|
+
|
|
162
|
+
if (!scrollbox || scrollbox.scrollTop === last) return;
|
|
163
|
+
last = scrollbox.scrollTop;
|
|
164
|
+
callback(last, false);
|
|
165
|
+
};
|
|
166
|
+
const stop = onFrame(report);
|
|
167
|
+
|
|
168
|
+
reportOffset.current = report;
|
|
169
|
+
|
|
170
|
+
return () => {
|
|
171
|
+
reportOffset.current = null;
|
|
172
|
+
stop();
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
// report the new offset in the same tick: the item window then follows the scroll at once,
|
|
176
|
+
// instead of one frame later with the target rows still unmounted
|
|
177
|
+
scrollToFn: (offset: number) => {
|
|
178
|
+
options.scrollbox.current?.scrollTo({ x: 0, y: Math.max(0, Math.round(offset)) });
|
|
179
|
+
reportOffset.current?.();
|
|
180
|
+
},
|
|
181
|
+
// a box measures 0 until Yoga has laid it out; keep the estimate rather than collapse the row
|
|
182
|
+
measureElement: (element: Element) =>
|
|
183
|
+
element.clientHeight > 0
|
|
184
|
+
? element.clientHeight
|
|
185
|
+
: options.estimateSize(indexOfView.current.get(element) ?? -1),
|
|
186
|
+
onChange: () => setRevision((revision) => revision + 1),
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const [virtualizer] = useState<CoreVirtualizer>(() => {
|
|
190
|
+
const instance = new Virtualizer<Element, Element>(coreOptions());
|
|
191
|
+
|
|
192
|
+
// the core looks an item's index up through a DOM attribute; ours is remembered per row view
|
|
193
|
+
instance.indexFromElement = (element) => indexOfView.current.get(element) ?? -1;
|
|
194
|
+
|
|
195
|
+
return instance;
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
virtualizer.setOptions(coreOptions());
|
|
199
|
+
useLayoutEffect(() => {
|
|
200
|
+
virtualizer._willUpdate();
|
|
201
|
+
});
|
|
202
|
+
useEffect(() => virtualizer._didMount(), [virtualizer]);
|
|
203
|
+
// no ResizeObserver here: a mounted row's height settles after layout and grows when a card
|
|
204
|
+
// opens under it, so every frame re-reads the mounted rows (the core only notifies on change)
|
|
205
|
+
useEffect(
|
|
206
|
+
() =>
|
|
207
|
+
onFrame(() => {
|
|
208
|
+
for (const element of virtualizer.elementsCache.values()) {
|
|
209
|
+
virtualizer.measureElement(element);
|
|
210
|
+
}
|
|
211
|
+
}),
|
|
212
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
213
|
+
[virtualizer, renderer],
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
return {
|
|
217
|
+
items: virtualizer.getVirtualItems(),
|
|
218
|
+
totalSize: virtualizer.getTotalSize(),
|
|
219
|
+
measureRef: (index) => (renderable) => {
|
|
220
|
+
if (!renderable) return;
|
|
221
|
+
const view = viewFor(renderable);
|
|
222
|
+
|
|
223
|
+
indexOfView.current.set(view, index);
|
|
224
|
+
virtualizer.measureElement(view);
|
|
225
|
+
|
|
226
|
+
// the row unmounted: forget its view so the frame re-measure stops reading it
|
|
227
|
+
return () => {
|
|
228
|
+
if (virtualizer.elementsCache.get(index) === view) virtualizer.elementsCache.delete(index);
|
|
229
|
+
};
|
|
230
|
+
},
|
|
231
|
+
scrollToIndex: (index, align = "auto") => virtualizer.scrollToIndex(index, { align }),
|
|
232
|
+
};
|
|
233
|
+
}
|
package/src/view-diff.ts
CHANGED
|
@@ -6,6 +6,19 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { parsePatchFiles, type FileDiffMetadata } from "@pierre/diffs";
|
|
9
|
+
import {
|
|
10
|
+
isAddressed,
|
|
11
|
+
resolveAnchor,
|
|
12
|
+
type Annotation,
|
|
13
|
+
type Block,
|
|
14
|
+
type ReviewSession,
|
|
15
|
+
} from "@cueloop/schema";
|
|
16
|
+
import { spanRangeInBlock, type TextSpan } from "./thread-selection";
|
|
17
|
+
import type { Mark } from "./view-plan";
|
|
18
|
+
import { discussionsFrom } from "./discussions";
|
|
19
|
+
|
|
20
|
+
// the diff sheet reads marks over rows as a diff concept; re-export so it need not reach into view-plan
|
|
21
|
+
export type { Mark } from "./view-plan";
|
|
9
22
|
|
|
10
23
|
export type DiffRowKind = "file" | "hunk" | "ctx" | "add" | "del";
|
|
11
24
|
|
|
@@ -66,12 +79,113 @@ export function diffRows(patchText: string): DiffRow[] {
|
|
|
66
79
|
return rows;
|
|
67
80
|
}
|
|
68
81
|
|
|
82
|
+
/** Added and removed line counts per file path, for the file band's badge; base rows only. */
|
|
83
|
+
export function fileChangeCounts(
|
|
84
|
+
rows: DiffRow[],
|
|
85
|
+
): Map<string, { additions: number; deletions: number }> {
|
|
86
|
+
const counts = new Map<string, { additions: number; deletions: number }>();
|
|
87
|
+
|
|
88
|
+
for (const row of rows) {
|
|
89
|
+
if (row.kind !== "add" && row.kind !== "del") continue;
|
|
90
|
+
const entry = counts.get(row.file) ?? { additions: 0, deletions: 0 };
|
|
91
|
+
|
|
92
|
+
if (row.kind === "add") entry.additions += 1;
|
|
93
|
+
else entry.deletions += 1;
|
|
94
|
+
counts.set(row.file, entry);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return counts;
|
|
98
|
+
}
|
|
99
|
+
|
|
69
100
|
function fileLabel(file: FileDiffMetadata): string {
|
|
70
101
|
return file.prevName && file.prevName !== file.name
|
|
71
102
|
? `${file.prevName} → ${file.name}`
|
|
72
103
|
: file.name;
|
|
73
104
|
}
|
|
74
105
|
|
|
106
|
+
/** Row text carries the patch's trailing newline; anchors and rendering strip it. */
|
|
107
|
+
export function diffRowText(row: DiffRow): string {
|
|
108
|
+
return row.text.replace(/\n$/, "");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* The diff rows as anchor blocks, one per row in row order, so a comment span anchors
|
|
113
|
+
* with the same quote/context/position selectors a plan block does. Header rows are
|
|
114
|
+
* blocks too (indices stay 1:1 with the rows) but hold no comment.
|
|
115
|
+
*/
|
|
116
|
+
export function diffRowBlocks(rows: DiffRow[]): Block[] {
|
|
117
|
+
return rows.map((row, index) => ({
|
|
118
|
+
kind: "code",
|
|
119
|
+
text: row.kind === "file" || row.kind === "hunk" ? "" : diffRowText(row),
|
|
120
|
+
lineStart: index,
|
|
121
|
+
lineEnd: index,
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Resolve annotations against the diff rows and group marks per row index, with
|
|
127
|
+
* character ranges and the whole span, so the diff sheet paints and threads them
|
|
128
|
+
* exactly as the plan view does its blocks.
|
|
129
|
+
*/
|
|
130
|
+
export function marksByRows(
|
|
131
|
+
annotations: Annotation[],
|
|
132
|
+
rows: DiffRow[],
|
|
133
|
+
focusedId?: string,
|
|
134
|
+
): Map<number, Mark[]> {
|
|
135
|
+
const blocks = diffRowBlocks(rows);
|
|
136
|
+
const marksByIndex = new Map<number, Mark[]>();
|
|
137
|
+
|
|
138
|
+
for (const annotation of annotations) {
|
|
139
|
+
// an addressed annotation keeps its record but paints no highlight
|
|
140
|
+
if (isAddressed(annotation)) continue;
|
|
141
|
+
const resolved = resolveAnchor(annotation.anchor, blocks);
|
|
142
|
+
|
|
143
|
+
if (!resolved) continue;
|
|
144
|
+
const span: TextSpan = {
|
|
145
|
+
start: { blockIndex: resolved.blockIndex, char: resolved.start },
|
|
146
|
+
end: { blockIndex: resolved.endBlockIndex, char: resolved.end },
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// a span paints on every row it covers; the mark carries the whole span
|
|
150
|
+
for (let rowIndex = resolved.blockIndex; rowIndex <= resolved.endBlockIndex; rowIndex++) {
|
|
151
|
+
const range = spanRangeInBlock(span, rowIndex, blocks[rowIndex]!.text.length);
|
|
152
|
+
|
|
153
|
+
if (!range) continue;
|
|
154
|
+
const marks = marksByIndex.get(rowIndex) ?? [];
|
|
155
|
+
|
|
156
|
+
marks.push({
|
|
157
|
+
start: range.start,
|
|
158
|
+
end: range.end,
|
|
159
|
+
role: annotation.id === focusedId ? "mark-focus" : "mark-comment",
|
|
160
|
+
annotationId: annotation.id,
|
|
161
|
+
span,
|
|
162
|
+
});
|
|
163
|
+
marksByIndex.set(rowIndex, marks);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return marksByIndex;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Comments per file path across the diff: each discussion counts its comments (root plus
|
|
172
|
+
* replies) toward the file its span ends in. Feeds the changed-files tree and tab badges, so a
|
|
173
|
+
* file whose tab is closed still shows it carries feedback.
|
|
174
|
+
*/
|
|
175
|
+
export function commentCountsByFile(session: ReviewSession, rows: DiffRow[]): Map<string, number> {
|
|
176
|
+
const discussions = discussionsFrom(session, marksByRows(session.annotations, rows));
|
|
177
|
+
const counts = new Map<string, number>();
|
|
178
|
+
|
|
179
|
+
for (const discussion of discussions) {
|
|
180
|
+
const file = rows[discussion.blockIndex]?.file;
|
|
181
|
+
|
|
182
|
+
if (file === undefined) continue;
|
|
183
|
+
counts.set(file, (counts.get(file) ?? 0) + discussion.annotations.length);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return counts;
|
|
187
|
+
}
|
|
188
|
+
|
|
75
189
|
/** Quote-primary anchor for a diff row: neighbors as context selectors. */
|
|
76
190
|
export function diffRowAnchor(rows: DiffRow[], rowIndex: number) {
|
|
77
191
|
const row = rows[rowIndex]!;
|