From aff8e688a505bd1905a39a781967218c99971d92 Mon Sep 17 00:00:00 2001 From: Antigravity Date: Fri, 29 May 2026 13:44:31 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20import=20markdown=20via=20input=20dynami?= =?UTF-8?q?que=20(pas=20d'input=20cach=C3=A9=20dans=20le=20DOM)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit L'input caché dans le toolbar était bloqué par le conteneur parent. Maintenant l'input est créé dynamiquement dans le handler et détruit après usage — garanti d'ouvrir l'explorateur fichiers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../note-editor/note-editor-toolbar.tsx | 54 +++++++++---------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/memento-note/components/note-editor/note-editor-toolbar.tsx b/memento-note/components/note-editor/note-editor-toolbar.tsx index 731ee7d..7224bd3 100644 --- a/memento-note/components/note-editor/note-editor-toolbar.tsx +++ b/memento-note/components/note-editor/note-editor-toolbar.tsx @@ -45,7 +45,6 @@ export function NoteEditorToolbar({ mode, onClose, onToggleAttachments, attachme const [isConverting, setIsConverting] = useState(false) const [shareOpen, setShareOpen] = useState(false) const [flashcardsOpen, setFlashcardsOpen] = useState(false) - const mdImportInputRef = useRef(null) const notebookName = notebooks.find(nb => nb.id === note.notebookId)?.name || null @@ -79,29 +78,31 @@ export function NoteEditorToolbar({ mode, onClose, onToggleAttachments, attachme } // ── Markdown import ─────────────────────────────────────────────────────── - const handleImportMarkdownFile = (e: React.ChangeEvent) => { - const file = e.target.files?.[0] - if (!file) return - const reader = new FileReader() - reader.onload = (ev) => { - try { - const md = ev.target?.result as string - const html = markdownToHTML(md) - const extractedTitle = extractMarkdownTitle(md) - const editor = richTextEditorRef?.current?.getEditor() - if (editor) { - editor.commands.setContent(html) + const openMarkdownImport = () => { + const input = document.createElement('input') + input.type = 'file' + input.accept = '.md,text/markdown' + input.onchange = (e) => { + const file = (e.target as HTMLInputElement).files?.[0] + if (!file) return + const reader = new FileReader() + reader.onload = (ev) => { + try { + const md = ev.target?.result as string + const html = markdownToHTML(md) + const extractedTitle = extractMarkdownTitle(md) + const editor = richTextEditorRef?.current?.getEditor() + if (editor) editor.commands.setContent(html) + actions.setContent(html) + if (extractedTitle) actions.setTitle(extractedTitle) + toast.success(t('richTextEditor.markdownImportSuccess')) + } catch { + toast.error(t('richTextEditor.markdownExportError')) } - actions.setContent(html) - if (extractedTitle) actions.setTitle(extractedTitle) - toast.success(t('richTextEditor.markdownImportSuccess')) - } catch { - toast.error(t('richTextEditor.markdownExportError')) } + reader.readAsText(file) } - reader.readAsText(file) - // Reset input so same file can be imported again - e.target.value = '' + input.click() } const handleConvertToRichtext = async () => { @@ -301,7 +302,7 @@ export function NoteEditorToolbar({ mode, onClose, onToggleAttachments, attachme {t('richTextEditor.exportMarkdown')} - setTimeout(() => mdImportInputRef.current?.click(), 0)}> + {t('richTextEditor.importMarkdown')} @@ -498,14 +499,7 @@ export function NoteEditorToolbar({ mode, onClose, onToggleAttachments, attachme )} - {/* Hidden file input for Markdown import */} - + {/* Hidden file input for Markdown import — remplacé par création dynamique dans openMarkdownImport */} ) }