feat(flow)!: Remove node/edge-types prop
* infer node/edge types from types used in elements Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -9,19 +9,8 @@ const onLoad = (flowInstance: FlowInstance) => {
|
|||||||
console.log(flowInstance.getNodes())
|
console.log(flowInstance.getNodes())
|
||||||
}
|
}
|
||||||
|
|
||||||
const { nodes, edges } = getElements(5, 5)
|
const { nodes, edges } = getElements(30, 30)
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<VueFlow :nodes="nodes" :edges="edges" @load="onLoad"> </VueFlow>
|
<VueFlow :nodes="nodes" :edges="edges" @load="onLoad"> </VueFlow>
|
||||||
</template>
|
</template>
|
||||||
<style>
|
|
||||||
.fade-enter-active,
|
|
||||||
.fade-leave-active {
|
|
||||||
transition: opacity 0.35s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.fade-enter-from,
|
|
||||||
.fade-leave-active {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
@@ -2,6 +2,5 @@ export * from './Nodes'
|
|||||||
export * from './Edges'
|
export * from './Edges'
|
||||||
export * from './ConnectionLine/ConnectionLine.vue'
|
export * from './ConnectionLine/ConnectionLine.vue'
|
||||||
export * from './Handle/Handle.vue'
|
export * from './Handle/Handle.vue'
|
||||||
export * from './Loading/LoadingIndicator.vue'
|
|
||||||
export * from './NodesSelection/NodesSelection.vue'
|
export * from './NodesSelection/NodesSelection.vue'
|
||||||
export * from './UserSelection/UserSelection.vue'
|
export * from './UserSelection/UserSelection.vue'
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ export default (state: FlowState): FlowGetters => {
|
|||||||
const edgeTypes: Record<string, any> = {
|
const edgeTypes: Record<string, any> = {
|
||||||
...defaultEdgeTypes,
|
...defaultEdgeTypes,
|
||||||
}
|
}
|
||||||
state.edgeTypes?.forEach((n) => (edgeTypes[n] = n))
|
const keys = Object.keys(edgeTypes)
|
||||||
|
state.edges?.forEach((e) => e.type && !keys.includes(e.type) && (edgeTypes[e.type] = e.type))
|
||||||
return edgeTypes
|
return edgeTypes
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -15,7 +16,8 @@ export default (state: FlowState): FlowGetters => {
|
|||||||
const nodeTypes: Record<string, any> = {
|
const nodeTypes: Record<string, any> = {
|
||||||
...defaultNodeTypes,
|
...defaultNodeTypes,
|
||||||
}
|
}
|
||||||
state.nodeTypes?.forEach((n) => (nodeTypes[n] = n))
|
const keys = Object.keys(nodeTypes)
|
||||||
|
state.nodes?.forEach((n) => n.type && !keys.includes(n.type) && (nodeTypes[n.type] = n.type))
|
||||||
return nodeTypes
|
return nodeTypes
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ export const initialState = (): FlowState => ({
|
|||||||
elements: [],
|
elements: [],
|
||||||
nodes: [],
|
nodes: [],
|
||||||
edges: [],
|
edges: [],
|
||||||
nodeTypes: [],
|
|
||||||
edgeTypes: [],
|
|
||||||
|
|
||||||
isReady: false,
|
isReady: false,
|
||||||
instance: undefined,
|
instance: undefined,
|
||||||
|
|||||||
+14
-19
@@ -1,15 +1,15 @@
|
|||||||
import { Component, CSSProperties, DefineComponent } from 'vue'
|
import { Component, CSSProperties, DefineComponent } from 'vue'
|
||||||
import { BackgroundVariant, Dimensions, FitViewParams, Position, XYPosition } from './flow'
|
import { BackgroundVariant, Dimensions, Position, XYPosition } from './flow'
|
||||||
import { Connection, ConnectionLineType } from './connection'
|
import { Connection, ConnectionLineType } from './connection'
|
||||||
import { GraphNode, Node, NodeProps } from './node'
|
import { GraphNode, Node, NodeProps } from './node'
|
||||||
import { EdgeProps } from './edge'
|
import { EdgeProps } from './edge'
|
||||||
|
import { FitViewParams } from './zoom'
|
||||||
|
|
||||||
|
type GlobalComponentName = string
|
||||||
export type DefaultEdgeTypes = { [key in 'default' | 'straight' | 'smoothstep' | 'step']: Component<EdgeProps> }
|
export type DefaultEdgeTypes = { [key in 'default' | 'straight' | 'smoothstep' | 'step']: Component<EdgeProps> }
|
||||||
export type EdgeTypes = (keyof DefaultEdgeTypes | string)[]
|
export type NodeComponent = Component<NodeProps> | DefineComponent<NodeProps, any, any, any, any> | GlobalComponentName
|
||||||
export type NodeComponent = Component<NodeProps> | DefineComponent<NodeProps, any, any, any, any> | string
|
|
||||||
export type DefaultNodeTypes = { [key in 'input' | 'output' | 'default']: Component<NodeProps> }
|
export type DefaultNodeTypes = { [key in 'input' | 'output' | 'default']: Component<NodeProps> }
|
||||||
export type NodeTypes = (keyof DefaultNodeTypes | string)[]
|
export type EdgeComponent = Component<EdgeProps> | DefineComponent<EdgeProps, any, any, any, any, any> | GlobalComponentName
|
||||||
export type EdgeComponent = Component<EdgeProps> | DefineComponent<EdgeProps, any, any, any, any, any> | string
|
|
||||||
|
|
||||||
export type HandleType = 'source' | 'target'
|
export type HandleType = 'source' | 'target'
|
||||||
|
|
||||||
@@ -49,13 +49,13 @@ export interface ControlEvents {
|
|||||||
(event: 'interaction-change', active: boolean): void
|
(event: 'interaction-change', active: boolean): void
|
||||||
}
|
}
|
||||||
|
|
||||||
export type StringFunc = (node: Node | GraphNode) => string
|
export type StringFunc<N = any> = (node: Node<N> | GraphNode<N>) => string
|
||||||
export type ShapeRendering = 'inherit' | 'auto' | 'geometricPrecision' | 'optimizeSpeed' | 'crispEdges' | undefined
|
export type ShapeRendering = 'inherit' | 'auto' | 'geometricPrecision' | 'optimizeSpeed' | 'crispEdges' | undefined
|
||||||
|
|
||||||
export interface MiniMapProps {
|
export interface MiniMapProps<N = any> {
|
||||||
nodeColor?: string | StringFunc
|
nodeColor?: string | StringFunc<N>
|
||||||
nodeStrokeColor?: string | StringFunc
|
nodeStrokeColor?: string | StringFunc<N>
|
||||||
nodeClassName?: string | StringFunc
|
nodeClassName?: string | StringFunc<N>
|
||||||
nodeBorderRadius?: number
|
nodeBorderRadius?: number
|
||||||
nodeStrokeWidth?: number
|
nodeStrokeWidth?: number
|
||||||
maskColor?: string
|
maskColor?: string
|
||||||
@@ -74,12 +74,7 @@ export interface MiniMapNodeProps {
|
|||||||
export interface EdgeTextProps {
|
export interface EdgeTextProps {
|
||||||
x: number
|
x: number
|
||||||
y: number
|
y: number
|
||||||
label?:
|
label?: string
|
||||||
| string
|
|
||||||
| {
|
|
||||||
component: any
|
|
||||||
props?: any
|
|
||||||
}
|
|
||||||
labelStyle?: CSSProperties
|
labelStyle?: CSSProperties
|
||||||
labelShowBg?: boolean
|
labelShowBg?: boolean
|
||||||
labelBgStyle?: any
|
labelBgStyle?: any
|
||||||
@@ -87,7 +82,7 @@ export interface EdgeTextProps {
|
|||||||
labelBgBorderRadius?: number
|
labelBgBorderRadius?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CustomConnectionLineProps {
|
export interface CustomConnectionLineProps<N = any> {
|
||||||
sourceX: number
|
sourceX: number
|
||||||
sourceY: number
|
sourceY: number
|
||||||
sourcePosition: Position
|
sourcePosition: Position
|
||||||
@@ -96,7 +91,7 @@ export interface CustomConnectionLineProps {
|
|||||||
targetPosition: Position
|
targetPosition: Position
|
||||||
connectionLineType: ConnectionLineType
|
connectionLineType: ConnectionLineType
|
||||||
connectionLineStyle: CSSProperties
|
connectionLineStyle: CSSProperties
|
||||||
nodes: GraphNode[]
|
nodes: GraphNode<N>[]
|
||||||
sourceNode: GraphNode
|
sourceNode: GraphNode<N>
|
||||||
sourceHandle: HandleElement
|
sourceHandle: HandleElement
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { GraphEdge, Edge } from './edge'
|
|||||||
import { GraphNode, CoordinateExtent, Node } from './node'
|
import { GraphNode, CoordinateExtent, Node } from './node'
|
||||||
import { ConnectionLineType, ConnectionMode } from './connection'
|
import { ConnectionLineType, ConnectionMode } from './connection'
|
||||||
import { KeyCode, PanOnScrollMode, UseZoomPanHelper } from './zoom'
|
import { KeyCode, PanOnScrollMode, UseZoomPanHelper } from './zoom'
|
||||||
import { EdgeTypes, NodeTypes } from './components'
|
|
||||||
|
|
||||||
export type FlowElement<N = any, E = any> = GraphNode<N> | GraphEdge<E>
|
export type FlowElement<N = any, E = any> = GraphNode<N> | GraphEdge<E>
|
||||||
export type FlowElements<N = any, E = any> = FlowElement<N, E>[]
|
export type FlowElements<N = any, E = any> = FlowElement<N, E>[]
|
||||||
@@ -81,8 +80,6 @@ export interface FlowProps<N = any, E = N> {
|
|||||||
edges?: Edge<E>[]
|
edges?: Edge<E>[]
|
||||||
elements?: Elements
|
elements?: Elements
|
||||||
id?: string
|
id?: string
|
||||||
nodeTypes?: NodeTypes
|
|
||||||
edgeTypes?: EdgeTypes
|
|
||||||
connectionMode?: ConnectionMode
|
connectionMode?: ConnectionMode
|
||||||
connectionLineType?: ConnectionLineType
|
connectionLineType?: ConnectionLineType
|
||||||
connectionLineStyle?: CSSProperties
|
connectionLineStyle?: CSSProperties
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,7 @@
|
|||||||
import { ComputedRef, ToRefs } from 'vue'
|
import { ComputedRef, ToRefs } from 'vue'
|
||||||
import { UnwrapNestedRefs } from '@vue/reactivity'
|
import { UnwrapNestedRefs } from '@vue/reactivity'
|
||||||
import { Dimensions, Elements, FlowElements, FlowInstance, FlowOptions, Rect, SnapGrid, Transform, XYPosition } from './flow'
|
import { Dimensions, Elements, FlowElements, FlowInstance, FlowOptions, Rect, SnapGrid, Transform, XYPosition } from './flow'
|
||||||
import { HandleType, EdgeComponent, NodeComponent, NodeTypes, EdgeTypes } from './components'
|
import { HandleType, EdgeComponent, NodeComponent } from './components'
|
||||||
import { ConnectionLineType, ConnectionMode, SetConnectionId } from './connection'
|
import { ConnectionLineType, ConnectionMode, SetConnectionId } from './connection'
|
||||||
import { Edge, GraphEdge } from './edge'
|
import { Edge, GraphEdge } from './edge'
|
||||||
import { GraphNode, CoordinateExtent, Node } from './node'
|
import { GraphNode, CoordinateExtent, Node } from './node'
|
||||||
@@ -15,8 +15,6 @@ export interface FlowState<N = any, E = N> extends Omit<FlowOptions<N, E>, 'id'>
|
|||||||
elements: Elements
|
elements: Elements
|
||||||
nodes: GraphNode[]
|
nodes: GraphNode[]
|
||||||
edges: GraphEdge[]
|
edges: GraphEdge[]
|
||||||
nodeTypes: NodeTypes
|
|
||||||
edgeTypes: EdgeTypes
|
|
||||||
|
|
||||||
d3Zoom?: D3Zoom
|
d3Zoom?: D3Zoom
|
||||||
d3Selection?: D3Selection
|
d3Selection?: D3Selection
|
||||||
|
|||||||
Reference in New Issue
Block a user