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