feat(core): store handle validation in store state
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -156,6 +156,7 @@ export default function useHandle({
|
|||||||
viewport.value,
|
viewport.value,
|
||||||
)
|
)
|
||||||
: connectionPosition,
|
: connectionPosition,
|
||||||
|
result,
|
||||||
getConnectionStatus(!!prevClosestHandle, isValid),
|
getConnectionStatus(!!prevClosestHandle, isValid),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -443,9 +443,14 @@ export function useActions(state: State, getters: ComputedGetters): Actions {
|
|||||||
if (position) state.connectionPosition = position
|
if (position) state.connectionPosition = position
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateConnection: Actions['updateConnection'] = (position, status = null) => {
|
const updateConnection: Actions['updateConnection'] = (position, result, status = null) => {
|
||||||
state.connectionPosition = position
|
if (state.connectionStartHandle) {
|
||||||
state.connectionStatus = status
|
state.connectionPosition = position
|
||||||
|
state.connectionStartHandle.result = result
|
||||||
|
state.connectionStatus = status
|
||||||
|
} else {
|
||||||
|
warn('Cannot update connection as it has not been started')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const endConnection: Actions['endConnection'] = (event, isClick) => {
|
const endConnection: Actions['endConnection'] = (event, isClick) => {
|
||||||
|
|||||||
@@ -18,10 +18,17 @@ export interface ConnectionHandle {
|
|||||||
y: number
|
y: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ValidHandleResult {
|
||||||
|
handleDomNode: Element | null
|
||||||
|
isValid: boolean
|
||||||
|
connection: Connection
|
||||||
|
}
|
||||||
|
|
||||||
export interface StartHandle {
|
export interface StartHandle {
|
||||||
nodeId: string
|
nodeId: string
|
||||||
type: HandleType
|
type: HandleType
|
||||||
handleId: string | null
|
handleId: string | null
|
||||||
|
result?: ValidHandleResult
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A valid connection function can determine if an attempted connection is valid or not, i.e. abort creating a new edge */
|
/** A valid connection function can determine if an attempted connection is valid or not, i.e. abort creating a new edge */
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import type { CoordinateExtent, GraphNode, Node } from './node'
|
|||||||
import type { D3Selection, D3Zoom, D3ZoomHandler, PanOnScrollMode, ViewportFunctions, ViewportTransform } from './zoom'
|
import type { D3Selection, D3Zoom, D3ZoomHandler, PanOnScrollMode, ViewportFunctions, ViewportTransform } from './zoom'
|
||||||
import type { CustomEvent, FlowHooks, FlowHooksEmit, FlowHooksOn } from './hooks'
|
import type { CustomEvent, FlowHooks, FlowHooksEmit, FlowHooksOn } from './hooks'
|
||||||
import type { EdgeChange, NodeChange, NodeDragItem } from './changes'
|
import type { EdgeChange, NodeChange, NodeDragItem } from './changes'
|
||||||
import type { StartHandle } from './handle'
|
import type { StartHandle, ValidHandleResult } from './handle'
|
||||||
|
|
||||||
export interface UpdateNodeDimensionsParams {
|
export interface UpdateNodeDimensionsParams {
|
||||||
id: string
|
id: string
|
||||||
@@ -248,7 +248,7 @@ export interface Actions extends ViewportFunctions {
|
|||||||
/** start a connection */
|
/** start a connection */
|
||||||
startConnection: (startHandle: StartHandle, position?: XYPosition, event?: MouseEvent | TouchEvent, isClick?: boolean) => void
|
startConnection: (startHandle: StartHandle, position?: XYPosition, event?: MouseEvent | TouchEvent, isClick?: boolean) => void
|
||||||
/** update connection position */
|
/** update connection position */
|
||||||
updateConnection: (position: XYPosition, status?: ConnectionStatus | null) => void
|
updateConnection: (position: XYPosition, result?: ValidHandleResult, status?: ConnectionStatus | null) => void
|
||||||
/** end (or cancel) a connection */
|
/** end (or cancel) a connection */
|
||||||
endConnection: (event?: MouseEvent | TouchEvent, isClick?: boolean) => void
|
endConnection: (event?: MouseEvent | TouchEvent, isClick?: boolean) => void
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import type {
|
|||||||
HandleType,
|
HandleType,
|
||||||
NodeHandleBounds,
|
NodeHandleBounds,
|
||||||
ValidConnectionFunc,
|
ValidConnectionFunc,
|
||||||
|
ValidHandleResult,
|
||||||
XYPosition,
|
XYPosition,
|
||||||
} from '~/types'
|
} from '~/types'
|
||||||
|
|
||||||
@@ -64,12 +65,6 @@ export function getClosestHandle(
|
|||||||
return closestHandle
|
return closestHandle
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Result {
|
|
||||||
handleDomNode: Element | null
|
|
||||||
isValid: boolean
|
|
||||||
connection: Connection
|
|
||||||
}
|
|
||||||
|
|
||||||
// checks if and returns connection in fom of an object { source: 123, target: 312 }
|
// checks if and returns connection in fom of an object { source: 123, target: 312 }
|
||||||
export function isValidHandle(
|
export function isValidHandle(
|
||||||
event: MouseEvent | TouchEvent,
|
event: MouseEvent | TouchEvent,
|
||||||
@@ -90,7 +85,7 @@ export function isValidHandle(
|
|||||||
const handleBelow = doc.elementFromPoint(x, y)
|
const handleBelow = doc.elementFromPoint(x, y)
|
||||||
const handleToCheck = handleBelow?.classList.contains('vue-flow__handle') ? handleBelow : handleDomNode
|
const handleToCheck = handleBelow?.classList.contains('vue-flow__handle') ? handleBelow : handleDomNode
|
||||||
|
|
||||||
const result: Result = {
|
const result: ValidHandleResult = {
|
||||||
handleDomNode: handleToCheck,
|
handleDomNode: handleToCheck,
|
||||||
isValid: false,
|
isValid: false,
|
||||||
connection: { source: '', target: '', sourceHandle: null, targetHandle: null },
|
connection: { source: '', target: '', sourceHandle: null, targetHandle: null },
|
||||||
|
|||||||
Reference in New Issue
Block a user