fix(nodes,drag): update xyz on select
This commit is contained in:
@@ -78,6 +78,7 @@ onMounted(() => {
|
|||||||
() => parentNode?.computedPosition.x,
|
() => parentNode?.computedPosition.x,
|
||||||
() => parentNode?.computedPosition.y,
|
() => parentNode?.computedPosition.y,
|
||||||
() => parentNode?.computedPosition.z,
|
() => parentNode?.computedPosition.z,
|
||||||
|
() => node.selected,
|
||||||
],
|
],
|
||||||
([newX, newY, parentX, parentY, parentZ]) => {
|
([newX, newY, parentX, parentY, parentZ]) => {
|
||||||
const xyzPos = {
|
const xyzPos = {
|
||||||
|
|||||||
@@ -100,8 +100,6 @@ function useDrag(params: UseDragParams) {
|
|||||||
.on('drag', (event: UseDragEvent) => {
|
.on('drag', (event: UseDragEvent) => {
|
||||||
const mousePos = getMousePosition(event)
|
const mousePos = getMousePosition(event)
|
||||||
|
|
||||||
console.log(node?.label)
|
|
||||||
|
|
||||||
// skip events without movement
|
// skip events without movement
|
||||||
if ((lastPos.x !== mousePos.x || lastPos.y !== mousePos.y) && dragItems) {
|
if ((lastPos.x !== mousePos.x || lastPos.y !== mousePos.y) && dragItems) {
|
||||||
lastPos = mousePos
|
lastPos = mousePos
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { Dimensions, ElementData, XYPosition } from './flow'
|
import type { Dimensions, ElementData, XYPosition } from './flow'
|
||||||
import type { GraphNode, NodeHandleBounds } from './node'
|
import type { GraphNode, Node, NodeHandleBounds } from './node'
|
||||||
import type { GraphEdge } from './edge'
|
import type { GraphEdge } from './edge'
|
||||||
|
|
||||||
export interface NodeDragItem {
|
export interface NodeDragItem {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import type {
|
|||||||
ElementChange,
|
ElementChange,
|
||||||
FlowElement,
|
FlowElement,
|
||||||
FlowElements,
|
FlowElements,
|
||||||
Getters,
|
|
||||||
GraphEdge,
|
GraphEdge,
|
||||||
GraphNode,
|
GraphNode,
|
||||||
Node,
|
Node,
|
||||||
@@ -16,8 +15,7 @@ import type {
|
|||||||
NodeSelectionChange,
|
NodeSelectionChange,
|
||||||
} from '~/types'
|
} from '~/types'
|
||||||
|
|
||||||
function handleParentExpand(updateItem: GraphNode, curr: GraphNode[]) {
|
function handleParentExpand(updateItem: GraphNode, parent: GraphNode) {
|
||||||
const parent = updateItem.parentNode ? curr.find((el) => el.id === updateItem.parentNode) : undefined
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
const extendWidth = updateItem.position.x + updateItem.dimensions.width - parent.dimensions.width
|
const extendWidth = updateItem.position.x + updateItem.dimensions.width - parent.dimensions.width
|
||||||
const extendHeight = updateItem.position.y + updateItem.dimensions.height - parent.dimensions.height
|
const extendHeight = updateItem.position.y + updateItem.dimensions.height - parent.dimensions.height
|
||||||
@@ -92,7 +90,6 @@ export const applyChanges = <
|
|||||||
): T[] => {
|
): T[] => {
|
||||||
let elementIds = elements.map((el) => el.id)
|
let elementIds = elements.map((el) => el.id)
|
||||||
changes.forEach((change) => {
|
changes.forEach((change) => {
|
||||||
nextTick(() => {
|
|
||||||
if (change.type === 'add') {
|
if (change.type === 'add') {
|
||||||
const item = <T>change.item
|
const item = <T>change.item
|
||||||
return elements.push(item)
|
return elements.push(item)
|
||||||
@@ -136,7 +133,6 @@ export const applyChanges = <
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
return elements
|
return elements
|
||||||
}
|
}
|
||||||
@@ -161,21 +157,15 @@ export const createAdditionChange = <
|
|||||||
type: 'add',
|
type: 'add',
|
||||||
}
|
}
|
||||||
|
|
||||||
const isParentSelected = (node: GraphNode, selectedIds: string[], getNode: Getters['getNode']): boolean => {
|
export const getSelectionChanges = (items: FlowElements, selectedIds: string[]) => {
|
||||||
const parent = node.parentNode ? getNode(node.parentNode) : undefined
|
|
||||||
if (!node.parentNode || !parent) return false
|
|
||||||
if (selectedIds.includes(node.parentNode)) return true
|
|
||||||
return isParentSelected(parent, selectedIds, getNode)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getSelectionChanges = (items: FlowElements, selectedIds: string[], getNode: Getters['getNode']) => {
|
|
||||||
return items.reduce((res, item) => {
|
return items.reduce((res, item) => {
|
||||||
const willBeSelected =
|
const willBeSelected = selectedIds.includes(item.id)
|
||||||
selectedIds.includes(item.id) || !!(isGraphNode(item) && item.parentNode && isParentSelected(item, selectedIds, getNode))
|
|
||||||
|
|
||||||
if (!item.selected && willBeSelected) {
|
if (!item.selected && willBeSelected) {
|
||||||
|
item.selected = true
|
||||||
res.push(createSelectionChange(item.id, true))
|
res.push(createSelectionChange(item.id, true))
|
||||||
} else if (item.selected && !willBeSelected) {
|
} else if (item.selected && !willBeSelected) {
|
||||||
|
item.selected = false
|
||||||
res.push(createSelectionChange(item.id, false))
|
res.push(createSelectionChange(item.id, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user