|
|
@ -26,8 +26,10 @@ |
|
|
const id = $builderStore.selectedComponentId |
|
|
const id = $builderStore.selectedComponentId |
|
|
const parent = document.getElementsByClassName(id)?.[0] |
|
|
const parent = document.getElementsByClassName(id)?.[0] |
|
|
const element = parent?.childNodes?.[0] |
|
|
const element = parent?.childNodes?.[0] |
|
|
|
|
|
const device = document.getElementById("device-root") |
|
|
if (element && self) { |
|
|
if (element && self) { |
|
|
// Batch reads to minimize reflow |
|
|
// Batch reads to minimize reflow |
|
|
|
|
|
const deviceBounds = device.getBoundingClientRect() |
|
|
const elBounds = element.getBoundingClientRect() |
|
|
const elBounds = element.getBoundingClientRect() |
|
|
const width = self.offsetWidth |
|
|
const width = self.offsetWidth |
|
|
const height = self.offsetHeight |
|
|
const height = self.offsetHeight |
|
|
@ -35,9 +37,16 @@ |
|
|
|
|
|
|
|
|
// Vertically, always render above unless no room, then render inside |
|
|
// Vertically, always render above unless no room, then render inside |
|
|
let newTop = elBounds.top + scrollY - verticalOffset - height |
|
|
let newTop = elBounds.top + scrollY - verticalOffset - height |
|
|
|
|
|
if (newTop < deviceBounds.top - 50) { |
|
|
|
|
|
newTop = deviceBounds.top - 50 |
|
|
|
|
|
} |
|
|
if (newTop < 0) { |
|
|
if (newTop < 0) { |
|
|
newTop = 0 |
|
|
newTop = 0 |
|
|
} |
|
|
} |
|
|
|
|
|
const deviceBottom = deviceBounds.top + deviceBounds.height |
|
|
|
|
|
if (newTop > deviceBottom - 44) { |
|
|
|
|
|
newTop = deviceBottom - 44 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Horizontally, try to center first. |
|
|
// Horizontally, try to center first. |
|
|
// Failing that, render to left edge of component. |
|
|
// Failing that, render to left edge of component. |
|
|
|