GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(desktop): browser annotations show above page popovers and modal … · pingdotgg/t3code@63bf014

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/desktop/src/preview
    • PickPreload.test.ts
    • PickPreload.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/desktop/src/preview/PickPreload.test.ts‎

Copy file name to clipboardExpand all lines: apps/desktop/src/preview/PickPreload.test.ts
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const startAnnotation = (): ShadowRoot => {
2929
disconnect() {}
3030
},
3131
);
32+
// jsdom has no popover API.
33+
HTMLElement.prototype.showPopover ??= () => {};
34+
HTMLElement.prototype.hidePopover ??= () => {};
3235
using attachShadow = vi.spyOn(Element.prototype, "attachShadow");
3336
for (const listener of ipcListeners.get(START_PICK_CHANNEL) ?? []) listener({}, undefined, false);
3437
const shadowRoot = attachShadow.mock.results[0]?.value;
Collapse file

‎apps/desktop/src/preview/PickPreload.ts‎

Copy file name to clipboardExpand all lines: apps/desktop/src/preview/PickPreload.ts
+41-3Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,9 @@ function startAnnotation(
563563
const host = document.createElement("div");
564564
host.setAttribute(OVERLAY_ATTRIBUTE, "");
565565
host.setAttribute("dir", "ltr");
566-
host.style.cssText = `position:fixed;inset:0;z-index:${Z_INDEX_OVERLAY};pointer-events:none`;
566+
host.popover = "manual";
567+
// Resets the UA popover box (fit-content size, auto margin, border, padding, Canvas background).
568+
host.style.cssText = `position:fixed;inset:0;width:auto;height:auto;margin:0;border:0;padding:0;overflow:visible;background:transparent;color:inherit;z-index:${Z_INDEX_OVERLAY};pointer-events:none`;
567569
applyAnnotationTheme(host, annotationTheme);
568570
const shadowRoot = host.attachShadow({ mode: "closed" });
569571
const themeStyle = document.createElement("style");
@@ -577,7 +579,7 @@ function startAnnotation(
577579
root.style.cssText = "pointer-events:none";
578580
const cursorStyle = document.createElement("style");
579581
cursorStyle.setAttribute(OVERLAY_ATTRIBUTE, "");
580-
cursorStyle.textContent = `html[data-t3code-annotation-tool] body, html[data-t3code-annotation-tool] body * { cursor: crosshair !important; } [${OVERLAY_ATTRIBUTE}], [${OVERLAY_ATTRIBUTE}] * { cursor: default !important; } [${OVERLAY_ATTRIBUTE}] input[type=number]::-webkit-inner-spin-button, [${OVERLAY_ATTRIBUTE}] input[type=number]::-webkit-outer-spin-button { appearance:none; margin:0; }`;
582+
cursorStyle.textContent = `[${OVERLAY_ATTRIBUTE}]::backdrop { display:none !important; } html[data-t3code-annotation-tool] body, html[data-t3code-annotation-tool] body * { cursor: crosshair !important; } [${OVERLAY_ATTRIBUTE}], [${OVERLAY_ATTRIBUTE}] * { cursor: default !important; } [${OVERLAY_ATTRIBUTE}] input[type=number]::-webkit-inner-spin-button, [${OVERLAY_ATTRIBUTE}] input[type=number]::-webkit-outer-spin-button { appearance:none; margin:0; }`;
581583
document.documentElement.appendChild(cursorStyle);
582584
shadowRoot.appendChild(root);
583585

@@ -1600,6 +1602,38 @@ function startAnnotation(
16001602
event.stopPropagation();
16011603
};
16021604

1605+
// Page popovers and modal dialogs sit in the top layer above any z-index, and a modal makes
1606+
// everything outside it inert, so the overlay is shown last and lives inside the topmost modal.
1607+
// Modals in the order they opened, since DOM order does not say which one blocks the rest.
1608+
const openedModals: Element[] = [];
1609+
const raiseOverlay = (): void => {
1610+
const focused = shadowRoot.activeElement;
1611+
const parent =
1612+
document.activeElement?.closest("dialog:modal") ??
1613+
openedModals.findLast((dialog) => dialog.matches(":modal")) ??
1614+
Array.from(document.querySelectorAll("dialog:modal")).at(-1) ??
1615+
document.documentElement;
1616+
if (host.parentElement !== parent) parent.appendChild(host);
1617+
if (host.matches(":popover-open")) host.hidePopover();
1618+
host.showPopover();
1619+
if (focused instanceof HTMLElement && !focused.matches(":focus"))
1620+
focused.focus({ preventScroll: true });
1621+
};
1622+
const onPageToggle = (event: Event): void => {
1623+
const target = event.target;
1624+
if (target === host) return;
1625+
if (target instanceof HTMLDialogElement) {
1626+
const index = openedModals.indexOf(target);
1627+
if (index !== -1) openedModals.splice(index, 1);
1628+
if (target.matches(":modal")) openedModals.push(target);
1629+
}
1630+
raiseOverlay();
1631+
};
1632+
// Removing an open dialog hides the overlay inside it without a toggle event.
1633+
const detachObserver = new MutationObserver(() => {
1634+
if (!host.isConnected || !host.matches(":popover-open")) raiseOverlay();
1635+
});
1636+
16031637
const onPointerOut = (event: PointerEvent): void => {
16041638
if (event.relatedTarget === null) clearHoverOutline();
16051639
};
@@ -1644,6 +1678,8 @@ function startAnnotation(
16441678
dragHandle.removeEventListener("pointerup", onEditorPointerUp);
16451679
dragHandle.removeEventListener("pointercancel", onEditorPointerUp);
16461680
for (const type of PAGE_ISOLATED_EVENTS) host.removeEventListener(type, stopAtOverlay);
1681+
window.removeEventListener("toggle", onPageToggle, true);
1682+
detachObserver.disconnect();
16471683
document.documentElement.removeEventListener("focusout", onFocusOutToOverlay);
16481684
if (editorLayoutFrame !== null) window.cancelAnimationFrame(editorLayoutFrame);
16491685
ipcRenderer.off(CANCEL_PICK_CHANNEL, onCancel);
@@ -1813,7 +1849,9 @@ function startAnnotation(
18131849
document.documentElement.appendChild(inputLayer);
18141850
inputLayer.focus({ preventScroll: true });
18151851
}
1816-
document.documentElement.appendChild(host);
1852+
raiseOverlay();
1853+
window.addEventListener("toggle", onPageToggle, true);
1854+
detachObserver.observe(document.documentElement, { childList: true, subtree: true });
18171855
rootResizeObserver.observe(document.documentElement);
18181856
refreshToolButtons();
18191857
updateStatus();

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.