refactor(nodes,edges,types!): Change label-type to string | VNode | Object
This commit is contained in:
@@ -17,8 +17,10 @@ const sourceHandle =
|
|||||||
store.connectionHandleId && store.connectionHandleType
|
store.connectionHandleId && store.connectionHandleType
|
||||||
? props.sourceNode.handleBounds[store.connectionHandleType]?.find((d: HandleElement) => d.id === store.connectionHandleId)
|
? props.sourceNode.handleBounds[store.connectionHandleType]?.find((d: HandleElement) => d.id === store.connectionHandleId)
|
||||||
: store.connectionHandleType && props.sourceNode.handleBounds[store.connectionHandleType ?? 'source']?.[0]
|
: store.connectionHandleType && props.sourceNode.handleBounds[store.connectionHandleType ?? 'source']?.[0]
|
||||||
|
|
||||||
const sourceHandleX = sourceHandle ? sourceHandle.x + sourceHandle.width / 2 : props.sourceNode.dimensions.width / 2
|
const sourceHandleX = sourceHandle ? sourceHandle.x + sourceHandle.width / 2 : props.sourceNode.dimensions.width / 2
|
||||||
const sourceHandleY = sourceHandle ? sourceHandle.y + sourceHandle.height / 2 : props.sourceNode.dimensions.height
|
const sourceHandleY = sourceHandle ? sourceHandle.y + sourceHandle.height / 2 : props.sourceNode.dimensions.height
|
||||||
|
|
||||||
const sourceX = props.sourceNode.computedPosition.x + sourceHandleX
|
const sourceX = props.sourceNode.computedPosition.x + sourceHandleX
|
||||||
const sourceY = props.sourceNode.computedPosition.y + sourceHandleY
|
const sourceY = props.sourceNode.computedPosition.y + sourceHandleY
|
||||||
|
|
||||||
|
|||||||
@@ -39,11 +39,7 @@ export default {
|
|||||||
/>
|
/>
|
||||||
<text ref="edge-text" class="vue-flow__edge-text" :y="edgeRefBbox.height / 2" dy="0.3em" :style="props.labelStyle">
|
<text ref="edge-text" class="vue-flow__edge-text" :y="edgeRefBbox.height / 2" dy="0.3em" :style="props.labelStyle">
|
||||||
<slot v-bind="props">
|
<slot v-bind="props">
|
||||||
<component
|
<component :is="props.label" v-if="typeof props.label !== 'string' && typeof props.label" />
|
||||||
:is="props.label?.component"
|
|
||||||
v-if="typeof props.label !== 'string' && typeof props.label?.component !== 'undefined'"
|
|
||||||
v-bind="props.label?.props"
|
|
||||||
/>
|
|
||||||
<template v-else v-html="props.label">
|
<template v-else v-html="props.label">
|
||||||
{{ props.label }}
|
{{ props.label }}
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export default {
|
|||||||
:is-connectable="props.connectable"
|
:is-connectable="props.connectable"
|
||||||
:is-valid-connection="props.isValidTargetPos"
|
:is-valid-connection="props.isValidTargetPos"
|
||||||
/>
|
/>
|
||||||
<component :is="props.label.component" v-bind="props.label.props" v-if="typeof props.label !== 'string' && props.label" />
|
<component :is="props.label" v-if="typeof props.label !== 'string' && props.label" />
|
||||||
<span v-else v-html="props.label" />
|
<span v-else v-html="props.label" />
|
||||||
<Handle
|
<Handle
|
||||||
type="source"
|
type="source"
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export default {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<component :is="props.label.component" v-bind="props.label.props" v-if="typeof props.label !== 'string' && props.label" />
|
<component :is="props.label" v-if="typeof props.label !== 'string' && props.label" />
|
||||||
<span v-else v-html="props.label" />
|
<span v-else v-html="props.label" />
|
||||||
<Handle
|
<Handle
|
||||||
type="source"
|
type="source"
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export default {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<component :is="props.label.component" v-bind="props.label.props" v-if="typeof props.label !== 'string' && props.label" />
|
<component :is="props.label" v-bind="props.label" v-if="typeof props.label !== 'string' && props.label" />
|
||||||
<span v-else v-html="props.label" />
|
<span v-else v-html="props.label" />
|
||||||
<Handle
|
<Handle
|
||||||
type="source"
|
type="source"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component, CSSProperties, DefineComponent, HTMLAttributes } from 'vue'
|
import { Component, CSSProperties, DefineComponent, HTMLAttributes, VNode } from 'vue'
|
||||||
import { BackgroundVariant, Dimensions, ElementData, XYPosition } from './flow'
|
import { BackgroundVariant, Dimensions, ElementData, XYPosition } from './flow'
|
||||||
import { GraphNode, Node, NodeProps } from './node'
|
import { GraphNode, Node, NodeProps } from './node'
|
||||||
import { EdgeProps } from './edge'
|
import { EdgeProps } from './edge'
|
||||||
@@ -99,12 +99,7 @@ export interface MiniMapNodeProps {
|
|||||||
export interface EdgeTextProps extends HTMLAttributes {
|
export interface EdgeTextProps extends HTMLAttributes {
|
||||||
x: number
|
x: number
|
||||||
y: number
|
y: number
|
||||||
label?:
|
label?: string | VNode | Object
|
||||||
| string
|
|
||||||
| {
|
|
||||||
component: any
|
|
||||||
props?: any
|
|
||||||
}
|
|
||||||
labelStyle?: CSSProperties
|
labelStyle?: CSSProperties
|
||||||
labelShowBg?: boolean
|
labelShowBg?: boolean
|
||||||
labelBgStyle?: CSSProperties
|
labelBgStyle?: CSSProperties
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { CSSProperties } from 'vue'
|
import { CSSProperties, VNode } from 'vue'
|
||||||
import { GraphEdge, Edge, DefaultEdgeOptions } from './edge'
|
import { GraphEdge, Edge, DefaultEdgeOptions } from './edge'
|
||||||
import { GraphNode, CoordinateExtent, Node } from './node'
|
import { GraphNode, CoordinateExtent, Node } from './node'
|
||||||
import { ConnectionLineType, ConnectionMode } from './connection'
|
import { ConnectionLineType, ConnectionMode } from './connection'
|
||||||
@@ -27,12 +27,7 @@ export type StyleFunc<Data = ElementData> = (element: FlowElement<Data>) => Styl
|
|||||||
/** base element props */
|
/** base element props */
|
||||||
export interface Element<Data extends ElementData = ElementData> {
|
export interface Element<Data extends ElementData = ElementData> {
|
||||||
id: string
|
id: string
|
||||||
label?:
|
label?: string | VNode
|
||||||
| string
|
|
||||||
| {
|
|
||||||
props?: any
|
|
||||||
component: any
|
|
||||||
}
|
|
||||||
type?: string
|
type?: string
|
||||||
data?: Data
|
data?: Data
|
||||||
class?: string | ClassFunc<Data>
|
class?: string | ClassFunc<Data>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { VNode } from 'vue'
|
||||||
import { XYPosition, Position, SnapGrid, Element, XYZPosition, Dimensions, ElementData } from './flow'
|
import { XYPosition, Position, SnapGrid, Element, XYZPosition, Dimensions, ElementData } from './flow'
|
||||||
import { DefaultNodeTypes } from './components'
|
import { DefaultNodeTypes } from './components'
|
||||||
import { HandleElement, ValidConnectionFunc } from './handle'
|
import { HandleElement, ValidConnectionFunc } from './handle'
|
||||||
@@ -79,16 +80,16 @@ export interface NodeProps<Data = ElementData> {
|
|||||||
connectable: boolean
|
connectable: boolean
|
||||||
/** absolute position in relation to parent elements + z-index */
|
/** absolute position in relation to parent elements + z-index */
|
||||||
computedPosition: XYZPosition
|
computedPosition: XYZPosition
|
||||||
/** x, y position */
|
/** node x, y (relative) position on graph */
|
||||||
position: XYPosition
|
position: XYPosition
|
||||||
/** dom element dimensions (width, height) */
|
/** dom element dimensions (width, height) */
|
||||||
dimensions: Dimensions
|
dimensions: Dimensions
|
||||||
label?:
|
/**
|
||||||
| string
|
* node label, either pass a string or a VNode
|
||||||
| {
|
* For example like this: `h('div', props, children)`)
|
||||||
props?: any
|
* Object is just a type-hack for Vue, ignore that
|
||||||
component: any
|
*/
|
||||||
}
|
label?: string | VNode | Object
|
||||||
/** called when used as target for new connection */
|
/** called when used as target for new connection */
|
||||||
isValidTargetPos?: ValidConnectionFunc
|
isValidTargetPos?: ValidConnectionFunc
|
||||||
/** called when used as source for new connection */
|
/** called when used as source for new connection */
|
||||||
|
|||||||
Reference in New Issue
Block a user