make $derived not required when using useSvelteFlow
This commit is contained in:
@@ -27,7 +27,7 @@
|
|||||||
let id = 1;
|
let id = 1;
|
||||||
const getId = () => `${id++}`;
|
const getId = () => `${id++}`;
|
||||||
|
|
||||||
const { screenToFlowPosition, flowToScreenPosition } = $derived(useSvelteFlow());
|
const { screenToFlowPosition, flowToScreenPosition } = useSvelteFlow();
|
||||||
|
|
||||||
const connections = useNodeConnections({ id: '0', handleType: 'source' });
|
const connections = useNodeConnections({ id: '0', handleType: 'source' });
|
||||||
|
|
||||||
@@ -37,7 +37,9 @@
|
|||||||
if (!connectingNodeId) return;
|
if (!connectingNodeId) return;
|
||||||
|
|
||||||
// See of connection landed inside the flow pane
|
// See of connection landed inside the flow pane
|
||||||
const targetIsPane = (event.target as Partial<Element> | null)?.classList?.contains('svelte-flow__pane');
|
const targetIsPane = (event.target as Partial<Element> | null)?.classList?.contains(
|
||||||
|
'svelte-flow__pane'
|
||||||
|
);
|
||||||
if (targetIsPane && 'clientX' in event && 'clientY' in event) {
|
if (targetIsPane && 'clientX' in event && 'clientY' in event) {
|
||||||
const id = getId();
|
const id = getId();
|
||||||
const position = {
|
const position = {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const { screenToFlowPosition } = $derived(useSvelteFlow());
|
const { screenToFlowPosition } = useSvelteFlow();
|
||||||
|
|
||||||
const onDragOver = (event: DragEvent) => {
|
const onDragOver = (event: DragEvent) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
let nodes = $state.raw<Node[]>(initialNodes);
|
let nodes = $state.raw<Node[]>(initialNodes);
|
||||||
let edges = $state.raw<Edge[]>(initialEdges);
|
let edges = $state.raw<Edge[]>(initialEdges);
|
||||||
|
|
||||||
const { getIntersectingNodes } = $derived(useSvelteFlow());
|
const { getIntersectingNodes } = useSvelteFlow();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div style="height:100vh;">
|
<div style="height:100vh;">
|
||||||
|
|||||||
@@ -144,7 +144,7 @@
|
|||||||
edges = [...edges];
|
edges = [...edges];
|
||||||
}
|
}
|
||||||
|
|
||||||
let { updateNode } = $derived(useSvelteFlow());
|
let { updateNode } = useSvelteFlow();
|
||||||
|
|
||||||
function hideUnhide() {
|
function hideUnhide() {
|
||||||
updateNode('hideunhide', (node) => ({ hidden: !node.hidden }));
|
updateNode('hideunhide', (node) => ({ hidden: !node.hidden }));
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
let edges = $state.raw([{ id: 'ab', source: 'A', target: 'B' }]);
|
let edges = $state.raw([{ id: 'ab', source: 'A', target: 'B' }]);
|
||||||
let viewport = $state<Viewport>({ x: 100, y: 100, zoom: 5 });
|
let viewport = $state<Viewport>({ x: 100, y: 100, zoom: 5 });
|
||||||
|
|
||||||
const { fitView } = $derived(useSvelteFlow());
|
const { fitView } = useSvelteFlow();
|
||||||
|
|
||||||
const updateViewport = () => {
|
const updateViewport = () => {
|
||||||
viewport.x += 10;
|
viewport.x += 10;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
getViewport,
|
getViewport,
|
||||||
toObject,
|
toObject,
|
||||||
deleteElements
|
deleteElements
|
||||||
} = $derived(useSvelteFlow());
|
} = useSvelteFlow();
|
||||||
|
|
||||||
let nodes = useNodes();
|
let nodes = useNodes();
|
||||||
let edges = useEdges();
|
let edges = useEdges();
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const { updateNode } = $derived(useSvelteFlow());
|
const { updateNode } = useSvelteFlow();
|
||||||
|
|
||||||
const updateNodePosition = () => {
|
const updateNodePosition = () => {
|
||||||
updateNode('1', (node) => ({
|
updateNode('1', (node) => ({
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import {
|
|||||||
import { useStore } from '$lib/store';
|
import { useStore } from '$lib/store';
|
||||||
import type { Edge, FitViewOptions, InternalNode, Node } from '$lib/types';
|
import type { Edge, FitViewOptions, InternalNode, Node } from '$lib/types';
|
||||||
import { isEdge, isNode } from '$lib/utils';
|
import { isEdge, isNode } from '$lib/utils';
|
||||||
import { derivedWarning } from './derivedWarning.svelte';
|
|
||||||
import { untrack } from 'svelte';
|
import { untrack } from 'svelte';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -277,11 +276,7 @@ export function useSvelteFlow<NodeType extends Node = Node, EdgeType extends Edg
|
|||||||
id?: string | null;
|
id?: string | null;
|
||||||
}) => HandleConnection[];
|
}) => HandleConnection[];
|
||||||
} {
|
} {
|
||||||
if (process.env.NODE_ENV === 'development') {
|
const store = $derived(useStore<NodeType, EdgeType>());
|
||||||
derivedWarning('useSvelteFlow');
|
|
||||||
}
|
|
||||||
|
|
||||||
const store = useStore<NodeType, EdgeType>();
|
|
||||||
|
|
||||||
const getNodeRect = (node: NodeType | { id: NodeType['id'] }): Rect | null => {
|
const getNodeRect = (node: NodeType | { id: NodeType['id'] }): Rect | null => {
|
||||||
const nodeToUse = isNode(node) ? node : store.nodeLookup.get(node.id)!;
|
const nodeToUse = isNode(node) ? node : store.nodeLookup.get(node.id)!;
|
||||||
|
|||||||
Reference in New Issue
Block a user