chore(system): rename BaseNode/BaseEdge types to NodeBase/EdgeBase
This commit is contained in:
@@ -33,7 +33,7 @@
|
|||||||
"cypress": "12.14.0",
|
"cypress": "12.14.0",
|
||||||
"cypress-real-events": "1.8.1",
|
"cypress-real-events": "1.8.1",
|
||||||
"start-server-and-test": "^1.14.0",
|
"start-server-and-test": "^1.14.0",
|
||||||
"typescript": "^4.9.4",
|
"typescript": "5.1.3",
|
||||||
"vite": "4.3.9"
|
"vite": "4.3.9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -37,6 +37,6 @@
|
|||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"rollup": "^3.23.0",
|
"rollup": "^3.23.0",
|
||||||
"turbo": "^1.10.0",
|
"turbo": "^1.10.0",
|
||||||
"typescript": "^4.9.4"
|
"typescript": "5.1.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,14 +55,14 @@
|
|||||||
"react-dom": ">=17"
|
"react-dom": ">=17"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@xyflow/eslint-config": "workspace:*",
|
|
||||||
"@xyflow/rollup-config": "workspace:*",
|
|
||||||
"@xyflow/tsconfig": "workspace:*",
|
|
||||||
"@types/node": "^18.7.16",
|
"@types/node": "^18.7.16",
|
||||||
"@types/react": ">=17",
|
"@types/react": ">=17",
|
||||||
"@types/react-dom": ">=17",
|
"@types/react-dom": ">=17",
|
||||||
|
"@xyflow/eslint-config": "workspace:*",
|
||||||
|
"@xyflow/rollup-config": "workspace:*",
|
||||||
|
"@xyflow/tsconfig": "workspace:*",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"typescript": "^4.9.4"
|
"typescript": "5.1.3"
|
||||||
},
|
},
|
||||||
"rollup": {
|
"rollup": {
|
||||||
"globals": {
|
"globals": {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import type { CSSProperties, HTMLAttributes, ReactNode, MouseEvent as ReactMouseEvent, ComponentType } from 'react';
|
import type { CSSProperties, HTMLAttributes, ReactNode, MouseEvent as ReactMouseEvent, ComponentType } from 'react';
|
||||||
import type {
|
import type {
|
||||||
BaseEdge,
|
EdgeBase,
|
||||||
BezierPathOptions,
|
BezierPathOptions,
|
||||||
Position,
|
Position,
|
||||||
SmoothStepPathOptions,
|
SmoothStepPathOptions,
|
||||||
@@ -28,7 +28,7 @@ export type EdgeLabelOptions = {
|
|||||||
|
|
||||||
export type EdgeUpdatable = boolean | HandleType;
|
export type EdgeUpdatable = boolean | HandleType;
|
||||||
|
|
||||||
export type DefaultEdge<EdgeData = any> = BaseEdge<EdgeData> & {
|
export type DefaultEdge<EdgeData = any> = EdgeBase<EdgeData> & {
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
className?: string;
|
className?: string;
|
||||||
sourceNode?: Node;
|
sourceNode?: Node;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { CSSProperties, MouseEvent as ReactMouseEvent } from 'react';
|
import type { CSSProperties, MouseEvent as ReactMouseEvent } from 'react';
|
||||||
import type { BaseNode } from '@xyflow/system';
|
import type { NodeBase } from '@xyflow/system';
|
||||||
|
|
||||||
export type Node<NodeData = any, NodeType extends string | undefined = string | undefined> = BaseNode<
|
export type Node<NodeData = any, NodeType extends string | undefined = string | undefined> = NodeBase<
|
||||||
NodeData,
|
NodeData,
|
||||||
NodeType
|
NodeType
|
||||||
> & {
|
> & {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
"svelte": "^3.59.1",
|
"svelte": "^3.59.1",
|
||||||
"svelte-check": "^3.4.3",
|
"svelte-check": "^3.4.3",
|
||||||
"tslib": "^2.4.1",
|
"tslib": "^2.4.1",
|
||||||
"typescript": "^4.9.3",
|
"typescript": "5.1.3",
|
||||||
"vite": "^4.3.9"
|
"vite": "^4.3.9"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ import {
|
|||||||
type Connection,
|
type Connection,
|
||||||
type XYPosition,
|
type XYPosition,
|
||||||
type CoordinateExtent,
|
type CoordinateExtent,
|
||||||
type UpdateConnection
|
type UpdateConnection,
|
||||||
|
type NodeBase,
|
||||||
|
type NodeDragItem
|
||||||
} from '@xyflow/system';
|
} from '@xyflow/system';
|
||||||
|
|
||||||
import { addEdge as addEdgeUtil } from '$lib/utils';
|
import { addEdge as addEdgeUtil } from '$lib/utils';
|
||||||
@@ -57,7 +59,9 @@ export function createStore(): SvelteFlowStore {
|
|||||||
const updateNodePositions: UpdateNodePositions = (nodeDragItems, dragging = false) => {
|
const updateNodePositions: UpdateNodePositions = (nodeDragItems, dragging = false) => {
|
||||||
store.nodes.update((nds) => {
|
store.nodes.update((nds) => {
|
||||||
return nds.map((n) => {
|
return nds.map((n) => {
|
||||||
const nodeDragItem = nodeDragItems.find((ndi) => ndi.id === n.id);
|
const nodeDragItem = (nodeDragItems as Array<NodeBase | NodeDragItem>).find(
|
||||||
|
(ndi) => ndi.id === n.id
|
||||||
|
);
|
||||||
|
|
||||||
if (nodeDragItem) {
|
if (nodeDragItem) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import type { SvelteComponentTyped } from 'svelte';
|
import type { SvelteComponentTyped } from 'svelte';
|
||||||
import type {
|
import type {
|
||||||
BaseEdge,
|
EdgeBase,
|
||||||
BezierPathOptions,
|
BezierPathOptions,
|
||||||
DefaultEdgeOptionsBase,
|
DefaultEdgeOptionsBase,
|
||||||
EdgePosition,
|
EdgePosition,
|
||||||
@@ -10,7 +10,7 @@ import type {
|
|||||||
|
|
||||||
import type { Node } from '$lib/types';
|
import type { Node } from '$lib/types';
|
||||||
|
|
||||||
export type DefaultEdge<EdgeData = any> = BaseEdge<EdgeData> & {
|
export type DefaultEdge<EdgeData = any> = EdgeBase<EdgeData> & {
|
||||||
label?: string;
|
label?: string;
|
||||||
labelStyle?: string;
|
labelStyle?: string;
|
||||||
style?: string;
|
style?: string;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
|
||||||
import type { SvelteComponentTyped } from 'svelte';
|
import type { SvelteComponentTyped } from 'svelte';
|
||||||
import type { BaseNode, NodeProps } from '@xyflow/system';
|
import type { NodeBase, NodeProps } from '@xyflow/system';
|
||||||
|
|
||||||
// @todo: currently the helper function only like Node from '@reactflow/core'
|
// @todo: currently the helper function only like Node from '@reactflow/core'
|
||||||
// we need a base node type or helpes that accept Node like types
|
// we need a base node type or helpes that accept Node like types
|
||||||
@@ -9,7 +9,7 @@ import type { BaseNode, NodeProps } from '@xyflow/system';
|
|||||||
export type Node<
|
export type Node<
|
||||||
NodeData = any,
|
NodeData = any,
|
||||||
NodeType extends string | undefined = string | undefined
|
NodeType extends string | undefined = string | undefined
|
||||||
> = BaseNode<NodeData, NodeType> & {
|
> = NodeBase<NodeData, NodeType> & {
|
||||||
class?: string;
|
class?: string;
|
||||||
style?: string;
|
style?: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@xyflow/system",
|
"name": "@xyflow/system",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "Core system of xyflow.",
|
"description": "xyflow core system that powers React Flow and Svelte Flow.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"node-based UI",
|
"node-based UI",
|
||||||
"graph",
|
"graph",
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
"@xyflow/eslint-config": "workspace:*",
|
"@xyflow/eslint-config": "workspace:*",
|
||||||
"@xyflow/rollup-config": "workspace:*",
|
"@xyflow/rollup-config": "workspace:*",
|
||||||
"@xyflow/tsconfig": "workspace:*",
|
"@xyflow/tsconfig": "workspace:*",
|
||||||
"typescript": "^4.9.4"
|
"typescript": "5.1.3"
|
||||||
},
|
},
|
||||||
"rollup": {
|
"rollup": {
|
||||||
"globals": {
|
"globals": {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Position } from './utils';
|
import { Position } from './utils';
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
export type BaseEdge<EdgeData = any> = {
|
export type EdgeBase<EdgeData = any> = {
|
||||||
id: string;
|
id: string;
|
||||||
type?: string;
|
type?: string;
|
||||||
source: string;
|
source: string;
|
||||||
@@ -31,7 +31,7 @@ export type BezierPathOptions = {
|
|||||||
curvature?: number;
|
curvature?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DefaultEdgeOptionsBase<EdgeType extends BaseEdge> = Omit<
|
export type DefaultEdgeOptionsBase<EdgeType extends EdgeBase> = Omit<
|
||||||
EdgeType,
|
EdgeType,
|
||||||
'id' | 'source' | 'target' | 'sourceHandle' | 'targetHandle' | 'sourceNode' | 'targetNode'
|
'id' | 'source' | 'target' | 'sourceHandle' | 'targetHandle' | 'sourceNode' | 'targetNode'
|
||||||
>;
|
>;
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
import type { D3DragEvent, Selection as D3Selection, SubjectPosition, ZoomBehavior } from 'd3';
|
import type { D3DragEvent, Selection as D3Selection, SubjectPosition, ZoomBehavior } from 'd3';
|
||||||
|
|
||||||
import type { XYPosition, Rect } from './utils';
|
import type { XYPosition, Rect } from './utils';
|
||||||
import type { BaseNode, NodeDragItem, NodeOrigin } from './nodes';
|
import type { NodeBase, NodeDragItem, NodeOrigin } from './nodes';
|
||||||
import type { ConnectingHandle, HandleType } from './handles';
|
import type { ConnectingHandle, HandleType } from './handles';
|
||||||
import { PanZoomInstance } from './panzoom';
|
import { PanZoomInstance } from './panzoom';
|
||||||
import { BaseEdge } from '..';
|
import { EdgeBase } from '..';
|
||||||
|
|
||||||
export type Project = (position: XYPosition) => XYPosition;
|
export type Project = (position: XYPosition) => XYPosition;
|
||||||
|
|
||||||
@@ -45,9 +45,9 @@ export type OnConnectStart = (event: MouseEvent | TouchEvent, params: OnConnectS
|
|||||||
export type OnConnect = (connection: Connection) => void;
|
export type OnConnect = (connection: Connection) => void;
|
||||||
export type OnConnectEnd = (event: MouseEvent | TouchEvent) => void;
|
export type OnConnectEnd = (event: MouseEvent | TouchEvent) => void;
|
||||||
|
|
||||||
export type IsValidConnection = (edge: BaseEdge | Connection) => boolean;
|
export type IsValidConnection = (edge: EdgeBase | Connection) => boolean;
|
||||||
|
|
||||||
export type FitViewParamsBase<NodeType extends BaseNode> = {
|
export type FitViewParamsBase<NodeType extends NodeBase> = {
|
||||||
nodes: NodeType[];
|
nodes: NodeType[];
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
@@ -57,7 +57,7 @@ export type FitViewParamsBase<NodeType extends BaseNode> = {
|
|||||||
nodeOrigin?: NodeOrigin;
|
nodeOrigin?: NodeOrigin;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FitViewOptionsBase<NodeType extends BaseNode> = {
|
export type FitViewOptionsBase<NodeType extends NodeBase> = {
|
||||||
padding?: number;
|
padding?: number;
|
||||||
includeHiddenNodes?: boolean;
|
includeHiddenNodes?: boolean;
|
||||||
minZoom?: number;
|
minZoom?: number;
|
||||||
@@ -124,7 +124,7 @@ export type SelectionRect = Rect & {
|
|||||||
export type OnError = (id: string, message: string) => void;
|
export type OnError = (id: string, message: string) => void;
|
||||||
|
|
||||||
export type UpdateNodePositions = (
|
export type UpdateNodePositions = (
|
||||||
dragItems: NodeDragItem[] | BaseNode[],
|
dragItems: NodeDragItem[] | NodeBase[],
|
||||||
positionChanged?: boolean,
|
positionChanged?: boolean,
|
||||||
dragging?: boolean
|
dragging?: boolean
|
||||||
) => void;
|
) => void;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { internalsSymbol } from '../constants';
|
|||||||
import type { XYPosition, Position, CoordinateExtent, HandleElement } 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 BaseNode<T = any, U extends string | undefined = string | undefined> = {
|
export type NodeBase<T = any, U extends string | undefined = string | undefined> = {
|
||||||
id: string;
|
id: string;
|
||||||
position: XYPosition;
|
position: XYPosition;
|
||||||
data: T;
|
data: T;
|
||||||
@@ -39,13 +39,13 @@ export type BaseNode<T = any, U extends string | undefined = string | undefined>
|
|||||||
|
|
||||||
// props that get passed to a custom node
|
// props that get passed to a custom node
|
||||||
export type NodeProps<T = any> = {
|
export type NodeProps<T = any> = {
|
||||||
id: BaseNode['id'];
|
id: NodeBase['id'];
|
||||||
data: T;
|
data: T;
|
||||||
dragHandle: BaseNode['dragHandle'];
|
dragHandle: NodeBase['dragHandle'];
|
||||||
type: BaseNode['type'];
|
type: NodeBase['type'];
|
||||||
selected: BaseNode['selected'];
|
selected: NodeBase['selected'];
|
||||||
isConnectable: BaseNode['connectable'];
|
isConnectable: NodeBase['connectable'];
|
||||||
zIndex: BaseNode['zIndex'];
|
zIndex: NodeBase['zIndex'];
|
||||||
xPos: number;
|
xPos: number;
|
||||||
yPos: number;
|
yPos: number;
|
||||||
dragging: boolean;
|
dragging: boolean;
|
||||||
@@ -85,6 +85,6 @@ export type NodeDragItem = {
|
|||||||
|
|
||||||
export type NodeOrigin = [number, number];
|
export type NodeOrigin = [number, number];
|
||||||
|
|
||||||
export type OnNodeDrag = (event: MouseEvent, node: BaseNode, nodes: BaseNode[]) => void;
|
export type OnNodeDrag = (event: MouseEvent, node: NodeBase, nodes: NodeBase[]) => void;
|
||||||
|
|
||||||
export type OnSelectionDrag = (event: MouseEvent, nodes: BaseNode[]) => void;
|
export type OnSelectionDrag = (event: MouseEvent, nodes: NodeBase[]) => void;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Connection, Transform, errorMessages, internalsSymbol, isEdgeBase } from '../..';
|
import { Connection, Transform, errorMessages, internalsSymbol, isEdgeBase } from '../..';
|
||||||
import { BaseEdge, BaseNode } from '../../types';
|
import { EdgeBase, NodeBase } from '../../types';
|
||||||
import { isNumeric, getOverlappingArea, boxToRect, nodeToBox, getBoundsOfBoxes, devWarn } from '../general';
|
import { isNumeric, getOverlappingArea, boxToRect, nodeToBox, getBoundsOfBoxes, devWarn } from '../general';
|
||||||
|
|
||||||
// this is used for straight edges and simple smoothstep edges (LTR, RTL, BTT, TTB)
|
// this is used for straight edges and simple smoothstep edges (LTR, RTL, BTT, TTB)
|
||||||
@@ -25,15 +25,15 @@ export function getEdgeCenter({
|
|||||||
|
|
||||||
const defaultEdgeTree = [{ level: 0, isMaxLevel: true, edges: [] }];
|
const defaultEdgeTree = [{ level: 0, isMaxLevel: true, edges: [] }];
|
||||||
|
|
||||||
export type GroupedEdges<EdgeType extends BaseEdge> = {
|
export type GroupedEdges<EdgeType extends EdgeBase> = {
|
||||||
edges: EdgeType[];
|
edges: EdgeType[];
|
||||||
level: number;
|
level: number;
|
||||||
isMaxLevel: boolean;
|
isMaxLevel: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function groupEdgesByZLevel<EdgeType extends BaseEdge>(
|
export function groupEdgesByZLevel<EdgeType extends EdgeBase>(
|
||||||
edges: EdgeType[],
|
edges: EdgeType[],
|
||||||
nodes: BaseNode[],
|
nodes: NodeBase[],
|
||||||
elevateEdgesOnSelect = false
|
elevateEdgesOnSelect = false
|
||||||
): GroupedEdges<EdgeType>[] {
|
): GroupedEdges<EdgeType>[] {
|
||||||
let maxLevel = -1;
|
let maxLevel = -1;
|
||||||
@@ -80,8 +80,8 @@ export function groupEdgesByZLevel<EdgeType extends BaseEdge>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
type IsEdgeVisibleParams = {
|
type IsEdgeVisibleParams = {
|
||||||
sourceNode: BaseNode;
|
sourceNode: NodeBase;
|
||||||
targetNode: BaseNode;
|
targetNode: NodeBase;
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
transform: Transform;
|
transform: Transform;
|
||||||
@@ -108,10 +108,10 @@ export function isEdgeVisible({ sourceNode, targetNode, width, height, transform
|
|||||||
return getOverlappingArea(viewRect, boxToRect(edgeBox)) > 0;
|
return getOverlappingArea(viewRect, boxToRect(edgeBox)) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getEdgeId = ({ source, sourceHandle, target, targetHandle }: Connection | BaseEdge): string =>
|
const getEdgeId = ({ source, sourceHandle, target, targetHandle }: Connection | EdgeBase): string =>
|
||||||
`xyflow__edge-${source}${sourceHandle || ''}-${target}${targetHandle || ''}`;
|
`xyflow__edge-${source}${sourceHandle || ''}-${target}${targetHandle || ''}`;
|
||||||
|
|
||||||
const connectionExists = (edge: BaseEdge, edges: BaseEdge[]) => {
|
const connectionExists = (edge: EdgeBase, edges: EdgeBase[]) => {
|
||||||
return edges.some(
|
return edges.some(
|
||||||
(el) =>
|
(el) =>
|
||||||
el.source === edge.source &&
|
el.source === edge.source &&
|
||||||
@@ -121,7 +121,7 @@ const connectionExists = (edge: BaseEdge, edges: BaseEdge[]) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addEdgeBase = <EdgeType extends BaseEdge>(
|
export const addEdgeBase = <EdgeType extends EdgeBase>(
|
||||||
edgeParams: EdgeType | Connection,
|
edgeParams: EdgeType | Connection,
|
||||||
edges: EdgeType[]
|
edges: EdgeType[]
|
||||||
): EdgeType[] => {
|
): EdgeType[] => {
|
||||||
@@ -152,7 +152,7 @@ export type UpdateEdgeOptions = {
|
|||||||
shouldReplaceId?: boolean;
|
shouldReplaceId?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateEdgeBase = <EdgeType extends BaseEdge>(
|
export const updateEdgeBase = <EdgeType extends EdgeBase>(
|
||||||
oldEdge: EdgeType,
|
oldEdge: EdgeType,
|
||||||
newConnection: Connection,
|
newConnection: Connection,
|
||||||
edges: EdgeType[],
|
edges: EdgeType[],
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import { EdgePosition } from '../../types/edges';
|
import { EdgePosition } from '../../types/edges';
|
||||||
import { ConnectionMode, OnError } from '../../types/general';
|
import { ConnectionMode, OnError } from '../../types/general';
|
||||||
import { BaseNode, NodeHandleBounds } from '../../types/nodes';
|
import { NodeBase, NodeHandleBounds } from '../../types/nodes';
|
||||||
import { Position, Rect, XYPosition } from '../../types/utils';
|
import { Position, Rect, XYPosition } from '../../types/utils';
|
||||||
import { errorMessages, internalsSymbol } from '../../constants';
|
import { errorMessages, internalsSymbol } from '../../constants';
|
||||||
import { HandleElement } from '../../types';
|
import { HandleElement } from '../../types';
|
||||||
|
|
||||||
export type GetEdgePositionParams = {
|
export type GetEdgePositionParams = {
|
||||||
id: string;
|
id: string;
|
||||||
sourceNode: BaseNode;
|
sourceNode: NodeBase;
|
||||||
sourceHandle: string | null;
|
sourceHandle: string | null;
|
||||||
targetNode: BaseNode;
|
targetNode: NodeBase;
|
||||||
targetHandle: string | null;
|
targetHandle: string | null;
|
||||||
connectionMode: ConnectionMode;
|
connectionMode: ConnectionMode;
|
||||||
onError?: OnError;
|
onError?: OnError;
|
||||||
@@ -59,7 +59,7 @@ export function getEdgePosition(params: GetEdgePositionParams): EdgePosition | n
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHandleDataByNode(node?: BaseNode): [Rect, NodeHandleBounds | null, boolean] {
|
function getHandleDataByNode(node?: NodeBase): [Rect, NodeHandleBounds | null, boolean] {
|
||||||
const handleBounds = node?.[internalsSymbol]?.handleBounds || null;
|
const handleBounds = node?.[internalsSymbol]?.handleBounds || null;
|
||||||
|
|
||||||
const isValid =
|
const isValid =
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import type {
|
|||||||
CoordinateExtent,
|
CoordinateExtent,
|
||||||
Box,
|
Box,
|
||||||
Rect,
|
Rect,
|
||||||
BaseNode,
|
NodeBase,
|
||||||
NodeOrigin,
|
NodeOrigin,
|
||||||
SnapGrid,
|
SnapGrid,
|
||||||
Transform,
|
Transform,
|
||||||
@@ -58,7 +58,7 @@ export const boxToRect = ({ x, y, x2, y2 }: Box): Rect => ({
|
|||||||
height: y2 - y,
|
height: y2 - y,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const nodeToRect = (node: BaseNode, nodeOrigin: NodeOrigin = [0, 0]): Rect => {
|
export const nodeToRect = (node: NodeBase, nodeOrigin: NodeOrigin = [0, 0]): Rect => {
|
||||||
const { positionAbsolute } = getNodePositionWithOrigin(node, node.origin || nodeOrigin);
|
const { positionAbsolute } = getNodePositionWithOrigin(node, node.origin || nodeOrigin);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -68,7 +68,7 @@ export const nodeToRect = (node: BaseNode, nodeOrigin: NodeOrigin = [0, 0]): Rec
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const nodeToBox = (node: BaseNode, nodeOrigin: NodeOrigin = [0, 0]): Box => {
|
export const nodeToBox = (node: NodeBase, nodeOrigin: NodeOrigin = [0, 0]): Box => {
|
||||||
const { positionAbsolute } = getNodePositionWithOrigin(node, node.origin || nodeOrigin);
|
const { positionAbsolute } = getNodePositionWithOrigin(node, node.origin || nodeOrigin);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ import {
|
|||||||
type XYPosition,
|
type XYPosition,
|
||||||
type Rect,
|
type Rect,
|
||||||
type NodeOrigin,
|
type NodeOrigin,
|
||||||
type BaseNode,
|
type NodeBase,
|
||||||
type BaseEdge,
|
type EdgeBase,
|
||||||
type FitViewParamsBase,
|
type FitViewParamsBase,
|
||||||
type FitViewOptionsBase,
|
type FitViewOptionsBase,
|
||||||
NodeDragItem,
|
NodeDragItem,
|
||||||
@@ -27,15 +27,15 @@ import {
|
|||||||
} from '../types';
|
} from '../types';
|
||||||
import { errorMessages } from '../constants';
|
import { errorMessages } from '../constants';
|
||||||
|
|
||||||
export const isEdgeBase = <NodeType extends BaseNode = BaseNode, EdgeType extends BaseEdge = BaseEdge>(
|
export const isEdgeBase = <NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase>(
|
||||||
element: NodeType | Connection | EdgeType
|
element: NodeType | Connection | EdgeType
|
||||||
): element is EdgeType => 'id' in element && 'source' in element && 'target' in element;
|
): element is EdgeType => 'id' in element && 'source' in element && 'target' in element;
|
||||||
|
|
||||||
export const isNodeBase = <NodeType extends BaseNode = BaseNode, EdgeType extends BaseEdge = BaseEdge>(
|
export const isNodeBase = <NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase>(
|
||||||
element: NodeType | Connection | EdgeType
|
element: NodeType | Connection | EdgeType
|
||||||
): element is NodeType => 'id' in element && !('source' in element) && !('target' in element);
|
): element is NodeType => 'id' in element && !('source' in element) && !('target' in element);
|
||||||
|
|
||||||
export const getOutgoersBase = <NodeType extends BaseNode = BaseNode, EdgeType extends BaseEdge = BaseEdge>(
|
export const getOutgoersBase = <NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase>(
|
||||||
node: NodeType,
|
node: NodeType,
|
||||||
nodes: NodeType[],
|
nodes: NodeType[],
|
||||||
edges: EdgeType[]
|
edges: EdgeType[]
|
||||||
@@ -48,7 +48,7 @@ export const getOutgoersBase = <NodeType extends BaseNode = BaseNode, EdgeType e
|
|||||||
return nodes.filter((n) => outgoerIds.includes(n.id));
|
return nodes.filter((n) => outgoerIds.includes(n.id));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getIncomersBase = <NodeType extends BaseNode = BaseNode, EdgeType extends BaseEdge = BaseEdge>(
|
export const getIncomersBase = <NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase>(
|
||||||
node: NodeType,
|
node: NodeType,
|
||||||
nodes: NodeType[],
|
nodes: NodeType[],
|
||||||
edges: EdgeType[]
|
edges: EdgeType[]
|
||||||
@@ -62,7 +62,7 @@ export const getIncomersBase = <NodeType extends BaseNode = BaseNode, EdgeType e
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getNodePositionWithOrigin = (
|
export const getNodePositionWithOrigin = (
|
||||||
node: BaseNode | undefined,
|
node: NodeBase | undefined,
|
||||||
nodeOrigin: NodeOrigin = [0, 0]
|
nodeOrigin: NodeOrigin = [0, 0]
|
||||||
): XYPosition & { positionAbsolute: XYPosition } => {
|
): XYPosition & { positionAbsolute: XYPosition } => {
|
||||||
if (!node) {
|
if (!node) {
|
||||||
@@ -95,7 +95,7 @@ export const getNodePositionWithOrigin = (
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getRectOfNodes = (nodes: BaseNode[], nodeOrigin: NodeOrigin = [0, 0]): Rect => {
|
export const getRectOfNodes = (nodes: NodeBase[], nodeOrigin: NodeOrigin = [0, 0]): Rect => {
|
||||||
if (nodes.length === 0) {
|
if (nodes.length === 0) {
|
||||||
return { x: 0, y: 0, width: 0, height: 0 };
|
return { x: 0, y: 0, width: 0, height: 0 };
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ export const getRectOfNodes = (nodes: BaseNode[], nodeOrigin: NodeOrigin = [0, 0
|
|||||||
return boxToRect(box);
|
return boxToRect(box);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getNodesInside = <NodeType extends BaseNode>(
|
export const getNodesInside = <NodeType extends NodeBase>(
|
||||||
nodes: NodeType[],
|
nodes: NodeType[],
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
[tx, ty, tScale]: Transform = [0, 0, 1],
|
[tx, ty, tScale]: Transform = [0, 0, 1],
|
||||||
@@ -158,7 +158,7 @@ export const getNodesInside = <NodeType extends BaseNode>(
|
|||||||
return visibleNodes;
|
return visibleNodes;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getConnectedEdgesBase = <NodeType extends BaseNode = BaseNode, EdgeType extends BaseEdge = BaseEdge>(
|
export const getConnectedEdgesBase = <NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase>(
|
||||||
nodes: NodeType[],
|
nodes: NodeType[],
|
||||||
edges: EdgeType[]
|
edges: EdgeType[]
|
||||||
): EdgeType[] => {
|
): EdgeType[] => {
|
||||||
@@ -167,7 +167,7 @@ export const getConnectedEdgesBase = <NodeType extends BaseNode = BaseNode, Edge
|
|||||||
return edges.filter((edge) => nodeIds.includes(edge.source) || nodeIds.includes(edge.target));
|
return edges.filter((edge) => nodeIds.includes(edge.source) || nodeIds.includes(edge.target));
|
||||||
};
|
};
|
||||||
|
|
||||||
export function fitView<Params extends FitViewParamsBase<BaseNode>, Options extends FitViewOptionsBase<BaseNode>>(
|
export function fitView<Params extends FitViewParamsBase<NodeBase>, Options extends FitViewOptionsBase<NodeBase>>(
|
||||||
{ nodes, width, height, panZoom, minZoom, maxZoom, nodeOrigin = [0, 0] }: Params,
|
{ nodes, width, height, panZoom, minZoom, maxZoom, nodeOrigin = [0, 0] }: Params,
|
||||||
options?: Options
|
options?: Options
|
||||||
) {
|
) {
|
||||||
@@ -203,7 +203,7 @@ export function fitView<Params extends FitViewParamsBase<BaseNode>, Options exte
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calcNextPosition<NodeType extends BaseNode>(
|
export function calcNextPosition<NodeType extends NodeBase>(
|
||||||
node: NodeDragItem | NodeType,
|
node: NodeDragItem | NodeType,
|
||||||
nextPosition: XYPosition,
|
nextPosition: XYPosition,
|
||||||
nodes: NodeType[],
|
nodes: NodeType[],
|
||||||
@@ -263,7 +263,7 @@ export function calcNextPosition<NodeType extends BaseNode>(
|
|||||||
// helper function to get arrays of nodes and edges that can be deleted
|
// helper function to get arrays of nodes and edges that can be deleted
|
||||||
// you can pass in a list of nodes and edges that should be deleted
|
// you can pass in a list of nodes and edges that should be deleted
|
||||||
// and the function only returns elements that are deletable and also handles connected nodes and child nodes
|
// and the function only returns elements that are deletable and also handles connected nodes and child nodes
|
||||||
export function getElementsToRemove<NodeType extends BaseNode = BaseNode, EdgeType extends BaseEdge = BaseEdge>({
|
export function getElementsToRemove<NodeType extends NodeBase = NodeBase, EdgeType extends EdgeBase = EdgeBase>({
|
||||||
nodesToRemove,
|
nodesToRemove,
|
||||||
edgesToRemove,
|
edgesToRemove,
|
||||||
nodes,
|
nodes,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { BaseEdge, EdgeMarker, EdgeMarkerType, MarkerProps } from '../types';
|
import type { EdgeBase, EdgeMarker, EdgeMarkerType, MarkerProps } from '../types';
|
||||||
|
|
||||||
export function getMarkerId(marker: EdgeMarkerType | undefined, id?: string | null): string {
|
export function getMarkerId(marker: EdgeMarkerType | undefined, id?: string | null): string {
|
||||||
if (!marker) {
|
if (!marker) {
|
||||||
@@ -18,7 +18,7 @@ export function getMarkerId(marker: EdgeMarkerType | undefined, id?: string | nu
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createMarkerIds(
|
export function createMarkerIds(
|
||||||
edges: BaseEdge[],
|
edges: EdgeBase[],
|
||||||
{ id, defaultColor }: { id?: string | null; defaultColor?: string }
|
{ id, defaultColor }: { id?: string | null; defaultColor?: string }
|
||||||
) {
|
) {
|
||||||
const ids: string[] = [];
|
const ids: string[] = [];
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { internalsSymbol } from '../constants';
|
import { internalsSymbol } from '../constants';
|
||||||
import {
|
import {
|
||||||
BaseNode,
|
NodeBase,
|
||||||
CoordinateExtent,
|
CoordinateExtent,
|
||||||
Dimensions,
|
Dimensions,
|
||||||
NodeDimensionUpdate,
|
NodeDimensionUpdate,
|
||||||
@@ -16,7 +16,7 @@ import { getNodePositionWithOrigin } from './graph';
|
|||||||
|
|
||||||
type ParentNodes = Record<string, boolean>;
|
type ParentNodes = Record<string, boolean>;
|
||||||
|
|
||||||
export function updateAbsolutePositions<NodeType extends BaseNode>(
|
export function updateAbsolutePositions<NodeType extends NodeBase>(
|
||||||
nodes: NodeType[],
|
nodes: NodeType[],
|
||||||
nodeOrigin: NodeOrigin = [0, 0],
|
nodeOrigin: NodeOrigin = [0, 0],
|
||||||
parentNodes?: ParentNodes
|
parentNodes?: ParentNodes
|
||||||
@@ -54,13 +54,13 @@ export function updateAbsolutePositions<NodeType extends BaseNode>(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateNodesOptions<NodeType extends BaseNode> = {
|
type UpdateNodesOptions<NodeType extends NodeBase> = {
|
||||||
nodeOrigin?: NodeOrigin;
|
nodeOrigin?: NodeOrigin;
|
||||||
elevateNodesOnSelect?: boolean;
|
elevateNodesOnSelect?: boolean;
|
||||||
defaults?: Partial<NodeType>;
|
defaults?: Partial<NodeType>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function updateNodes<NodeType extends BaseNode>(
|
export function updateNodes<NodeType extends NodeBase>(
|
||||||
nodes: NodeType[],
|
nodes: NodeType[],
|
||||||
storeNodes: NodeType[],
|
storeNodes: NodeType[],
|
||||||
options: UpdateNodesOptions<NodeType> = {
|
options: UpdateNodesOptions<NodeType> = {
|
||||||
@@ -104,7 +104,7 @@ export function updateNodes<NodeType extends BaseNode>(
|
|||||||
return nodesWithPositions;
|
return nodesWithPositions;
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateXYZPosition<NodeType extends BaseNode>(
|
function calculateXYZPosition<NodeType extends NodeBase>(
|
||||||
node: NodeType,
|
node: NodeType,
|
||||||
nodes: NodeType[],
|
nodes: NodeType[],
|
||||||
result: XYZPosition,
|
result: XYZPosition,
|
||||||
@@ -131,11 +131,11 @@ function calculateXYZPosition<NodeType extends BaseNode>(
|
|||||||
|
|
||||||
export function updateNodeDimensions(
|
export function updateNodeDimensions(
|
||||||
updates: NodeDimensionUpdate[],
|
updates: NodeDimensionUpdate[],
|
||||||
nodes: BaseNode[],
|
nodes: NodeBase[],
|
||||||
domNode: HTMLElement | null,
|
domNode: HTMLElement | null,
|
||||||
nodeOrigin?: NodeOrigin,
|
nodeOrigin?: NodeOrigin,
|
||||||
onUpdate?: (id: string, dimensions: Dimensions) => void
|
onUpdate?: (id: string, dimensions: Dimensions) => void
|
||||||
): BaseNode[] | null {
|
): NodeBase[] | null {
|
||||||
const viewportNode = domNode?.querySelector('.xyflow__viewport');
|
const viewportNode = domNode?.querySelector('.xyflow__viewport');
|
||||||
|
|
||||||
if (!viewportNode) {
|
if (!viewportNode) {
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import { select } from 'd3-selection';
|
|||||||
import { calcAutoPan, getEventPosition, getPointerPosition, calcNextPosition, snapPosition } from '../utils';
|
import { calcAutoPan, getEventPosition, getPointerPosition, calcNextPosition, snapPosition } from '../utils';
|
||||||
import { getDragItems, getEventHandlerParams, hasSelector, wrapSelectionDragFunc } from './utils';
|
import { getDragItems, getEventHandlerParams, hasSelector, wrapSelectionDragFunc } from './utils';
|
||||||
import type {
|
import type {
|
||||||
BaseNode,
|
NodeBase,
|
||||||
NodeDragItem,
|
NodeDragItem,
|
||||||
UseDragEvent,
|
UseDragEvent,
|
||||||
XYPosition,
|
XYPosition,
|
||||||
BaseEdge,
|
EdgeBase,
|
||||||
CoordinateExtent,
|
CoordinateExtent,
|
||||||
NodeOrigin,
|
NodeOrigin,
|
||||||
OnError,
|
OnError,
|
||||||
@@ -20,11 +20,11 @@ import type {
|
|||||||
UpdateNodePositions,
|
UpdateNodePositions,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
export type OnDrag = (event: MouseEvent, dragItems: NodeDragItem[], node: BaseNode, nodes: BaseNode[]) => void;
|
export type OnDrag = (event: MouseEvent, dragItems: NodeDragItem[], node: NodeBase, nodes: NodeBase[]) => void;
|
||||||
|
|
||||||
type StoreItems = {
|
type StoreItems = {
|
||||||
nodes: BaseNode[];
|
nodes: NodeBase[];
|
||||||
edges: BaseEdge[];
|
edges: EdgeBase[];
|
||||||
nodeExtent: CoordinateExtent;
|
nodeExtent: CoordinateExtent;
|
||||||
snapGrid: SnapGrid;
|
snapGrid: SnapGrid;
|
||||||
snapToGrid: boolean;
|
snapToGrid: boolean;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { type NodeDragItem, type XYPosition, BaseNode } from '../types';
|
import { type NodeDragItem, type XYPosition, NodeBase } from '../types';
|
||||||
|
|
||||||
export function wrapSelectionDragFunc(selectionFunc?: (event: MouseEvent, nodes: BaseNode[]) => void) {
|
export function wrapSelectionDragFunc(selectionFunc?: (event: MouseEvent, nodes: NodeBase[]) => void) {
|
||||||
return (event: MouseEvent, _: BaseNode, nodes: BaseNode[]) => selectionFunc?.(event, nodes);
|
return (event: MouseEvent, _: NodeBase, nodes: NodeBase[]) => selectionFunc?.(event, nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isParentSelected<NodeType extends BaseNode>(node: NodeType, nodes: NodeType[]): boolean {
|
export function isParentSelected<NodeType extends NodeBase>(node: NodeType, nodes: NodeType[]): boolean {
|
||||||
if (!node.parentNode) {
|
if (!node.parentNode) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ export function hasSelector(target: Element, selector: string, domNode: Element)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// looks for all selected nodes and created a NodeDragItem for each of them
|
// looks for all selected nodes and created a NodeDragItem for each of them
|
||||||
export function getDragItems<NodeType extends BaseNode>(
|
export function getDragItems<NodeType extends NodeBase>(
|
||||||
nodes: NodeType[],
|
nodes: NodeType[],
|
||||||
nodesDraggable: boolean,
|
nodesDraggable: boolean,
|
||||||
mousePos: XYPosition,
|
mousePos: XYPosition,
|
||||||
@@ -71,7 +71,7 @@ export function getDragItems<NodeType extends BaseNode>(
|
|||||||
// returns two params:
|
// returns two params:
|
||||||
// 1. the dragged node (or the first of the list, if we are dragging a node selection)
|
// 1. the dragged node (or the first of the list, if we are dragging a node selection)
|
||||||
// 2. array of selected nodes (for multi selections)
|
// 2. array of selected nodes (for multi selections)
|
||||||
export function getEventHandlerParams<NodeType extends BaseNode>({
|
export function getEventHandlerParams<NodeType extends NodeBase>({
|
||||||
nodeId,
|
nodeId,
|
||||||
dragItems,
|
dragItems,
|
||||||
nodes,
|
nodes,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
type HandleType,
|
type HandleType,
|
||||||
type Connection,
|
type Connection,
|
||||||
type PanBy,
|
type PanBy,
|
||||||
type BaseNode,
|
type NodeBase,
|
||||||
type Transform,
|
type Transform,
|
||||||
type ConnectingHandle,
|
type ConnectingHandle,
|
||||||
type OnConnectEnd,
|
type OnConnectEnd,
|
||||||
@@ -25,7 +25,7 @@ export type OnPointerDownParams = {
|
|||||||
handleId: string | null;
|
handleId: string | null;
|
||||||
nodeId: string;
|
nodeId: string;
|
||||||
isTarget: boolean;
|
isTarget: boolean;
|
||||||
nodes: BaseNode[];
|
nodes: NodeBase[];
|
||||||
lib: string;
|
lib: string;
|
||||||
edgeUpdaterType?: HandleType;
|
edgeUpdaterType?: HandleType;
|
||||||
updateConnection: UpdateConnection;
|
updateConnection: UpdateConnection;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
type HandleType,
|
type HandleType,
|
||||||
type NodeHandleBounds,
|
type NodeHandleBounds,
|
||||||
type XYPosition,
|
type XYPosition,
|
||||||
type BaseNode,
|
type NodeBase,
|
||||||
type ConnectionHandle,
|
type ConnectionHandle,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import { internalsSymbol } from '../constants';
|
import { internalsSymbol } from '../constants';
|
||||||
@@ -11,7 +11,7 @@ import { internalsSymbol } from '../constants';
|
|||||||
// this functions collects all handles and adds an absolute position
|
// this functions collects all handles and adds an absolute position
|
||||||
// so that we can later find the closest handle to the mouse position
|
// so that we can later find the closest handle to the mouse position
|
||||||
export function getHandles(
|
export function getHandles(
|
||||||
node: BaseNode,
|
node: NodeBase,
|
||||||
handleBounds: NodeHandleBounds,
|
handleBounds: NodeHandleBounds,
|
||||||
type: HandleType,
|
type: HandleType,
|
||||||
currentHandle: string
|
currentHandle: string
|
||||||
@@ -62,7 +62,7 @@ export function getClosestHandle(
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetHandleLookupParams = {
|
type GetHandleLookupParams = {
|
||||||
nodes: BaseNode[];
|
nodes: NodeBase[];
|
||||||
nodeId: string;
|
nodeId: string;
|
||||||
handleId: string | null;
|
handleId: string | null;
|
||||||
handleType: string;
|
handleType: string;
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
{
|
{
|
||||||
"extends": "@xyflow/tsconfig/react.json",
|
|
||||||
"display": "@xyflow/system",
|
"display": "@xyflow/system",
|
||||||
|
"extends": "@xyflow/tsconfig/base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"lib": ["dom", "esnext"],
|
||||||
|
"module": "esnext",
|
||||||
|
"target": "esnext",
|
||||||
|
"outDir": "dist"
|
||||||
|
},
|
||||||
"include": ["**/*.ts", "**/*.tsx"],
|
"include": ["**/*.ts", "**/*.tsx"],
|
||||||
"exclude": ["node_modules", "dist"]
|
"exclude": ["node_modules", "dist"]
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+397
-458
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user