Skip to content

Commit

Permalink
Merge branch 'v11' into next-v11
Browse files Browse the repository at this point in the history
  • Loading branch information
moklick committed Jan 17, 2024
2 parents 61c3197 + 22e0db7 commit 5920faa
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions examples/vite-app/src/examples/DragNDrop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const DnDFlow = () => {

if (reactFlowInstance) {
const type = event.dataTransfer.getData('application/reactflow');
const position = reactFlowInstance.project({
const position = reactFlowInstance.screenToFlowPosition({
x: event.clientX,
y: event.clientY - 40,
y: event.clientY,
});
const newNode: Node = {
id: getId(),
Expand Down
6 changes: 3 additions & 3 deletions examples/vite-app/src/examples/Undirectional/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const getId = () => `${id++}`;
const UpdateNodeInternalsFlow = () => {
const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
const { project } = useReactFlow();
const { screenToFlowPosition } = useReactFlow();

const onConnect = useCallback((params: Edge | Connection) => setEdges((els) => addEdge(params, els)), [setEdges]);
const onEdgeUpdate = useCallback(
Expand All @@ -195,12 +195,12 @@ const UpdateNodeInternalsFlow = () => {
setNodes((nds) =>
nds.concat({
id: getId(),
position: project({ x: evt.clientX, y: evt.clientY - 40 }),
position: screenToFlowPosition({ x: evt.clientX, y: evt.clientY }),
type: 'custom',
data: null,
})
),
[project, setNodes]
[screenToFlowPosition, setNodes]
);

return (
Expand Down
8 changes: 4 additions & 4 deletions examples/vite-app/src/examples/UseReactFlow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const UseZoomPanHelperFlow = () => {
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);
const onConnect = (params: Connection | Edge) => setEdges((eds) => addEdge(params, eds));
const {
project,
screenToFlowPosition,
setCenter,
zoomIn,
zoomOut,
Expand All @@ -71,9 +71,9 @@ const UseZoomPanHelperFlow = () => {

const onPaneClick = useCallback(
(evt: MouseEvent) => {
const projectedPosition = project({
const projectedPosition = screenToFlowPosition({
x: evt.clientX,
y: evt.clientY - 40,
y: evt.clientY,
});

setNodes((nds) =>
Expand All @@ -86,7 +86,7 @@ const UseZoomPanHelperFlow = () => {
})
);
},
[project, setNodes]
[screenToFlowPosition, setNodes]
);

const onNodeClick = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ const UpdateNodeInternalsFlow = () => {
const [edges, setEdges, onEdgesChange] = useEdgesState([]);
const onConnect = useCallback((params: Edge | Connection) => setEdges((els) => addEdge(params, els)), [setEdges]);

const { project } = useReactFlow();
const { screenToFlowPosition } = useReactFlow();

const onPaneClick = useCallback(
(evt: MouseEvent) =>
setNodes((nds) =>
nds.concat({
id: getId(),
position: project({ x: evt.clientX, y: evt.clientY - 40 }),
position: screenToFlowPosition({ x: evt.clientX, y: evt.clientY - 40 }),
data: { label: 'new node' },
targetPosition: Position.Left,
sourcePosition: Position.Right,
})
),
[project, setNodes]
[screenToFlowPosition, setNodes]
);

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ We want to make the migration for v12 as smooth as possible. That's why we added

### Minor Changes

- [#3597](https://github.com/xyflow/xyflow/pull/3597) [`a114c75b`](https://github.com/xyflow/xyflow/commit/a114c75b79d1d7bd24937318119a824879fe0b54) Thanks - chore(utils): add renamed functions and deprecations, add `useReactFlow.flowToScreenPosition`
- [#3597](https://github.com/xyflow/xyflow/pull/3597) [`a114c75b`](https://github.com/xyflow/xyflow/commit/a114c75b79d1d7bd24937318119a824879fe0b54) - chore(utils): add renamed functions and deprecations, add `useReactFlow.flowToScreenPosition`

### Patch Changes

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/hooks/useViewportHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const initialViewportHelper: ViewportHelperFunctions = {
setCenter: noop,
fitBounds: noop,
project: (position: XYPosition) => position,
screenToFlowPosition: (position: XYPosition) => position,
flowToScreenPosition: (position: XYPosition) => position,
viewportInitialized: false,
};

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/types/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ export type ViewportHelperFunctions = {
setCenter: SetCenter;
fitBounds: FitBounds;
project: Project;
screenToFlowPosition: (position: XYPosition) => XYPosition;
flowToScreenPosition: (position: XYPosition) => XYPosition;
viewportInitialized: boolean;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/reactflow/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ We want to make the migration for v12 as smooth as possible. That's why we added

### Minor Changes

- [#3597](https://github.com/xyflow/xyflow/pull/3597) [`a114c75b`](https://github.com/xyflow/xyflow/commit/a114c75b79d1d7bd24937318119a824879fe0b54) Thanks - chore(utils): add renamed functions and deprecations, add `useReactFlow.flowToScreenPosition`
- [#3597](https://github.com/xyflow/xyflow/pull/3597) [`a114c75b`](https://github.com/xyflow/xyflow/commit/a114c75b79d1d7bd24937318119a824879fe0b54) - chore(utils): add renamed functions and deprecations, add `useReactFlow.flowToScreenPosition`

### Patch Changes

Expand Down

0 comments on commit 5920faa

Please sign in to comment.