diff --git a/src/features/boards/Board.vue b/src/features/boards/Board.vue index ef613b2..00799fe 100644 --- a/src/features/boards/Board.vue +++ b/src/features/boards/Board.vue @@ -122,7 +122,7 @@ watchEffect(() => { return smallest; } const nodeType = props.types.value[curr.type]; - const canAccept = getNodeProperty(nodeType.canAccept, curr); + const canAccept = getNodeProperty(nodeType.canAccept, curr, node); if (!canAccept) { return smallest; } @@ -225,8 +225,10 @@ function drag(e: MouseEvent | TouchEvent) { function endDragging(node: BoardNode | null) { if (props.draggingNode.value != null && props.draggingNode.value === node) { - props.draggingNode.value.position.x += Math.round(dragged.value.x / 25) * 25; - props.draggingNode.value.position.y += Math.round(dragged.value.y / 25) * 25; + if (props.receivingNode.value == null) { + props.draggingNode.value.position.x += Math.round(dragged.value.x / 25) * 25; + props.draggingNode.value.position.y += Math.round(dragged.value.y / 25) * 25; + } const nodes = props.nodes.value; nodes.push(nodes.splice(nodes.indexOf(props.draggingNode.value), 1)[0]); diff --git a/src/features/boards/BoardNode.vue b/src/features/boards/BoardNode.vue index e5e292d..b40357a 100644 --- a/src/features/boards/BoardNode.vue +++ b/src/features/boards/BoardNode.vue @@ -253,9 +253,9 @@ const progressDisplay = computed(() => ); const canAccept = computed( () => - unref(props.dragging) != null && + props.dragging.value != null && unref(props.hasDragged) && - getNodeProperty(props.nodeType.value.canAccept, unref(props.node)) + getNodeProperty(props.nodeType.value.canAccept, unref(props.node), props.dragging.value) ); const style = computed(() => getNodeProperty(props.nodeType.value.style, unref(props.node))); const classes = computed(() => getNodeProperty(props.nodeType.value.classes, unref(props.node))); diff --git a/src/features/boards/board.ts b/src/features/boards/board.ts index d6ac58a..3754591 100644 --- a/src/features/boards/board.ts +++ b/src/features/boards/board.ts @@ -33,7 +33,9 @@ export const BoardType = Symbol("Board"); /** * A type representing a computable value for a node on the board. Used for node types to return different values based on the given node and the state of the board. */ -export type NodeComputable = Computable | ((node: BoardNode) => T); +export type NodeComputable = + | Computable + | ((node: BoardNode, ...args: S) => T); /** Ways to display progress of an action with a duration. */ export enum ProgressDisplay { @@ -101,7 +103,7 @@ export interface NodeTypeOptions { /** The shape of the node. */ shape: NodeComputable; /** Whether the node can accept another node being dropped upon it. */ - canAccept?: boolean | Ref | ((node: BoardNode, otherNode: BoardNode) => boolean); + canAccept?: NodeComputable; /** The progress value of the node. */ progress?: NodeComputable; /** How the progress should be displayed on the node. */ @@ -164,7 +166,7 @@ export type GenericNodeType = Replace< size: NodeComputable; draggable: NodeComputable; shape: NodeComputable; - canAccept: NodeComputable; + canAccept: NodeComputable; progressDisplay: NodeComputable; progressColor: NodeComputable; actionDistance: NodeComputable; @@ -490,8 +492,14 @@ export function createBoard( * @param property The property to find the value of * @param node The node to get the property of */ -export function getNodeProperty(property: NodeComputable, node: BoardNode): T { - return isFunction>(property) ? property(node) : unref(property); +export function getNodeProperty( + property: NodeComputable, + node: BoardNode, + ...args: S +): T { + return isFunction>(property) + ? property(node, ...args) + : unref(property); } /**