Skip to content

Image Pipeline Playground

feat(frontend/canvas): add collapsible canvas minimap

Mohammad Rajaei28951c9d6fbb
diff --git a/frontend/src/features/canvas/CanvasMiniMap.tsx b/frontend/src/features/canvas/CanvasMiniMap.tsx
new file mode 100644
index 0000000..e3f82d0
--- /dev/null
+++ b/frontend/src/features/canvas/CanvasMiniMap.tsx
@@ -0,0 +1,127 @@
+import { useState } from 'react'
+import { MiniMap, Panel } from '@xyflow/react'
+import { Box, IconButton, Tooltip, Typography } from '@mui/material'
+
+const STORAGE_KEY = 'image-pipes.canvasMinimapOpen'
+
+function readStoredOpen(): boolean {
+ try {
+ return localStorage.getItem(STORAGE_KEY) !== 'false'
+ } catch {
+ return true
+ }
+}
+
+const toggleButtonSx = {
+ width: 26,
+ height: 26,
+ borderRadius: 0.75,
+ color: 'rgba(244,241,234,0.85)',
+ bgcolor: '#2b2b2b',
+ border: '1px solid rgba(255,255,255,0.12)',
+ boxShadow: '0 0 2px 1px rgba(0,0,0,0.08)',
+ '&:hover': { bgcolor: '#3e3e3e' },
+} as const
+
+export function CanvasMiniMap() {
+ const [open, setOpen] = useState(readStoredOpen)
+
+ const setOpenPersisted = (next: boolean) => {
+ setOpen(next)
+ try {
+ localStorage.setItem(STORAGE_KEY, String(next))
+ } catch {
+ // Ignore storage failures (private mode, quota, etc.).
+ }
+ }
+
+ if (!open) {
+ return (
+ <Panel position="bottom-right" className="nodrag nopan">
+ <Tooltip title="Show map" arrow enterDelay={400}>
+ <IconButton
+ size="small"
+ className="nodrag nopan"
+ aria-label="Show map"
+ onClick={() => setOpenPersisted(true)}
+ sx={toggleButtonSx}
+ >
+ <Box component="span" sx={{ fontSize: 13, lineHeight: 1 }}>
+ ▣
+ </Box>
+ </IconButton>
+ </Tooltip>
+ </Panel>
+ )
+ }
+
+ return (
+ <Panel position="bottom-right" className="nodrag nopan">
+ <Box
+ sx={{
+ width: 200,
+ borderRadius: 1,
+ overflow: 'hidden',
+ border: '1px solid rgba(255,255,255,0.12)',
+ boxShadow: '0 0 2px 1px rgba(0,0,0,0.08)',
+ bgcolor: '#1a1a1a',
+ '& .canvas-minimap-embedded': {
+ position: 'relative !important',
+ inset: 'auto !important',
+ margin: 0,
+ width: '100%',
+ },
+ }}
+ >
+ <Box
+ sx={{
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'space-between',
+ px: 0.75,
+ py: 0.25,
+ borderBottom: '1px solid rgba(255,255,255,0.08)',
+ bgcolor: '#2b2b2b',
+ }}
+ >
+ <Typography
+ sx={{
+ fontSize: 11,
+ fontWeight: 650,
+ color: 'rgba(244,241,234,0.7)',
+ letterSpacing: '0.02em',
+ }}
+ >
+ Map
+ </Typography>
+ <Tooltip title="Hide map" arrow enterDelay={400}>
+ <IconButton
+ size="small"
+ className="nodrag nopan"
+ aria-label="Hide map"
+ onClick={() => setOpenPersisted(false)}
+ sx={{
+ ...toggleButtonSx,
+ width: 22,
+ height: 22,
+ border: 'none',
+ boxShadow: 'none',
+ }}
+ >
+ <Box component="span" sx={{ fontSize: 14, lineHeight: 1 }}>
+ −
+ </Box>
+ </IconButton>
+ </Tooltip>
+ </Box>
+ <MiniMap
+ className="canvas-minimap-embedded"
+ pannable
+ zoomable
+ style={{ background: '#1a1a1a' }}
+ maskColor="rgba(0,0,0,0.55)"
+ />
+ </Box>
+ </Panel>
+ )
+}
diff --git a/frontend/src/features/canvas/PipelineCanvas.tsx b/frontend/src/features/canvas/PipelineCanvas.tsx
index 5c64638..26053aa 100644
--- a/frontend/src/features/canvas/PipelineCanvas.tsx
+++ b/frontend/src/features/canvas/PipelineCanvas.tsx
@@ -2,7 +2,6 @@ import { useCallback, useEffect, useMemo } from 'react'
import {
Background,
Controls,
- MiniMap,
ReactFlow,
reconnectEdge,
useReactFlow,
@@ -16,6 +15,7 @@ import { Box } from '@mui/material'
import { useGraphStore } from '../../store/graphStore'
import { PipelineNodeView } from './PipelineNode'
import { EditableEdge } from './EditableEdge'
+import { CanvasMiniMap } from './CanvasMiniMap'
import type { NodeMetadata, PortSpec } from '../../types'
import { portsCompatible } from '../../lib/portTypes'
import { isUserScriptType } from '../../workflow/customCodeTrust'
@@ -163,12 +163,7 @@ export function PipelineCanvas() {
}}
>
<FitViewOnGraphChange />
- <MiniMap
- pannable
- zoomable
- style={{ background: '#1a1a1a' }}
- maskColor="rgba(0,0,0,0.55)"
- />
+ <CanvasMiniMap />
<Controls />
<Background gap={20} color="rgba(255,255,255,0.05)" />
</ReactFlow>