|
1 | 1 | import { useLayoutEffect, useRef, useState } from "react"; |
2 | 2 | import "./artifact-layout.css"; |
3 | 3 |
|
4 | | -const storageKey = "agentflow.artifactPanelWidth"; |
5 | | -const defaultWidth = 440; |
6 | 4 | const sashWidth = 4; |
7 | 5 | const snapDistance = 16; |
8 | 6 | export const ARTIFACT_COMPACT_WIDTH = 800; |
9 | 7 |
|
10 | | -function readWidth() { |
| 8 | +function readWidth(storageKey, defaultWidth) { |
11 | 9 | try { |
12 | 10 | const saved = localStorage.getItem(storageKey); |
13 | 11 | const width = Number(saved); |
@@ -41,8 +39,14 @@ function capturePassage(shell) { |
41 | 39 | // Pane sizing and keyboard behavior adapted from Grasp (MIT). |
42 | 40 | // See artifact-preview.css for the upstream license. |
43 | 41 | /** Grasp's 440px pane, 4px sash and 800px conversation breakpoint. */ |
44 | | -export function useArtifactPanelLayout(root, onClose, nodeId = null, open = true) { |
45 | | - const [layout, setLayout] = useState(readWidth); |
| 42 | +export function useArtifactPanelLayout( |
| 43 | + root, |
| 44 | + onClose, |
| 45 | + nodeId = null, |
| 46 | + open = true, |
| 47 | + { defaultWidth = 440, storageKey = "agentflow.artifactPanelWidth" } = {}, |
| 48 | +) { |
| 49 | + const [layout, setLayout] = useState(() => readWidth(storageKey, defaultWidth)); |
46 | 50 | const [available, setAvailable] = useState(0); |
47 | 51 | const [dragging, setDragging] = useState(false); |
48 | 52 | const shell = useRef(null); |
|
0 commit comments