refactor(core): rename onError arg to triggerError
This commit is contained in:
@@ -127,7 +127,7 @@ function getParentExtent(
|
|||||||
|
|
||||||
export function getExtent<T extends NodeDragItem | GraphNode>(
|
export function getExtent<T extends NodeDragItem | GraphNode>(
|
||||||
item: T,
|
item: T,
|
||||||
onError: State['hooks']['error']['trigger'],
|
triggerError: State['hooks']['error']['trigger'],
|
||||||
extent?: State['nodeExtent'],
|
extent?: State['nodeExtent'],
|
||||||
parent?: GraphNode,
|
parent?: GraphNode,
|
||||||
) {
|
) {
|
||||||
@@ -144,7 +144,7 @@ export function getExtent<T extends NodeDragItem | GraphNode>(
|
|||||||
currentExtent = parentExtent
|
currentExtent = parentExtent
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
onError(new VueFlowError(ErrorCode.NODE_EXTENT_INVALID, item.id))
|
triggerError(new VueFlowError(ErrorCode.NODE_EXTENT_INVALID, item.id))
|
||||||
|
|
||||||
currentExtent = extent
|
currentExtent = extent
|
||||||
}
|
}
|
||||||
@@ -185,11 +185,11 @@ function clampNodeExtent({ width, height }: Dimensions, extent: CoordinateExtent
|
|||||||
export function calcNextPosition(
|
export function calcNextPosition(
|
||||||
node: GraphNode | NodeDragItem,
|
node: GraphNode | NodeDragItem,
|
||||||
nextPosition: XYPosition,
|
nextPosition: XYPosition,
|
||||||
onError: State['hooks']['error']['trigger'],
|
triggerError: State['hooks']['error']['trigger'],
|
||||||
nodeExtent?: State['nodeExtent'],
|
nodeExtent?: State['nodeExtent'],
|
||||||
parentNode?: GraphNode,
|
parentNode?: GraphNode,
|
||||||
) {
|
) {
|
||||||
const extent = clampNodeExtent(node.dimensions, getExtent(node, onError, nodeExtent, parentNode))
|
const extent = clampNodeExtent(node.dimensions, getExtent(node, triggerError, nodeExtent, parentNode))
|
||||||
|
|
||||||
const clampedPos = clampPosition(nextPosition, extent)
|
const clampedPos = clampPosition(nextPosition, extent)
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ export function isDef<T>(val: T): val is NonUndefined<T> {
|
|||||||
return typeof unrefVal !== 'undefined'
|
return typeof unrefVal !== 'undefined'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addEdgeToStore(edgeParams: Edge | Connection, edges: Edge[], onError: State['hooks']['error']['trigger']) {
|
export function addEdgeToStore(edgeParams: Edge | Connection, edges: Edge[], triggerError: State['hooks']['error']['trigger']) {
|
||||||
if (!edgeParams.source || !edgeParams.target) {
|
if (!edgeParams.source || !edgeParams.target) {
|
||||||
onError(new VueFlowError(ErrorCode.EDGE_INVALID, (edgeParams as Edge).id))
|
triggerError(new VueFlowError(ErrorCode.EDGE_INVALID, (edgeParams as Edge).id))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,17 +41,17 @@ export function updateEdgeAction(
|
|||||||
edges: GraphEdge[],
|
edges: GraphEdge[],
|
||||||
findEdge: Actions['findEdge'],
|
findEdge: Actions['findEdge'],
|
||||||
shouldReplaceId: boolean,
|
shouldReplaceId: boolean,
|
||||||
onError: State['hooks']['error']['trigger'],
|
triggerError: State['hooks']['error']['trigger'],
|
||||||
) {
|
) {
|
||||||
if (!newConnection.source || !newConnection.target) {
|
if (!newConnection.source || !newConnection.target) {
|
||||||
onError(new VueFlowError(ErrorCode.EDGE_INVALID, edge.id))
|
triggerError(new VueFlowError(ErrorCode.EDGE_INVALID, edge.id))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const foundEdge = findEdge(edge.id)
|
const foundEdge = findEdge(edge.id)
|
||||||
|
|
||||||
if (!foundEdge) {
|
if (!foundEdge) {
|
||||||
onError(new VueFlowError(ErrorCode.EDGE_NOT_FOUND, edge.id))
|
triggerError(new VueFlowError(ErrorCode.EDGE_NOT_FOUND, edge.id))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,14 +75,14 @@ export function createGraphNodes(
|
|||||||
nodes: Node[],
|
nodes: Node[],
|
||||||
currGraphNodes: GraphNode[],
|
currGraphNodes: GraphNode[],
|
||||||
findNode: Actions['findNode'],
|
findNode: Actions['findNode'],
|
||||||
onError: State['hooks']['error']['trigger'],
|
triggerError: State['hooks']['error']['trigger'],
|
||||||
) {
|
) {
|
||||||
const parentNodes: Record<string, true> = {}
|
const parentNodes: Record<string, true> = {}
|
||||||
|
|
||||||
const graphNodes = nodes.reduce((nextNodes, node) => {
|
const graphNodes = nodes.reduce((nextNodes, node) => {
|
||||||
// make sure we don't try to add invalid nodes
|
// make sure we don't try to add invalid nodes
|
||||||
if (!isNode(node)) {
|
if (!isNode(node)) {
|
||||||
onError(new VueFlowError(ErrorCode.NODE_INVALID))
|
triggerError(new VueFlowError(ErrorCode.NODE_INVALID))
|
||||||
return nextNodes
|
return nextNodes
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ export function createGraphNodes(
|
|||||||
const parentNode = nextNodes.find((n) => n.id === node.parentNode)
|
const parentNode = nextNodes.find((n) => n.id === node.parentNode)
|
||||||
|
|
||||||
if (node.parentNode && !parentNode) {
|
if (node.parentNode && !parentNode) {
|
||||||
onError(new VueFlowError(ErrorCode.NODE_MISSING_PARENT, node.id, node.parentNode))
|
triggerError(new VueFlowError(ErrorCode.NODE_MISSING_PARENT, node.id, node.parentNode))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.parentNode || parentNodes[node.id]) {
|
if (node.parentNode || parentNodes[node.id]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user