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