feat(svelte): add node option 'origin'

This commit is contained in:
moklick
2023-03-14 13:20:52 +01:00
parent 653db49ea4
commit 154be3f900
7 changed files with 20 additions and 17 deletions
@@ -1,7 +1,8 @@
import { derived } from 'svelte/store';
import { Position } from '@reactflow/system';
import { getHandle } from '@reactflow/edge-utils';
import { getEdgePositions, getHandle, getNodeData } from '$lib/container/EdgeRenderer/utils';
import { getEdgePositions, getNodeData } from '$lib/container/EdgeRenderer/utils';
import type { EdgeLayouted } from '$lib/types';
import type { SvelteFlowStoreState } from './types';
@@ -26,6 +27,8 @@ export function getEdgesLayouted(store: SvelteFlowStoreState) {
const sourcePosition = sourceHandle?.position || Position.Bottom;
const targetPosition = targetHandle?.position || Position.Top;
console.log(sourceNodeRect);
if (!sourceHandle || !targetHandle) {
return null;
}
+6 -5
View File
@@ -14,10 +14,11 @@ import {
fitView as fitViewUtil,
getD3Transition,
getDimensions,
getElementsToRemove
getElementsToRemove,
getHandleBounds
} from '@reactflow/utils';
import { getHandleBounds, addEdge as addEdgeUtil } from '$lib/utils';
import { addEdge as addEdgeUtil } from '$lib/utils';
import type { EdgeTypes, NodeTypes, Node, Edge, ConnectionData } from '$lib/types';
import { getEdgesLayouted } from './edges-layouted';
import { getConnectionPath } from './connection-path';
@@ -104,8 +105,8 @@ export function createStore(params: CreateStoreParams): SvelteFlowStore {
node[internalsSymbol] = {
...node[internalsSymbol],
handleBounds: {
source: getHandleBounds('.source', update.nodeElement, zoom),
target: getHandleBounds('.target', update.nodeElement, zoom)
source: getHandleBounds('.source', update.nodeElement, zoom, node.origin),
target: getHandleBounds('.target', update.nodeElement, zoom, node.origin)
}
};
node.width = dimensions.width;
@@ -176,7 +177,7 @@ export function createStore(params: CreateStoreParams): SvelteFlowStore {
maxZoom: 2,
d3Selection,
d3Zoom,
nodeOrigin: get(store.nodeOrigin)
nodeOrigin: [0, 0]
},
{}
);
@@ -6,8 +6,7 @@ import {
ConnectionMode,
ConnectionLineType,
type SelectionRect,
type Transform,
type NodeOrigin
type Transform
} from '@reactflow/system';
import DefaultNode from '$lib/components/nodes/DefaultNode.svelte';
@@ -49,7 +48,6 @@ export const initialStoreState = {
maxZoom: writable<number>(2),
fitViewOnInit: writable<boolean>(false),
fitViewOnInitDone: writable<boolean>(false),
nodeOrigin: writable<NodeOrigin>([0, 0]),
d3: writable<{ zoom: D3ZoomInstance | null; selection: D3SelectionInstance | null }>({
zoom: null,
selection: null