refactor(core): wait for next tick to expand parent if parent is not initialized yet

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2023-01-18 20:47:32 +01:00
committed by Braks
parent 203b4815f8
commit f0fde0ac96
2 changed files with 10 additions and 13 deletions
@@ -141,18 +141,13 @@ watch(
watch([() => node.extent, () => nodeExtent], ([nodeExtent, globalExtent], [oldNodeExtent, oldGlobalExtent]) => {
// update position if extent has actually changed
if (nodeExtent !== oldNodeExtent || globalExtent !== oldGlobalExtent) {
if (isParentExtent()) {
// todo: can we solve this without a timeout? Without the timeout the initial extent is not properly calculated
setTimeout(clampPosition, 1)
} else {
clampPosition()
}
clampPosition()
}
})
// clamp initial position to nodes' extent
// if extent is parent, we need dimensions to properly clamp the position
if (isParentExtent()) {
if (node.extent === 'parent' || (typeof node.extent === 'object' && 'range' in node.extent && node.extent.range === 'parent')) {
until(() => node.initialized)
.toBe(true)
.then(clampPosition)
@@ -162,10 +157,6 @@ else {
clampPosition()
}
function isParentExtent() {
return node.extent === 'parent' || (typeof node.extent === 'object' && 'range' in node.extent && node.extent.range === 'parent')
}
/** this re-calculates the current position, necessary for clamping by a node's extent */
function clampPosition() {
const { computedPosition, position } = calcNextPosition(node, node.computedPosition, nodeExtent, parentNode)