Skip to content

Commit c402c9b

Browse files
committed
fix: ruler lines appearing even for invisible elements
1 parent a64ddd8 commit c402c9b

File tree

2 files changed

+81
-55
lines changed

2 files changed

+81
-55
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 41 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3464,14 +3464,7 @@ function RemoteFunctions(config = {}) {
34643464
*/
34653465
function RulerLines(element) {
34663466
this.element = element;
3467-
3468-
const editable = element.hasAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR);
3469-
this.color = editable
3470-
? "rgba(66, 133, 244, 0.4)"
3471-
: "rgba(60, 63, 65, 0.8)";
3472-
this.labelColor = editable
3473-
? "rgba(66, 133, 244, 1)"
3474-
: "rgba(60, 63, 65, 1)";
3467+
this.editable = element.hasAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR);
34753468

34763469
this.sides = ["left", "right", "top", "bottom"];
34773470
this.lineElements = {};
@@ -3483,45 +3476,43 @@ function RemoteFunctions(config = {}) {
34833476

34843477
RulerLines.prototype = {
34853478
create: function() {
3486-
const body = document.body;
3487-
3488-
const makeDiv = () => {
3489-
const el = document.createElement("div");
3490-
el.setAttribute(GLOBALS.PHCODE_INTERNAL_ATTR, "true");
3491-
return el;
3492-
};
3479+
this.container = window.document.createElement("div");
3480+
this.container.setAttribute(GLOBALS.PHCODE_INTERNAL_ATTR, "true");
34933481

3494-
const styleLine = (el) => {
3495-
el.style.position = "absolute";
3496-
el.style.backgroundColor = this.color;
3497-
el.style.pointerEvents = "none";
3498-
el.style.zIndex = "2147483645";
3499-
};
3482+
const shadow = this.container.attachShadow({ mode: "open" });
3483+
this._shadow = shadow;
35003484

3501-
const styleLabel = (el) => {
3502-
el.style.position = "absolute";
3503-
el.style.color = this.labelColor;
3504-
el.style.fontSize = "9px";
3505-
el.style.fontFamily = "Arial, sans-serif";
3506-
el.style.pointerEvents = "none";
3507-
el.style.zIndex = "2147483646";
3508-
el.style.whiteSpace = "nowrap";
3509-
el.style.backgroundColor = "transparent";
3510-
};
3485+
const lineClass = this.editable ? "phoenix-ruler-line-editable" : "phoenix-ruler-line-non-editable";
3486+
const labelClass = this.editable ? "phoenix-ruler-label-editable" : "phoenix-ruler-label-non-editable";
35113487

3488+
let html = "";
35123489
for (const side of this.sides) {
3513-
const line = makeDiv();
3514-
const label = makeDiv();
3515-
3516-
styleLine(line);
3517-
styleLabel(label);
3490+
html += `<div class="phoenix-ruler-line ${lineClass}" data-side="${side}"></div>`;
3491+
html += `<div class="phoenix-ruler-label ${labelClass}" data-side="${side}"></div>`;
3492+
}
35183493

3519-
this.lineElements[side] = line;
3520-
this.labelElements[side] = label;
3494+
shadow.innerHTML = `
3495+
<style>
3496+
${config.styles.ruler}
3497+
</style>
3498+
${html}
3499+
`;
3500+
3501+
window.document.body.appendChild(this.container);
3502+
3503+
this.lineElements = {
3504+
left: shadow.querySelector('.phoenix-ruler-line[data-side="left"]'),
3505+
right: shadow.querySelector('.phoenix-ruler-line[data-side="right"]'),
3506+
top: shadow.querySelector('.phoenix-ruler-line[data-side="top"]'),
3507+
bottom: shadow.querySelector('.phoenix-ruler-line[data-side="bottom"]')
3508+
};
35213509

3522-
body.appendChild(line);
3523-
body.appendChild(label);
3524-
}
3510+
this.labelElements = {
3511+
left: shadow.querySelector('.phoenix-ruler-label[data-side="left"]'),
3512+
right: shadow.querySelector('.phoenix-ruler-label[data-side="right"]'),
3513+
top: shadow.querySelector('.phoenix-ruler-label[data-side="top"]'),
3514+
bottom: shadow.querySelector('.phoenix-ruler-label[data-side="bottom"]')
3515+
};
35253516
},
35263517

35273518
update: function() {
@@ -3610,16 +3601,12 @@ function RemoteFunctions(config = {}) {
36103601
},
36113602

36123603
remove: function() {
3613-
const body = document.body;
3614-
3615-
for (const side of this.sides) {
3616-
const line = this.lineElements[side];
3617-
const label = this.labelElements[side];
3618-
3619-
if (line && line.parentNode) { body.removeChild(line); }
3620-
if (label && label.parentNode) { body.removeChild(label); }
3604+
if (this.container && this.container.parentNode) {
3605+
window.document.body.removeChild(this.container);
36213606
}
36223607

3608+
this.container = null;
3609+
this._shadow = null;
36233610
this.lineElements = {};
36243611
this.labelElements = {};
36253612
}
@@ -3875,6 +3862,11 @@ function RemoteFunctions(config = {}) {
38753862
}
38763863
// Always show info box for inspectable elements
38773864
_nodeInfoBox = new NodeInfoBox(element);
3865+
3866+
// show ruler lines (only when enabled)
3867+
if (config.showRulerLines) {
3868+
_currentRulerLines = new RulerLines(element);
3869+
}
38783870
} else {
38793871
// Element is hidden, so don't show UI boxes but still apply visual styling
38803872
_nodeMoreOptionsBox = null;
@@ -3897,11 +3889,6 @@ function RemoteFunctions(config = {}) {
38973889
_hoverHighlight.add(element, true);
38983890
}
38993891

3900-
// to show ruler lines (only when its enabled)
3901-
if (config.showRulerLines) {
3902-
_currentRulerLines = new RulerLines(element);
3903-
}
3904-
39053892
previouslyClickedElement = element;
39063893
}
39073894

src/LiveDevelopment/RemoteHelper.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,44 @@ define(function (require, exports, module) {
404404
}
405405
`;
406406

407+
const rulerStyles = `
408+
:host {
409+
all: initial !important;
410+
}
411+
412+
.phoenix-ruler-line {
413+
position: absolute !important;
414+
pointer-events: none !important;
415+
z-index: 2147483645 !important;
416+
}
417+
418+
.phoenix-ruler-line-editable {
419+
background-color: rgba(66, 133, 244, 0.4) !important;
420+
}
421+
422+
.phoenix-ruler-line-non-editable {
423+
background-color: rgba(60, 63, 65, 0.8) !important;
424+
}
425+
426+
.phoenix-ruler-label {
427+
position: absolute !important;
428+
font-size: 9px !important;
429+
font-family: Arial, sans-serif !important;
430+
pointer-events: none !important;
431+
z-index: 2147483646 !important;
432+
white-space: nowrap !important;
433+
background-color: transparent !important;
434+
}
435+
436+
.phoenix-ruler-label-editable {
437+
color: rgba(66, 133, 244, 1) !important;
438+
}
439+
440+
.phoenix-ruler-label-non-editable {
441+
color: rgba(60, 63, 65, 1) !important;
442+
}
443+
`;
444+
407445
const toastMessageStyles = `
408446
:host {
409447
all: initial !important;
@@ -1027,7 +1065,8 @@ define(function (require, exports, module) {
10271065
dialogOverlay: dialogOverlayStyles,
10281066
aiPromptBox: aiPromptBoxStyles,
10291067
imageGallery: imageGalleryStyles,
1030-
hyperlinkEditor: hyperlinkEditorStyles
1068+
hyperlinkEditor: hyperlinkEditorStyles,
1069+
ruler: rulerStyles
10311070
};
10321071

10331072
exports.remoteStrings = remoteStrings;

0 commit comments

Comments
 (0)