chore(autoPanOnNodeFocus): cleanup

This commit is contained in:
moklick
2025-06-10 09:19:23 +02:00
parent 1a25bff52b
commit 34274eb44d
5 changed files with 10 additions and 10 deletions
@@ -29,7 +29,6 @@ export function NodeWrapper<NodeType extends Node>({
onContextMenu, onContextMenu,
onDoubleClick, onDoubleClick,
nodesDraggable, nodesDraggable,
autoPanOnNodeFocus,
elementsSelectable, elementsSelectable,
nodesConnectable, nodesConnectable,
nodesFocusable, nodesFocusable,
@@ -162,11 +161,16 @@ export function NodeWrapper<NodeType extends Node>({
}; };
const onFocus = () => { const onFocus = () => {
if (disableKeyboardA11y || !autoPanOnNodeFocus || !nodeRef.current?.matches(':focus-visible')) { if (disableKeyboardA11y || !nodeRef.current?.matches(':focus-visible')) {
return;
}
const { transform, width, height, autoPanOnNodeFocus, setCenter } = store.getState();
if (!autoPanOnNodeFocus) {
return; return;
} }
const { transform, width, height, setCenter } = store.getState();
const withinViewport = const withinViewport =
getNodesInside(new Map([[id, node]]), { x: 0, y: 0, width, height }, transform, true).length > 0; getNodesInside(new Map([[id, node]]), { x: 0, y: 0, width, height }, transform, true).length > 0;
@@ -29,7 +29,6 @@ export type NodeRendererProps<NodeType extends Node> = Pick<
const selector = (s: ReactFlowState) => ({ const selector = (s: ReactFlowState) => ({
nodesDraggable: s.nodesDraggable, nodesDraggable: s.nodesDraggable,
autoPanOnNodeFocus: s.autoPanOnNodeFocus,
nodesConnectable: s.nodesConnectable, nodesConnectable: s.nodesConnectable,
nodesFocusable: s.nodesFocusable, nodesFocusable: s.nodesFocusable,
elementsSelectable: s.elementsSelectable, elementsSelectable: s.elementsSelectable,
@@ -37,8 +36,7 @@ const selector = (s: ReactFlowState) => ({
}); });
function NodeRendererComponent<NodeType extends Node>(props: NodeRendererProps<NodeType>) { function NodeRendererComponent<NodeType extends Node>(props: NodeRendererProps<NodeType>) {
const { nodesDraggable, nodesConnectable, nodesFocusable, elementsSelectable, autoPanOnNodeFocus, onError } = const { nodesDraggable, nodesConnectable, nodesFocusable, elementsSelectable, onError } = useStore(selector, shallow);
useStore(selector, shallow);
const nodeIds = useVisibleNodeIds(props.onlyRenderVisibleElements); const nodeIds = useVisibleNodeIds(props.onlyRenderVisibleElements);
const resizeObserver = useResizeObserver(); const resizeObserver = useResizeObserver();
@@ -88,7 +86,6 @@ function NodeRendererComponent<NodeType extends Node>(props: NodeRendererProps<N
disableKeyboardA11y={props.disableKeyboardA11y} disableKeyboardA11y={props.disableKeyboardA11y}
resizeObserver={resizeObserver} resizeObserver={resizeObserver}
nodesDraggable={nodesDraggable} nodesDraggable={nodesDraggable}
autoPanOnNodeFocus={autoPanOnNodeFocus}
nodesConnectable={nodesConnectable} nodesConnectable={nodesConnectable}
nodesFocusable={nodesFocusable} nodesFocusable={nodesFocusable}
elementsSelectable={elementsSelectable} elementsSelectable={elementsSelectable}
+1 -1
View File
@@ -385,7 +385,7 @@ export interface ReactFlowProps<NodeType extends Node = Node, EdgeType extends E
nodesDraggable?: boolean; nodesDraggable?: boolean;
/** /**
* When `true`, the viewport will pan when a node is focused. * When `true`, the viewport will pan when a node is focused.
* @default false * @default true
*/ */
autoPanOnNodeFocus?: boolean; autoPanOnNodeFocus?: boolean;
/** /**
-1
View File
@@ -48,7 +48,6 @@ export type NodeWrapperProps<NodeType extends Node> = {
nodesConnectable: boolean; nodesConnectable: boolean;
elementsSelectable: boolean; elementsSelectable: boolean;
nodesDraggable: boolean; nodesDraggable: boolean;
autoPanOnNodeFocus: boolean;
nodesFocusable: boolean; nodesFocusable: boolean;
onClick?: NodeMouseHandler<NodeType>; onClick?: NodeMouseHandler<NodeType>;
onDoubleClick?: NodeMouseHandler<NodeType>; onDoubleClick?: NodeMouseHandler<NodeType>;
@@ -234,7 +234,7 @@ export type SvelteFlowProps<
nodesDraggable?: boolean; nodesDraggable?: boolean;
/** /**
* When `true`, the viewport will pan when a node is focused. * When `true`, the viewport will pan when a node is focused.
* @default false * @default true
*/ */
autoPanOnNodeFocus?: boolean; autoPanOnNodeFocus?: boolean;
/** /**