Refine BIM comment modal glass and resize
This commit is contained in:
+111
-1
@@ -525,7 +525,7 @@ const getShareTokenFromPath = () => {
|
||||
|
||||
const COMMENT_TARGET_ICON = `
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M6.5 5.5h11a2.5 2.5 0 0 1 2.5 2.5v6.25a2.5 2.5 0 0 1-2.5 2.5H12l-4.3 3.1v-3.1H6.5A2.5 2.5 0 0 1 4 14.25V8a2.5 2.5 0 0 1 2.5-2.5Z"></path>
|
||||
<path d="M6.5 4.75h11A3.25 3.25 0 0 1 20.75 8v6.25a3.25 3.25 0 0 1-3.25 3.25h-5.26l-5.29 3.82V17.5H6.5a3.25 3.25 0 0 1-3.25-3.25V8A3.25 3.25 0 0 1 6.5 4.75Z"></path>
|
||||
</svg>
|
||||
`;
|
||||
|
||||
@@ -1485,6 +1485,115 @@ const setupDraggableFixedWindow = (element, handle) => {
|
||||
handle.addEventListener("pointercancel", endDrag);
|
||||
};
|
||||
|
||||
const setupResizableFixedWindow = (element, { minWidth = 520, minHeight = 420, margin = 8 } = {}) => {
|
||||
if (!element || element.dataset.resizableReady === "true") return;
|
||||
element.dataset.resizableReady = "true";
|
||||
const directions = ["n", "e", "s", "w", "ne", "nw", "se", "sw"];
|
||||
let resize = null;
|
||||
|
||||
const fixCurrentRect = () => {
|
||||
const rect = element.getBoundingClientRect();
|
||||
element.style.left = `${rect.left}px`;
|
||||
element.style.top = `${rect.top}px`;
|
||||
element.style.right = "auto";
|
||||
element.style.bottom = "auto";
|
||||
element.style.width = `${rect.width}px`;
|
||||
element.style.height = `${rect.height}px`;
|
||||
element.style.maxHeight = "none";
|
||||
element.style.transform = "none";
|
||||
return rect;
|
||||
};
|
||||
|
||||
const beginResize = (direction, pointerId, clientX, clientY) => {
|
||||
bringFloatingWindowToFront(element.id === "commentModal" ? "commentModal" : element.id);
|
||||
const rect = fixCurrentRect();
|
||||
resize = {
|
||||
pointerId,
|
||||
direction,
|
||||
startX: clientX,
|
||||
startY: clientY,
|
||||
left: rect.left,
|
||||
top: rect.top,
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
};
|
||||
};
|
||||
|
||||
const updateResize = (clientX, clientY) => {
|
||||
if (!resize) return;
|
||||
const dx = clientX - resize.startX;
|
||||
const dy = clientY - resize.startY;
|
||||
const right = resize.left + resize.width;
|
||||
const bottom = resize.top + resize.height;
|
||||
let left = resize.left;
|
||||
let top = resize.top;
|
||||
let width = resize.width;
|
||||
let height = resize.height;
|
||||
|
||||
if (resize.direction.includes("w")) {
|
||||
left = Math.max(margin, Math.min(resize.left + dx, right - minWidth));
|
||||
width = right - left;
|
||||
}
|
||||
if (resize.direction.includes("e")) {
|
||||
width = Math.max(minWidth, resize.width + dx);
|
||||
width = Math.min(width, window.innerWidth - margin - left);
|
||||
}
|
||||
if (resize.direction.includes("n")) {
|
||||
top = Math.max(margin, Math.min(resize.top + dy, bottom - minHeight));
|
||||
height = bottom - top;
|
||||
}
|
||||
if (resize.direction.includes("s")) {
|
||||
height = Math.max(minHeight, resize.height + dy);
|
||||
height = Math.min(height, window.innerHeight - margin - top);
|
||||
}
|
||||
|
||||
element.style.left = `${Math.round(left)}px`;
|
||||
element.style.top = `${Math.round(top)}px`;
|
||||
element.style.width = `${Math.round(width)}px`;
|
||||
element.style.height = `${Math.round(height)}px`;
|
||||
};
|
||||
|
||||
directions.forEach((direction) => {
|
||||
const handle = document.createElement("span");
|
||||
handle.className = `window-resize-handle window-resize-handle--${direction}`;
|
||||
handle.dataset.resizeDirection = direction;
|
||||
handle.setAttribute("aria-hidden", "true");
|
||||
element.appendChild(handle);
|
||||
handle.addEventListener("pointerdown", (event) => {
|
||||
if (event.pointerType === "mouse" && event.button !== 0) return;
|
||||
if (element.classList.contains("is-expanded")) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
beginResize(direction, event.pointerId, event.clientX, event.clientY);
|
||||
handle.setPointerCapture?.(event.pointerId);
|
||||
});
|
||||
handle.addEventListener("pointermove", (event) => {
|
||||
if (!resize || resize.pointerId !== event.pointerId) return;
|
||||
updateResize(event.clientX, event.clientY);
|
||||
});
|
||||
handle.addEventListener("mousedown", (event) => {
|
||||
if (event.button !== 0 || element.classList.contains("is-expanded")) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
beginResize(direction, "mouse", event.clientX, event.clientY);
|
||||
});
|
||||
const endResize = (event) => {
|
||||
if (!resize || resize.pointerId !== event.pointerId) return;
|
||||
handle.releasePointerCapture?.(event.pointerId);
|
||||
resize = null;
|
||||
};
|
||||
handle.addEventListener("pointerup", endResize);
|
||||
handle.addEventListener("pointercancel", endResize);
|
||||
});
|
||||
window.addEventListener("mousemove", (event) => {
|
||||
if (!resize || resize.pointerId !== "mouse") return;
|
||||
updateResize(event.clientX, event.clientY);
|
||||
});
|
||||
window.addEventListener("mouseup", () => {
|
||||
if (resize?.pointerId === "mouse") resize = null;
|
||||
});
|
||||
};
|
||||
|
||||
const bindFooterButtonAction = (button, handler) => {
|
||||
if (!button || typeof handler !== "function") return;
|
||||
button.addEventListener("click", handler);
|
||||
@@ -5308,6 +5417,7 @@ const loadProjectSnapshot = async (project) => {
|
||||
registerFloatingWindowElement("commentModal", commentModal);
|
||||
setupDraggableFixedWindow(commentsPanel, commentsPanelHeader);
|
||||
setupDraggableFixedWindow(commentModal, commentModalHeader);
|
||||
setupResizableFixedWindow(commentModal, { minWidth: 560, minHeight: 420 });
|
||||
commentsCollapseButton?.addEventListener("click", () => setCommentsCollapsed(true));
|
||||
commentsRestoreButton?.addEventListener("click", () => {
|
||||
commentsModeActive = true;
|
||||
|
||||
Reference in New Issue
Block a user