Skip to content

Commit b4419e4

Browse files
committed
feat(panel): new panel layout
1 parent ef87124 commit b4419e4

File tree

20 files changed

+719
-926
lines changed

20 files changed

+719
-926
lines changed

apps/sim/app/globals.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@
1919
--sidebar-width: 232px;
2020
--triggers-height: 200px;
2121
--blocks-height: 200px;
22+
--panel-width: 232px;
2223
}
2324

2425
.sidebar-container {
2526
width: var(--sidebar-width);
2627
}
2728

29+
.panel-container {
30+
width: var(--panel-width);
31+
}
32+
2833
.triggers-container {
2934
height: var(--triggers-height);
3035
}

apps/sim/app/layout.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ export default function RootLayout({ children }: { children: React.ReactNode })
9090
} catch (e) {
9191
// Fallback handled by CSS defaults
9292
}
93+
94+
// Set panel width
95+
try {
96+
var panelStored = localStorage.getItem('panel-state');
97+
if (panelStored) {
98+
var panelParsed = JSON.parse(panelStored);
99+
var panelState = panelParsed?.state;
100+
var panelWidth = panelState?.panelWidth;
101+
if (panelWidth >= 232 && panelWidth <= 400) {
102+
document.documentElement.style.setProperty('--panel-width', panelWidth + 'px');
103+
}
104+
}
105+
} catch (e) {
106+
// Fallback handled by CSS defaults
107+
}
93108
})();
94109
`,
95110
}}

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/control-bar/control-bar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,8 @@ export function ControlBar({ hasValidationErrors = false }: ControlBarProps) {
788788

789789
setIsAutoLayouting(true)
790790
try {
791-
// Use the shared auto layout utility for immediate frontend updates
792-
const { applyAutoLayoutAndUpdateStore } = await import('../../utils/auto-layout')
791+
// Use the standalone auto layout utility for immediate frontend updates
792+
const { applyAutoLayoutAndUpdateStore } = await import('../../utils')
793793

794794
const result = await applyAutoLayoutAndUpdateStore(activeWorkflowId!)
795795

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/copilot/copilot.tsx

Whitespace-only changes.

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/design/design.tsx

Whitespace-only changes.

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/index.ts

Whitespace-only changes.

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/variables/variables.tsx

Whitespace-only changes.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { useCallback, useEffect, useState } from 'react'
2+
import { usePanelStore } from '@/stores/panel-new/store'
3+
4+
/**
5+
* Constants for panel sizing
6+
*/
7+
const MIN_WIDTH = 232
8+
const MAX_WIDTH = 400
9+
10+
/**
11+
* Custom hook to handle panel resize functionality.
12+
* Manages mouse events for resizing and enforces min/max width constraints.
13+
*
14+
* @returns Resize state and handlers
15+
*/
16+
export function usePanelResize() {
17+
const { setPanelWidth } = usePanelStore()
18+
const [isResizing, setIsResizing] = useState(false)
19+
20+
/**
21+
* Handles mouse down on resize handle
22+
*/
23+
const handleMouseDown = useCallback(() => {
24+
setIsResizing(true)
25+
}, [])
26+
27+
/**
28+
* Setup resize event listeners and body styles when resizing
29+
* Cleanup is handled automatically by the effect's return function
30+
*/
31+
useEffect(() => {
32+
if (!isResizing) return
33+
34+
const handleMouseMove = (e: MouseEvent) => {
35+
// Calculate width from the right edge of the viewport
36+
const newWidth = window.innerWidth - e.clientX
37+
if (newWidth >= MIN_WIDTH && newWidth <= MAX_WIDTH) {
38+
setPanelWidth(newWidth)
39+
}
40+
}
41+
42+
const handleMouseUp = () => {
43+
setIsResizing(false)
44+
}
45+
46+
document.addEventListener('mousemove', handleMouseMove)
47+
document.addEventListener('mouseup', handleMouseUp)
48+
document.body.style.cursor = 'ew-resize'
49+
document.body.style.userSelect = 'none'
50+
51+
return () => {
52+
document.removeEventListener('mousemove', handleMouseMove)
53+
document.removeEventListener('mouseup', handleMouseUp)
54+
document.body.style.cursor = ''
55+
document.body.style.userSelect = ''
56+
}
57+
}, [isResizing, setPanelWidth])
58+
59+
return {
60+
isResizing,
61+
handleMouseDown,
62+
}
63+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use client'
2+
3+
import { useRef } from 'react'
4+
import { usePanelResize } from './hooks/use-panel-resize'
5+
6+
/**
7+
* Panel component with resizable width that persists across page refreshes.
8+
*
9+
* Uses a CSS-based approach to prevent hydration mismatches:
10+
* 1. Width is controlled by CSS variable (--panel-width)
11+
* 2. Blocking script in layout.tsx can set CSS variable before React hydrates
12+
* 3. Store updates CSS variable when width changes
13+
*
14+
* This ensures server and client render identical HTML, preventing hydration errors.
15+
*
16+
* @returns Panel on the right side of the workflow
17+
*/
18+
export function Panel() {
19+
const panelRef = useRef<HTMLElement>(null)
20+
21+
// Panel resize hook
22+
const { handleMouseDown } = usePanelResize()
23+
24+
return (
25+
<>
26+
<aside
27+
ref={panelRef}
28+
className='panel-container fixed inset-y-0 right-0 z-10 overflow-hidden dark:bg-[#1E1E1E]'
29+
aria-label='Workflow panel'
30+
>
31+
<div className='flex h-full flex-col border-l pt-[14px] dark:border-[#2C2C2C]'>
32+
<></>
33+
</div>
34+
</aside>
35+
36+
{/* Resize Handle */}
37+
<div
38+
className='fixed top-0 right-[calc(var(--panel-width)-4px)] bottom-0 z-20 w-[8px] cursor-ew-resize'
39+
onMouseDown={handleMouseDown}
40+
role='separator'
41+
aria-orientation='vertical'
42+
aria-label='Resize panel'
43+
/>
44+
</>
45+
)
46+
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Export the current workflow abstraction
2-
1+
export { useAutoLayout } from './use-auto-layout'
32
export { type CurrentWorkflow, useCurrentWorkflow } from './use-current-workflow'
4-
// Export other workflow-related hooks
3+
export { useNodeUtilities } from './use-node-utilities'
54
export { useWorkflowExecution } from './use-workflow-execution'

0 commit comments

Comments
 (0)