Add sticky note support to obsidian

This commit is contained in:
Idrees Hassan
2025-11-14 00:06:49 -05:00
parent 3ec124a1b3
commit 7639c7c36a
12 changed files with 253 additions and 68 deletions

View File

@@ -67,8 +67,9 @@ export function onClick(element, action) {
* @param {HTMLElement|null} element The element to detect drag events on
* @param {boolean} [parent] Whether to move the parent element when the child is dragged
* @param {(top: number, left: number) => void} [callback] Callback for when element is moved
* @param {HTMLElement} [pageElement] The page element to constrain movement within
*/
export function makeDraggable(element, parent = true, callback = () => { }) {
export function makeDraggable(element, parent = true, callback = () => { }, pageElement) {
if (!element) {
return;
}
@@ -114,9 +115,12 @@ export function makeDraggable(element, parent = true, callback = () => { }) {
});
document.addEventListener("mousemove", (e) => {
const page = pageElement || document.documentElement;
const maxX = page.scrollWidth - elementToMove.clientWidth;
const maxY = page.scrollHeight - elementToMove.clientHeight;
if (isMouseDown) {
elementToMove.style.left = `${Math.max(0, e.clientX - offsetX)}px`;
elementToMove.style.top = `${Math.max(0, e.clientY - offsetY)}px`;
elementToMove.style.left = `${Math.max(0, Math.min(maxX, e.clientX - offsetX))}px`;
elementToMove.style.top = `${Math.max(0, Math.min(maxY, e.clientY - offsetY))}px`;
}
});