From 375e7adc4a2c885185588a6df33e47f16370723d Mon Sep 17 00:00:00 2001 From: Hiren Kangad Date: Fri, 13 Mar 2026 09:51:54 +0530 Subject: [PATCH] feat(markdown): add PasteChoicePopup component for paste-as choice --- frontend/src/components/PasteChoicePopup.tsx | 106 +++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 frontend/src/components/PasteChoicePopup.tsx diff --git a/frontend/src/components/PasteChoicePopup.tsx b/frontend/src/components/PasteChoicePopup.tsx new file mode 100644 index 0000000..46d6229 --- /dev/null +++ b/frontend/src/components/PasteChoicePopup.tsx @@ -0,0 +1,106 @@ +/** + * PasteChoicePopup — floating popup for paste-as choice. + * Shows "Text" / "Markdown" buttons (and optionally "Image"). + * Auto-dismisses after 5 seconds. + */ + +import React, { useEffect } from 'react'; + +export type PasteChoice = 'text' | 'markdown' | 'image'; + +interface PasteChoicePopupProps { + x: number; + y: number; + showImage?: boolean; + onChoice: (choice: PasteChoice) => void; + onDismiss: () => void; +} + +export default function PasteChoicePopup(props: PasteChoicePopupProps) { + const { x, y, showImage, onChoice, onDismiss } = props; + + // Auto-dismiss after 5 seconds + useEffect(() => { + const timer = setTimeout(onDismiss, 5000); + return () => clearTimeout(timer); + }, [onDismiss]); + + // Escape to dismiss + useEffect(() => { + const onKey = (e: KeyboardEvent) => { + if (e.key === 'Escape') { + e.preventDefault(); + onDismiss(); + } + }; + document.addEventListener('keydown', onKey); + return () => document.removeEventListener('keydown', onKey); + }, [onDismiss]); + + const btnStyle: React.CSSProperties = { + background: '#333', + border: '1px solid #444', + borderRadius: '6px', + color: '#ccc', + padding: '6px 14px', + fontSize: '12px', + cursor: 'pointer', + fontFamily: 'system-ui, sans-serif', + transition: 'background 0.1s', + }; + + return ( +
e.stopPropagation()} + > + {/* Full-screen backdrop to block canvas interaction while popup is visible */} +
+ Paste as: + {showImage && ( + + )} + + +
+ ); +}