@lukstei/dsh-client-split-view 0.0.0-stage → 0.2.2-rc.5.10
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/LICENSE +21 -0
- package/README.md +137 -2
- package/cordis.patch.yml +3 -0
- package/dist/client.js +2457 -0
- package/dist/index.js +4 -0
- package/package.json +114 -3
- package/src/client/SplitLayout.tsx +48 -0
- package/src/client/SplitPane.tsx +1076 -0
- package/src/client/SplitPaneHeader.tsx +79 -0
- package/src/client/contract.ts +113 -0
- package/src/client/css.d.ts +5 -0
- package/src/client/dsh.d.ts +18 -0
- package/src/client/file-preview.ts +67 -0
- package/src/client/index.tsx +267 -0
- package/src/client/split-store.ts +759 -0
- package/src/client/styles.ts +780 -0
- package/src/index.ts +8 -0
|
@@ -0,0 +1,1076 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Purpose: Render full-bleed, equal-width concurrent session splits in the main view.
|
|
3
|
+
* Contract:
|
|
4
|
+
* - Inputs: PropsRuntime, PropsRenderSlots, and PropsRenderFactories from the DSH slots system.
|
|
5
|
+
* - Outputs: Split container with session headers and per-pane overlay tabs (session, slot, file).
|
|
6
|
+
* - Errors: Never throws; renders empty columns if references are unready.
|
|
7
|
+
*/
|
|
8
|
+
import type {
|
|
9
|
+
SessionListState,
|
|
10
|
+
SessionSummary,
|
|
11
|
+
} from "@deepseek-ai/dsh-api-session-controller/client";
|
|
12
|
+
import { workspaceDisplayTitle } from "@deepseek-ai/dsh-api-workspace-controller/default-workspace";
|
|
13
|
+
import type {
|
|
14
|
+
WorkspaceFileBytes,
|
|
15
|
+
WorkspaceFileText,
|
|
16
|
+
} from "@deepseek-ai/dsh-api-workspace-files/types";
|
|
17
|
+
import type { InputActions } from "@deepseek-ai/dsh-client-ui-conversation/client";
|
|
18
|
+
import type { MarkdownLabels } from "@deepseek-ai/dsh-client-ui-primitives";
|
|
19
|
+
import {
|
|
20
|
+
Button,
|
|
21
|
+
CodeBlock,
|
|
22
|
+
IconCheckOutlineRegular,
|
|
23
|
+
IconChevronDownOutlineRegular,
|
|
24
|
+
IconCloseOutlineRegular,
|
|
25
|
+
IconCompareSplitOutlineRegular,
|
|
26
|
+
IconCopyOutlineRegular,
|
|
27
|
+
IconFullscreenOutlineRegular,
|
|
28
|
+
IconRightUpOutlineRegular,
|
|
29
|
+
languageForPath,
|
|
30
|
+
MarkdownText,
|
|
31
|
+
Menu,
|
|
32
|
+
PathLabel,
|
|
33
|
+
Tooltip,
|
|
34
|
+
useClipboardCopy,
|
|
35
|
+
} from "@deepseek-ai/dsh-client-ui-primitives";
|
|
36
|
+
import type {
|
|
37
|
+
PropsRenderFactories,
|
|
38
|
+
PropsRenderSlots,
|
|
39
|
+
PropsRuntime,
|
|
40
|
+
} from "@deepseek-ai/dsh-client-ui-slots";
|
|
41
|
+
import type { SessionId } from "@deepseek-ai/dsh-session/types";
|
|
42
|
+
import type {
|
|
43
|
+
RemoteDecoded,
|
|
44
|
+
RemoteResult,
|
|
45
|
+
} from "@deepseek-ai/dsh-typert-protocol";
|
|
46
|
+
import {
|
|
47
|
+
createContext,
|
|
48
|
+
useContext,
|
|
49
|
+
useEffect,
|
|
50
|
+
useMemo,
|
|
51
|
+
useRef,
|
|
52
|
+
useState,
|
|
53
|
+
useSyncExternalStore,
|
|
54
|
+
} from "react";
|
|
55
|
+
import { imageMimeTypeOf, previewKindOf } from "./file-preview.ts";
|
|
56
|
+
import { SplitLayout } from "./SplitLayout.tsx";
|
|
57
|
+
import { SplitPaneHeader } from "./SplitPaneHeader.tsx";
|
|
58
|
+
import "./contract.ts";
|
|
59
|
+
import { quoteToComposer } from "@lukstei/util-review-ui/client/quote.ts";
|
|
60
|
+
import { useSelectionQuote } from "@lukstei/util-review-ui/client/useSelectionQuote.ts";
|
|
61
|
+
import { type SplitOverlay, splitStore } from "./split-store.ts";
|
|
62
|
+
|
|
63
|
+
/** English chrome for Markdown rendered inside a split pane. */
|
|
64
|
+
const MARKDOWN_LABELS: MarkdownLabels = {
|
|
65
|
+
code: {
|
|
66
|
+
copyLabel: "Copy",
|
|
67
|
+
copiedLabel: "Copied",
|
|
68
|
+
toolbarLabels: {
|
|
69
|
+
codeLabel: "Code",
|
|
70
|
+
wrapLabel: "Wrap",
|
|
71
|
+
unwrapLabel: "Unwrap",
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
footnotes: "Footnotes",
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/** Host services the overlay occupants need, supplied by the plugin's inject face. */
|
|
78
|
+
export interface SplitOverlayServices {
|
|
79
|
+
readFile: (
|
|
80
|
+
sessionId: SessionId,
|
|
81
|
+
path: string,
|
|
82
|
+
offset: number,
|
|
83
|
+
signal: AbortSignal,
|
|
84
|
+
) => Promise<RemoteResult<WorkspaceFileText>>;
|
|
85
|
+
readBytes: (
|
|
86
|
+
sessionId: SessionId,
|
|
87
|
+
path: string,
|
|
88
|
+
signal: AbortSignal,
|
|
89
|
+
) => Promise<RemoteResult<RemoteDecoded<WorkspaceFileBytes>>>;
|
|
90
|
+
openNativeResource: (address: string) => void;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function deriveAncestry(list: SessionListState, id: SessionId) {
|
|
94
|
+
const chain: Array<{
|
|
95
|
+
id: SessionId;
|
|
96
|
+
displayTitle: string;
|
|
97
|
+
subagent: boolean;
|
|
98
|
+
}> = [];
|
|
99
|
+
const seen = new Set<SessionId>();
|
|
100
|
+
let cursor: SessionId | undefined = id;
|
|
101
|
+
while (cursor !== undefined) {
|
|
102
|
+
if (seen.has(cursor)) break;
|
|
103
|
+
seen.add(cursor);
|
|
104
|
+
const summary: SessionSummary | undefined = list.byId[cursor];
|
|
105
|
+
if (summary === undefined) break;
|
|
106
|
+
chain.unshift({
|
|
107
|
+
id: summary.id,
|
|
108
|
+
displayTitle: summary.displayTitle || "Untitled Task",
|
|
109
|
+
subagent: summary.origin === "subagent",
|
|
110
|
+
});
|
|
111
|
+
if (summary.origin !== "subagent") break;
|
|
112
|
+
cursor = summary.parentId;
|
|
113
|
+
}
|
|
114
|
+
return chain;
|
|
115
|
+
}
|
|
116
|
+
const isAncestryEqual = (
|
|
117
|
+
a: ReturnType<typeof deriveAncestry>,
|
|
118
|
+
b: ReturnType<typeof deriveAncestry>,
|
|
119
|
+
): boolean =>
|
|
120
|
+
a.length === b.length &&
|
|
121
|
+
a.every(
|
|
122
|
+
(item, i) =>
|
|
123
|
+
item.id === b[i].id &&
|
|
124
|
+
item.displayTitle === b[i].displayTitle &&
|
|
125
|
+
item.subagent === b[i].subagent,
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const isSubagentsEqual = (
|
|
129
|
+
a: readonly SessionSummary[],
|
|
130
|
+
b: readonly SessionSummary[],
|
|
131
|
+
): boolean =>
|
|
132
|
+
a.length === b.length &&
|
|
133
|
+
a.every(
|
|
134
|
+
(item, i) =>
|
|
135
|
+
item.id === b[i].id &&
|
|
136
|
+
item.running === b[i].running &&
|
|
137
|
+
item.displayTitle === b[i].displayTitle,
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
type PaneHooks = Pick<
|
|
141
|
+
PropsRuntime<"split.pane">,
|
|
142
|
+
"useSession" | "useConversation" | "useSessions"
|
|
143
|
+
>;
|
|
144
|
+
|
|
145
|
+
function useSplitPhase(
|
|
146
|
+
sessionId: SessionId,
|
|
147
|
+
{ useSession, useConversation, useSessions }: PaneHooks,
|
|
148
|
+
): { phase: "settling" | "hero" | "active"; hero: boolean } {
|
|
149
|
+
const session = useSession((value) => value);
|
|
150
|
+
const conversation = useConversation((value) => value);
|
|
151
|
+
// smell: conversation phase duplicated because client bundle cannot require non-platform plugin @deepseek-ai/dsh-client-ui-conversation; upgrade when harness exports conversationPhase in platform runtime
|
|
152
|
+
const active =
|
|
153
|
+
conversation.activeTargets.size > 0 ||
|
|
154
|
+
(!session.blank && !session.awaitingFirstTurn) ||
|
|
155
|
+
session.running;
|
|
156
|
+
const shellPhase = active
|
|
157
|
+
? "active"
|
|
158
|
+
: session.promptAttempted
|
|
159
|
+
? "engaging"
|
|
160
|
+
: "blank";
|
|
161
|
+
const summaryBlank = useSessions((state) => state.byId[sessionId]?.blank);
|
|
162
|
+
const settling =
|
|
163
|
+
shellPhase === "blank" &&
|
|
164
|
+
session.openState === "loading" &&
|
|
165
|
+
summaryBlank !== true;
|
|
166
|
+
const hero =
|
|
167
|
+
shellPhase === "blank" &&
|
|
168
|
+
(session.openState === "open" || summaryBlank === true);
|
|
169
|
+
return { phase: settling ? "settling" : hero ? "hero" : "active", hero };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
type FilePageState =
|
|
173
|
+
| { status: "markdown"; text: string; nextOffset: number | undefined }
|
|
174
|
+
| { status: "text"; text: string; nextOffset: number | undefined };
|
|
175
|
+
|
|
176
|
+
type FileViewState =
|
|
177
|
+
| { status: "loading" }
|
|
178
|
+
| FilePageState
|
|
179
|
+
| { status: "image"; url: string }
|
|
180
|
+
| { status: "failed"; message: string };
|
|
181
|
+
|
|
182
|
+
/** Copies a file overlay's text; disabled until every page has loaded. */
|
|
183
|
+
function CopyContentsButton({ contents }: { contents: string | undefined }) {
|
|
184
|
+
const { copied, onCopy } = useClipboardCopy(contents ?? "");
|
|
185
|
+
const label =
|
|
186
|
+
contents === undefined
|
|
187
|
+
? "Loading full file…"
|
|
188
|
+
: copied
|
|
189
|
+
? "Copied!"
|
|
190
|
+
: "Copy contents";
|
|
191
|
+
return (
|
|
192
|
+
<Tooltip label={label} portal>
|
|
193
|
+
<button
|
|
194
|
+
type="button"
|
|
195
|
+
className="dsh-split-overlay-close"
|
|
196
|
+
aria-label="Copy contents"
|
|
197
|
+
disabled={contents === undefined}
|
|
198
|
+
onClick={(event) => {
|
|
199
|
+
event.stopPropagation();
|
|
200
|
+
onCopy();
|
|
201
|
+
}}
|
|
202
|
+
>
|
|
203
|
+
{copied ? (
|
|
204
|
+
<IconCheckOutlineRegular size={14} />
|
|
205
|
+
) : (
|
|
206
|
+
<IconCopyOutlineRegular size={14} />
|
|
207
|
+
)}
|
|
208
|
+
</button>
|
|
209
|
+
</Tooltip>
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Inline Markdown/text/image preview for one addressed file; other formats fall back to the Sidebar. */
|
|
214
|
+
function SplitFileOverlay({
|
|
215
|
+
hostSessionId,
|
|
216
|
+
overlay,
|
|
217
|
+
readFile,
|
|
218
|
+
readBytes,
|
|
219
|
+
openNativeResource,
|
|
220
|
+
inputActions,
|
|
221
|
+
}: Pick<
|
|
222
|
+
SplitOverlayServices,
|
|
223
|
+
"readFile" | "readBytes" | "openNativeResource"
|
|
224
|
+
> & {
|
|
225
|
+
hostSessionId: SessionId;
|
|
226
|
+
overlay: Extract<SplitOverlay, { kind: "file" }>;
|
|
227
|
+
inputActions?: Pick<
|
|
228
|
+
InputActions,
|
|
229
|
+
"insertQuote" | "insertText" | "captureInsertion" | "persistDraft"
|
|
230
|
+
>;
|
|
231
|
+
}) {
|
|
232
|
+
const { path, ownerSessionId } = overlay;
|
|
233
|
+
const kind = previewKindOf(path);
|
|
234
|
+
const [state, setState] = useState<FileViewState>({ status: "loading" });
|
|
235
|
+
const [loadingMore, setLoadingMore] = useState(false);
|
|
236
|
+
const controllerRef = useRef<AbortController | null>(null);
|
|
237
|
+
const objectUrlRef = useRef<string | undefined>(undefined);
|
|
238
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
239
|
+
const { floatingQuote, clearFloatingQuote } = useSelectionQuote({
|
|
240
|
+
containerRef,
|
|
241
|
+
enabled: inputActions !== undefined,
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
const fullText =
|
|
245
|
+
(state.status === "markdown" || state.status === "text") &&
|
|
246
|
+
state.nextOffset === undefined
|
|
247
|
+
? state.text
|
|
248
|
+
: undefined;
|
|
249
|
+
useEffect(() => {
|
|
250
|
+
if (fullText !== undefined) {
|
|
251
|
+
splitStore.updateFileOverlayContents(
|
|
252
|
+
hostSessionId,
|
|
253
|
+
overlay.address,
|
|
254
|
+
fullText,
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
}, [fullText, hostSessionId, overlay]);
|
|
258
|
+
|
|
259
|
+
const handleQuote = (e: React.SyntheticEvent) => {
|
|
260
|
+
e.preventDefault();
|
|
261
|
+
if (!floatingQuote || !inputActions) return;
|
|
262
|
+
quoteToComposer(
|
|
263
|
+
{
|
|
264
|
+
text: floatingQuote.text,
|
|
265
|
+
path: overlay.path,
|
|
266
|
+
lines: floatingQuote.lines,
|
|
267
|
+
},
|
|
268
|
+
inputActions,
|
|
269
|
+
);
|
|
270
|
+
clearFloatingQuote();
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
useEffect(() => {
|
|
274
|
+
const controller = new AbortController();
|
|
275
|
+
controllerRef.current = controller;
|
|
276
|
+
setState({ status: "loading" });
|
|
277
|
+
setLoadingMore(false);
|
|
278
|
+
const load = async () => {
|
|
279
|
+
if (kind === "image") {
|
|
280
|
+
const mime = imageMimeTypeOf(path);
|
|
281
|
+
if (mime === undefined) {
|
|
282
|
+
setState({ status: "failed", message: "Unsupported preview" });
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const bytes = await readBytes(ownerSessionId, path, controller.signal);
|
|
286
|
+
if (controller.signal.aborted) return;
|
|
287
|
+
if (!bytes.ok) {
|
|
288
|
+
setState({ status: "failed", message: bytes.error.message });
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (bytes.value.absolutePath) {
|
|
292
|
+
splitStore.updateFileOverlayFullPath(
|
|
293
|
+
hostSessionId,
|
|
294
|
+
overlay.address,
|
|
295
|
+
bytes.value.absolutePath,
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
const objectUrl = URL.createObjectURL(
|
|
299
|
+
new Blob([bytes.value.data], { type: mime }),
|
|
300
|
+
);
|
|
301
|
+
objectUrlRef.current = objectUrl;
|
|
302
|
+
setState({ status: "image", url: objectUrl });
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const page = await readFile(ownerSessionId, path, 1, controller.signal);
|
|
306
|
+
if (controller.signal.aborted) return;
|
|
307
|
+
if (!page.ok) {
|
|
308
|
+
setState({ status: "failed", message: page.error.message });
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (page.value.absolutePath) {
|
|
312
|
+
splitStore.updateFileOverlayFullPath(
|
|
313
|
+
hostSessionId,
|
|
314
|
+
overlay.address,
|
|
315
|
+
page.value.absolutePath,
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
setState({
|
|
319
|
+
status: kind,
|
|
320
|
+
text: page.value.text,
|
|
321
|
+
nextOffset:
|
|
322
|
+
page.value.eof || page.value.lines === 0
|
|
323
|
+
? undefined
|
|
324
|
+
: page.value.offset + page.value.lines,
|
|
325
|
+
});
|
|
326
|
+
};
|
|
327
|
+
void load();
|
|
328
|
+
return () => {
|
|
329
|
+
controller.abort();
|
|
330
|
+
if (controllerRef.current === controller) controllerRef.current = null;
|
|
331
|
+
if (objectUrlRef.current !== undefined) {
|
|
332
|
+
URL.revokeObjectURL(objectUrlRef.current);
|
|
333
|
+
objectUrlRef.current = undefined;
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
}, [
|
|
337
|
+
kind,
|
|
338
|
+
path,
|
|
339
|
+
ownerSessionId,
|
|
340
|
+
hostSessionId,
|
|
341
|
+
readFile,
|
|
342
|
+
readBytes,
|
|
343
|
+
overlay.address,
|
|
344
|
+
]);
|
|
345
|
+
|
|
346
|
+
const loadMore = async () => {
|
|
347
|
+
if (loadingMore) return;
|
|
348
|
+
if (state.status !== "text" && state.status !== "markdown") return;
|
|
349
|
+
const nextOffset = state.nextOffset;
|
|
350
|
+
const controller = controllerRef.current;
|
|
351
|
+
if (
|
|
352
|
+
nextOffset === undefined ||
|
|
353
|
+
controller === null ||
|
|
354
|
+
controller.signal.aborted
|
|
355
|
+
) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
setLoadingMore(true);
|
|
359
|
+
const page = await readFile(
|
|
360
|
+
ownerSessionId,
|
|
361
|
+
path,
|
|
362
|
+
nextOffset,
|
|
363
|
+
controller.signal,
|
|
364
|
+
);
|
|
365
|
+
if (controller.signal.aborted) return;
|
|
366
|
+
setLoadingMore(false);
|
|
367
|
+
if (!page.ok) {
|
|
368
|
+
setState((previous) =>
|
|
369
|
+
previous.status === "text" || previous.status === "markdown"
|
|
370
|
+
? { ...previous, nextOffset: undefined }
|
|
371
|
+
: previous,
|
|
372
|
+
);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
setState((previous) =>
|
|
376
|
+
previous.status === "text" || previous.status === "markdown"
|
|
377
|
+
? {
|
|
378
|
+
...previous,
|
|
379
|
+
text: `${previous.text}\n${page.value.text}`,
|
|
380
|
+
nextOffset:
|
|
381
|
+
page.value.eof || page.value.lines === 0
|
|
382
|
+
? undefined
|
|
383
|
+
: page.value.offset + page.value.lines,
|
|
384
|
+
}
|
|
385
|
+
: previous,
|
|
386
|
+
);
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
if (state.status === "loading") {
|
|
390
|
+
return <p className="dsh-split-file-note">Loading…</p>;
|
|
391
|
+
}
|
|
392
|
+
if (state.status === "failed") {
|
|
393
|
+
return (
|
|
394
|
+
<div className="dsh-split-file-note">
|
|
395
|
+
<p>{state.message}</p>
|
|
396
|
+
<button
|
|
397
|
+
type="button"
|
|
398
|
+
className="dsh-split-btn"
|
|
399
|
+
onClick={() => openNativeResource(overlay.address)}
|
|
400
|
+
>
|
|
401
|
+
Open in sidebar
|
|
402
|
+
</button>
|
|
403
|
+
</div>
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
if (state.status === "image") {
|
|
407
|
+
return (
|
|
408
|
+
<div className="dsh-split-file dsh-split-file-media">
|
|
409
|
+
<img
|
|
410
|
+
className="dsh-split-file-image"
|
|
411
|
+
src={state.url}
|
|
412
|
+
alt={overlay.title}
|
|
413
|
+
/>
|
|
414
|
+
</div>
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
const truncated = state.nextOffset !== undefined;
|
|
418
|
+
return (
|
|
419
|
+
<div ref={containerRef} className="dsh-split-file">
|
|
420
|
+
{floatingQuote !== null && inputActions !== undefined && (
|
|
421
|
+
<div
|
|
422
|
+
className="dsh-split-floating-quote"
|
|
423
|
+
style={{
|
|
424
|
+
top: `${floatingQuote.top}px`,
|
|
425
|
+
left: `${floatingQuote.left}px`,
|
|
426
|
+
}}
|
|
427
|
+
>
|
|
428
|
+
<button
|
|
429
|
+
type="button"
|
|
430
|
+
className="dsh-split-floating-quote-btn"
|
|
431
|
+
onPointerDown={(e) => {
|
|
432
|
+
e.preventDefault();
|
|
433
|
+
}}
|
|
434
|
+
onClick={handleQuote}
|
|
435
|
+
>
|
|
436
|
+
Quote
|
|
437
|
+
</button>
|
|
438
|
+
</div>
|
|
439
|
+
)}
|
|
440
|
+
{state.status === "markdown" ? (
|
|
441
|
+
<div className="dsh-split-file-markdown">
|
|
442
|
+
<MarkdownText text={state.text} labels={MARKDOWN_LABELS} />
|
|
443
|
+
</div>
|
|
444
|
+
) : (
|
|
445
|
+
<div className="dsh-split-file-code">
|
|
446
|
+
<CodeBlock
|
|
447
|
+
code={state.text}
|
|
448
|
+
lang={languageForPath(path)}
|
|
449
|
+
lineNumbers
|
|
450
|
+
streaming={truncated}
|
|
451
|
+
copyLabel={MARKDOWN_LABELS.code.copyLabel}
|
|
452
|
+
copiedLabel={MARKDOWN_LABELS.code.copiedLabel}
|
|
453
|
+
toolbarLabels={MARKDOWN_LABELS.code.toolbarLabels}
|
|
454
|
+
/>
|
|
455
|
+
</div>
|
|
456
|
+
)}
|
|
457
|
+
{truncated && (
|
|
458
|
+
<p className="dsh-split-file-note">
|
|
459
|
+
{loadingMore ? "Loading…" : "Showing the first page only."}{" "}
|
|
460
|
+
<button
|
|
461
|
+
type="button"
|
|
462
|
+
className="dsh-split-btn"
|
|
463
|
+
disabled={loadingMore}
|
|
464
|
+
onClick={() => {
|
|
465
|
+
void loadMore();
|
|
466
|
+
}}
|
|
467
|
+
>
|
|
468
|
+
Load more
|
|
469
|
+
</button>{" "}
|
|
470
|
+
<button
|
|
471
|
+
type="button"
|
|
472
|
+
className="dsh-split-btn"
|
|
473
|
+
onClick={() => openNativeResource(overlay.address)}
|
|
474
|
+
>
|
|
475
|
+
Open in sidebar
|
|
476
|
+
</button>
|
|
477
|
+
</p>
|
|
478
|
+
)}
|
|
479
|
+
</div>
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function SplitSessionOverlay({
|
|
484
|
+
sessionId,
|
|
485
|
+
useSession,
|
|
486
|
+
useConversation,
|
|
487
|
+
useSessions,
|
|
488
|
+
renderFactorySlot,
|
|
489
|
+
}: {
|
|
490
|
+
sessionId: SessionId;
|
|
491
|
+
useSession: PaneHooks["useSession"];
|
|
492
|
+
useConversation: PaneHooks["useConversation"];
|
|
493
|
+
useSessions: PaneHooks["useSessions"];
|
|
494
|
+
renderFactorySlot: PropsRenderFactories["renderFactorySlot"];
|
|
495
|
+
}) {
|
|
496
|
+
const { phase, hero } = useSplitPhase(sessionId, {
|
|
497
|
+
useSession,
|
|
498
|
+
useConversation,
|
|
499
|
+
useSessions,
|
|
500
|
+
});
|
|
501
|
+
return renderFactorySlot("conversation.content", {
|
|
502
|
+
variant: "embedded",
|
|
503
|
+
phase,
|
|
504
|
+
hero,
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** Occupant of `split.overlay`: renders whichever overlay covers the host pane. */
|
|
509
|
+
export function SplitOverlayContent({
|
|
510
|
+
hostSessionId,
|
|
511
|
+
sessionId,
|
|
512
|
+
useSession,
|
|
513
|
+
useConversation,
|
|
514
|
+
useSessions,
|
|
515
|
+
renderFactorySlot,
|
|
516
|
+
readFile,
|
|
517
|
+
readBytes,
|
|
518
|
+
openNativeResource,
|
|
519
|
+
inputActions,
|
|
520
|
+
}: PropsRuntime<"split.overlay"> &
|
|
521
|
+
PropsRenderFactories &
|
|
522
|
+
SplitOverlayServices) {
|
|
523
|
+
const state = useSyncExternalStore(
|
|
524
|
+
splitStore.subscribe,
|
|
525
|
+
splitStore.getSnapshot,
|
|
526
|
+
);
|
|
527
|
+
const overlay = state.overlays.get(hostSessionId);
|
|
528
|
+
|
|
529
|
+
if (overlay === undefined) return null;
|
|
530
|
+
if (overlay.kind === "session") {
|
|
531
|
+
return (
|
|
532
|
+
<SplitSessionOverlay
|
|
533
|
+
sessionId={sessionId}
|
|
534
|
+
useSession={useSession}
|
|
535
|
+
useConversation={useConversation}
|
|
536
|
+
useSessions={useSessions}
|
|
537
|
+
renderFactorySlot={renderFactorySlot}
|
|
538
|
+
/>
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
if (overlay.kind === "slot") {
|
|
542
|
+
return renderFactorySlot(overlay.slotName, overlay.props);
|
|
543
|
+
}
|
|
544
|
+
if (overlay.kind === "file") {
|
|
545
|
+
return (
|
|
546
|
+
<SplitFileOverlay
|
|
547
|
+
hostSessionId={hostSessionId}
|
|
548
|
+
overlay={overlay}
|
|
549
|
+
readFile={readFile}
|
|
550
|
+
readBytes={readBytes}
|
|
551
|
+
openNativeResource={openNativeResource}
|
|
552
|
+
inputActions={inputActions}
|
|
553
|
+
/>
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
return null;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/** @internal */
|
|
560
|
+
export interface SplitOverlayHostContextValue {
|
|
561
|
+
sessionId: SessionId;
|
|
562
|
+
renderSlot: PropsRenderSlots<"split.overlay">["renderSlot"];
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/** @internal */
|
|
566
|
+
export const SplitOverlayHostContext =
|
|
567
|
+
createContext<SplitOverlayHostContextValue | null>(null);
|
|
568
|
+
|
|
569
|
+
/** @internal */
|
|
570
|
+
export function SplitOverlayConversationView() {
|
|
571
|
+
const host = useContext(SplitOverlayHostContext);
|
|
572
|
+
if (host === null) return null;
|
|
573
|
+
return (
|
|
574
|
+
<div className="dsh-split-overlay-view">
|
|
575
|
+
{host.renderSlot("split.overlay", { hostSessionId: host.sessionId })}
|
|
576
|
+
</div>
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
const SPLIT_OVERLAY_CONVERSATION_OPTIONS = {
|
|
581
|
+
slots: {
|
|
582
|
+
views: SplitOverlayConversationView,
|
|
583
|
+
},
|
|
584
|
+
} as const;
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Purpose: Session-scoped occupant for an individual split pane including session header.
|
|
588
|
+
* Contract:
|
|
589
|
+
* - Inputs: Standard session props, renderSlot/renderFactorySlot, and SessionProvider.
|
|
590
|
+
* - Outputs: Embedded conversation content or the pane overlay with its tab row.
|
|
591
|
+
*/
|
|
592
|
+
export function SplitPaneContent({
|
|
593
|
+
sessionId,
|
|
594
|
+
useSession,
|
|
595
|
+
useInput,
|
|
596
|
+
useConversation,
|
|
597
|
+
useSessions,
|
|
598
|
+
useSessionStatus,
|
|
599
|
+
useWorkspaces,
|
|
600
|
+
renderSlot,
|
|
601
|
+
renderFactorySlot,
|
|
602
|
+
SessionProvider,
|
|
603
|
+
}: PropsRuntime<"split.pane"> &
|
|
604
|
+
PropsRenderFactories &
|
|
605
|
+
PropsRenderSlots<
|
|
606
|
+
| "split.overlay"
|
|
607
|
+
| "split.pane.status"
|
|
608
|
+
| "split.subagent.status"
|
|
609
|
+
| "split.pane.header.actions"
|
|
610
|
+
>) {
|
|
611
|
+
const overlayHostValue = useMemo<SplitOverlayHostContextValue>(
|
|
612
|
+
() => ({ sessionId, renderSlot }),
|
|
613
|
+
[sessionId, renderSlot],
|
|
614
|
+
);
|
|
615
|
+
const state = useSyncExternalStore(
|
|
616
|
+
splitStore.subscribe,
|
|
617
|
+
splitStore.getSnapshot,
|
|
618
|
+
);
|
|
619
|
+
const overlay = state.overlays.get(sessionId);
|
|
620
|
+
const isFocused = state.focusedSessionId === sessionId;
|
|
621
|
+
const isMaximized = state.maximizedSessionId === sessionId;
|
|
622
|
+
const isHovered = state.hoveredSessionId === sessionId;
|
|
623
|
+
const [isDragOver, setIsDragOver] = useState(false);
|
|
624
|
+
const canDrag =
|
|
625
|
+
state.sessionIds.length > 1 && state.maximizedSessionId === undefined;
|
|
626
|
+
|
|
627
|
+
const inputPhase = useInput((s) => s.phase);
|
|
628
|
+
const prevPhaseRef = useRef(inputPhase);
|
|
629
|
+
const pendingCount = useSession((s) => s.pendingSubmissions.length);
|
|
630
|
+
const isRunning = useSession((s) => s.running);
|
|
631
|
+
const prevPendingRef = useRef(pendingCount);
|
|
632
|
+
const prevRunningRef = useRef(isRunning);
|
|
633
|
+
|
|
634
|
+
useEffect(() => {
|
|
635
|
+
const isSubmitting =
|
|
636
|
+
(prevPhaseRef.current === "plain" ||
|
|
637
|
+
prevPhaseRef.current === "claimed") &&
|
|
638
|
+
(inputPhase === "sending" ||
|
|
639
|
+
inputPhase === "submitting" ||
|
|
640
|
+
inputPhase === "adjudicating");
|
|
641
|
+
const pendingIncreased = pendingCount > prevPendingRef.current;
|
|
642
|
+
const becameRunning = !prevRunningRef.current && isRunning;
|
|
643
|
+
const isReviewOverlay =
|
|
644
|
+
overlay !== undefined &&
|
|
645
|
+
(overlay.kind === "slot" || overlay.kind === "file");
|
|
646
|
+
|
|
647
|
+
if (
|
|
648
|
+
(isSubmitting || pendingIncreased || becameRunning) &&
|
|
649
|
+
isReviewOverlay
|
|
650
|
+
) {
|
|
651
|
+
splitStore.closeOverlay(sessionId);
|
|
652
|
+
}
|
|
653
|
+
prevPhaseRef.current = inputPhase;
|
|
654
|
+
prevPendingRef.current = pendingCount;
|
|
655
|
+
prevRunningRef.current = isRunning;
|
|
656
|
+
}, [inputPhase, pendingCount, isRunning, overlay, sessionId]);
|
|
657
|
+
|
|
658
|
+
const { phase, hero } = useSplitPhase(sessionId, {
|
|
659
|
+
useSession,
|
|
660
|
+
useConversation,
|
|
661
|
+
useSessions,
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
const statuses = useSessionStatus((s) => s);
|
|
665
|
+
const isSubagentRunning = (item: SessionSummary): boolean => {
|
|
666
|
+
const status = statuses.get(item.id);
|
|
667
|
+
return status !== undefined && status.running !== undefined
|
|
668
|
+
? status.running
|
|
669
|
+
: item.running;
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
const ancestry = useSessions(
|
|
673
|
+
(s) => deriveAncestry(s, sessionId),
|
|
674
|
+
isAncestryEqual,
|
|
675
|
+
);
|
|
676
|
+
const currentSummary = useSessions((s) => s.byId[sessionId]);
|
|
677
|
+
const displayTitle = currentSummary?.displayTitle || "Untitled Task";
|
|
678
|
+
const subagents = useSessions(
|
|
679
|
+
(s) =>
|
|
680
|
+
Object.values(s.byId).filter((item): item is SessionSummary =>
|
|
681
|
+
Boolean(
|
|
682
|
+
item && item.origin === "subagent" && item.parentId === sessionId,
|
|
683
|
+
),
|
|
684
|
+
),
|
|
685
|
+
isSubagentsEqual,
|
|
686
|
+
);
|
|
687
|
+
const runningSubagents = subagents.filter(isSubagentRunning);
|
|
688
|
+
const hasRunningSubagents = runningSubagents.length > 0;
|
|
689
|
+
const workspace = useWorkspaces((s) =>
|
|
690
|
+
s.items.find((item) =>
|
|
691
|
+
item.sessionIds.includes(
|
|
692
|
+
ancestry.length === 0 ? sessionId : ancestry[0].id,
|
|
693
|
+
),
|
|
694
|
+
),
|
|
695
|
+
);
|
|
696
|
+
const workspaceTitle =
|
|
697
|
+
workspace === undefined
|
|
698
|
+
? undefined
|
|
699
|
+
: workspaceDisplayTitle(workspace.title, "Default workspace");
|
|
700
|
+
const [subagentMenuOpen, setSubagentMenuOpen] = useState(false);
|
|
701
|
+
|
|
702
|
+
const subagentPillLabel =
|
|
703
|
+
subagents.length === 1
|
|
704
|
+
? "1 subagent"
|
|
705
|
+
: hasRunningSubagents
|
|
706
|
+
? `${runningSubagents.length}/${subagents.length} subagents`
|
|
707
|
+
: `${subagents.length} subagents`;
|
|
708
|
+
|
|
709
|
+
const subagentPillTooltip =
|
|
710
|
+
subagents.length === 1
|
|
711
|
+
? hasRunningSubagents
|
|
712
|
+
? `Subagent active: ${subagents[0].displayTitle || "Untitled"}. Click to select.`
|
|
713
|
+
: `Subagent finished: ${subagents[0].displayTitle || "Untitled"}. Click to select.`
|
|
714
|
+
: hasRunningSubagents
|
|
715
|
+
? `${runningSubagents.length} active of ${subagents.length} subagents. Click to select.`
|
|
716
|
+
: `${subagents.length} subagents finished. Click to select.`;
|
|
717
|
+
|
|
718
|
+
useEffect(() => {
|
|
719
|
+
if (overlay === undefined) return;
|
|
720
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
721
|
+
if (event.key !== "Escape" || event.defaultPrevented) return;
|
|
722
|
+
if (splitStore.getSnapshot().focusedSessionId !== sessionId) return;
|
|
723
|
+
splitStore.closeOverlay(sessionId);
|
|
724
|
+
};
|
|
725
|
+
document.addEventListener("keydown", onKeyDown);
|
|
726
|
+
return () => document.removeEventListener("keydown", onKeyDown);
|
|
727
|
+
}, [overlay, sessionId]);
|
|
728
|
+
|
|
729
|
+
return (
|
|
730
|
+
<div
|
|
731
|
+
className={`dsh-split-pane-wrapper ${isDragOver ? "is-drag-over" : ""} ${isHovered ? "is-hovered" : ""} ${currentSummary?.origin === "subagent" || overlay?.kind === "session" ? "is-subagent" : ""}`}
|
|
732
|
+
onDragOver={(event) => {
|
|
733
|
+
if (
|
|
734
|
+
!Array.from(event.dataTransfer.types).includes(
|
|
735
|
+
"application/x-dsh-split-session",
|
|
736
|
+
)
|
|
737
|
+
) {
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
event.preventDefault();
|
|
741
|
+
event.dataTransfer.dropEffect = "move";
|
|
742
|
+
if (!isDragOver) setIsDragOver(true);
|
|
743
|
+
}}
|
|
744
|
+
onDragLeave={(event) => {
|
|
745
|
+
if (event.currentTarget.contains(event.relatedTarget as Node)) {
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
setIsDragOver(false);
|
|
749
|
+
}}
|
|
750
|
+
onDrop={(event) => {
|
|
751
|
+
setIsDragOver(false);
|
|
752
|
+
(event.currentTarget as HTMLElement)
|
|
753
|
+
.closest(".dsh-split-shell")
|
|
754
|
+
?.classList.remove("is-dragging");
|
|
755
|
+
const sourceId = event.dataTransfer.getData(
|
|
756
|
+
"application/x-dsh-split-session",
|
|
757
|
+
) as SessionId;
|
|
758
|
+
if (sourceId) {
|
|
759
|
+
event.preventDefault();
|
|
760
|
+
splitStore.reorderSession(sourceId, sessionId);
|
|
761
|
+
}
|
|
762
|
+
}}
|
|
763
|
+
>
|
|
764
|
+
<SplitPaneHeader
|
|
765
|
+
focused={isFocused}
|
|
766
|
+
status={renderSlot("split.pane.status", {})}
|
|
767
|
+
workspaceTitle={workspaceTitle}
|
|
768
|
+
ancestry={ancestry}
|
|
769
|
+
displayTitle={displayTitle}
|
|
770
|
+
draggable={canDrag}
|
|
771
|
+
onDragStart={(event) => {
|
|
772
|
+
if (
|
|
773
|
+
event.defaultPrevented ||
|
|
774
|
+
(event.target as HTMLElement).closest("button, [role='menu']")
|
|
775
|
+
) {
|
|
776
|
+
event.preventDefault();
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
(event.currentTarget as HTMLElement)
|
|
780
|
+
.closest(".dsh-split-shell")
|
|
781
|
+
?.classList.add("is-dragging");
|
|
782
|
+
event.dataTransfer.setData(
|
|
783
|
+
"application/x-dsh-split-session",
|
|
784
|
+
sessionId,
|
|
785
|
+
);
|
|
786
|
+
event.dataTransfer.effectAllowed = "move";
|
|
787
|
+
}}
|
|
788
|
+
onDragEnd={(event) => {
|
|
789
|
+
setIsDragOver(false);
|
|
790
|
+
(event.currentTarget as HTMLElement)
|
|
791
|
+
.closest(".dsh-split-shell")
|
|
792
|
+
?.classList.remove("is-dragging");
|
|
793
|
+
}}
|
|
794
|
+
onDoubleClick={(event) => {
|
|
795
|
+
if (
|
|
796
|
+
event.defaultPrevented ||
|
|
797
|
+
(event.target as HTMLElement).closest("button")
|
|
798
|
+
) {
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
splitStore.toggleMaximize(sessionId);
|
|
802
|
+
}}
|
|
803
|
+
actions={
|
|
804
|
+
<>
|
|
805
|
+
{renderSlot("split.pane.header.actions", {})}
|
|
806
|
+
{state.sessionIds.length > 1 && (
|
|
807
|
+
<Tooltip
|
|
808
|
+
label={
|
|
809
|
+
isMaximized
|
|
810
|
+
? "Restore split layout"
|
|
811
|
+
: "Maximize pane in split screen"
|
|
812
|
+
}
|
|
813
|
+
portal
|
|
814
|
+
>
|
|
815
|
+
<Button
|
|
816
|
+
variant="ghost"
|
|
817
|
+
size="sm"
|
|
818
|
+
className={`dsh-split-icon-btn dsh-split-maximize-btn ${isMaximized ? "is-pressed" : ""}`}
|
|
819
|
+
aria-label={
|
|
820
|
+
isMaximized
|
|
821
|
+
? "Restore split layout"
|
|
822
|
+
: "Maximize pane in split screen"
|
|
823
|
+
}
|
|
824
|
+
aria-pressed={isMaximized}
|
|
825
|
+
icon={<IconFullscreenOutlineRegular size={14} />}
|
|
826
|
+
onClick={(event) => {
|
|
827
|
+
event.stopPropagation();
|
|
828
|
+
splitStore.toggleMaximize(sessionId);
|
|
829
|
+
}}
|
|
830
|
+
/>
|
|
831
|
+
</Tooltip>
|
|
832
|
+
)}
|
|
833
|
+
<Tooltip label="Open this session in the native view" portal>
|
|
834
|
+
<Button
|
|
835
|
+
variant="ghost"
|
|
836
|
+
size="sm"
|
|
837
|
+
className="dsh-split-icon-btn"
|
|
838
|
+
aria-label="Open this session in the native view"
|
|
839
|
+
icon={<IconRightUpOutlineRegular size={14} />}
|
|
840
|
+
onClick={(event) => {
|
|
841
|
+
event.stopPropagation();
|
|
842
|
+
const targetSessionId =
|
|
843
|
+
overlay?.kind === "session"
|
|
844
|
+
? typeof overlay.target === "string"
|
|
845
|
+
? overlay.target
|
|
846
|
+
: overlay.target.childSessionId
|
|
847
|
+
: sessionId;
|
|
848
|
+
splitStore.suspend(targetSessionId);
|
|
849
|
+
}}
|
|
850
|
+
/>
|
|
851
|
+
</Tooltip>
|
|
852
|
+
<Tooltip label="Close pane" portal>
|
|
853
|
+
<Button
|
|
854
|
+
variant="ghost"
|
|
855
|
+
size="sm"
|
|
856
|
+
className="dsh-split-icon-btn dsh-split-pane-close"
|
|
857
|
+
aria-label="Close pane"
|
|
858
|
+
icon={<IconCloseOutlineRegular size={14} />}
|
|
859
|
+
onClick={(event) => {
|
|
860
|
+
event.stopPropagation();
|
|
861
|
+
splitStore.removeSession(sessionId);
|
|
862
|
+
}}
|
|
863
|
+
/>
|
|
864
|
+
</Tooltip>
|
|
865
|
+
</>
|
|
866
|
+
}
|
|
867
|
+
>
|
|
868
|
+
{subagents.length > 0 && (
|
|
869
|
+
<Menu
|
|
870
|
+
open={subagentMenuOpen}
|
|
871
|
+
portal
|
|
872
|
+
compact
|
|
873
|
+
align="start"
|
|
874
|
+
onClose={() => setSubagentMenuOpen(false)}
|
|
875
|
+
onSelect={(id) => {
|
|
876
|
+
setSubagentMenuOpen(false);
|
|
877
|
+
const target = subagents.find((item) => item.id === id);
|
|
878
|
+
const targetTitle = target?.displayTitle || "Untitled Task";
|
|
879
|
+
splitStore.openSessionOverlay(
|
|
880
|
+
sessionId,
|
|
881
|
+
id as SessionId,
|
|
882
|
+
`Subagent: ${targetTitle}`,
|
|
883
|
+
);
|
|
884
|
+
}}
|
|
885
|
+
items={subagents.map((item) => {
|
|
886
|
+
const running = isSubagentRunning(item);
|
|
887
|
+
return {
|
|
888
|
+
id: item.id,
|
|
889
|
+
icon: renderSlot("split.subagent.status", {
|
|
890
|
+
state: running ? "active" : "review",
|
|
891
|
+
}),
|
|
892
|
+
label: (
|
|
893
|
+
<span className="dsh-split-subagent-menu-item">
|
|
894
|
+
<span
|
|
895
|
+
className="dsh-split-subagent-menu-title"
|
|
896
|
+
title={item.displayTitle}
|
|
897
|
+
>
|
|
898
|
+
{item.displayTitle || "Untitled Subagent"}
|
|
899
|
+
</span>
|
|
900
|
+
<span className="dsh-split-subagent-menu-status">
|
|
901
|
+
{running ? "Running" : "Finished"}
|
|
902
|
+
</span>
|
|
903
|
+
</span>
|
|
904
|
+
),
|
|
905
|
+
};
|
|
906
|
+
})}
|
|
907
|
+
anchor={
|
|
908
|
+
<Button
|
|
909
|
+
variant="ghost"
|
|
910
|
+
size="sm"
|
|
911
|
+
className={`dsh-split-subagent-pill ${subagentMenuOpen ? "is-active" : ""}`}
|
|
912
|
+
title={subagentPillTooltip}
|
|
913
|
+
aria-haspopup="menu"
|
|
914
|
+
aria-expanded={subagentMenuOpen}
|
|
915
|
+
onClick={(event) => {
|
|
916
|
+
event.stopPropagation();
|
|
917
|
+
setSubagentMenuOpen((open) => !open);
|
|
918
|
+
}}
|
|
919
|
+
>
|
|
920
|
+
{renderSlot("split.subagent.status", {
|
|
921
|
+
state: hasRunningSubagents ? "active" : "review",
|
|
922
|
+
})}
|
|
923
|
+
<span className="dsh-split-subagent-text">
|
|
924
|
+
{subagentPillLabel}
|
|
925
|
+
</span>
|
|
926
|
+
<IconChevronDownOutlineRegular size={12} />
|
|
927
|
+
</Button>
|
|
928
|
+
}
|
|
929
|
+
/>
|
|
930
|
+
)}
|
|
931
|
+
</SplitPaneHeader>
|
|
932
|
+
{overlay !== undefined && (
|
|
933
|
+
<div className="dsh-split-overlay-tab">
|
|
934
|
+
{overlay.kind === "file" ? (
|
|
935
|
+
<PathLabel
|
|
936
|
+
path={overlay.fullPath ?? overlay.path}
|
|
937
|
+
className="dsh-split-overlay-tab-path"
|
|
938
|
+
/>
|
|
939
|
+
) : (
|
|
940
|
+
<span className="dsh-split-overlay-tab-title" title={overlay.title}>
|
|
941
|
+
{overlay.title}
|
|
942
|
+
</span>
|
|
943
|
+
)}
|
|
944
|
+
{overlay.kind === "file" &&
|
|
945
|
+
previewKindOf(overlay.path) !== "image" && (
|
|
946
|
+
<CopyContentsButton contents={overlay.contents} />
|
|
947
|
+
)}
|
|
948
|
+
<button
|
|
949
|
+
type="button"
|
|
950
|
+
className="dsh-split-overlay-close"
|
|
951
|
+
title="Close"
|
|
952
|
+
aria-label="Close overlay"
|
|
953
|
+
onClick={(event) => {
|
|
954
|
+
event.stopPropagation();
|
|
955
|
+
splitStore.closeOverlay(sessionId);
|
|
956
|
+
}}
|
|
957
|
+
>
|
|
958
|
+
<IconCloseOutlineRegular size={14} />
|
|
959
|
+
</button>
|
|
960
|
+
</div>
|
|
961
|
+
)}
|
|
962
|
+
<div className="dsh-split-pane-body" data-phase={phase}>
|
|
963
|
+
<SplitOverlayHostContext.Provider value={overlayHostValue}>
|
|
964
|
+
{overlay === undefined ? (
|
|
965
|
+
renderFactorySlot("conversation.content", {
|
|
966
|
+
variant: "embedded",
|
|
967
|
+
phase,
|
|
968
|
+
hero,
|
|
969
|
+
})
|
|
970
|
+
) : overlay.kind === "session" ? (
|
|
971
|
+
<SessionProvider session={overlay.reference}>
|
|
972
|
+
{renderSlot("split.overlay", { hostSessionId: sessionId })}
|
|
973
|
+
</SessionProvider>
|
|
974
|
+
) : (
|
|
975
|
+
renderFactorySlot(
|
|
976
|
+
"conversation.content",
|
|
977
|
+
{
|
|
978
|
+
variant: "embedded",
|
|
979
|
+
phase,
|
|
980
|
+
hero,
|
|
981
|
+
},
|
|
982
|
+
SPLIT_OVERLAY_CONVERSATION_OPTIONS,
|
|
983
|
+
)
|
|
984
|
+
)}
|
|
985
|
+
</SplitOverlayHostContext.Provider>
|
|
986
|
+
</div>
|
|
987
|
+
</div>
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* Purpose: Root-scoped main panel rendering N equal-width vertical splits.
|
|
993
|
+
* Contract:
|
|
994
|
+
* - Inputs: SessionProvider and renderSlot from PropsRenderSlots.
|
|
995
|
+
* - Outputs: Equal-width flexbox container with focused pane border.
|
|
996
|
+
*/
|
|
997
|
+
export function SplitView({
|
|
998
|
+
SessionProvider,
|
|
999
|
+
renderSlot,
|
|
1000
|
+
}: PropsRuntime<"main", "split-view"> & PropsRenderSlots<"split.pane">) {
|
|
1001
|
+
const { sessionIds, focusedSessionId, maximizedSessionId } =
|
|
1002
|
+
useSyncExternalStore(splitStore.subscribe, splitStore.getSnapshot);
|
|
1003
|
+
|
|
1004
|
+
useEffect(
|
|
1005
|
+
() => () => {
|
|
1006
|
+
const { maximizedSessionId } = splitStore.getSnapshot();
|
|
1007
|
+
if (maximizedSessionId !== undefined) {
|
|
1008
|
+
splitStore.toggleMaximize(maximizedSessionId);
|
|
1009
|
+
}
|
|
1010
|
+
},
|
|
1011
|
+
[],
|
|
1012
|
+
);
|
|
1013
|
+
|
|
1014
|
+
const activeFocusedId =
|
|
1015
|
+
focusedSessionId !== undefined && sessionIds.includes(focusedSessionId)
|
|
1016
|
+
? focusedSessionId
|
|
1017
|
+
: sessionIds[0];
|
|
1018
|
+
|
|
1019
|
+
return (
|
|
1020
|
+
<SplitLayout sessionIds={sessionIds}>
|
|
1021
|
+
{sessionIds.map((id) => {
|
|
1022
|
+
const ref = splitStore.getReference(id);
|
|
1023
|
+
if (ref === undefined) return null;
|
|
1024
|
+
const isFocused = id === activeFocusedId;
|
|
1025
|
+
const isHidden =
|
|
1026
|
+
maximizedSessionId !== undefined &&
|
|
1027
|
+
maximizedSessionId !== id &&
|
|
1028
|
+
sessionIds.includes(maximizedSessionId);
|
|
1029
|
+
return (
|
|
1030
|
+
<div
|
|
1031
|
+
key={id}
|
|
1032
|
+
data-split-pane={id}
|
|
1033
|
+
className={`dsh-split-col ${isFocused ? "is-focused" : ""}`}
|
|
1034
|
+
style={isHidden ? { display: "none" } : undefined}
|
|
1035
|
+
onPointerDownCapture={() => {
|
|
1036
|
+
splitStore.setFocus(id);
|
|
1037
|
+
splitStore.setPointerOrigin(id);
|
|
1038
|
+
}}
|
|
1039
|
+
onFocusCapture={() => {
|
|
1040
|
+
splitStore.setFocus(id);
|
|
1041
|
+
splitStore.setPointerOrigin(id);
|
|
1042
|
+
}}
|
|
1043
|
+
>
|
|
1044
|
+
<SessionProvider session={ref}>
|
|
1045
|
+
{renderSlot("split.pane", {})}
|
|
1046
|
+
</SessionProvider>
|
|
1047
|
+
</div>
|
|
1048
|
+
);
|
|
1049
|
+
})}
|
|
1050
|
+
</SplitLayout>
|
|
1051
|
+
);
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
/** Header utility that returns from a suspended native view to the retained split. */
|
|
1055
|
+
export function SplitRestoreHeaderAction(
|
|
1056
|
+
_props?: Partial<PropsRuntime<"conversation.session.header.utilities">>,
|
|
1057
|
+
) {
|
|
1058
|
+
const { suspended } = useSyncExternalStore(
|
|
1059
|
+
splitStore.subscribe,
|
|
1060
|
+
splitStore.getSnapshot,
|
|
1061
|
+
);
|
|
1062
|
+
if (!suspended) return null;
|
|
1063
|
+
return (
|
|
1064
|
+
<Button
|
|
1065
|
+
variant="primary"
|
|
1066
|
+
size="sm"
|
|
1067
|
+
className="dsh-split-restore-btn"
|
|
1068
|
+
icon={<IconCompareSplitOutlineRegular size={16} />}
|
|
1069
|
+
title="Back to split view"
|
|
1070
|
+
aria-label="Back to split view"
|
|
1071
|
+
onClick={() => splitStore.resume()}
|
|
1072
|
+
>
|
|
1073
|
+
Back to split
|
|
1074
|
+
</Button>
|
|
1075
|
+
);
|
|
1076
|
+
}
|