refactor(types)!: Remove ElementId type
Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import Sidebar from './Sidebar.vue'
|
import Sidebar from './Sidebar.vue'
|
||||||
import { VueFlow, addEdge, removeElements, Controls, FlowInstance, Elements, Connection, Edge, ElementId, Node } from '~/index'
|
import { VueFlow, addEdge, removeElements, Controls, FlowInstance, Elements, Connection, Edge, Node } from '~/index'
|
||||||
import './dnd.css'
|
import './dnd.css'
|
||||||
|
|
||||||
const flowInstance = ref<FlowInstance>()
|
const flowInstance = ref<FlowInstance>()
|
||||||
@@ -14,7 +14,7 @@ const elements = ref<Elements>([
|
|||||||
])
|
])
|
||||||
|
|
||||||
let id = 0
|
let id = 0
|
||||||
const getId = (): ElementId => `dndnode_${id++}`
|
const getId = () => `dndnode_${id++}`
|
||||||
|
|
||||||
const onDragOver = (event: DragEvent) => {
|
const onDragOver = (event: DragEvent) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ElementId, Elements, Position } from '../../src'
|
import { Elements, Position } from '../../src'
|
||||||
|
|
||||||
const nodeWidth = 80
|
const nodeWidth = 80
|
||||||
const nodeGapWidth = nodeWidth * 2
|
const nodeGapWidth = nodeWidth * 2
|
||||||
@@ -49,7 +49,7 @@ const offsets = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
let id = 0
|
let id = 0
|
||||||
const getNodeId = (): ElementId => (id++).toString()
|
const getNodeId = () => (id++).toString()
|
||||||
|
|
||||||
export function getElements(): Elements {
|
export function getElements(): Elements {
|
||||||
const initialElements = []
|
const initialElements = []
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { getEdgeCenter, getBezierPath, getMarkerEnd, ArrowHeadType, ElementId, Position, useVueFlow, EdgeProps } from '~/index'
|
import { getEdgeCenter, getBezierPath, getMarkerEnd, ArrowHeadType, Position, useVueFlow, EdgeProps } from '~/index'
|
||||||
|
|
||||||
interface CustomEdgeProps<T = any> extends EdgeProps<T> {
|
interface CustomEdgeProps<T = any> extends EdgeProps<T> {
|
||||||
id: ElementId
|
id: string
|
||||||
sourceX: number
|
sourceX: number
|
||||||
sourceY: number
|
sourceY: number
|
||||||
targetX: number
|
targetX: number
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ArrowHeadType, ElementId, getBezierPath, getMarkerEnd, Position, EdgeProps } from '~/index'
|
import { ArrowHeadType, getBezierPath, getMarkerEnd, Position, EdgeProps } from '~/index'
|
||||||
|
|
||||||
interface CustomEdgeProps<T = { text: string }> extends EdgeProps<T> {
|
interface CustomEdgeProps<T = { text: string }> extends EdgeProps<T> {
|
||||||
source: ElementId
|
source: string
|
||||||
target: ElementId
|
target: string
|
||||||
sourceHandleId?: ElementId
|
sourceHandleId?: string
|
||||||
targetHandleId?: ElementId
|
targetHandleId?: string
|
||||||
id: ElementId
|
id: string
|
||||||
sourceX: number
|
sourceX: number
|
||||||
sourceY: number
|
sourceY: number
|
||||||
targetX: number
|
targetX: number
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { getBezierPath, getMarkerEnd } from '~/components/Edges/utils'
|
import { getBezierPath, getMarkerEnd } from '~/components/Edges/utils'
|
||||||
import { ArrowHeadType, ElementId, getEdgeCenter, Position, EdgeText, EdgeProps } from '~/index'
|
import { ArrowHeadType, getEdgeCenter, Position, EdgeText, EdgeProps } from '~/index'
|
||||||
|
|
||||||
interface CustomEdgeProps extends EdgeProps {
|
interface CustomEdgeProps extends EdgeProps {
|
||||||
source: ElementId
|
source: string
|
||||||
target: ElementId
|
target: string
|
||||||
sourceHandleId?: ElementId
|
sourceHandleId?: string
|
||||||
targetHandleId?: ElementId
|
targetHandleId?: string
|
||||||
id: ElementId
|
id: string
|
||||||
sourceX: number
|
sourceX: number
|
||||||
sourceY: number
|
sourceY: number
|
||||||
targetX: number
|
targetX: number
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import {
|
|||||||
BackgroundVariant,
|
BackgroundVariant,
|
||||||
Connection,
|
Connection,
|
||||||
Edge,
|
Edge,
|
||||||
ElementId,
|
|
||||||
Elements,
|
Elements,
|
||||||
FlowElement,
|
FlowElement,
|
||||||
Node,
|
Node,
|
||||||
@@ -27,7 +26,7 @@ const onNodeDragStop = (node: Node) => console.log('drag stop', node)
|
|||||||
|
|
||||||
const buttonStyle: CSSProperties = { position: 'absolute', left: '10px', top: '10px', zIndex: 4 }
|
const buttonStyle: CSSProperties = { position: 'absolute', left: '10px', top: '10px', zIndex: 4 }
|
||||||
const addRandomNode = () => {
|
const addRandomNode = () => {
|
||||||
const nodeId: ElementId = (elements.value.length + 1).toString()
|
const nodeId = (elements.value.length + 1).toString()
|
||||||
const newNode: Node = {
|
const newNode: Node = {
|
||||||
id: nodeId,
|
id: nodeId,
|
||||||
data: { label: `Node: ${nodeId}` },
|
data: { label: `Node: ${nodeId}` },
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import {
|
|||||||
Elements,
|
Elements,
|
||||||
Connection,
|
Connection,
|
||||||
Edge,
|
Edge,
|
||||||
ElementId,
|
|
||||||
Node,
|
Node,
|
||||||
ConnectionLineType,
|
ConnectionLineType,
|
||||||
ConnectionMode,
|
ConnectionMode,
|
||||||
@@ -172,7 +171,7 @@ const initialElements: Elements = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
let id = 4
|
let id = 4
|
||||||
const getId = (): ElementId => `${id++}`
|
const getId = () => `${id++}`
|
||||||
|
|
||||||
const elements = ref(initialElements)
|
const elements = ref(initialElements)
|
||||||
const onConnect = (params: Connection | Edge) => (elements.value = addEdge({ ...params, type: 'smoothstep' }, elements.value))
|
const onConnect = (params: Connection | Edge) => (elements.value = addEdge({ ...params, type: 'smoothstep' }, elements.value))
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import {
|
|||||||
Elements,
|
Elements,
|
||||||
Connection,
|
Connection,
|
||||||
Edge,
|
Edge,
|
||||||
ElementId,
|
|
||||||
Position,
|
Position,
|
||||||
isEdge,
|
isEdge,
|
||||||
FlowInstance,
|
FlowInstance,
|
||||||
@@ -29,7 +28,7 @@ const initialElements: Elements = [
|
|||||||
const buttonWrapperStyles: CSSProperties = { position: 'absolute', right: 10, top: 10, zIndex: 10 }
|
const buttonWrapperStyles: CSSProperties = { position: 'absolute', right: 10, top: 10, zIndex: 10 }
|
||||||
|
|
||||||
let id = 5
|
let id = 5
|
||||||
const getId = (): ElementId => `${id++}`
|
const getId = () => `${id++}`
|
||||||
|
|
||||||
const elements = ref<Elements>(initialElements)
|
const elements = ref<Elements>(initialElements)
|
||||||
const flowInstance = ref<FlowInstance>()
|
const flowInstance = ref<FlowInstance>()
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import {
|
|||||||
MiniMap,
|
MiniMap,
|
||||||
useZoomPanHelper,
|
useZoomPanHelper,
|
||||||
Elements,
|
Elements,
|
||||||
ElementId,
|
|
||||||
Connection,
|
Connection,
|
||||||
Edge,
|
Edge,
|
||||||
Node,
|
Node,
|
||||||
@@ -23,7 +22,7 @@ const initialElements: Elements = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
let id = 5
|
let id = 5
|
||||||
const getId = (): ElementId => `${id++}`
|
const getId = () => `${id++}`
|
||||||
|
|
||||||
const { project } = useZoomPanHelper()
|
const { project } = useZoomPanHelper()
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import {
|
|||||||
ConnectionLineType,
|
ConnectionLineType,
|
||||||
HandleElement,
|
HandleElement,
|
||||||
Position,
|
Position,
|
||||||
ElementId,
|
|
||||||
HandleType,
|
HandleType,
|
||||||
XYPosition,
|
XYPosition,
|
||||||
ConnectionMode,
|
ConnectionMode,
|
||||||
@@ -17,8 +16,8 @@ interface ConnectionLineProps {
|
|||||||
sourceNode: GraphNode
|
sourceNode: GraphNode
|
||||||
connectionLineType?: ConnectionLineType
|
connectionLineType?: ConnectionLineType
|
||||||
connectionLineStyle?: CSSProperties
|
connectionLineStyle?: CSSProperties
|
||||||
connectionHandleId?: ElementId
|
connectionHandleId?: string
|
||||||
connectionNodeId?: ElementId
|
connectionNodeId?: string
|
||||||
connectionHandleType?: HandleType
|
connectionHandleType?: HandleType
|
||||||
connectionPosition?: XYPosition
|
connectionPosition?: XYPosition
|
||||||
connectionMode: ConnectionMode
|
connectionMode: ConnectionMode
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { CSSProperties } from 'vue'
|
import { CSSProperties } from 'vue'
|
||||||
import { ArrowHeadType, EdgeProps, EdgeTextProps, ElementId, Position } from '../../types'
|
import { ArrowHeadType, EdgeProps, Position } from '../../types'
|
||||||
import { getCenter, getMarkerEnd, getBezierPath } from './utils'
|
import { getCenter, getMarkerEnd, getBezierPath } from './utils'
|
||||||
import EdgeText from './EdgeText.vue'
|
import EdgeText from './EdgeText.vue'
|
||||||
|
|
||||||
interface BezierEdgeProps extends EdgeProps {
|
interface BezierEdgeProps extends EdgeProps {
|
||||||
id: ElementId
|
id: string
|
||||||
source: ElementId
|
source: string
|
||||||
target: ElementId
|
target: string
|
||||||
sourceX: number
|
sourceX: number
|
||||||
sourceY: number
|
sourceY: number
|
||||||
targetX: number
|
targetX: number
|
||||||
@@ -16,12 +16,7 @@ interface BezierEdgeProps extends EdgeProps {
|
|||||||
animated?: boolean
|
animated?: boolean
|
||||||
sourcePosition: Position
|
sourcePosition: Position
|
||||||
targetPosition: Position
|
targetPosition: Position
|
||||||
label?:
|
label?: string
|
||||||
| string
|
|
||||||
| {
|
|
||||||
component: any
|
|
||||||
props?: Record<string, any> & Partial<EdgeTextProps>
|
|
||||||
}
|
|
||||||
labelStyle?: CSSProperties
|
labelStyle?: CSSProperties
|
||||||
labelShowBg?: boolean
|
labelShowBg?: boolean
|
||||||
labelBgStyle?: CSSProperties
|
labelBgStyle?: CSSProperties
|
||||||
@@ -29,8 +24,8 @@ interface BezierEdgeProps extends EdgeProps {
|
|||||||
labelBgBorderRadius?: number
|
labelBgBorderRadius?: number
|
||||||
arrowHeadType?: ArrowHeadType
|
arrowHeadType?: ArrowHeadType
|
||||||
markerEndId?: string
|
markerEndId?: string
|
||||||
sourceHandleId?: ElementId
|
sourceHandleId?: string
|
||||||
targetHandleId?: ElementId
|
targetHandleId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<BezierEdgeProps>(), {
|
const props = withDefaults(defineProps<BezierEdgeProps>(), {
|
||||||
|
|||||||
@@ -4,12 +4,7 @@ import { CSSProperties } from 'vue'
|
|||||||
interface EdgeTextProps {
|
interface EdgeTextProps {
|
||||||
x: number
|
x: number
|
||||||
y: number
|
y: number
|
||||||
label?:
|
label?: string
|
||||||
| string
|
|
||||||
| {
|
|
||||||
component: any
|
|
||||||
props?: Record<string, any> & Partial<EdgeTextProps>
|
|
||||||
}
|
|
||||||
labelStyle?: CSSProperties
|
labelStyle?: CSSProperties
|
||||||
labelShowBg?: boolean
|
labelShowBg?: boolean
|
||||||
labelBgStyle?: CSSProperties
|
labelBgStyle?: CSSProperties
|
||||||
@@ -48,16 +43,7 @@ export default {
|
|||||||
:ry="props.labelBgBorderRadius"
|
:ry="props.labelBgBorderRadius"
|
||||||
/>
|
/>
|
||||||
<text ref="edge-text" class="vue-flow__edge-text" :y="height / 2" dy="0.3em" :style="props.labelStyle">
|
<text ref="edge-text" class="vue-flow__edge-text" :y="height / 2" dy="0.3em" :style="props.labelStyle">
|
||||||
<slot v-bind="props">
|
{{ props.label }}
|
||||||
<component
|
|
||||||
:is="props.label?.component"
|
|
||||||
v-if="typeof props.label !== 'string' && typeof props.label?.component !== 'undefined'"
|
|
||||||
v-bind="{ ...props, ...props.label?.props, width, height, x, y }"
|
|
||||||
/>
|
|
||||||
<template v-else v-html="props.label">
|
|
||||||
{{ props.label }}
|
|
||||||
</template>
|
|
||||||
</slot>
|
|
||||||
</text>
|
</text>
|
||||||
</g>
|
</g>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { CSSProperties } from 'vue'
|
import { CSSProperties } from 'vue'
|
||||||
import { ArrowHeadType, EdgeProps, EdgeTextProps, ElementId, Position } from '../../types'
|
import { ArrowHeadType, EdgeProps, EdgeTextProps, Position } from '../../types'
|
||||||
import EdgeText from './EdgeText.vue'
|
import EdgeText from './EdgeText.vue'
|
||||||
import { getCenter, getMarkerEnd, getSmoothStepPath } from './utils'
|
import { getCenter, getMarkerEnd, getSmoothStepPath } from './utils'
|
||||||
|
|
||||||
interface SmoothStepEdgeProps extends EdgeProps {
|
interface SmoothStepEdgeProps extends EdgeProps {
|
||||||
id: ElementId
|
id: string
|
||||||
source: ElementId
|
source: string
|
||||||
target: ElementId
|
target: string
|
||||||
sourceX: number
|
sourceX: number
|
||||||
sourceY: number
|
sourceY: number
|
||||||
targetX: number
|
targetX: number
|
||||||
@@ -16,12 +16,7 @@ interface SmoothStepEdgeProps extends EdgeProps {
|
|||||||
animated?: boolean
|
animated?: boolean
|
||||||
sourcePosition: Position
|
sourcePosition: Position
|
||||||
targetPosition: Position
|
targetPosition: Position
|
||||||
label?:
|
label?: string
|
||||||
| string
|
|
||||||
| {
|
|
||||||
component: any
|
|
||||||
props?: Record<string, any> & Partial<EdgeTextProps>
|
|
||||||
}
|
|
||||||
labelStyle?: CSSProperties
|
labelStyle?: CSSProperties
|
||||||
labelShowBg?: boolean
|
labelShowBg?: boolean
|
||||||
labelBgStyle?: CSSProperties
|
labelBgStyle?: CSSProperties
|
||||||
@@ -30,8 +25,8 @@ interface SmoothStepEdgeProps extends EdgeProps {
|
|||||||
arrowHeadType?: ArrowHeadType
|
arrowHeadType?: ArrowHeadType
|
||||||
markerEndId?: string
|
markerEndId?: string
|
||||||
borderRadius?: number
|
borderRadius?: number
|
||||||
sourceHandleId?: ElementId | null
|
sourceHandleId?: string
|
||||||
targetHandleId?: ElementId | null
|
targetHandleId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<SmoothStepEdgeProps>(), {
|
const props = withDefaults(defineProps<SmoothStepEdgeProps>(), {
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { CSSProperties } from 'vue'
|
import { CSSProperties } from 'vue'
|
||||||
import { ArrowHeadType, EdgeProps, EdgeTextProps, ElementId, Position } from '../../types'
|
import { ArrowHeadType, EdgeProps, Position } from '../../types'
|
||||||
import SmoothStepEdge from './SmoothStepEdge.vue'
|
import SmoothStepEdge from './SmoothStepEdge.vue'
|
||||||
|
|
||||||
interface StepEdgeProps extends EdgeProps {
|
interface StepEdgeProps extends EdgeProps {
|
||||||
id: ElementId
|
id: string
|
||||||
source: ElementId
|
source: string
|
||||||
target: ElementId
|
target: string
|
||||||
sourceX: number
|
sourceX: number
|
||||||
sourceY: number
|
sourceY: number
|
||||||
targetX: number
|
targetX: number
|
||||||
@@ -15,12 +15,7 @@ interface StepEdgeProps extends EdgeProps {
|
|||||||
animated?: boolean
|
animated?: boolean
|
||||||
sourcePosition: Position
|
sourcePosition: Position
|
||||||
targetPosition: Position
|
targetPosition: Position
|
||||||
label?:
|
label?: string
|
||||||
| string
|
|
||||||
| {
|
|
||||||
component: any
|
|
||||||
props?: Record<string, any> & Partial<EdgeTextProps>
|
|
||||||
}
|
|
||||||
labelStyle?: CSSProperties
|
labelStyle?: CSSProperties
|
||||||
labelShowBg?: boolean
|
labelShowBg?: boolean
|
||||||
labelBgStyle?: CSSProperties
|
labelBgStyle?: CSSProperties
|
||||||
@@ -28,8 +23,8 @@ interface StepEdgeProps extends EdgeProps {
|
|||||||
labelBgBorderRadius?: number
|
labelBgBorderRadius?: number
|
||||||
arrowHeadType?: ArrowHeadType
|
arrowHeadType?: ArrowHeadType
|
||||||
markerEndId?: string
|
markerEndId?: string
|
||||||
sourceHandleId?: ElementId | null
|
sourceHandleId?: string
|
||||||
targetHandleId?: ElementId | null
|
targetHandleId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<StepEdgeProps>(), {
|
const props = withDefaults(defineProps<StepEdgeProps>(), {
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { CSSProperties } from 'vue'
|
import { CSSProperties } from 'vue'
|
||||||
import { ArrowHeadType, EdgeProps, EdgeTextProps, ElementId, Position } from '../../types'
|
import { ArrowHeadType, EdgeProps, Position } from '../../types'
|
||||||
import EdgeText from './EdgeText.vue'
|
import EdgeText from './EdgeText.vue'
|
||||||
import { getMarkerEnd, getBezierPath } from './utils'
|
import { getMarkerEnd, getBezierPath } from './utils'
|
||||||
|
|
||||||
interface StraightEdgeProps extends EdgeProps {
|
interface StraightEdgeProps extends EdgeProps {
|
||||||
id: ElementId
|
id: string
|
||||||
source: ElementId
|
source: string
|
||||||
target: ElementId
|
target: string
|
||||||
sourceX: number
|
sourceX: number
|
||||||
sourceY: number
|
sourceY: number
|
||||||
targetX: number
|
targetX: number
|
||||||
@@ -16,12 +16,7 @@ interface StraightEdgeProps extends EdgeProps {
|
|||||||
animated?: boolean
|
animated?: boolean
|
||||||
sourcePosition: Position
|
sourcePosition: Position
|
||||||
targetPosition: Position
|
targetPosition: Position
|
||||||
label?:
|
label?: string
|
||||||
| string
|
|
||||||
| {
|
|
||||||
component: any
|
|
||||||
props?: Record<string, any> & Partial<EdgeTextProps>
|
|
||||||
}
|
|
||||||
labelStyle?: CSSProperties
|
labelStyle?: CSSProperties
|
||||||
labelShowBg?: boolean
|
labelShowBg?: boolean
|
||||||
labelBgStyle?: CSSProperties
|
labelBgStyle?: CSSProperties
|
||||||
@@ -29,8 +24,8 @@ interface StraightEdgeProps extends EdgeProps {
|
|||||||
labelBgBorderRadius?: number
|
labelBgBorderRadius?: number
|
||||||
arrowHeadType?: ArrowHeadType
|
arrowHeadType?: ArrowHeadType
|
||||||
markerEndId?: string
|
markerEndId?: string
|
||||||
sourceHandleId?: ElementId | null
|
sourceHandleId?: string
|
||||||
targetHandleId?: ElementId | null
|
targetHandleId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<StraightEdgeProps>(), {
|
const props = withDefaults(defineProps<StraightEdgeProps>(), {
|
||||||
|
|||||||
@@ -61,12 +61,13 @@ const onDragStart: DraggableEventListener = ({ event }) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const onDrag: DraggableEventListener = ({ event, data: { deltaY, deltaX } }) => {
|
const onDrag: DraggableEventListener = ({ event, data: { deltaY, deltaX } }) => {
|
||||||
|
const extent = node.value.extent ?? store.nodeExtent
|
||||||
node.value.position = clampPosition(
|
node.value.position = clampPosition(
|
||||||
{
|
{
|
||||||
x: (node.value.position.x += deltaX),
|
x: (node.value.position.x += deltaX),
|
||||||
y: (node.value.position.y += deltaY),
|
y: (node.value.position.y += deltaY),
|
||||||
},
|
},
|
||||||
store.nodeExtent,
|
extent,
|
||||||
)
|
)
|
||||||
node.value.__vf.isDragging = true
|
node.value.__vf.isDragging = true
|
||||||
store.hooks.nodeDrag.trigger({ event, node: props.node })
|
store.hooks.nodeDrag.trigger({ event, node: props.node })
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import useStore from './useStore'
|
import useStore from './useStore'
|
||||||
import { getHostForElement } from '~/utils'
|
import { getHostForElement } from '~/utils'
|
||||||
import { Connection, ConnectionMode, ElementId, HandleType, FlowStore, ValidConnectionFunc } from '~/types'
|
import { Connection, ConnectionMode, HandleType, FlowStore, ValidConnectionFunc } from '~/types'
|
||||||
|
|
||||||
type Result = {
|
type Result = {
|
||||||
elementBelow: Element | null
|
elementBelow: Element | null
|
||||||
@@ -14,8 +14,8 @@ export const checkElementBelowIsValid = (
|
|||||||
event: MouseEvent,
|
event: MouseEvent,
|
||||||
connectionMode: ConnectionMode,
|
connectionMode: ConnectionMode,
|
||||||
isTarget: boolean,
|
isTarget: boolean,
|
||||||
nodeId: ElementId,
|
nodeId: string,
|
||||||
handleId: ElementId,
|
handleId: string,
|
||||||
isValidConnection: ValidConnectionFunc,
|
isValidConnection: ValidConnectionFunc,
|
||||||
doc: Document,
|
doc: Document,
|
||||||
) => {
|
) => {
|
||||||
@@ -70,8 +70,8 @@ const resetRecentHandle = (hoveredHandle: Element): void => {
|
|||||||
export default (store: FlowStore = useStore()) =>
|
export default (store: FlowStore = useStore()) =>
|
||||||
(
|
(
|
||||||
event: MouseEvent,
|
event: MouseEvent,
|
||||||
handleId: ElementId,
|
handleId: string,
|
||||||
nodeId: ElementId,
|
nodeId: string,
|
||||||
isTarget: boolean,
|
isTarget: boolean,
|
||||||
isValidConnection?: ValidConnectionFunc,
|
isValidConnection?: ValidConnectionFunc,
|
||||||
elementEdgeUpdaterType?: HandleType,
|
elementEdgeUpdaterType?: HandleType,
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import {
|
|||||||
ConnectionMode,
|
ConnectionMode,
|
||||||
Dimensions,
|
Dimensions,
|
||||||
EdgeComponent,
|
EdgeComponent,
|
||||||
ElementId,
|
|
||||||
GraphEdge,
|
GraphEdge,
|
||||||
GraphNode,
|
GraphNode,
|
||||||
HandleType,
|
HandleType,
|
||||||
@@ -28,9 +27,9 @@ interface EdgeRendererProps {
|
|||||||
markerEndId?: string
|
markerEndId?: string
|
||||||
elementsSelectable?: boolean
|
elementsSelectable?: boolean
|
||||||
edgeUpdaterRadius?: number
|
edgeUpdaterRadius?: number
|
||||||
connectionNodeId?: ElementId
|
connectionNodeId?: string
|
||||||
connectionHandleType?: HandleType
|
connectionHandleType?: HandleType
|
||||||
connectionHandleId?: ElementId
|
connectionHandleId?: string
|
||||||
connectionPosition?: XYPosition
|
connectionPosition?: XYPosition
|
||||||
connectionMode: ConnectionMode
|
connectionMode: ConnectionMode
|
||||||
nodesConnectable?: boolean
|
nodesConnectable?: boolean
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ElementId, FlowElement, FlowElements, GraphEdge, KeyCode } from '../../types'
|
import { FlowElement, FlowElements, GraphEdge, KeyCode } from '../../types'
|
||||||
import { useStore, useKeyPress } from '../../composables'
|
import { useStore, useKeyPress } from '../../composables'
|
||||||
import { getConnectedEdges, isGraphNode } from '../../utils'
|
import { getConnectedEdges, isGraphNode } from '../../utils'
|
||||||
import NodesSelection from '../../components/NodesSelection/NodesSelection.vue'
|
import NodesSelection from '../../components/NodesSelection/NodesSelection.vue'
|
||||||
@@ -44,7 +44,7 @@ tryOnMounted(() => {
|
|||||||
const connectedEdges = getConnectedEdges(selectedNodes, props.edges)
|
const connectedEdges = getConnectedEdges(selectedNodes, props.edges)
|
||||||
const elementsToRemove = [...props.selectedElements, ...connectedEdges].reduce(
|
const elementsToRemove = [...props.selectedElements, ...connectedEdges].reduce(
|
||||||
(res, item) => res.set(item.id, item),
|
(res, item) => res.set(item.id, item),
|
||||||
new Map<ElementId, FlowElement>(),
|
new Map<string, FlowElement>(),
|
||||||
)
|
)
|
||||||
|
|
||||||
store.hooks.elementsRemove.trigger(Array.from(elementsToRemove.values()))
|
store.hooks.elementsRemove.trigger(Array.from(elementsToRemove.values()))
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { InjectionKey } from 'vue'
|
import { InjectionKey } from 'vue'
|
||||||
import { ElementId, Store as TStore } from '~/types'
|
import { Store as TStore } from '~/types'
|
||||||
|
|
||||||
export const StoreSymbol: InjectionKey<TStore> = Symbol('store')
|
export const StoreSymbol: InjectionKey<TStore> = Symbol('store')
|
||||||
export const NodeId: InjectionKey<ElementId> = Symbol('nodeId')
|
export const NodeId: InjectionKey<string> = Symbol('nodeId')
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Component, CSSProperties, DefineComponent } from 'vue'
|
import { Component, CSSProperties, DefineComponent } from 'vue'
|
||||||
import { BackgroundVariant, Dimensions, ElementId, Elements, FitViewParams, FlowOptions, Position, XYPosition } from './flow'
|
import { BackgroundVariant, Dimensions, Elements, FitViewParams, FlowOptions, Position, XYPosition } from './flow'
|
||||||
import { Connection, ConnectionLineType, ConnectionMode } from './connection'
|
import { Connection, ConnectionLineType, ConnectionMode } from './connection'
|
||||||
import { GraphNode, Node, NodeProps, CoordinateExtent } from './node'
|
import { GraphNode, Node, NodeProps, CoordinateExtent } from './node'
|
||||||
import { EdgeProps } from './edge'
|
import { EdgeProps } from './edge'
|
||||||
@@ -15,7 +15,7 @@ export type EdgeComponent = Component<EdgeProps> | DefineComponent<EdgeProps, an
|
|||||||
export type HandleType = 'source' | 'target'
|
export type HandleType = 'source' | 'target'
|
||||||
|
|
||||||
export interface HandleElement extends XYPosition, Dimensions {
|
export interface HandleElement extends XYPosition, Dimensions {
|
||||||
id?: ElementId
|
id?: string
|
||||||
position: Position
|
position: Position
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ElementId, Position } from './flow'
|
import { Position } from './flow'
|
||||||
import { HandleType } from './components'
|
import { HandleType } from './components'
|
||||||
|
|
||||||
export enum ConnectionLineType {
|
export enum ConnectionLineType {
|
||||||
@@ -9,10 +9,10 @@ export enum ConnectionLineType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Connection {
|
export interface Connection {
|
||||||
source: ElementId
|
source: string
|
||||||
target: ElementId
|
target: string
|
||||||
sourceHandle?: ElementId
|
sourceHandle?: string
|
||||||
targetHandle?: ElementId
|
targetHandle?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ConnectionLineProps = {
|
export type ConnectionLineProps = {
|
||||||
@@ -28,8 +28,8 @@ export type ConnectionLineProps = {
|
|||||||
|
|
||||||
export type OnConnectFunc = (connection: Connection) => void
|
export type OnConnectFunc = (connection: Connection) => void
|
||||||
export type OnConnectStartParams = {
|
export type OnConnectStartParams = {
|
||||||
nodeId?: ElementId
|
nodeId?: string
|
||||||
handleId?: ElementId
|
handleId?: string
|
||||||
handleType?: HandleType
|
handleType?: HandleType
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ export enum ConnectionMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type SetConnectionId = {
|
export type SetConnectionId = {
|
||||||
connectionNodeId: ElementId | undefined
|
connectionNodeId: string | undefined
|
||||||
connectionHandleId: ElementId | undefined
|
connectionHandleId: string | undefined
|
||||||
connectionHandleType: HandleType | undefined
|
connectionHandleType: HandleType | undefined
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -1,11 +1,11 @@
|
|||||||
import { ArrowHeadType, ElementId, Position, Element } from './flow'
|
import { ArrowHeadType, Position, Element } from './flow'
|
||||||
import { GraphNode } from './node'
|
import { GraphNode } from './node'
|
||||||
|
|
||||||
export interface Edge<T = any> extends Element<T> {
|
export interface Edge<T = any> extends Element<T> {
|
||||||
source: ElementId
|
source: string
|
||||||
target: ElementId
|
target: string
|
||||||
sourceHandle?: ElementId
|
sourceHandle?: string
|
||||||
targetHandle?: ElementId
|
targetHandle?: string
|
||||||
sourcePosition?: Position
|
sourcePosition?: Position
|
||||||
targetPosition?: Position
|
targetPosition?: Position
|
||||||
labelStyle?: any
|
labelStyle?: any
|
||||||
@@ -33,8 +33,8 @@ export interface EdgeProps<T = any> extends GraphEdge<T> {
|
|||||||
sourcePosition: Position
|
sourcePosition: Position
|
||||||
targetPosition: Position
|
targetPosition: Position
|
||||||
markerEndId?: string
|
markerEndId?: string
|
||||||
sourceHandleId?: ElementId | null
|
sourceHandleId?: string
|
||||||
targetHandleId?: ElementId | null
|
targetHandleId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EdgeSmoothStepProps<T = any> extends EdgeProps<T> {
|
export interface EdgeSmoothStepProps<T = any> extends EdgeProps<T> {
|
||||||
|
|||||||
+2
-3
@@ -5,11 +5,10 @@ import { ConnectionLineType, ConnectionMode } from './connection'
|
|||||||
import { KeyCode, PanOnScrollMode } from './zoom'
|
import { KeyCode, PanOnScrollMode } from './zoom'
|
||||||
import { EdgeTypes, NodeTypes } from './components'
|
import { EdgeTypes, NodeTypes } from './components'
|
||||||
|
|
||||||
export type ElementId = string
|
|
||||||
export type FlowElement<DataNode = any, DataEdge = any> = GraphNode<DataNode> | GraphEdge<DataEdge>
|
export type FlowElement<DataNode = any, DataEdge = any> = GraphNode<DataNode> | GraphEdge<DataEdge>
|
||||||
export type FlowElements<DataNode = any, DataEdge = any> = FlowElement<DataNode, DataEdge>[]
|
export type FlowElements<DataNode = any, DataEdge = any> = FlowElement<DataNode, DataEdge>[]
|
||||||
export interface Element<Data = any> {
|
export interface Element<Data = any> {
|
||||||
id: ElementId
|
id: string
|
||||||
label?: string
|
label?: string
|
||||||
type?: string
|
type?: string
|
||||||
data?: Data
|
data?: Data
|
||||||
@@ -78,7 +77,7 @@ export type FitViewParams = {
|
|||||||
y?: number
|
y?: number
|
||||||
}
|
}
|
||||||
transitionDuration?: number
|
transitionDuration?: number
|
||||||
nodes?: ElementId[]
|
nodes?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FlowExportObject<T = any> = {
|
export type FlowExportObject<T = any> = {
|
||||||
|
|||||||
+7
-5
@@ -1,7 +1,9 @@
|
|||||||
import { DraggableOptions } from '@braks/revue-draggable'
|
import { DraggableOptions } from '@braks/revue-draggable'
|
||||||
import { XYPosition, ElementId, Position, SnapGrid, Element } from './flow'
|
import { XYPosition, Position, SnapGrid, Element } from './flow'
|
||||||
import { HandleElement, ValidConnectionFunc } from './components'
|
import { HandleElement, ValidConnectionFunc } from './components'
|
||||||
|
|
||||||
|
export type CoordinateExtent = [[number, number], [number, number]]
|
||||||
|
|
||||||
export interface VFInternals {
|
export interface VFInternals {
|
||||||
isDragging?: boolean
|
isDragging?: boolean
|
||||||
width: number
|
width: number
|
||||||
@@ -25,6 +27,8 @@ export interface Node<T = any> extends Element<T> {
|
|||||||
snapGrid?: SnapGrid
|
snapGrid?: SnapGrid
|
||||||
isValidTargetPos?: ValidConnectionFunc
|
isValidTargetPos?: ValidConnectionFunc
|
||||||
isValidSourcePos?: ValidConnectionFunc
|
isValidSourcePos?: ValidConnectionFunc
|
||||||
|
extent?: 'parent' | CoordinateExtent
|
||||||
|
parentNode?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GraphNode<T = any> extends Node<T> {
|
export interface GraphNode<T = any> extends Node<T> {
|
||||||
@@ -32,7 +36,7 @@ export interface GraphNode<T = any> extends Node<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface NodeProps<T = any> extends GraphNode {
|
export interface NodeProps<T = any> extends GraphNode {
|
||||||
id: ElementId
|
id: string
|
||||||
position: XYPosition
|
position: XYPosition
|
||||||
type?: string
|
type?: string
|
||||||
data?: T
|
data?: T
|
||||||
@@ -46,10 +50,8 @@ export interface NodeProps<T = any> extends GraphNode {
|
|||||||
__vf: VFInternals
|
__vf: VFInternals
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CoordinateExtent = [[number, number], [number, number]]
|
|
||||||
|
|
||||||
export type NodeDimensionUpdate = {
|
export type NodeDimensionUpdate = {
|
||||||
id: ElementId
|
id: string
|
||||||
nodeElement: HTMLDivElement
|
nodeElement: HTMLDivElement
|
||||||
forceUpdate?: boolean
|
forceUpdate?: boolean
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -2,7 +2,6 @@ import { ComputedRef, ToRefs } from 'vue'
|
|||||||
import { UnwrapNestedRefs } from '@vue/reactivity'
|
import { UnwrapNestedRefs } from '@vue/reactivity'
|
||||||
import {
|
import {
|
||||||
Dimensions,
|
Dimensions,
|
||||||
ElementId,
|
|
||||||
Elements,
|
Elements,
|
||||||
FlowElements,
|
FlowElements,
|
||||||
FlowInstance,
|
FlowInstance,
|
||||||
@@ -52,8 +51,8 @@ export interface FlowState extends Omit<FlowOptions, 'elements' | 'id'> {
|
|||||||
multiSelectionKeyCode: KeyCode
|
multiSelectionKeyCode: KeyCode
|
||||||
zoomActivationKeyCode: KeyCode
|
zoomActivationKeyCode: KeyCode
|
||||||
|
|
||||||
connectionNodeId?: ElementId
|
connectionNodeId?: string
|
||||||
connectionHandleId?: ElementId
|
connectionHandleId?: string
|
||||||
connectionHandleType?: HandleType
|
connectionHandleType?: HandleType
|
||||||
connectionPosition: XYPosition
|
connectionPosition: XYPosition
|
||||||
connectionMode: ConnectionMode
|
connectionMode: ConnectionMode
|
||||||
|
|||||||
+2
-13
@@ -1,16 +1,5 @@
|
|||||||
import { isGraphNode, rectToBox } from './graph'
|
import { isGraphNode, rectToBox } from './graph'
|
||||||
import {
|
import { Edge, EdgePositions, GraphNode, HandleElement, Position, Transform, XYPosition, FlowElements, GraphEdge } from '~/types'
|
||||||
Edge,
|
|
||||||
EdgePositions,
|
|
||||||
ElementId,
|
|
||||||
GraphNode,
|
|
||||||
HandleElement,
|
|
||||||
Position,
|
|
||||||
Transform,
|
|
||||||
XYPosition,
|
|
||||||
FlowElements,
|
|
||||||
GraphEdge,
|
|
||||||
} from '~/types'
|
|
||||||
|
|
||||||
export function getHandlePosition(position: Position, node: GraphNode, handle?: HandleElement): XYPosition {
|
export function getHandlePosition(position: Position, node: GraphNode, handle?: HandleElement): XYPosition {
|
||||||
const x = (handle?.x ?? 0) + node.position.x
|
const x = (handle?.x ?? 0) + node.position.x
|
||||||
@@ -42,7 +31,7 @@ export function getHandlePosition(position: Position, node: GraphNode, handle?:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getHandle(bounds: HandleElement[], handleId?: ElementId): HandleElement | undefined {
|
export function getHandle(bounds: HandleElement[], handleId?: string): HandleElement | undefined {
|
||||||
if (!bounds) return undefined
|
if (!bounds) return undefined
|
||||||
|
|
||||||
// there is no handleId when there are no multiple handles/ handles with ids
|
// there is no handleId when there are no multiple handles/ handles with ids
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
import { getSourceTargetNodes } from './edge'
|
import { getSourceTargetNodes } from './edge'
|
||||||
import {
|
import {
|
||||||
ElementId,
|
|
||||||
Node,
|
Node,
|
||||||
Edge,
|
Edge,
|
||||||
Elements,
|
Elements,
|
||||||
@@ -81,7 +80,7 @@ export const removeElements = (elementsToRemove: Elements, elements: Elements) =
|
|||||||
return elements.filter((element) => !shouldRemove(element))
|
return elements.filter((element) => !shouldRemove(element))
|
||||||
}
|
}
|
||||||
|
|
||||||
const getEdgeId = ({ source, sourceHandle, target, targetHandle }: Connection): ElementId =>
|
const getEdgeId = ({ source, sourceHandle, target, targetHandle }: Connection) =>
|
||||||
`vueflow__edge-${source}${sourceHandle}-${target}${targetHandle}`
|
`vueflow__edge-${source}${sourceHandle}-${target}${targetHandle}`
|
||||||
|
|
||||||
const connectionExists = (edge: Edge, elements: Elements) => {
|
const connectionExists = (edge: Edge, elements: Elements) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user