resolved some requested changes
This commit is contained in:
@@ -74,7 +74,7 @@ export function NodeToolbar({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const nodeRect: Rect = getNodesBounds(nodes, { nodeOrigin });
|
const nodeRect: Rect = getNodesBounds(nodes, { nodeOrigin });
|
||||||
const zIndex: number = Math.max(...nodes.map((node) => (node.internals?.z || 1) + 1));
|
const zIndex: number = Math.max(...nodes.map((node) => node.internals.z + 1));
|
||||||
|
|
||||||
const wrapperStyle: CSSProperties = {
|
const wrapperStyle: CSSProperties = {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ const ConnectionLine = ({
|
|||||||
),
|
),
|
||||||
shallow
|
shallow
|
||||||
);
|
);
|
||||||
const fromHandleBounds = fromNode?.internals?.handleBounds;
|
const fromHandleBounds = fromNode?.internals.handleBounds;
|
||||||
let handleBounds = fromHandleBounds?.[handleType];
|
let handleBounds = fromHandleBounds?.[handleType];
|
||||||
|
|
||||||
if (connectionMode === ConnectionMode.Loose) {
|
if (connectionMode === ConnectionMode.Loose) {
|
||||||
@@ -66,8 +66,8 @@ const ConnectionLine = ({
|
|||||||
const fromHandle = handleId ? handleBounds.find((d) => d.id === handleId) : handleBounds[0];
|
const fromHandle = handleId ? handleBounds.find((d) => d.id === handleId) : handleBounds[0];
|
||||||
const fromHandleX = fromHandle ? fromHandle.x + fromHandle.width / 2 : (fromNode.measured.width ?? 0) / 2;
|
const fromHandleX = fromHandle ? fromHandle.x + fromHandle.width / 2 : (fromNode.measured.width ?? 0) / 2;
|
||||||
const fromHandleY = fromHandle ? fromHandle.y + fromHandle.height / 2 : fromNode.measured.height ?? 0;
|
const fromHandleY = fromHandle ? fromHandle.y + fromHandle.height / 2 : fromNode.measured.height ?? 0;
|
||||||
const fromX = (fromNode.internals.positionAbsolute.x ?? 0) + fromHandleX;
|
const fromX = fromNode.internals.positionAbsolute.x + fromHandleX;
|
||||||
const fromY = (fromNode.internals.positionAbsolute.y ?? 0) + fromHandleY;
|
const fromY = fromNode.internals.positionAbsolute.y + fromHandleY;
|
||||||
const fromPosition = fromHandle?.position;
|
const fromPosition = fromHandle?.position;
|
||||||
const toPosition = fromPosition ? oppositePosition[fromPosition] : null;
|
const toPosition = fromPosition ? oppositePosition[fromPosition] : null;
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,8 @@
|
|||||||
export let sourcePosition: $$Props['sourcePosition'] = undefined;
|
export let sourcePosition: $$Props['sourcePosition'] = undefined;
|
||||||
export let targetPosition: $$Props['targetPosition'] = undefined;
|
export let targetPosition: $$Props['targetPosition'] = undefined;
|
||||||
export let zIndex: $$Props['zIndex'];
|
export let zIndex: $$Props['zIndex'];
|
||||||
export let computedWidth: $$Props['computedWidth'] = undefined;
|
export let measuredWidth: $$Props['measuredWidth'] = undefined;
|
||||||
export let computedHeight: $$Props['computedHeight'] = undefined;
|
export let measuredHeight: $$Props['measuredHeight'] = undefined;
|
||||||
export let initialWidth: $$Props['initialWidth'] = undefined;
|
export let initialWidth: $$Props['initialWidth'] = undefined;
|
||||||
export let initialHeight: $$Props['initialHeight'] = undefined;
|
export let initialHeight: $$Props['initialHeight'] = undefined;
|
||||||
export let width: $$Props['width'] = undefined;
|
export let width: $$Props['width'] = undefined;
|
||||||
@@ -79,8 +79,8 @@
|
|||||||
height,
|
height,
|
||||||
initialWidth,
|
initialWidth,
|
||||||
initialHeight,
|
initialHeight,
|
||||||
computedWidth,
|
measuredWidth,
|
||||||
computedHeight
|
measuredHeight
|
||||||
});
|
});
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ export type NodeWrapperProps = Pick<
|
|||||||
| 'initialWidth'
|
| 'initialWidth'
|
||||||
| 'initialHeight'
|
| 'initialHeight'
|
||||||
> & {
|
> & {
|
||||||
computedWidth?: number;
|
measuredWidth?: number;
|
||||||
computedHeight?: number;
|
measuredHeight?: number;
|
||||||
type: string;
|
type: string;
|
||||||
positionX: number;
|
positionX: number;
|
||||||
positionY: number;
|
positionY: number;
|
||||||
|
|||||||
@@ -3,20 +3,20 @@ export function getNodeInlineStyleDimensions({
|
|||||||
height,
|
height,
|
||||||
initialWidth,
|
initialWidth,
|
||||||
initialHeight,
|
initialHeight,
|
||||||
computedWidth,
|
measuredWidth,
|
||||||
computedHeight
|
measuredHeight
|
||||||
}: {
|
}: {
|
||||||
width?: number;
|
width?: number;
|
||||||
height?: number;
|
height?: number;
|
||||||
initialWidth?: number;
|
initialWidth?: number;
|
||||||
initialHeight?: number;
|
initialHeight?: number;
|
||||||
computedWidth?: number;
|
measuredWidth?: number;
|
||||||
computedHeight?: number;
|
measuredHeight?: number;
|
||||||
}): {
|
}): {
|
||||||
width: string | undefined;
|
width: string | undefined;
|
||||||
height: string | undefined;
|
height: string | undefined;
|
||||||
} {
|
} {
|
||||||
if (computedWidth === undefined && computedHeight === undefined) {
|
if (measuredWidth === undefined && measuredHeight === undefined) {
|
||||||
const styleWidth = width ?? initialWidth;
|
const styleWidth = width ?? initialWidth;
|
||||||
const styleHeight = height ?? initialHeight;
|
const styleHeight = height ?? initialHeight;
|
||||||
|
|
||||||
|
|||||||
@@ -41,8 +41,8 @@
|
|||||||
{#each $visibleNodes as node (node.id)}
|
{#each $visibleNodes as node (node.id)}
|
||||||
{@const nodeDimesions = getNodeDimensions(node)}
|
{@const nodeDimesions = getNodeDimensions(node)}
|
||||||
{@const posOrigin = getPositionWithOrigin({
|
{@const posOrigin = getPositionWithOrigin({
|
||||||
x: node.internals.positionAbsolute.x ?? 0,
|
x: node.internals.positionAbsolute.x,
|
||||||
y: node.internals.positionAbsolute.y ?? 0,
|
y: node.internals.positionAbsolute.y,
|
||||||
...nodeDimesions,
|
...nodeDimesions,
|
||||||
origin: node.origin
|
origin: node.origin
|
||||||
})}
|
})}
|
||||||
@@ -61,8 +61,8 @@
|
|||||||
node.connectable ||
|
node.connectable ||
|
||||||
($nodesConnectable && typeof node.connectable === 'undefined')
|
($nodesConnectable && typeof node.connectable === 'undefined')
|
||||||
)}
|
)}
|
||||||
positionX={node.internals.positionAbsolute?.x ?? 0}
|
positionX={node.internals.positionAbsolute.x}
|
||||||
positionY={node.internals.positionAbsolute?.y ?? 0}
|
positionY={node.internals.positionAbsolute.y}
|
||||||
positionOriginX={posOrigin.x ?? 0}
|
positionOriginX={posOrigin.x ?? 0}
|
||||||
positionOriginY={posOrigin.y ?? 0}
|
positionOriginY={posOrigin.y ?? 0}
|
||||||
isParent={!!node.internals.isParent}
|
isParent={!!node.internals.isParent}
|
||||||
@@ -79,8 +79,8 @@
|
|||||||
height={node.height}
|
height={node.height}
|
||||||
initialWidth={node.initialWidth}
|
initialWidth={node.initialWidth}
|
||||||
initialHeight={node.initialHeight}
|
initialHeight={node.initialHeight}
|
||||||
computedWidth={node.measured.width}
|
measuredWidth={node.measured.width}
|
||||||
computedHeight={node.measured.height}
|
measuredHeight={node.measured.height}
|
||||||
{resizeObserver}
|
{resizeObserver}
|
||||||
on:nodeclick
|
on:nodeclick
|
||||||
on:nodemouseenter
|
on:nodemouseenter
|
||||||
|
|||||||
@@ -467,11 +467,7 @@ export function useSvelteFlow(): {
|
|||||||
|
|
||||||
const nextData = typeof dataUpdate === 'function' ? dataUpdate(node) : dataUpdate;
|
const nextData = typeof dataUpdate === 'function' ? dataUpdate(node) : dataUpdate;
|
||||||
|
|
||||||
if (options?.replace) {
|
node.data = options?.replace ? nextData : { ...node.data, ...nextData };
|
||||||
node.data = nextData;
|
|
||||||
} else {
|
|
||||||
node.data = { ...node.data, ...nextData };
|
|
||||||
}
|
|
||||||
|
|
||||||
nodes.update((nds) => nds);
|
nodes.update((nds) => nds);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -80,14 +80,14 @@ export function createStore({
|
|||||||
|
|
||||||
function updateNodeDimensions(updates: Map<string, NodeDimensionUpdate>) {
|
function updateNodeDimensions(updates: Map<string, NodeDimensionUpdate>) {
|
||||||
const nodeLookup = get(store.nodeLookup);
|
const nodeLookup = get(store.nodeLookup);
|
||||||
const nodeUpdates = updateNodeDimensionsSystem(
|
const changes = updateNodeDimensionsSystem(
|
||||||
updates,
|
updates,
|
||||||
nodeLookup,
|
nodeLookup,
|
||||||
get(store.domNode),
|
get(store.domNode),
|
||||||
get(store.nodeOrigin)
|
get(store.nodeOrigin)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!nodeUpdates) {
|
if (!changes) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,23 +100,23 @@ export function createStore({
|
|||||||
store.fitViewOnInitDone.set(fitViewOnInitDone);
|
store.fitViewOnInitDone.set(fitViewOnInitDone);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const nodeUpdate of nodeUpdates) {
|
for (const change of changes) {
|
||||||
const node = nodeLookup.get(nodeUpdate.id)?.internals.userNode;
|
const node = nodeLookup.get(change.id)?.internals.userNode;
|
||||||
|
|
||||||
if (!node) {
|
if (!node) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (nodeUpdate.type) {
|
switch (change.type) {
|
||||||
case 'dimensions': {
|
case 'dimensions': {
|
||||||
const measured = { ...node.measured, ...nodeUpdate.dimensions };
|
const measured = { ...node.measured, ...change.dimensions };
|
||||||
node.width = nodeUpdate.dimensions?.width ?? node.width;
|
node.width = change.dimensions?.width ?? node.width;
|
||||||
node.height = nodeUpdate.dimensions?.height ?? node.height;
|
node.height = change.dimensions?.height ?? node.height;
|
||||||
node.measured = measured;
|
node.measured = measured;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'position':
|
case 'position':
|
||||||
node.position = nodeUpdate.position ?? node.position;
|
node.position = change.position ?? node.position;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ export const getInitialStore = ({
|
|||||||
let viewport: Viewport = { x: 0, y: 0, zoom: 1 };
|
let viewport: Viewport = { x: 0, y: 0, zoom: 1 };
|
||||||
|
|
||||||
if (fitView && width && height) {
|
if (fitView && width && height) {
|
||||||
const nodesWithDimensions = Array.from(nodeLookup.values()).filter(
|
const nodesWithDimensions = nodes.filter(
|
||||||
(node) => (node.width && node.height) || (node.initialWidth && node.initialHeight)
|
(node) => (node.width && node.height) || (node.initialWidth && node.initialHeight)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -97,8 +97,8 @@ function toHandleBounds(handles?: NodeHandle[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getHandlePosition(position: Position, node: InternalNodeBase, handle: HandleElement | null = null): number[] {
|
function getHandlePosition(position: Position, node: InternalNodeBase, handle: HandleElement | null = null): number[] {
|
||||||
const x = (handle?.x ?? 0) + (node.internals.positionAbsolute?.x ?? 0);
|
const x = (handle?.x ?? 0) + node.internals.positionAbsolute.x;
|
||||||
const y = (handle?.y ?? 0) + (node.internals.positionAbsolute?.y ?? 0);
|
const y = (handle?.y ?? 0) + node.internals.positionAbsolute.y;
|
||||||
const { width, height } = handle ?? getNodeDimensions(node);
|
const { width, height } = handle ?? getNodeDimensions(node);
|
||||||
|
|
||||||
switch (position) {
|
switch (position) {
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ export function adoptUserNodes<NodeType extends NodeBase>(
|
|||||||
},
|
},
|
||||||
internals: {
|
internals: {
|
||||||
positionAbsolute: userNode.position,
|
positionAbsolute: userNode.position,
|
||||||
handleBounds: currentStoreNode?.internals?.handleBounds,
|
handleBounds: currentStoreNode?.internals.handleBounds,
|
||||||
z: (isNumeric(userNode.zIndex) ? userNode.zIndex : 0) + (userNode.selected ? selectedNodeZ : 0),
|
z: (isNumeric(userNode.zIndex) ? userNode.zIndex : 0) + (userNode.selected ? selectedNodeZ : 0),
|
||||||
userNode,
|
userNode,
|
||||||
isParent: false,
|
isParent: false,
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ export function getDragItems<NodeType extends NodeBase>(
|
|||||||
id: internalNode.id,
|
id: internalNode.id,
|
||||||
position: internalNode.position || { x: 0, y: 0 },
|
position: internalNode.position || { x: 0, y: 0 },
|
||||||
distance: {
|
distance: {
|
||||||
x: mousePos.x - (internalNode.internals.positionAbsolute?.x ?? 0),
|
x: mousePos.x - internalNode.internals.positionAbsolute.x,
|
||||||
y: mousePos.y - (internalNode.internals.positionAbsolute?.y ?? 0),
|
y: mousePos.y - internalNode.internals.positionAbsolute.y,
|
||||||
},
|
},
|
||||||
extent: internalNode.extent,
|
extent: internalNode.extent,
|
||||||
parentId: internalNode.parentId,
|
parentId: internalNode.parentId,
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ export function getHandles(
|
|||||||
id: h.id || null,
|
id: h.id || null,
|
||||||
type,
|
type,
|
||||||
nodeId: node.id,
|
nodeId: node.id,
|
||||||
x: (node.internals.positionAbsolute.x ?? 0) + h.x + h.width / 2,
|
x: node.internals.positionAbsolute.x + h.x + h.width / 2,
|
||||||
y: (node.internals.positionAbsolute.y ?? 0) + h.y + h.height / 2,
|
y: node.internals.positionAbsolute.y + h.y + h.height / 2,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
Reference in New Issue
Block a user