Skip to content

Commit e3945a1

Browse files
committed
fix: node more options box positioning
1 parent 3e47d63 commit e3945a1

File tree

1 file changed

+20
-35
lines changed

1 file changed

+20
-35
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -501,17 +501,15 @@ function RemoteFunctions(config) {
501501
});
502502
},
503503

504-
// note: this box width is the width of the more options box
505-
// we need this as the value is not consistent, it depends on the number of options we show in the box
506-
_getBoxPosition: function(boxWidth) {
504+
_getBoxPosition: function(boxWidth, boxHeight) {
507505
const elemBounds = this.element.getBoundingClientRect();
508506
const offset = _screenOffset(this.element);
509507

510-
let topPos = offset.top - 30;
508+
let topPos = offset.top - boxHeight - 6; // 6 for just some little space to breathe
511509
let leftPos = offset.left + elemBounds.width - boxWidth;
512510

513-
if (offset.top - 30 < 0) {
514-
topPos = offset.top + elemBounds.height + 5;
511+
if (offset.top - boxHeight < 0) {
512+
topPos = offset.top + elemBounds.height + 6;
515513
}
516514

517515
return {topPos: topPos, leftPos: leftPos};
@@ -522,33 +520,13 @@ function RemoteFunctions(config) {
522520

523521
// this is shadow DOM.
524522
// we need it because if we add the box directly to the DOM then users style might override it.
525-
// {mode: "closed"} means that users will not be able to access the shadow DOM
526-
const shadow = this.body.attachShadow({ mode: "closed" });
523+
// {mode: "open"} allows us to access the shadow DOM to get actual height/position of the boxes
524+
const shadow = this.body.attachShadow({ mode: "open" });
527525

528526
// check which options should be shown to determine box width
529527
const showEditTextOption = _shouldShowEditTextOption(this.element);
530528
const showSelectParentOption = _shouldShowSelectParentOption(this.element);
531529

532-
// calculate box width based on visible options
533-
// NOTE: duplicate and delete buttons are always shown
534-
let optionCount = 2;
535-
if (showSelectParentOption) {
536-
optionCount++;
537-
}
538-
if (showEditTextOption) {
539-
optionCount++;
540-
}
541-
542-
// box width we need to decide based on the no. of options
543-
let boxWidth;
544-
if (optionCount === 2) {
545-
boxWidth = 48;
546-
} else if (optionCount === 3) {
547-
boxWidth = 72;
548-
} else {
549-
boxWidth = 96;
550-
}
551-
552530
// the icons that is displayed in the box
553531
const ICONS = {
554532
arrowUp: `
@@ -603,10 +581,8 @@ function RemoteFunctions(config) {
603581
</span>
604582
</div>`;
605583

606-
const boxPos = this._getBoxPosition(boxWidth);
607-
608584
const styles = `
609-
.box {
585+
.phoenix-more-options-box {
610586
background-color: #4285F4;
611587
color: white;
612588
border-radius: 3px;
@@ -615,9 +591,8 @@ function RemoteFunctions(config) {
615591
font-family: Arial, sans-serif;
616592
z-index: 2147483647;
617593
position: absolute;
618-
left: ${boxPos.leftPos}px;
619-
top: ${boxPos.topPos}px;
620-
width: ${boxWidth}px;
594+
left: -1000px;
595+
top: -1000px;
621596
box-sizing: border-box;
622597
}
623598
@@ -654,7 +629,7 @@ function RemoteFunctions(config) {
654629
`;
655630

656631
// add everything to the shadow box
657-
shadow.innerHTML = `<style>${styles}</style><div class="box">${content}</div>`;
632+
shadow.innerHTML = `<style>${styles}</style><div class="phoenix-more-options-box">${content}</div>`;
658633
this._shadow = shadow;
659634
},
660635

@@ -664,6 +639,16 @@ function RemoteFunctions(config) {
664639

665640
window.document.body.appendChild(this.body);
666641

642+
// get the actual rendered dimensions of the box and then we reposition it to the actual place
643+
const boxElement = this._shadow.querySelector('.phoenix-more-options-box');
644+
if (boxElement) {
645+
const boxRect = boxElement.getBoundingClientRect();
646+
const pos = this._getBoxPosition(boxRect.width, boxRect.height);
647+
648+
boxElement.style.left = pos.leftPos + 'px';
649+
boxElement.style.top = pos.topPos + 'px';
650+
}
651+
667652
// add click handler to all the buttons
668653
const spans = this._shadow.querySelectorAll('.node-options span');
669654
spans.forEach(span => {

0 commit comments

Comments
 (0)