feat(ui): truncate long file names and auto-close context menu

- Add `.file-name` class with ellipsis truncation for long file names to prevent layout overflow.
- Apply truncation to metadata and file items in download and preview pages.
- Add `title` attributes to truncated names to show the full text on hover.
- Automatically close the file context menu when the mouse moves more than 80px away from it.
This commit is contained in:
2026-05-25 17:37:06 +03:00
parent bba84d4194
commit 720b45a9a6
4 changed files with 41 additions and 2 deletions

View File

@@ -19,6 +19,7 @@
const fileContextMenu = document.querySelector("[data-file-context-menu]");
let ctrlCopyMode = false;
let contextFile = null;
const contextMenuCloseDistance = 80;
if (fileBrowser) {
viewButtons.forEach((button) => {
@@ -79,6 +80,13 @@
}
});
document.addEventListener("mousemove", (event) => {
if (fileContextMenu.hidden || isPointerNearContextMenu(event.clientX, event.clientY)) {
return;
}
hideContextMenu();
});
window.addEventListener("resize", hideContextMenu);
window.addEventListener("scroll", hideContextMenu, true);
}
@@ -295,7 +303,9 @@
const body = document.createElement("span");
const name = document.createElement("strong");
name.className = "file-name";
name.textContent = file.name;
name.title = file.name;
const meta = document.createElement("code");
meta.textContent = file.meta;
body.append(name, meta);
@@ -428,6 +438,14 @@
contextFile = null;
}
function isPointerNearContextMenu(x, y) {
const rect = fileContextMenu.getBoundingClientRect();
return x >= rect.left - contextMenuCloseDistance &&
x <= rect.right + contextMenuCloseDistance &&
y >= rect.top - contextMenuCloseDistance &&
y <= rect.bottom + contextMenuCloseDistance;
}
function openInNewTab(url) {
window.open(url, "_blank", "noopener,noreferrer");
}