Spaces:
Running
Running
Commit Β·
df77603
1
Parent(s): 6149a4f
feat: support vertical and diagonal resizing for AI Chat popup and persist panel size
Browse filesFiles changed (2)
36 unmodified lines373839404142434445464748495051525354555657585928 unmodified lines88899091929394958 unmodified lines104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146126 unmodified lines27327427527627727827928028128228328428528628728828929029129229329429529636 unmodified linesconst [pos, setPos] = useState<{ x: number; y: number } | null>(null);// ββ Resize state ββββββββββββββββββββββββββββββββββββββββββββconst [isResizing, setIsResizing] = useState(false);const resizeStartX = useRef(0);const resizeStartW = useRef(400);const { panelWidth, setPanelWidth } = useAIStore();const [width, setWidth] = useState(panelWidth);// Restore saved position + width on mountuseEffect(() => {if (dragPos) setPos(dragPos);const savedW = localStorage.getItem('tipitaka-ai-panel-width');if (savedW) {const w = parseInt(savedW, 10);if (w >= 300 && w <= window.innerWidth * 0.8) {setWidth(w);setPanelWidth(w);}}}, []);// Disclaimer Logic: Show for 5s when opening28 unmodified linesconst x = e.clientX - dragOffset.current.x;const y = e.clientY - dragOffset.current.y;// Clamp to viewportconst clampedX = Math.max(0, Math.min(x, window.innerWidth - 320));const clampedY = Math.max(0, Math.min(y, window.innerHeight - 200));setPos({ x: clampedX, y: clampedY });};8 unmodified linesdocument.removeEventListener('mousemove', onMove);document.removeEventListener('mouseup', onUp);};}, [isDragging, pos, setDragPos]);// ββ Resize handlers βββββββββββββββββββββββββββββββββββββββββconst handleResizeStart = useCallback((e: React.MouseEvent) => {if (window.innerWidth < 768) return;if (expandedIndex !== null) return;e.preventDefault();e.stopPropagation();setIsResizing(true);resizeStartX.current = e.clientX;resizeStartW.current = (panelRef.current?.getBoundingClientRect().width ?? width);}, [expandedIndex, width]);useEffect(() => {if (!isResizing) return;const onMove = (e: MouseEvent) => {const newW = Math.max(300, Math.min(resizeStartW.current + (e.clientX - resizeStartX.current), window.innerWidth * 0.8));setWidth(newW);};const onUp = () => {setIsResizing(false);setWidth(w => {setPanelWidth(w);return w;});};document.addEventListener('mousemove', onMove);document.addEventListener('mouseup', onUp);document.body.style.cursor = 'ew-resize';document.body.style.userSelect = 'none';return () => {document.removeEventListener('mousemove', onMove);document.removeEventListener('mouseup', onUp);document.body.style.cursor = '';document.body.style.userSelect = '';};}, [isResizing, setPanelWidth]);const s = PANEL_STYLES[theme] ?? PANEL_STYLES.dark;126 unmodified lines${pos && window.innerWidth >= 768 ? '' : 'left-1/2 -translate-x-1/2 md:left-auto md:right-14 md:translate-x-0'}md:w-autow-[calc(100vw-32px)]h-[80vh] md:h-[550px]${isDragging ? 'cursor-grabbing select-none' : ''}${isResizing ? 'select-none' : ''}${expandedIndex !== null ? 'pointer-events-none opacity-0' : ''}transition-opacity duration-300`}style={{width: window.innerWidth >= 768 ? width : undefined,...(pos && window.innerWidth >= 768 ? { left: pos.x, top: pos.y } : {}),}}>{/* ββ Resize handle (right edge) ββ */}{window.innerWidth >= 768 && (<divonMouseDown={handleResizeStart}className="absolute right-0 top-0 bottom-0 w-2 cursor-ew-resize hover:bg-[#c8860a]/20 active:bg-[#c8860a]/40 transition-colors rounded-r-2xl z-10"style={{ touchAction: 'none' }}/>)}{/* βββββββββββ Compact Header + Drag Handle βββββββββββ */}<div36 unmodified lines37383940414243444546474849505152535455565758596061626364656667686970717228 unmodified lines1011021031041051061071088 unmodified lines117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175126 unmodified lines30230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934036 unmodified linesconst [pos, setPos] = useState<{ x: number; y: number } | null>(null);// ββ Resize state ββββββββββββββββββββββββββββββββββββββββββββconst [resizeDir, setResizeDir] = useState<'w' | 'h' | 'both' | null>(null);const resizeStartX = useRef(0);const resizeStartY = useRef(0);const resizeStartW = useRef(400);const resizeStartH = useRef(550);const { panelWidth, panelHeight, setPanelWidth, setPanelHeight } = useAIStore();const [width, setWidth] = useState(panelWidth);const [height, setHeight] = useState(panelHeight);// Restore saved position + width/height on mountuseEffect(() => {if (dragPos) setPos(dragPos);const savedW = localStorage.getItem('tipitaka-ai-panel-width');if (savedW) {const w = parseInt(savedW, 10);if (w >= 300 && w <= window.innerWidth * 0.95) {setWidth(w);setPanelWidth(w);}}const savedH = localStorage.getItem('tipitaka-ai-panel-height');if (savedH) {const h = parseInt(savedH, 10);if (h >= 200 && h <= window.innerHeight * 0.9) {setHeight(h);setPanelHeight(h);}}}, []);// Disclaimer Logic: Show for 5s when opening28 unmodified linesconst x = e.clientX - dragOffset.current.x;const y = e.clientY - dragOffset.current.y;// Clamp to viewportconst clampedX = Math.max(0, Math.min(x, window.innerWidth - width));const clampedY = Math.max(0, Math.min(y, window.innerHeight - height));setPos({ x: clampedX, y: clampedY });};8 unmodified linesdocument.removeEventListener('mousemove', onMove);document.removeEventListener('mouseup', onUp);};}, [isDragging, pos, setDragPos, width, height]);// ββ Resize handlers βββββββββββββββββββββββββββββββββββββββββconst handleResizeStart = useCallback((e: React.MouseEvent, dir: 'w' | 'h' | 'both') => {if (window.innerWidth < 768) return;if (expandedIndex !== null) return;e.preventDefault();e.stopPropagation();setResizeDir(dir);resizeStartX.current = e.clientX;resizeStartY.current = e.clientY;const rect = panelRef.current?.getBoundingClientRect();if (rect) {resizeStartW.current = rect.width;resizeStartH.current = rect.height;}}, [expandedIndex]);useEffect(() => {if (!resizeDir) return;const onMove = (e: MouseEvent) => {if (resizeDir === 'w' || resizeDir === 'both') {const newW = Math.max(300, Math.min(resizeStartW.current + (e.clientX - resizeStartX.current), window.innerWidth * 0.9));setWidth(newW);}if (resizeDir === 'h' || resizeDir === 'both') {const newH = Math.max(200, Math.min(resizeStartH.current + (e.clientY - resizeStartY.current), window.innerHeight * 0.9));setHeight(newH);}};const onUp = () => {const finalDir = resizeDir;setResizeDir(null);if (finalDir === 'w' || finalDir === 'both') setPanelWidth(width);if (finalDir === 'h' || finalDir === 'both') setPanelHeight(height);};document.addEventListener('mousemove', onMove);document.addEventListener('mouseup', onUp);const cursor = resizeDir === 'both' ? 'nwse-resize' : resizeDir === 'w' ? 'ew-resize' : 'ns-resize';document.body.style.cursor = cursor;document.body.style.userSelect = 'none';return () => {document.removeEventListener('mousemove', onMove);document.removeEventListener('mouseup', onUp);document.body.style.cursor = '';document.body.style.userSelect = '';};}, [resizeDir, width, height, setPanelWidth, setPanelHeight]);const s = PANEL_STYLES[theme] ?? PANEL_STYLES.dark;126 unmodified lines${pos && window.innerWidth >= 768 ? '' : 'left-1/2 -translate-x-1/2 md:left-auto md:right-14 md:translate-x-0'}md:w-autow-[calc(100vw-32px)]h-[80vh] md:h-auto${isDragging ? 'cursor-grabbing select-none' : ''}${resizeDir ? 'select-none' : ''}${expandedIndex !== null ? 'pointer-events-none opacity-0' : ''}transition-opacity duration-300`}style={{width: window.innerWidth >= 768 ? width : undefined,height: window.innerWidth >= 768 ? height : undefined,...(pos && window.innerWidth >= 768 ? { left: pos.x, top: pos.y } : {}),}}>{/* ββ Resize handles (Desktop only) ββ */}{window.innerWidth >= 768 && (<>{/* Right edge */}<divonMouseDown={(e) => handleResizeStart(e, 'w')}className="absolute right-0 top-0 bottom-0 w-1.5 cursor-ew-resize hover:bg-[#c8860a]/20 active:bg-[#c8860a]/40 transition-colors z-10"/>{/* Bottom edge */}<divonMouseDown={(e) => handleResizeStart(e, 'h')}className="absolute left-0 right-0 bottom-0 h-1.5 cursor-ns-resize hover:bg-[#c8860a]/20 active:bg-[#c8860a]/40 transition-colors z-10"/>{/* Corner (Bottom-right) */}<divonMouseDown={(e) => handleResizeStart(e, 'both')}className="absolute right-0 bottom-0 w-4 h-4 cursor-nwse-resize z-20 flex items-end justify-end p-0.5"><div className="w-1.5 h-1.5 rounded-full bg-[#c8860a]/30" /></div></>)}{/* βββββββββββ Compact Header + Drag Handle βββββββββββ */}<div
16 unmodified lines1718192021223 unmodified lines26272829303111 unmodified lines43444546474811 unmodified lines60616263646516 unmodified linesragLoading: boolean; // true when Qdrant exists but Reranker still loadingdragPos: { x: number; y: number } | null; // saved drag position (desktop)panelWidth: number; // saved panel width (desktop)// ActionstoggleOpen: () => void;3 unmodified linesclearHistory: () => void;setDragPos: (pos: { x: number; y: number }) => void;setPanelWidth: (w: number) => void;// SSE Streaming logicaskAI: (question: string, context: string) => Promise<void>;11 unmodified linesragLoading: false,dragPos: null,panelWidth: 400,toggleOpen: () => set((state) => ({ isOpen: !state.isOpen })),setMode: (mode) => set({ mode }),11 unmodified linestry { localStorage.setItem('tipitaka-ai-panel-width', String(w)); } catch {}},checkRagStatus: async () => {set({ ragChecking: true });try {16 unmodified lines171819202122233 unmodified lines2728293031323311 unmodified lines4546474849505111 unmodified lines636465666768697071727316 unmodified linesragLoading: boolean; // true when Qdrant exists but Reranker still loadingdragPos: { x: number; y: number } | null; // saved drag position (desktop)panelWidth: number; // saved panel width (desktop)panelHeight: number; // saved panel height (desktop)// ActionstoggleOpen: () => void;3 unmodified linesclearHistory: () => void;setDragPos: (pos: { x: number; y: number }) => void;setPanelWidth: (w: number) => void;setPanelHeight: (h: number) => void;// SSE Streaming logicaskAI: (question: string, context: string) => Promise<void>;11 unmodified linesragLoading: false,dragPos: null,panelWidth: 400,panelHeight: 550,toggleOpen: () => set((state) => ({ isOpen: !state.isOpen })),setMode: (mode) => set({ mode }),11 unmodified linestry { localStorage.setItem('tipitaka-ai-panel-width', String(w)); } catch {}},setPanelHeight: (h) => {set({ panelHeight: h });try { localStorage.setItem('tipitaka-ai-panel-height', String(h)); } catch {}},checkRagStatus: async () => {set({ ragChecking: true });try {
webapp/tipitaka-web/src/components/ai/AIPopup.tsx+73-29
webapp/tipitaka-web/src/stores/aiStore.ts+8