MCPcopy Create free account
hub / github.com/Gan-Xing/CodexBridge / WorkspaceShell

Function WorkspaceShell

apps/web/components/workspace-shell.tsx:14–86  ·  view source on GitHub ↗
({
  children,
  contextPanel,
  onSidebarWidthChange,
  sidebar,
  sidebarOpen,
  sidebarWidth,
}: WorkspaceShellProps)

Source from the content-addressed store, hash-verified

12};
13
14export function WorkspaceShell({
15 children,
16 contextPanel,
17 onSidebarWidthChange,
18 sidebar,
19 sidebarOpen,
20 sidebarWidth,
21}: WorkspaceShellProps) {
22 const resizeOriginRef = useRef<{ pointerId: number; startX: number; startWidth: number } | null>(null);
23
24 useEffect(() => {
25 function handlePointerMove(event: PointerEvent | globalThis.PointerEvent) {
26 const origin = resizeOriginRef.current;
27 if (!origin) {
28 return;
29 }
30 const delta = event.clientX - origin.startX;
31 onSidebarWidthChange(origin.startWidth + delta);
32 }
33
34 function handlePointerUp(event: globalThis.PointerEvent) {
35 const origin = resizeOriginRef.current;
36 if (!origin || event.pointerId !== origin.pointerId) {
37 return;
38 }
39 resizeOriginRef.current = null;
40 document.body.classList.remove('workspace-resizing');
41 }
42
43 window.addEventListener('pointermove', handlePointerMove);
44 window.addEventListener('pointerup', handlePointerUp);
45 return () => {
46 document.body.classList.remove('workspace-resizing');
47 window.removeEventListener('pointermove', handlePointerMove);
48 window.removeEventListener('pointerup', handlePointerUp);
49 };
50 }, [onSidebarWidthChange]);
51
52 function handleResizeStart(event: PointerEvent<HTMLButtonElement>) {
53 resizeOriginRef.current = {
54 pointerId: event.pointerId,
55 startX: event.clientX,
56 startWidth: sidebarWidth,
57 };
58 document.body.classList.add('workspace-resizing');
59 event.currentTarget.setPointerCapture(event.pointerId);
60 }
61
62 return (
63 <section
64 className={`workspace-shell${sidebarOpen ? ' sidebar-open' : ' sidebar-closed'}${contextPanel ? ' has-context-panel' : ''}`}
65 style={{ ['--sidebar-width' as string]: `${sidebarWidth}px` }}
66 >
67 <div className="workspace-shell-body">
68 <div className="workspace-shell-sidebar">{sidebar}</div>
69 {sidebarOpen ? (
70 <button
71 aria-label="调整目录宽度"

Callers

nothing calls this directly

Calls 1

removeMethod · 0.65

Tested by

no test coverage detected