From 5c025b9349d57688829c4e56704226be4c39961c Mon Sep 17 00:00:00 2001 From: Fovway Date: Sat, 1 Nov 2025 13:03:19 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=20=D1=83=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=BE=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=B2=D1=8B=D0=BF=D0=B0=D0=B4=D0=B0=D1=8E=D1=89=D0=B5?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=BC=D0=B5=D0=BD=D1=8E=20=D0=B2=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=BD=D0=B5=D0=BB=D0=B8=20=D0=B8=D0=BD=D1=81=D1=82=D1=80=D1=83?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2=20Markdown,=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=81=D1=81=D1=8B?= =?UTF-8?q?=D0=BB=D0=BA=D0=B8=20=D0=BD=D0=B0=20=D0=BA=D0=BD=D0=BE=D0=BF?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B8=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=BA=D0=BB=D0=B8=D0=BA=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B2=D0=BD=D0=B5=20=D0=BC=D0=B5=D0=BD=D1=8E.=20=D0=9E=D0=B1?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=81=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=20=D0=BA=D0=B0=D0=BB=D0=B5=D0=BD=D0=B4=D0=B0=D1=80?= =?UTF-8?q?=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5?= =?UTF-8?q?=D1=80=D0=B6=D0=BA=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D1=85=20=D1=86=D0=B2=D0=B5=D1=82=D0=B0=20?= =?UTF-8?q?=D0=B0=D0=BA=D1=86=D0=B5=D0=BD=D1=82=D0=B0,=20=D1=83=D0=BB?= =?UTF-8?q?=D1=83=D1=87=D1=88=D0=B5=D0=BD=D0=B0=20=D0=B2=D0=B8=D0=B7=D1=83?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=8D=D0=BB?= =?UTF-8?q?=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=20=D0=BD=D0=B0=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=B8=20=D0=B2=D1=8B=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D0=B8?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/notes/MarkdownToolbar.tsx | 64 ++++++++-- src/styles/style-calendar.css | 32 +++-- src/styles/style.css | 153 ++++++++++++++++++----- 3 files changed, 197 insertions(+), 52 deletions(-) diff --git a/src/components/notes/MarkdownToolbar.tsx b/src/components/notes/MarkdownToolbar.tsx index 7b9a57c..e9babc4 100644 --- a/src/components/notes/MarkdownToolbar.tsx +++ b/src/components/notes/MarkdownToolbar.tsx @@ -21,28 +21,55 @@ export const MarkdownToolbar: React.FC = ({ const [showHeaderDropdown, setShowHeaderDropdown] = useState(false); const dispatch = useAppDispatch(); const dropdownRef = useRef(null); + const buttonRef = useRef(null); + const menuRef = useRef(null); const containerRef = useRef(null); const [isDragging, setIsDragging] = useState(false); const [startX, setStartX] = useState(0); const [scrollLeft, setScrollLeft] = useState(0); + const [menuPosition, setMenuPosition] = useState<{ top: number; left: number } | null>(null); useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if ( dropdownRef.current && - !dropdownRef.current.contains(event.target as Node) + !dropdownRef.current.contains(event.target as Node) && + menuRef.current && + !menuRef.current.contains(event.target as Node) ) { setShowHeaderDropdown(false); + setMenuPosition(null); + } + }; + + const updateMenuPosition = () => { + if (buttonRef.current && showHeaderDropdown) { + const rect = buttonRef.current.getBoundingClientRect(); + setMenuPosition({ + top: rect.bottom + window.scrollY + 2, + left: rect.left + window.scrollX, + }); } }; if (showHeaderDropdown) { - document.addEventListener("mousedown", handleClickOutside); - } + updateMenuPosition(); + // Используем небольшой таймаут, чтобы не перехватить клик на кнопке + const timeoutId = setTimeout(() => { + document.addEventListener("mousedown", handleClickOutside); + window.addEventListener("resize", updateMenuPosition); + window.addEventListener("scroll", updateMenuPosition); + }, 100); - return () => { - document.removeEventListener("mousedown", handleClickOutside); - }; + return () => { + clearTimeout(timeoutId); + document.removeEventListener("mousedown", handleClickOutside); + window.removeEventListener("resize", updateMenuPosition); + window.removeEventListener("scroll", updateMenuPosition); + }; + } else { + setMenuPosition(null); + } }, [showHeaderDropdown]); const handleMouseDown = (e: React.MouseEvent) => { @@ -118,8 +145,15 @@ export const MarkdownToolbar: React.FC = ({
- {showHeaderDropdown && ( -
+ {showHeaderDropdown && menuPosition && ( +
{[1, 2, 3, 4, 5].map((level) => (