fix(nodeExtent): use for initial rendering closes #2384
This commit is contained in:
@@ -99,6 +99,7 @@ const GraphView = ({
|
|||||||
elevateEdgesOnSelect,
|
elevateEdgesOnSelect,
|
||||||
disableKeyboardA11y,
|
disableKeyboardA11y,
|
||||||
nodeOrigin,
|
nodeOrigin,
|
||||||
|
nodeExtent,
|
||||||
rfId,
|
rfId,
|
||||||
}: GraphViewProps) => {
|
}: GraphViewProps) => {
|
||||||
useOnInitHandler(onInit);
|
useOnInitHandler(onInit);
|
||||||
@@ -175,6 +176,7 @@ const GraphView = ({
|
|||||||
noDragClassName={noDragClassName}
|
noDragClassName={noDragClassName}
|
||||||
disableKeyboardA11y={disableKeyboardA11y}
|
disableKeyboardA11y={disableKeyboardA11y}
|
||||||
nodeOrigin={nodeOrigin}
|
nodeOrigin={nodeOrigin}
|
||||||
|
nodeExtent={nodeExtent}
|
||||||
rfId={rfId}
|
rfId={rfId}
|
||||||
/>
|
/>
|
||||||
</ViewportWrapper>
|
</ViewportWrapper>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import shallow from 'zustand/shallow';
|
|||||||
|
|
||||||
import useVisibleNodes from '../../hooks/useVisibleNodes';
|
import useVisibleNodes from '../../hooks/useVisibleNodes';
|
||||||
import { useStore } from '../../hooks/useStore';
|
import { useStore } from '../../hooks/useStore';
|
||||||
import { devWarn, internalsSymbol } from '../../utils';
|
import { clampPosition, devWarn, internalsSymbol } from '../../utils';
|
||||||
import { containerStyle } from '../../styles';
|
import { containerStyle } from '../../styles';
|
||||||
import { GraphViewProps } from '../GraphView';
|
import { GraphViewProps } from '../GraphView';
|
||||||
import { Position, ReactFlowState, WrapNodeProps } from '../../types';
|
import { Position, ReactFlowState, WrapNodeProps } from '../../types';
|
||||||
@@ -25,6 +25,7 @@ type NodeRendererProps = Pick<
|
|||||||
| 'rfId'
|
| 'rfId'
|
||||||
| 'disableKeyboardA11y'
|
| 'disableKeyboardA11y'
|
||||||
| 'nodeOrigin'
|
| 'nodeOrigin'
|
||||||
|
| 'nodeExtent'
|
||||||
>;
|
>;
|
||||||
|
|
||||||
const selector = (s: ReactFlowState) => ({
|
const selector = (s: ReactFlowState) => ({
|
||||||
@@ -81,8 +82,12 @@ const NodeRenderer = (props: NodeRendererProps) => {
|
|||||||
const isDraggable = !!(node.draggable || (nodesDraggable && typeof node.draggable === 'undefined'));
|
const isDraggable = !!(node.draggable || (nodesDraggable && typeof node.draggable === 'undefined'));
|
||||||
const isSelectable = !!(node.selectable || (elementsSelectable && typeof node.selectable === 'undefined'));
|
const isSelectable = !!(node.selectable || (elementsSelectable && typeof node.selectable === 'undefined'));
|
||||||
const isConnectable = !!(node.connectable || (nodesConnectable && typeof node.connectable === 'undefined'));
|
const isConnectable = !!(node.connectable || (nodesConnectable && typeof node.connectable === 'undefined'));
|
||||||
const posX = node.position?.x ?? 0;
|
const clampedPosition = props.nodeExtent
|
||||||
const posY = node.position?.y ?? 0;
|
? clampPosition(node.positionAbsolute, props.nodeExtent)
|
||||||
|
: node.positionAbsolute;
|
||||||
|
|
||||||
|
const posX = clampedPosition?.x ?? 0;
|
||||||
|
const posY = clampedPosition?.y ?? 0;
|
||||||
const posOrigin = getPositionWithOrigin({
|
const posOrigin = getPositionWithOrigin({
|
||||||
x: posX,
|
x: posX,
|
||||||
y: posY,
|
y: posY,
|
||||||
|
|||||||
@@ -225,6 +225,7 @@ const ReactFlow = forwardRef<ReactFlowRefType, ReactFlowProps>(
|
|||||||
rfId={rfId}
|
rfId={rfId}
|
||||||
disableKeyboardA11y={disableKeyboardA11y}
|
disableKeyboardA11y={disableKeyboardA11y}
|
||||||
nodeOrigin={nodeOrigin}
|
nodeOrigin={nodeOrigin}
|
||||||
|
nodeExtent={nodeExtent}
|
||||||
/>
|
/>
|
||||||
<StoreUpdater
|
<StoreUpdater
|
||||||
nodes={nodes}
|
nodes={nodes}
|
||||||
|
|||||||
Reference in New Issue
Block a user