chore(examples): cleanup
This commit is contained in:
@@ -49,7 +49,7 @@ const DnDFlow = () => {
|
|||||||
|
|
||||||
if (reactFlowInstance) {
|
if (reactFlowInstance) {
|
||||||
const type = event.dataTransfer.getData('application/reactflow');
|
const type = event.dataTransfer.getData('application/reactflow');
|
||||||
const position = reactFlowInstance.screenToFlowCoordinate({
|
const position = reactFlowInstance.screenToFlowPosition({
|
||||||
x: event.clientX,
|
x: event.clientX,
|
||||||
y: event.clientY,
|
y: event.clientY,
|
||||||
});
|
});
|
||||||
@@ -66,7 +66,7 @@ const DnDFlow = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.dndflow}>
|
<div className={styles.dndflow}>
|
||||||
<ReactFlowProvider nodes={initialNodes} edges={[]}>
|
<ReactFlowProvider initialNodes={initialNodes} initialEdges={[]}>
|
||||||
<div className={styles.wrapper}>
|
<div className={styles.wrapper}>
|
||||||
<ReactFlow
|
<ReactFlow
|
||||||
nodes={nodes}
|
nodes={nodes}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { SvelteFlow, useSvelteFlow } from '@xyflow/svelte';
|
|
||||||
import type { Edge, Node } from '@xyflow/svelte';
|
|
||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
|
import { SvelteFlow, useSvelteFlow, type Edge, type Node } from '@xyflow/svelte';
|
||||||
|
|
||||||
import '@xyflow/svelte/dist/style.css';
|
import '@xyflow/svelte/dist/style.css';
|
||||||
|
|
||||||
@@ -22,7 +21,7 @@
|
|||||||
let id = 1;
|
let id = 1;
|
||||||
const getId = () => `${id++}`;
|
const getId = () => `${id++}`;
|
||||||
|
|
||||||
const { screenToFlowCoordinate, flowToScreenCoordinate } = useSvelteFlow();
|
const { screenToFlowPosition, flowToScreenPosition } = useSvelteFlow();
|
||||||
|
|
||||||
function handleConnectEnd({ detail: { event } }: { detail: { event: MouseEvent | TouchEvent } }) {
|
function handleConnectEnd({ detail: { event } }: { detail: { event: MouseEvent | TouchEvent } }) {
|
||||||
// See of connection landed inside the flow pane
|
// See of connection landed inside the flow pane
|
||||||
@@ -34,7 +33,7 @@
|
|||||||
y: event.clientY
|
y: event.clientY
|
||||||
};
|
};
|
||||||
|
|
||||||
const doubleTransformedPosition = flowToScreenCoordinate(screenToFlowCoordinate(position));
|
const doubleTransformedPosition = flowToScreenPosition(screenToFlowPosition(position));
|
||||||
console.log(
|
console.log(
|
||||||
'Is transforming in both directions (screen-flow, flow-screen) the same?',
|
'Is transforming in both directions (screen-flow, flow-screen) the same?',
|
||||||
position.x === doubleTransformedPosition.x && position.y === doubleTransformedPosition.y
|
position.x === doubleTransformedPosition.x && position.y === doubleTransformedPosition.y
|
||||||
@@ -43,8 +42,8 @@
|
|||||||
const newNode: Node = {
|
const newNode: Node = {
|
||||||
id,
|
id,
|
||||||
data: { label: `Node ${id}` },
|
data: { label: `Node ${id}` },
|
||||||
// project the screen coordinates to pane coordinates
|
// project the screen position to pane position
|
||||||
position: screenToFlowCoordinate(position),
|
position: screenToFlowPosition(position),
|
||||||
// set the origin of the new node so it is centered
|
// set the origin of the new node so it is centered
|
||||||
origin: [0.5, 0.0]
|
origin: [0.5, 0.0]
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user