update(types): Correct __vf typing
* fix all uses of __vf so the actual type works properly * correct the class and style props Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -102,15 +102,19 @@ const nodes = computed(() => {
|
|||||||
// when connection type is loose we can define all handles as sources
|
// when connection type is loose we can define all handles as sources
|
||||||
const targetNodeHandles = computed(() =>
|
const targetNodeHandles = computed(() =>
|
||||||
store.connectionMode === ConnectionMode.Strict
|
store.connectionMode === ConnectionMode.Strict
|
||||||
? nodes.value.targetNode?.__vf?.handleBounds.target
|
? nodes.value.targetNode?.__vf?.handleBounds?.target
|
||||||
: nodes.value.targetNode?.__vf?.handleBounds.target ?? nodes.value.targetNode?.__vf?.handleBounds.source,
|
: nodes.value.targetNode?.__vf?.handleBounds?.target ?? nodes.value.targetNode?.__vf?.handleBounds?.source,
|
||||||
)
|
)
|
||||||
|
|
||||||
const sourceHandle = computed(() => {
|
const sourceHandle = computed(() => {
|
||||||
if (nodes.value.sourceNode) return getHandle(nodes.value.sourceNode.__vf?.handleBounds.source, props.edge.sourceHandle ?? null)
|
if (nodes.value.sourceNode && nodes.value.sourceNode.__vf?.handleBounds?.source)
|
||||||
|
return getHandle(nodes.value.sourceNode.__vf.handleBounds.source, props.edge.sourceHandle ?? null)
|
||||||
|
else return null
|
||||||
|
})
|
||||||
|
const targetHandle = computed(() => {
|
||||||
|
if (targetNodeHandles.value) return getHandle(targetNodeHandles.value, props.edge.targetHandle ?? null)
|
||||||
else return null
|
else return null
|
||||||
})
|
})
|
||||||
const targetHandle = computed(() => getHandle(targetNodeHandles.value, props.edge.targetHandle ?? null))
|
|
||||||
const sourcePosition = computed(() => (sourceHandle.value ? sourceHandle.value.position : Position.Bottom))
|
const sourcePosition = computed(() => (sourceHandle.value ? sourceHandle.value.position : Position.Bottom))
|
||||||
const targetPosition = computed(() => (targetHandle.value ? targetHandle.value.position : Position.Top))
|
const targetPosition = computed(() => (targetHandle.value ? targetHandle.value.position : Position.Top))
|
||||||
|
|
||||||
|
|||||||
+15
-8
@@ -91,11 +91,10 @@ export default function flowStore(
|
|||||||
const node = this.nodes[i]
|
const node = this.nodes[i]
|
||||||
const dimensions = getDimensions(nodeElement)
|
const dimensions = getDimensions(nodeElement)
|
||||||
|
|
||||||
if (!node.__vf) node.__vf = {}
|
|
||||||
const doUpdate =
|
const doUpdate =
|
||||||
dimensions.width &&
|
dimensions.width &&
|
||||||
dimensions.height &&
|
dimensions.height &&
|
||||||
(node.__vf.width !== dimensions.width || node.__vf.height !== dimensions.height || forceUpdate)
|
(node.__vf?.width !== dimensions.width || node.__vf?.height !== dimensions.height || forceUpdate)
|
||||||
|
|
||||||
if (doUpdate) {
|
if (doUpdate) {
|
||||||
const handleBounds = getHandleBounds(nodeElement, this.transform[2])
|
const handleBounds = getHandleBounds(nodeElement, this.transform[2])
|
||||||
@@ -103,6 +102,7 @@ export default function flowStore(
|
|||||||
this.nodes.splice(i, 1, {
|
this.nodes.splice(i, 1, {
|
||||||
...node,
|
...node,
|
||||||
__vf: {
|
__vf: {
|
||||||
|
position: { x: 0, y: 0 },
|
||||||
...node.__vf,
|
...node.__vf,
|
||||||
...dimensions,
|
...dimensions,
|
||||||
handleBounds,
|
handleBounds,
|
||||||
@@ -125,6 +125,8 @@ export default function flowStore(
|
|||||||
this.nodes.splice(i, 1, {
|
this.nodes.splice(i, 1, {
|
||||||
...node,
|
...node,
|
||||||
__vf: {
|
__vf: {
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
...node.__vf,
|
...node.__vf,
|
||||||
position: pos,
|
position: pos,
|
||||||
},
|
},
|
||||||
@@ -132,18 +134,21 @@ export default function flowStore(
|
|||||||
},
|
},
|
||||||
updateNodePosDiff({ id, diff, isDragging }) {
|
updateNodePosDiff({ id, diff, isDragging }) {
|
||||||
const update = (node: Node, i: number) => {
|
const update = (node: Node, i: number) => {
|
||||||
const updatedNode = {
|
const updatedNode: Node = {
|
||||||
...node,
|
...node,
|
||||||
__vf: {
|
__vf: {
|
||||||
|
width: 0,
|
||||||
|
height: 0,
|
||||||
|
position: { x: 0, y: 0 },
|
||||||
...node.__vf,
|
...node.__vf,
|
||||||
isDragging,
|
isDragging,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if (diff) {
|
if (diff && node.__vf) {
|
||||||
updatedNode.__vf.position = {
|
updatedNode.__vf!.position = {
|
||||||
x: (node.__vf?.position?.x as number) + diff.x,
|
x: node.__vf.position.x + diff.x,
|
||||||
y: (node.__vf?.position?.y as number) + diff.y,
|
y: node.__vf.position.y + diff.y,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,8 +243,10 @@ export default function flowStore(
|
|||||||
return {
|
return {
|
||||||
...node,
|
...node,
|
||||||
__vf: {
|
__vf: {
|
||||||
|
height: 0,
|
||||||
|
width: 0,
|
||||||
...node.__vf,
|
...node.__vf,
|
||||||
position: node.__vf?.position && clampPosition(node.__vf.position, nodeExtent),
|
position: node.__vf?.position ? clampPosition(node.__vf.position, nodeExtent) : { x: 0, y: 0 },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
+14
-12
@@ -1,22 +1,24 @@
|
|||||||
import { Component, DefineComponent } from 'vue'
|
import { Component, CSSProperties, DefineComponent } from 'vue'
|
||||||
import { XYPosition, ElementId, Position } from './types'
|
import { XYPosition, ElementId, Position } from './types'
|
||||||
|
import { HandleElement } from '~/types/handle'
|
||||||
|
|
||||||
export interface Node<T = any> {
|
export interface Node<T = any> {
|
||||||
id: ElementId
|
id: ElementId
|
||||||
position: XYPosition
|
position: XYPosition
|
||||||
type?: string
|
type?: string
|
||||||
__vf?:
|
__vf?: {
|
||||||
| {
|
position: XYPosition
|
||||||
position?: XYPosition
|
isDragging?: boolean
|
||||||
isDragging?: boolean
|
width: number
|
||||||
width?: number
|
height: number
|
||||||
height?: number
|
handleBounds?: {
|
||||||
handleBounds?: any
|
source?: HandleElement[] | null
|
||||||
}
|
target?: HandleElement[] | null
|
||||||
| any
|
}
|
||||||
data?: T
|
}
|
||||||
style?: any
|
|
||||||
class?: string
|
class?: string
|
||||||
|
style?: CSSProperties
|
||||||
|
data?: T
|
||||||
targetPosition?: Position
|
targetPosition?: Position
|
||||||
sourcePosition?: Position
|
sourcePosition?: Position
|
||||||
isHidden?: boolean
|
isHidden?: boolean
|
||||||
|
|||||||
+3
-3
@@ -172,8 +172,8 @@ export const parseNode = (node: Node, nodeExtent: NodeExtent): Node => ({
|
|||||||
type: node.type || 'default',
|
type: node.type || 'default',
|
||||||
__vf: {
|
__vf: {
|
||||||
position: clampPosition(node.position, nodeExtent),
|
position: clampPosition(node.position, nodeExtent),
|
||||||
width: undefined,
|
width: 0,
|
||||||
height: undefined,
|
height: 0,
|
||||||
handleBounds: {},
|
handleBounds: {},
|
||||||
isDragging: false,
|
isDragging: false,
|
||||||
},
|
},
|
||||||
@@ -215,7 +215,7 @@ export const getBoundsofRects = (rect1: Rect, rect2: Rect): Rect =>
|
|||||||
|
|
||||||
export const getRectOfNodes = (nodes: Node[]): Rect => {
|
export const getRectOfNodes = (nodes: Node[]): Rect => {
|
||||||
const box = nodes.reduce(
|
const box = nodes.reduce(
|
||||||
(currBox, { __vf: { position, width, height } = {} }) =>
|
(currBox, { __vf: { position = { x: 0, y: 0 }, width = 0, height = 0 } = {} }) =>
|
||||||
getBoundsOfBoxes(
|
getBoundsOfBoxes(
|
||||||
currBox,
|
currBox,
|
||||||
rectToBox({
|
rectToBox({
|
||||||
|
|||||||
Reference in New Issue
Block a user