fix: import markdown via input dynamique (pas d'input caché dans le DOM)
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>
This commit is contained in:
@@ -45,7 +45,6 @@ export function NoteEditorToolbar({ mode, onClose, onToggleAttachments, attachme
|
|||||||
const [isConverting, setIsConverting] = useState(false)
|
const [isConverting, setIsConverting] = useState(false)
|
||||||
const [shareOpen, setShareOpen] = useState(false)
|
const [shareOpen, setShareOpen] = useState(false)
|
||||||
const [flashcardsOpen, setFlashcardsOpen] = useState(false)
|
const [flashcardsOpen, setFlashcardsOpen] = useState(false)
|
||||||
const mdImportInputRef = useRef<HTMLInputElement>(null)
|
|
||||||
|
|
||||||
const notebookName = notebooks.find(nb => nb.id === note.notebookId)?.name || null
|
const notebookName = notebooks.find(nb => nb.id === note.notebookId)?.name || null
|
||||||
|
|
||||||
@@ -79,8 +78,12 @@ export function NoteEditorToolbar({ mode, onClose, onToggleAttachments, attachme
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ── Markdown import ───────────────────────────────────────────────────────
|
// ── Markdown import ───────────────────────────────────────────────────────
|
||||||
const handleImportMarkdownFile = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const openMarkdownImport = () => {
|
||||||
const file = e.target.files?.[0]
|
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
|
if (!file) return
|
||||||
const reader = new FileReader()
|
const reader = new FileReader()
|
||||||
reader.onload = (ev) => {
|
reader.onload = (ev) => {
|
||||||
@@ -89,9 +92,7 @@ export function NoteEditorToolbar({ mode, onClose, onToggleAttachments, attachme
|
|||||||
const html = markdownToHTML(md)
|
const html = markdownToHTML(md)
|
||||||
const extractedTitle = extractMarkdownTitle(md)
|
const extractedTitle = extractMarkdownTitle(md)
|
||||||
const editor = richTextEditorRef?.current?.getEditor()
|
const editor = richTextEditorRef?.current?.getEditor()
|
||||||
if (editor) {
|
if (editor) editor.commands.setContent(html)
|
||||||
editor.commands.setContent(html)
|
|
||||||
}
|
|
||||||
actions.setContent(html)
|
actions.setContent(html)
|
||||||
if (extractedTitle) actions.setTitle(extractedTitle)
|
if (extractedTitle) actions.setTitle(extractedTitle)
|
||||||
toast.success(t('richTextEditor.markdownImportSuccess'))
|
toast.success(t('richTextEditor.markdownImportSuccess'))
|
||||||
@@ -100,8 +101,8 @@ export function NoteEditorToolbar({ mode, onClose, onToggleAttachments, attachme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
reader.readAsText(file)
|
reader.readAsText(file)
|
||||||
// Reset input so same file can be imported again
|
}
|
||||||
e.target.value = ''
|
input.click()
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleConvertToRichtext = async () => {
|
const handleConvertToRichtext = async () => {
|
||||||
@@ -301,7 +302,7 @@ export function NoteEditorToolbar({ mode, onClose, onToggleAttachments, attachme
|
|||||||
<FileDown className="h-4 w-4 me-2" />
|
<FileDown className="h-4 w-4 me-2" />
|
||||||
{t('richTextEditor.exportMarkdown')}
|
{t('richTextEditor.exportMarkdown')}
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem onClick={() => setTimeout(() => mdImportInputRef.current?.click(), 0)}>
|
<DropdownMenuItem onClick={openMarkdownImport}>
|
||||||
<FileUp className="h-4 w-4 me-2" />
|
<FileUp className="h-4 w-4 me-2" />
|
||||||
{t('richTextEditor.importMarkdown')}
|
{t('richTextEditor.importMarkdown')}
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
@@ -498,14 +499,7 @@ export function NoteEditorToolbar({ mode, onClose, onToggleAttachments, attachme
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/* Hidden file input for Markdown import */}
|
{/* Hidden file input for Markdown import — remplacé par création dynamique dans openMarkdownImport */}
|
||||||
<input
|
|
||||||
ref={mdImportInputRef}
|
|
||||||
type="file"
|
|
||||||
accept=".md,text/markdown"
|
|
||||||
className="hidden"
|
|
||||||
onChange={handleImportMarkdownFile}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user