fix(nodes): watch parent nodes deeply to trigger xyz-pos calculation

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-12-20 19:29:52 +01:00
parent 0e82420142
commit fbe62b9ab9
2 changed files with 22 additions and 12 deletions
+15 -11
View File
@@ -26,17 +26,21 @@ const scale = controlledComputed(
() => store.transform[2],
() => store.transform[2],
)
watch([() => node.value.position, () => node.value.parentNode?.position], () => {
const xyzPos = {
...node.value.position,
z: node.value.computedPosition.z,
}
if (node.value.parentNode) {
node.value.computedPosition = getXYZPos(node.value.parentNode, xyzPos)
} else {
node.value.computedPosition = xyzPos
}
})
watch(
[() => node.value.position, () => node.value.parentNode],
([pos, parent]) => {
const xyzPos = {
...pos,
z: node.value.computedPosition.z,
}
if (parent) {
node.value.computedPosition = getXYZPos(parent, xyzPos)
} else {
node.value.computedPosition = xyzPos
}
},
{ deep: true },
)
const onMouseEnterHandler = () =>
node.value.dragging && ((event: MouseEvent) => store.hooks.nodeMouseEnter.trigger({ event, node: node.value }))
+7 -1
View File
@@ -81,10 +81,16 @@ export const createPositionChange = ({ node, diff, dragging, nodeExtent }: Creat
return change
}
const isParentSelected = (node: GraphNode, selectedIds: string[]): boolean => {
if (!node.parentNode) return false
if (selectedIds.includes(node.parentNode.id)) return true
return isParentSelected(node.parentNode, selectedIds)
}
export const getSelectionChanges = (items: FlowElements, selectedIds: string[]) => {
return items.reduce((res, item) => {
const willBeSelected =
selectedIds.includes(item.id) || !!(isGraphNode(item) && item.parentNode && selectedIds.includes(item.parentNode?.id))
selectedIds.includes(item.id) || !!(isGraphNode(item) && item.parentNode && isParentSelected(item, selectedIds))
if (!item.selected && willBeSelected) {
res.push(createSelectionChange(item.id, true))