fixed wrong initial set on store
This commit is contained in:
@@ -12,8 +12,8 @@
|
||||
|
||||
const { getIntersectingNodes } = useSvelteFlow();
|
||||
|
||||
function onNodeDrag({ detail: { node } }) {
|
||||
const intersections = getIntersectingNodes(node).map((n) => n.id);
|
||||
function onNodeDrag({ detail: { targetNode } }) {
|
||||
const intersections = getIntersectingNodes(targetNode).map((n) => n.id);
|
||||
|
||||
$nodes.forEach((n) => {
|
||||
n.class = intersections.includes(n.id) ? 'highlight' : '';
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
import type { Node, Edge } from '@xyflow/svelte';
|
||||
|
||||
export const initialNodes: Node[] = [
|
||||
{
|
||||
id: '1',
|
||||
data: { label: 'Node 1' },
|
||||
position: { x: 0, y: 0 },
|
||||
style: 'width: 200px; height: 100px;'
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
data: { label: 'Node 2' },
|
||||
position: { x: 0, y: 150 }
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
data: { label: 'Node 3' },
|
||||
position: { x: 250, y: 0 }
|
||||
},
|
||||
{
|
||||
id: '4',
|
||||
data: { label: 'Node' },
|
||||
position: { x: 350, y: 150 },
|
||||
style: 'width: 50px; height: 50px;'
|
||||
}
|
||||
{
|
||||
id: '1',
|
||||
data: { label: 'Node 1' },
|
||||
position: { x: 0, y: 0 },
|
||||
style: 'width: 200px; height: 100px;'
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
data: { label: 'Node 2' },
|
||||
position: { x: 0, y: 150 }
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
data: { label: 'Node 3' },
|
||||
position: { x: 250, y: 0 }
|
||||
},
|
||||
{
|
||||
id: '4',
|
||||
data: { label: 'Node' },
|
||||
position: { x: 350, y: 150 },
|
||||
style: 'width: 50px; height: 50px;'
|
||||
}
|
||||
];
|
||||
|
||||
export const initialEdges: Edge[] = [];
|
||||
|
||||
@@ -75,7 +75,7 @@ export function createStore({
|
||||
node.dragging = dragging;
|
||||
}
|
||||
|
||||
store.nodes.set(get(store.nodes));
|
||||
store.nodes.update((nds) => nds);
|
||||
};
|
||||
|
||||
function updateNodeDimensions(updates: Map<string, NodeDimensionUpdate>) {
|
||||
@@ -121,7 +121,7 @@ export function createStore({
|
||||
}
|
||||
}
|
||||
|
||||
store.nodes.set(get(store.nodes));
|
||||
store.nodes.update((nds) => nds);
|
||||
|
||||
if (!get(store.nodesInitialized)) {
|
||||
store.nodesInitialized.set(true);
|
||||
@@ -205,10 +205,10 @@ export function createStore({
|
||||
|
||||
function unselectNodesAndEdges(params?: { nodes?: Node[]; edges?: Edge[] }) {
|
||||
const resetNodes = resetSelectedElements(params?.nodes || get(store.nodes));
|
||||
if (resetNodes) store.nodes.set(get(store.nodes));
|
||||
if (resetNodes) store.nodes.update((nds) => nds);
|
||||
|
||||
const resetEdges = resetSelectedElements(params?.edges || get(store.edges));
|
||||
if (resetEdges) store.edges.set(get(store.edges));
|
||||
if (resetEdges) store.edges.update((nds) => nds);
|
||||
}
|
||||
|
||||
store.deleteKeyPressed.subscribe(async (deleteKeyPressed) => {
|
||||
|
||||
@@ -147,7 +147,7 @@ export const createNodesStore = (
|
||||
checkEquality: false
|
||||
});
|
||||
|
||||
value = nodes;
|
||||
value = nds;
|
||||
|
||||
set(value);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user