mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-06 03:00:16 -04:00
* feat(fonts): season replacing geist * feat(emcnn): created emcn * feat(sidebar): created new sidebar with header and workflow list * improvement(sidebar): expanded workflow/folder item text sizing and adjusted button padding * feat(sidebar): added search UI, updated workflows styling * improvement: globals styling with antialiased in dark mode only * feat(sidebar): blocks and triggers ui/ux updated * refactor(sidebar): moved logic into hooks * feat(sidebar): improved workflow/folder dragging UI/UX; refactored logic into hooks * improvement(sidebar): adjusted triggers/blocks padding for header * improvement(sidebar): dragging hover handler; closed folders by default minus active path * improvement(sidebar): panel resize logic * improvement(sidebar): blocks and triggers expanded indicator * feat(tooltips): new emcn component emerged * feat(sidebar): workflow list handling updated * refactor: added cursorrules * feat(panel): new panel layout * improvement(workspaces): firname's workspace instead of fn ln's workspace * feat(platform): panel header, new emcn icons, more button variants, refactor sidebar components * improvement(emcn): added button variants * feat(panel): tab system * feat(copilot): refactor, adjusted welcome and user-input UI/UX * feat(copilot): baseline user-input ui/ux improvement * feat(emcn): badge outline variant * fix: build errors * feat(copilot): base UI copilot * refactor(workflow-block): added hooks, components * feat(design): created design panel and removed isWide * refactor(subblock): edited components, styling * feat: emcn, editor * feat(panel): toolbar, editor * feat(workflow-block): refactor, adjust base styling * feat(workflow-block): new block, edge * feat: workflow-block, connections, action-bar, copilot * feat: panel, workflow, emcn, workflow block, subblocks; clean copilot * sim-326: remove remote code execution toggle, hide dropdown for language if E2B is not enabled * feat: sidebar navigation, tag coloring; refactor: rebased to staging * fix: build errors * improvement: subblock styles * feat: workspaces, terminal, emcn, controls * feat: delete workflow * fix: rebased * fix build errors --------- Co-authored-by: Vikhyath Mondreti <vikhyath@simstudio.ai>
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { useCallback } from 'react'
|
|
import { useReactFlow } from 'reactflow'
|
|
import { createLogger } from '@/lib/logs/console/logger'
|
|
|
|
const logger = createLogger('useFocusOnBlock')
|
|
|
|
/**
|
|
* Hook to focus the canvas on a specific block with smooth animation.
|
|
* Can be called from any component within the workflow (editor, toolbar, action bar, etc.).
|
|
*
|
|
* @returns Function to focus on a block by its ID
|
|
*
|
|
* @example
|
|
* const focusOnBlock = useFocusOnBlock()
|
|
* focusOnBlock('block-id-123')
|
|
*/
|
|
export function useFocusOnBlock() {
|
|
const { getNodes, fitView } = useReactFlow()
|
|
|
|
return useCallback(
|
|
(blockId: string) => {
|
|
if (!blockId) {
|
|
logger.warn('Cannot focus on block: no blockId provided')
|
|
return
|
|
}
|
|
|
|
try {
|
|
// Check if the node exists
|
|
const node = getNodes().find((n) => n.id === blockId)
|
|
if (!node) {
|
|
logger.warn('Cannot focus on block: block not found', { blockId })
|
|
return
|
|
}
|
|
|
|
// Focus on the specific node with smooth animation
|
|
fitView({
|
|
nodes: [node],
|
|
duration: 400,
|
|
padding: 0.3,
|
|
minZoom: 0.5,
|
|
maxZoom: 1.0,
|
|
})
|
|
|
|
logger.info('Focused on block', { blockId })
|
|
} catch (err) {
|
|
logger.error('Failed to focus on block', { err, blockId })
|
|
}
|
|
},
|
|
[getNodes, fitView]
|
|
)
|
|
}
|