chore(react/svelte): rename node.dimensions to node.size

This commit is contained in:
moklick
2023-10-09 17:04:11 +02:00
parent d78b2aad6f
commit afa6365e12
8 changed files with 31 additions and 28 deletions
@@ -16,7 +16,7 @@ import CustomNode from './CustomNode';
import '@xyflow/react/dist/style.css';
const nodeDimensions = {
const nodeSize = {
width: 100,
height: 40,
};
@@ -29,13 +29,13 @@ const initialNodes: Node[] = [
type: 'input',
data: { label: 'Node 1' },
position: { x: 250, y: 5 },
dimensions: nodeDimensions,
size: nodeSize,
handles: [
{
type: 'source',
position: Position.Bottom,
x: nodeDimensions.width * 0.5,
y: nodeDimensions.height,
x: nodeSize.width * 0.5,
y: nodeSize.height,
width: 1,
height: 1,
},
@@ -45,20 +45,20 @@ const initialNodes: Node[] = [
id: '2',
data: { label: 'Node 2' },
position: { x: 100, y: 100 },
dimensions: nodeDimensions,
size: nodeSize,
handles: [
{
type: 'source',
position: Position.Bottom,
x: nodeDimensions.width * 0.5,
y: nodeDimensions.height,
x: nodeSize.width * 0.5,
y: nodeSize.height,
width: 1,
height: 1,
},
{
type: 'target',
position: Position.Top,
x: nodeDimensions.width * 0.5,
x: nodeSize.width * 0.5,
y: 0,
width: 1,
height: 1,
@@ -69,20 +69,20 @@ const initialNodes: Node[] = [
id: '3',
data: { label: 'Node 3' },
position: { x: 400, y: 100 },
dimensions: nodeDimensions,
size: nodeSize,
handles: [
{
type: 'source',
position: Position.Bottom,
x: nodeDimensions.width * 0.5,
y: nodeDimensions.height,
x: nodeSize.width * 0.5,
y: nodeSize.height,
width: 1,
height: 1,
},
{
type: 'target',
position: Position.Top,
x: nodeDimensions.width * 0.5,
x: nodeSize.width * 0.5,
y: 0,
width: 1,
height: 1,
@@ -7,7 +7,7 @@
const nodeDefaults = {
sourcePosition: Position.Right,
targetPosition: Position.Left,
dimensions: {
size: {
width: 100,
height: 40,
},
@@ -52,8 +52,8 @@ export default (NodeComponent: ComponentType<NodeProps>) => {
disableKeyboardA11y,
ariaLabel,
rfId,
dimensionWidth,
dimensionHeight,
sizeWidth,
sizeHeight,
}: WrapNodeProps) => {
const store = useStoreApi();
const nodeRef = useRef<HTMLDivElement>(null);
@@ -184,8 +184,8 @@ export default (NodeComponent: ComponentType<NodeProps>) => {
transform: `translate(${xPosOrigin}px,${yPosOrigin}px)`,
pointerEvents: hasPointerEvents ? 'all' : 'none',
visibility: initialized ? 'visible' : 'hidden',
width: dimensionWidth,
height: dimensionHeight,
width: sizeWidth,
height: sizeHeight,
...style,
}}
data-id={id}
@@ -98,7 +98,7 @@ const NodeRenderer = (props: NodeRendererProps) => {
height: node.height ?? 0,
origin: node.origin || props.nodeOrigin,
});
const initialized = (!!node.width && !!node.height) || (!!node.dimensions?.width && !!node.dimensions?.height);
const initialized = (!!node.width && !!node.height) || (!!node.size?.width && !!node.size?.height);
return (
<NodeComponent
@@ -106,8 +106,8 @@ const NodeRenderer = (props: NodeRendererProps) => {
id={node.id}
className={node.className}
style={node.style}
dimensionWidth={node.dimensions?.width}
dimensionHeight={node.dimensions?.height}
sizeWidth={node.size?.width}
sizeHeight={node.size?.height}
type={nodeType}
data={node.data}
sourcePosition={node.sourcePosition || Position.Bottom}
+2 -2
View File
@@ -40,6 +40,6 @@ export type WrapNodeProps<NodeData = any> = Pick<
noPanClassName: string;
rfId: string;
disableKeyboardA11y: boolean;
dimensionWidth?: number;
dimensionHeight?: number;
sizeWidth?: number;
sizeHeight?: number;
};
@@ -118,8 +118,8 @@
class:parent={isParent}
style:z-index={zIndex}
style:transform="translate({positionOrigin?.x ?? 0}px, {positionOrigin?.y ?? 0}px)"
style:width={node.dimensions?.width && `${node.dimensions?.width}px`}
style:height={node.dimensions?.height && `${node.dimensions?.height}px`}
style:width={node.size?.width && `${node.size?.width}px`}
style:height={node.size?.height && `${node.size?.height}px`}
{style}
on:click={onSelectNodeHandler}
on:mouseenter={(event) => dispatch('nodemouseenter', { node, event })}
+5 -2
View File
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { internalsSymbol } from '../constants';
import type { XYPosition, Position, CoordinateExtent, HandleElement, Dimensions } from '.';
import type { XYPosition, Position, CoordinateExtent, HandleElement } from '.';
// this is stuff that all nodes share independent of the framework
export type NodeBase<T = any, U extends string | undefined = string | undefined> = {
@@ -29,7 +29,10 @@ export type NodeBase<T = any, U extends string | undefined = string | undefined>
focusable?: boolean;
origin?: NodeOrigin;
handles?: HandleElement[];
dimensions?: Dimensions;
size?: {
width?: number;
height?: number;
};
// only used internally
[internalsSymbol]?: {
+2 -2
View File
@@ -85,8 +85,8 @@ function toHandleBounds(handles?: HandleElement[]) {
function getHandleDataByNode(node?: NodeBase): [Rect, NodeHandleBounds | null, boolean] {
const handleBounds = node?.[internalsSymbol]?.handleBounds || toHandleBounds(node?.handles) || null;
const nodeWidth = node?.width || node?.dimensions?.width;
const nodeHeight = node?.height || node?.dimensions?.height;
const nodeWidth = node?.width || node?.size?.width;
const nodeHeight = node?.height || node?.size?.height;
const isValid =
handleBounds &&