diff --git a/src/components/NoteCard.tsx b/src/components/NoteCard.tsx index 3d6c168..b798717 100644 --- a/src/components/NoteCard.tsx +++ b/src/components/NoteCard.tsx @@ -18,6 +18,9 @@ export function NoteCard({ key: itemKey, data: item }: NoteCard.NoteCardProps) { const newY = useRef(0) const offsetX = useRef(0) const offsetY = useRef(0) + const initialResizeX = useRef(0) + const initialResizeY = useRef(0) + const { debounce } = useDebounce() function updateLocalStorage(time?: number) { @@ -54,6 +57,25 @@ export function NoteCard({ key: itemKey, data: item }: NoteCard.NoteCardProps) { window.addEventListener('mouseup', _handleMouseUp) } + function _handleResizeMove(e: MouseEvent) { + const { pageX, pageY } = e + const [newX, newY] = [initialResizeX.current - pageX, initialResizeY.current - pageY] + NotesSigal.default.updateNoteProperty(itemKey, 'dimensions', { w: -newX + item.dimensions.w, h: -newY + item.dimensions.h }) + } + + function _handleResizeMouseDown(e: MouseEvent) { + if (pressed.value) return _handleResizeMouseUp() + initialResizeX.current = e.pageX + initialResizeY.current = e.pageY + pressed.value = true + window.addEventListener('mousemove', _handleResizeMove) + } + + function _handleResizeMouseUp() { + pressed.value = false + window.removeEventListener('mousemove', _handleResizeMove) + } + return (