@lukstei/dsh-client-split-view 0.0.0-stage → 0.2.2-rc.5.4

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.
@@ -0,0 +1,79 @@
1
+ import type { SessionId } from "@deepseek-ai/dsh-session/types";
2
+ import type { HTMLAttributes, ReactNode } from "react";
3
+
4
+ /** Presentational pane chrome shared by the live session controller and Ladle. */
5
+ export function SplitPaneHeader({
6
+ focused,
7
+ status,
8
+ workspaceTitle,
9
+ ancestry,
10
+ displayTitle,
11
+ children,
12
+ actions,
13
+ ...events
14
+ }: Pick<
15
+ HTMLAttributes<HTMLElement>,
16
+ "draggable" | "onDragStart" | "onDragEnd" | "onDoubleClick"
17
+ > & {
18
+ focused: boolean;
19
+ status: ReactNode;
20
+ workspaceTitle: string | undefined;
21
+ ancestry: readonly {
22
+ id: SessionId;
23
+ displayTitle: string;
24
+ subagent: boolean;
25
+ }[];
26
+ displayTitle: string;
27
+ children: ReactNode;
28
+ actions: ReactNode;
29
+ }) {
30
+ return (
31
+ <header
32
+ {...events}
33
+ className={`dsh-split-pane-header ${focused ? "is-focused" : ""}`}
34
+ >
35
+ <span className="dsh-split-pane-status">{status}</span>
36
+ <div className="dsh-split-header-left">
37
+ <nav className="dsh-split-crumbs" aria-label="Session hierarchy">
38
+ {workspaceTitle !== undefined && (
39
+ <span className="dsh-split-crumb-seg is-workspace">
40
+ <span
41
+ className="dsh-split-crumb is-workspace"
42
+ title={workspaceTitle}
43
+ >
44
+ {workspaceTitle}
45
+ </span>
46
+ <span className="dsh-split-crumb-sep" aria-hidden="true">
47
+ /
48
+ </span>
49
+ </span>
50
+ )}
51
+ {ancestry.map((summary, index) => {
52
+ const isLast = index === ancestry.length - 1;
53
+ const crumbTitle = summary.subagent
54
+ ? `Subagent: ${summary.displayTitle}`
55
+ : summary.displayTitle;
56
+ return (
57
+ <span key={summary.id} className="dsh-split-crumb-seg">
58
+ {index > 0 && <span className="dsh-split-crumb-sep">/</span>}
59
+ <span
60
+ className={`dsh-split-crumb ${isLast ? "is-current" : "is-parent"} ${summary.subagent ? "is-subagent" : ""}`}
61
+ title={crumbTitle}
62
+ >
63
+ {crumbTitle}
64
+ </span>
65
+ </span>
66
+ );
67
+ })}
68
+ {ancestry.length === 0 && (
69
+ <span className="dsh-split-crumb is-current" title={displayTitle}>
70
+ {displayTitle}
71
+ </span>
72
+ )}
73
+ </nav>
74
+ <div className="dsh-split-header-actions">{actions}</div>
75
+ </div>
76
+ {children}
77
+ </header>
78
+ );
79
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Purpose: Publish the reusable Split View contract and Cordis augmentations.
3
+ * Contract:
4
+ * - Types and interfaces for split view state, overlays, and service.
5
+ */
6
+ import type {
7
+ SessionReference,
8
+ SessionTarget,
9
+ } from "@deepseek-ai/dsh-api-session-controller/client";
10
+ import type { SlotFactoryMap } from "@deepseek-ai/dsh-client-ui-slots";
11
+ import type { SessionId } from "@deepseek-ai/dsh-session/types";
12
+
13
+ type FactoryProps<F extends keyof SlotFactoryMap & string> =
14
+ SlotFactoryMap[F] extends { props: infer P extends object } ? P : object;
15
+
16
+ type FactoryOverlay = {
17
+ [F in keyof SlotFactoryMap & string]: {
18
+ readonly kind: "slot";
19
+ readonly slotName: F;
20
+ readonly title: string;
21
+ readonly props: FactoryProps<F>;
22
+ };
23
+ }[keyof SlotFactoryMap & string];
24
+
25
+ export type SplitOverlay =
26
+ | {
27
+ readonly kind: "session";
28
+ readonly target: SessionTarget;
29
+ readonly title: string;
30
+ readonly reference: SessionReference;
31
+ }
32
+ | FactoryOverlay
33
+ | {
34
+ readonly kind: "file";
35
+ readonly address: string;
36
+ readonly ownerSessionId: SessionId;
37
+ readonly path: string;
38
+ readonly title: string;
39
+ readonly fullPath?: string;
40
+ /** Complete text of a text/markdown file; set only once every page has loaded. */
41
+ readonly contents?: string;
42
+ };
43
+
44
+ export interface SplitState {
45
+ readonly sessionIds: readonly SessionId[];
46
+ readonly focusedSessionId: SessionId | undefined;
47
+ readonly maximizedSessionId: SessionId | undefined;
48
+ /** Pane highlighted because its sidebar row is hovered; transient, never persisted. */
49
+ readonly hoveredSessionId: SessionId | undefined;
50
+ readonly suspended: boolean;
51
+ readonly overlays: ReadonlyMap<SessionId, SplitOverlay>;
52
+ }
53
+
54
+ export interface ISplitView {
55
+ setFallbackPanelId(id: string | null): void;
56
+ openSlotOverlay<F extends keyof SlotFactoryMap & string>(
57
+ hostId: SessionId,
58
+ slotName: F,
59
+ title: string,
60
+ props: NoInfer<FactoryProps<F>>,
61
+ ): void;
62
+ closeOverlay(hostId: SessionId): void;
63
+ readonly getSnapshot: () => SplitState;
64
+ readonly subscribe: (listener: () => void) => () => void;
65
+ readonly isSuspended: () => boolean;
66
+ readonly isSplitActive: () => boolean;
67
+ readonly toggleSession: (targetId: SessionId) => void;
68
+ readonly openSession: (targetId: SessionId) => void;
69
+ readonly removeSession: (targetId: SessionId) => void;
70
+ readonly resetToSingle: () => void;
71
+ readonly suspend: (targetId: SessionId) => void;
72
+ readonly resume: () => void;
73
+ readonly setFocus: (id: SessionId) => void;
74
+ readonly toggleMaximize: (sessionId: SessionId) => void;
75
+ readonly setHoveredSession: (targetId: SessionId | undefined) => void;
76
+ readonly reorderSession: (sourceId: SessionId, targetId: SessionId) => void;
77
+ }
78
+
79
+ declare module "@deepseek-ai/cordis" {
80
+ interface Context {
81
+ splitView: ISplitView;
82
+ }
83
+ }
84
+
85
+ declare module "@deepseek-ai/dsh-api-session-controller/client" {
86
+ interface SessionReferenceSourceMap {
87
+ splitView: unknown;
88
+ }
89
+ }
90
+
91
+ declare module "@deepseek-ai/dsh-client-ui-slots" {
92
+ interface SlotMap {
93
+ "split.pane": { kind: "single"; scope: "session" };
94
+ "split.pane.header.actions": { kind: "list"; scope: "session" };
95
+ "split.pane.status": {
96
+ kind: "single";
97
+ scope: "session";
98
+ };
99
+ "split.subagent.status": {
100
+ kind: "single";
101
+ scope: "session";
102
+ owner: { state: "active" | "review" };
103
+ };
104
+ "split.overlay": {
105
+ kind: "single";
106
+ scope: "session";
107
+ owner: {
108
+ hostSessionId: SessionId;
109
+ };
110
+ };
111
+ }
112
+ }
@@ -0,0 +1,5 @@
1
+ declare module "*.module.css" {
2
+ const classes: Record<string, string>;
3
+ export const cssText: string;
4
+ export default classes;
5
+ }
@@ -0,0 +1,18 @@
1
+ /** Ambient runtime type augmentations for DSH Split View. */
2
+ import type {} from "@deepseek-ai/dsh-api-workspace-controller/client";
3
+ import type {} from "@deepseek-ai/dsh-client-ui-chat/client";
4
+ import type {} from "@deepseek-ai/dsh-client-ui-conversation/client";
5
+ import type {} from "@deepseek-ai/dsh-client-ui-layout/client";
6
+ import type {} from "@deepseek-ai/dsh-client-ui-renderer/client";
7
+ import type {} from "@deepseek-ai/dsh-client-ui-session/client";
8
+ import type {} from "@deepseek-ai/dsh-client-ui-sidebar/client";
9
+ import type {} from "@deepseek-ai/dsh-client-ui-sidebar-right/client";
10
+ import type {} from "@deepseek-ai/dsh-client-ui-workspace/client";
11
+ import type {} from "./contract.ts";
12
+
13
+ export type {
14
+ IWorkspaces,
15
+ WorkspaceId,
16
+ WorkspaceSnapshot,
17
+ WorkspaceView,
18
+ } from "@deepseek-ai/dsh-api-workspace-controller/client";
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Purpose: Classify a workspace file path for the split pane's inline preview.
3
+ * Contract:
4
+ * - Inputs: one workspace file path in POSIX or Windows spelling.
5
+ * - Outputs: preview kind and displayable image MIME type.
6
+ * - Errors: never throws; unknown extensions classify as plain text.
7
+ */
8
+
9
+ const MARKDOWN_EXTENSIONS: ReadonlySet<string> = new Set([
10
+ "md",
11
+ "markdown",
12
+ "mdx",
13
+ ]);
14
+
15
+ const IMAGE_MIME_TYPES: Readonly<Record<string, string>> = {
16
+ png: "image/png",
17
+ jpg: "image/jpeg",
18
+ jpeg: "image/jpeg",
19
+ gif: "image/gif",
20
+ webp: "image/webp",
21
+ avif: "image/avif",
22
+ bmp: "image/bmp",
23
+ svg: "image/svg+xml",
24
+ };
25
+
26
+ /**
27
+ * Purpose: Read the lowercased extension from a path's final segment.
28
+ * Contract:
29
+ * - Inputs: one POSIX or Windows path.
30
+ * - Outputs: extension without the dot; empty for dotfiles, bare names, and trailing separators.
31
+ * - Errors: never throws.
32
+ * @internal
33
+ */
34
+ export function extensionOf(path: string): string {
35
+ const separator = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
36
+ const name = path.slice(separator + 1);
37
+ const dot = name.lastIndexOf(".");
38
+ return dot <= 0 ? "" : name.slice(dot + 1).toLowerCase();
39
+ }
40
+
41
+ /**
42
+ * Purpose: Map one path to a displayable image MIME type.
43
+ * Contract:
44
+ * - Inputs: one POSIX or Windows path.
45
+ * - Outputs: the MIME type for known image extensions, otherwise `undefined`.
46
+ * - Errors: never throws.
47
+ */
48
+ export function imageMimeTypeOf(path: string): string | undefined {
49
+ return IMAGE_MIME_TYPES[extensionOf(path)];
50
+ }
51
+
52
+ /** How the pane previews one file: rendered Markdown, an image, or plain text. */
53
+ export type PreviewKind = "markdown" | "image" | "text";
54
+
55
+ /**
56
+ * Purpose: Classify one path into the pane preview strategy.
57
+ * Contract:
58
+ * - Inputs: one POSIX or Windows path.
59
+ * - Outputs: `markdown` for Markdown documents, `image` for displayable images, otherwise `text`.
60
+ * - Errors: never throws.
61
+ */
62
+ export function previewKindOf(path: string): PreviewKind {
63
+ const extension = extensionOf(path);
64
+ if (MARKDOWN_EXTENSIONS.has(extension)) return "markdown";
65
+ if (IMAGE_MIME_TYPES[extension] !== undefined) return "image";
66
+ return "text";
67
+ }
@@ -0,0 +1,267 @@
1
+ /** Client plugin entrypoint for DSH Split View. */
2
+ import type { Context as ClientContext } from "@deepseek-ai/cordis";
3
+ import type {} from "@deepseek-ai/dsh-api-gateway/client";
4
+ import type { SessionTarget } from "@deepseek-ai/dsh-api-session-controller/client";
5
+ import type {} from "@deepseek-ai/dsh-api-workspace-files/remote";
6
+ import { SessionId } from "@deepseek-ai/dsh-session/types";
7
+ import {
8
+ parseFileAddress,
9
+ workspaceTitleOf,
10
+ } from "@deepseek-ai/dsh-util-workspace-path";
11
+ import "./contract.ts";
12
+ import "./dsh.d.ts";
13
+ import {
14
+ SplitOverlayContent,
15
+ type SplitOverlayServices,
16
+ SplitPaneContent,
17
+ SplitRestoreHeaderAction,
18
+ SplitView,
19
+ } from "./SplitPane.tsx";
20
+ import { splitStore } from "./split-store.ts";
21
+ import { registerSplitStyles } from "./styles.ts";
22
+
23
+ export type { ISplitView, SplitOverlay, SplitState } from "./contract.ts";
24
+ export { SplitStore, splitStore } from "./split-store.ts";
25
+
26
+ export const name = "dsh-client-split-view";
27
+
28
+ export const inject = [
29
+ "slots",
30
+ "sessions",
31
+ "uiWorkspace",
32
+ "uiSession",
33
+ "layout",
34
+ "remote",
35
+ "sidebarRight",
36
+ "remote.workspaceFiles",
37
+ ] as const;
38
+
39
+ export function apply(ctx: ClientContext): void {
40
+ const sessions = ctx.sessions;
41
+
42
+ const getActiveSessionId = (): SessionId | undefined => {
43
+ if (ctx.layout.panelInfo.getSnapshot().activePanelId !== null) {
44
+ return undefined;
45
+ }
46
+ const list = sessions.list.getSnapshot();
47
+ return list.ids.find((id) => (list.byId[id]?.retainedBy.mainView ?? 0) > 0);
48
+ };
49
+
50
+ splitStore.setCallbacks(
51
+ (id) => ctx.layout.selectPanel(id as never),
52
+ (id) => ctx.uiWorkspace.openSession(id),
53
+ () => ctx.sessions,
54
+ getActiveSessionId,
55
+ );
56
+
57
+ ctx.provide("splitView", splitStore);
58
+
59
+ // Services the pane overlay occupant needs from the plugin's Host-facing scope
60
+ const cachedOverlayServices: SplitOverlayServices = {
61
+ readFile: (sessionId, path, offset, signal) =>
62
+ ctx.remote.workspaceFiles.read(sessionId, path, { offset }, signal),
63
+ readBytes: (sessionId, path, signal) =>
64
+ ctx.remote.workspaceFiles.readBytes(sessionId, path, {}, signal),
65
+ openNativeResource: (address) => {
66
+ ctx.sidebarRight.openResource(address);
67
+ },
68
+ };
69
+ const overlayServices = (): SplitOverlayServices => cachedOverlayServices;
70
+
71
+ // Register split main panel view, its pane content, and the pane overlay occupant.
72
+ // Registration precedes hydration: a re-applied fiber restores a ready session
73
+ // list synchronously, and selecting the panel before it exists throws.
74
+ ctx.effect(() => {
75
+ return ctx.slots.inject("main", () => {
76
+ const unregisterMain = ctx.slots.register(
77
+ {
78
+ name: "main",
79
+ key: "split-view",
80
+ children: {
81
+ "split.pane": { kind: "single", scope: "session" },
82
+ },
83
+ },
84
+ SplitView,
85
+ );
86
+ const unregisterPane = ctx.slots.register(
87
+ {
88
+ name: "split.pane",
89
+ children: {
90
+ "split.overlay": { kind: "single", scope: "session" },
91
+ "split.pane.status": { kind: "single", scope: "session" },
92
+ "split.pane.header.actions": { kind: "list", scope: "session" },
93
+ "split.subagent.status": { kind: "single", scope: "session" },
94
+ },
95
+ },
96
+ SplitPaneContent,
97
+ );
98
+ const unregisterOverlay = ctx.slots.register(
99
+ {
100
+ name: "split.overlay",
101
+ inject: overlayServices,
102
+ },
103
+ SplitOverlayContent,
104
+ );
105
+ return () => {
106
+ unregisterOverlay();
107
+ unregisterPane();
108
+ unregisterMain();
109
+ };
110
+ });
111
+ }, "split-view: main view");
112
+
113
+ // Hydrate persisted split view state once session list becomes ready
114
+ ctx.effect(() => {
115
+ let hydrated = false;
116
+ const attemptHydration = () => {
117
+ if (hydrated) return;
118
+ const snapshot = sessions.list.getSnapshot();
119
+ if (snapshot.phase !== "ready") return;
120
+ hydrated = true;
121
+ splitStore.hydrate(ctx.sessions);
122
+ };
123
+ attemptHydration();
124
+ return sessions.list.subscribe(attemptHydration);
125
+ }, "split-view: hydrate on session readiness");
126
+
127
+ ctx.effect(
128
+ () => () => {
129
+ splitStore.dispose();
130
+ },
131
+ "split-view: store lifecycle",
132
+ );
133
+
134
+ ctx.effect(
135
+ () => registerSplitStyles(ctx, "dsh-client-split-view"),
136
+ "split-view: styles",
137
+ );
138
+
139
+ // Route pane-originated navigation into pane overlays instead of the Sidebar
140
+ ctx.effect(() => {
141
+ const uiWorkspace = ctx.uiWorkspace;
142
+ const sidebarRight = ctx.sidebarRight;
143
+ const originalOpenSession = uiWorkspace.openSession;
144
+ const originalStartSession = uiWorkspace.startSession;
145
+ const originalOpenResource = sidebarRight.openResource;
146
+ const splitHost = (): SessionId | undefined => {
147
+ if (splitStore.isSuspended()) return undefined;
148
+ const activePanelId = ctx.layout.panelInfo.getSnapshot().activePanelId;
149
+ if (activePanelId !== "split-view") {
150
+ return undefined;
151
+ }
152
+ const origin = splitStore.getPointerOrigin();
153
+ if (origin === undefined) return undefined;
154
+ return splitStore.getSnapshot().sessionIds.includes(origin)
155
+ ? origin
156
+ : undefined;
157
+ };
158
+
159
+ uiWorkspace.openSession = (target: SessionTarget) => {
160
+ const hostId = splitHost();
161
+ if (hostId !== undefined) {
162
+ const targetId =
163
+ typeof target === "string" ? target : target.childSessionId;
164
+ const title =
165
+ sessions.list.getSnapshot().byId[targetId]?.displayTitle ||
166
+ "Untitled Task";
167
+ splitStore.openSessionOverlay(hostId, target, title, sessions);
168
+ return;
169
+ }
170
+ originalOpenSession.call(uiWorkspace, target);
171
+ };
172
+
173
+ uiWorkspace.startSession = (
174
+ workspaceId?: Parameters<typeof originalStartSession>[0],
175
+ options?: Parameters<typeof originalStartSession>[1],
176
+ ) => {
177
+ const activePanelId = ctx.layout.panelInfo.getSnapshot().activePanelId;
178
+ if (activePanelId !== "split-view" || splitStore.isSuspended()) {
179
+ originalStartSession.call(uiWorkspace, workspaceId, options);
180
+ return;
181
+ }
182
+ void sessions
183
+ .create({
184
+ // edge case: nominal WorkspaceId brand differs across nested packages in node_modules
185
+ ...(workspaceId
186
+ ? {
187
+ workspaceId: workspaceId as unknown as NonNullable<
188
+ Parameters<typeof sessions.create>[0]
189
+ >["workspaceId"],
190
+ }
191
+ : undefined),
192
+ ...options,
193
+ })
194
+ .then((newId) => {
195
+ splitStore.toggleSession(newId);
196
+ });
197
+ };
198
+
199
+ sidebarRight.openResource = (address, options) => {
200
+ const hostId = splitHost();
201
+ if (hostId !== undefined) {
202
+ const parsed = parseFileAddress(address);
203
+ if (parsed !== undefined) {
204
+ const isAbsolute =
205
+ parsed.scope === "absolute" ||
206
+ parsed.path.startsWith("/") ||
207
+ /^[A-Za-z]:[\\/]/.test(parsed.path);
208
+ splitStore.openFileOverlay(hostId, {
209
+ address,
210
+ ownerSessionId:
211
+ parsed.scope === "session" ? SessionId(parsed.sessionId) : hostId,
212
+ path: parsed.path,
213
+ title: workspaceTitleOf(parsed.path) || "File",
214
+ fullPath: isAbsolute ? parsed.path : undefined,
215
+ });
216
+ return;
217
+ }
218
+ }
219
+ originalOpenResource.call(sidebarRight, address, options);
220
+ };
221
+
222
+ // A pointer or focus interaction outside every pane ends the pane origin
223
+ const forgetOrigin = (event: Event) => {
224
+ const target = event.target;
225
+ if (
226
+ target instanceof Element &&
227
+ (target.closest("[data-split-pane]") !== null ||
228
+ target.closest(
229
+ "[role='menu'], [role='dialog'], [data-radix-popper-content-wrapper]",
230
+ ) !== null)
231
+ ) {
232
+ return;
233
+ }
234
+ splitStore.clearPointerOrigin();
235
+ };
236
+ if (typeof document !== "undefined") {
237
+ document.addEventListener("pointerdown", forgetOrigin, true);
238
+ document.addEventListener("focusin", forgetOrigin, true);
239
+ }
240
+
241
+ return () => {
242
+ uiWorkspace.openSession = originalOpenSession;
243
+ uiWorkspace.startSession = originalStartSession;
244
+ sidebarRight.openResource = originalOpenResource;
245
+ if (typeof document !== "undefined") {
246
+ document.removeEventListener("pointerdown", forgetOrigin, true);
247
+ document.removeEventListener("focusin", forgetOrigin, true);
248
+ }
249
+ };
250
+ }, "split-view: navigation");
251
+
252
+ // Register split main panel view, its pane content, and the pane overlay occupant
253
+ ctx.effect(
254
+ () =>
255
+ ctx.slots.inject("conversation.session.header.utilities", () =>
256
+ ctx.slots.register(
257
+ {
258
+ name: "conversation.session.header.utilities",
259
+ id: "split-view-restore",
260
+ order: 100,
261
+ },
262
+ SplitRestoreHeaderAction,
263
+ ),
264
+ ),
265
+ "split-view: restore control",
266
+ );
267
+ }