Skip to content

Commit 8a6875c

Browse files
committed
feat: add hover box support in preview
1 parent 183c91a commit 8a6875c

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function RemoteFunctions(config = {}) {
5454
"dismiss", // when handler gets this event, it should dismiss all ui it renders in the live preview
5555
"createToolBox",
5656
"createInfoBox",
57+
"createHoverBox",
5758
"createMoreOptionsDropdown",
5859
// render an icon or html when the selected element toolbox appears in edit mode.
5960
"renderToolBoxItem",
@@ -455,12 +456,14 @@ function RemoteFunctions(config = {}) {
455456
_hoverHighlight.add(element);
456457
}
457458

458-
// commented out for unified box redesign
459-
// const infoBoxHandler = LivePreviewView.getToolHandler("InfoBox");
460-
// if (infoBoxHandler) {
461-
// infoBoxHandler.dismiss();
462-
// infoBoxHandler.createInfoBox(element);
463-
// }
459+
// Show minimal hover tooltip (tag + dimensions)
460+
const hoverBoxHandler = LivePreviewView.getToolHandler("HoverBox");
461+
if (hoverBoxHandler) {
462+
hoverBoxHandler.dismiss();
463+
if (element !== previouslySelectedElement) {
464+
hoverBoxHandler.createHoverBox(element);
465+
}
466+
}
464467
}
465468
}
466469

@@ -469,15 +472,17 @@ function RemoteFunctions(config = {}) {
469472
if (SHARED_STATE.isAutoScrolling) { return; }
470473

471474
const element = event.target;
472-
if(LivePreviewView.isElementEditable(element) && element.nodeType === Node.ELEMENT_NODE) {
475+
// Use isElementInspectable (not isElementEditable) so that JS-rendered
476+
// elements also get their hover highlight and hover box properly dismissed.
477+
if(LivePreviewView.isElementInspectable(element) && element.nodeType === Node.ELEMENT_NODE) {
473478
// this is to check the user's settings, if they want to show the elements highlights on hover or click
474479
if (_hoverHighlight && shouldShowHighlightOnHover()) {
475480
_hoverHighlight.clear();
476481
clearElementHoverHighlight(element);
477-
// dismiss the info box
478-
const infoBoxHandler = LivePreviewView.getToolHandler("InfoBox");
479-
if (infoBoxHandler) {
480-
infoBoxHandler.dismiss();
482+
// dismiss the hover box
483+
const hoverBoxHandler = LivePreviewView.getToolHandler("HoverBox");
484+
if (hoverBoxHandler) {
485+
hoverBoxHandler.dismiss();
481486
}
482487
}
483488
}

0 commit comments

Comments
 (0)