feat: mobile app complet + flashcards fixes + drag handle améliorations
Some checks failed
CI / Lint, Unit Tests & Build (push) Failing after 1m32s
CI / Deploy production (on server) (push) Has been skipped

Mobile app:
- Révision flashcards : liste decks, session flip-card SM-2, couleurs harmonisées web
- Génération flashcards depuis note (FlashcardSheet + route /api/mobile/flashcards/generate)
- Audio Whisper : hook useAudioRecorder reécrit, MicButton avec erreurs
- IA : AISheet (améliorer/clarifier/résumer), TitleSheet (titre automatique)
- Suppression note (soft delete + confirmation Alert)
- Note du jour : titre lisible + HTML (plus JSON TipTap brut)
- Parser TipTap→HTML côté mobile (tipTapToHtml)
- Icône 🎓 dans header note → génération flashcards
- Endpoint flashcardGenerate dans config.ts

Web fixes:
- Bug flashcards groupées par carnet → deck par note (migration + schema)
- Bug filtre 'cartes dues' ignoré (suppression fallback buildSessionQueue)
- Suppression UI création deck manuelle (inutile)
- Fix setViewType is not defined dans home-client.tsx

Drag handle menu:
- Fix : clearNodes() avant transformation (heading→liste/code/citation)
- Ajout : option 'Texte' (paragraphe) dans Transformer en
- Ajout : Monter / Descendre le bloc
- Ajout : Copier le contenu du bloc
- Fix : sous-menu hover stable (délai 200ms)
- Fix : Supprimer en rouge via classe --danger (plus :first-child)
- i18n : nouvelles clés dans 15 locales

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Antigravity
2026-05-29 18:49:40 +00:00
parent 1121b8c345
commit 0fa8978395
54 changed files with 2648 additions and 245 deletions

View File

@@ -13,6 +13,7 @@ import {
Trash2, Copy, Repeat, Link, ChevronRight,
Heading1, Heading2, Heading3, List, ListOrdered,
CheckSquare, Quote, CodeXml, Database,
ArrowUp, ArrowDown, AlignLeft, ClipboardCopy,
} from 'lucide-react'
import { replaceBlockWithStructuredView } from '@/components/tiptap-structured-view-block-extension'
@@ -28,6 +29,7 @@ interface BlockActionMenuProps {
}
type TurnIntoType =
| 'paragraph'
| 'heading1' | 'heading2' | 'heading3'
| 'bulletList' | 'orderedList' | 'taskList'
| 'blockquote' | 'codeBlock' | 'database'
@@ -39,24 +41,39 @@ interface TurnIntoOption {
isDatabase?: boolean
}
const TURN_INTO_OPTIONS: TurnIntoOption[] = [
{ id: 'heading1', icon: Heading1, command: (e) => e.chain().focus().toggleHeading({ level: 1 }).run() },
{ id: 'heading2', icon: Heading2, command: (e) => e.chain().focus().toggleHeading({ level: 2 }).run() },
{ id: 'heading3', icon: Heading3, command: (e) => e.chain().focus().toggleHeading({ level: 3 }).run() },
{ id: 'bulletList', icon: List, command: (e) => e.chain().focus().toggleBulletList().run() },
{ id: 'orderedList', icon: ListOrdered, command: (e) => e.chain().focus().toggleOrderedList().run() },
{ id: 'taskList', icon: CheckSquare, command: (e) => e.chain().focus().toggleTaskList().run() },
{ id: 'blockquote', icon: Quote, command: (e) => e.chain().focus().toggleBlockquote().run() },
{ id: 'codeBlock', icon: CodeXml, command: (e) => e.chain().focus().toggleCodeBlock().run() },
{ id: 'database', icon: Database, isDatabase: true },
]
/** Positionne le curseur dans le bloc avant d'appliquer une transformation */
function focusBlock(editor: Editor, blockPos: number) {
const docSize = editor.state.doc.content.size
const cursorPos = Math.min(blockPos + 1, docSize)
editor.chain().focus().setTextSelection(cursorPos).run()
}
/**
* Applique une transformation en passant d'abord par paragraphe.
* Ceci corrige le cas heading → liste / blockquote / codeBlock qui échoue
* avec un toggle direct.
*/
function makeTurnCommand(cmd: (e: Editor) => void): (e: Editor) => void {
return (editor: Editor) => {
// clearNodes remet en paragraphe sans perte de texte
editor.chain().focus().clearNodes().run()
cmd(editor)
}
}
const TURN_INTO_OPTIONS: TurnIntoOption[] = [
{ id: 'paragraph', icon: AlignLeft, command: (e) => e.chain().focus().clearNodes().run() },
{ id: 'heading1', icon: Heading1, command: (e) => e.chain().focus().clearNodes().toggleHeading({ level: 1 }).run() },
{ id: 'heading2', icon: Heading2, command: (e) => e.chain().focus().clearNodes().toggleHeading({ level: 2 }).run() },
{ id: 'heading3', icon: Heading3, command: (e) => e.chain().focus().clearNodes().toggleHeading({ level: 3 }).run() },
{ id: 'bulletList', icon: List, command: makeTurnCommand((e) => e.chain().focus().toggleBulletList().run()) },
{ id: 'orderedList', icon: ListOrdered, command: makeTurnCommand((e) => e.chain().focus().toggleOrderedList().run()) },
{ id: 'taskList', icon: CheckSquare, command: makeTurnCommand((e) => e.chain().focus().toggleTaskList().run()) },
{ id: 'blockquote', icon: Quote, command: makeTurnCommand((e) => e.chain().focus().toggleBlockquote().run()) },
{ id: 'codeBlock', icon: CodeXml, command: makeTurnCommand((e) => e.chain().focus().toggleCodeBlock().run()) },
{ id: 'database', icon: Database, isDatabase: true },
]
function getBlockPlainContent(editor: Editor, blockPos: number, blockNode: PMNode | null): string {
const node = blockNode ?? (blockPos >= 0 ? editor.state.doc.nodeAt(blockPos) : null)
if (!node || blockPos < 0) return ''
@@ -68,6 +85,47 @@ function getBlockPlainContent(editor: Editor, blockPos: number, blockNode: PMNod
return node.textContent?.trim() ?? ''
}
/** Déplace un bloc vers le haut (échange avec le frère précédent) */
function moveBlockUp(editor: Editor, blockPos: number, blockNode: PMNode): boolean {
const { doc } = editor.state
let prevPos = -1
let prevNode: PMNode | null = null
doc.forEach((node, offset) => {
if (offset + node.nodeSize === blockPos) {
prevPos = offset
prevNode = node
}
})
if (prevPos < 0 || !prevNode) return false
const safePrev = prevNode as PMNode
const tr = editor.state.tr
const from = prevPos
const to = blockPos + blockNode.nodeSize
tr.replaceWith(from, to, [blockNode.copy(blockNode.content), safePrev.copy(safePrev.content)])
editor.view.dispatch(tr)
// Repositionne le curseur dans le bloc déplacé (maintenant à prevPos)
const docSize = editor.state.doc.content.size
editor.chain().focus().setTextSelection(Math.min(prevPos + 1, docSize)).run()
return true
}
/** Déplace un bloc vers le bas (échange avec le frère suivant) */
function moveBlockDown(editor: Editor, blockPos: number, blockNode: PMNode): boolean {
const { doc } = editor.state
const nextPos = blockPos + blockNode.nodeSize
const nextNode = doc.nodeAt(nextPos)
if (!nextNode) return false
const tr = editor.state.tr
const from = blockPos
const to = nextPos + nextNode.nodeSize
tr.replaceWith(from, to, [nextNode.copy(nextNode.content), blockNode.copy(blockNode.content)])
editor.view.dispatch(tr)
const newPos = blockPos + nextNode.nodeSize
const docSize = editor.state.doc.content.size
editor.chain().focus().setTextSelection(Math.min(newPos + 1, docSize)).run()
return true
}
export function BlockActionMenu({
editor,
onClose,
@@ -81,6 +139,7 @@ export function BlockActionMenu({
const { t } = useLanguage()
const menuRef = useRef<HTMLDivElement>(null)
const [showTurnInto, setShowTurnInto] = useState(false)
const hoverTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const handleDelete = useCallback(() => {
if (blockNode && blockPos >= 0) {
@@ -92,32 +151,52 @@ export function BlockActionMenu({
const handleDuplicate = useCallback(() => {
if (blockNode && blockPos >= 0) {
const insertPos = blockPos + blockNode.nodeSize
editor.view.dispatch(
editor.state.tr.insert(insertPos, blockNode.copy())
)
editor.view.dispatch(editor.state.tr.insert(insertPos, blockNode.copy()))
editor.commands.focus()
}
onClose()
}, [editor, blockNode, blockPos, onClose])
const handleMoveUp = useCallback(() => {
if (blockNode && blockPos >= 0) {
const ok = moveBlockUp(editor, blockPos, blockNode)
if (!ok) toast(t('blockAction.moveUpFirst'))
}
onClose()
}, [editor, blockNode, blockPos, onClose, t])
const handleMoveDown = useCallback(() => {
if (blockNode && blockPos >= 0) {
const ok = moveBlockDown(editor, blockPos, blockNode)
if (!ok) toast(t('blockAction.moveDownLast'))
}
onClose()
}, [editor, blockNode, blockPos, onClose, t])
const handleCopyContent = useCallback(async () => {
const text = getBlockPlainContent(editor, blockPos, blockNode)
if (!text) { toast(t('blockAction.emptyBlock')); onClose(); return }
const ok = await copyTextToClipboard(text)
if (ok) toast.success(t('blockAction.contentCopied'))
else toast.error(t('blockAction.copyRefFailed'))
onClose()
}, [editor, blockPos, blockNode, onClose, t])
const handleCopyRef = useCallback(async () => {
if (!noteId?.trim()) {
toast.error(t('blockAction.copyRefNoNote'))
onClose()
return
}
const blockId = ensureBlockReferenceId(editor, blockPos, blockNode)
if (!blockId) {
toast.error(t('blockAction.copyRefUnsupported'))
onClose()
return
}
const html = editor.getHTML()
const blockContent = getBlockPlainContent(editor, blockPos, blockNode)
onBlockReferenceCopied?.(html)
const ref = `${window.location.origin}/home?openNote=${encodeURIComponent(noteId)}#block-${encodeURIComponent(blockId)}`
const copied = await copyTextToClipboard(ref)
if (copied) {
@@ -143,6 +222,19 @@ export function BlockActionMenu({
onClose()
}, [editor, blockNode, blockPos, onClose])
const handleTurnIntoEnter = useCallback(() => {
if (hoverTimerRef.current) clearTimeout(hoverTimerRef.current)
setShowTurnInto(true)
}, [])
const handleTurnIntoLeave = useCallback(() => {
hoverTimerRef.current = setTimeout(() => setShowTurnInto(false), 200)
}, [])
const handleSubmenuEnter = useCallback(() => {
if (hoverTimerRef.current) clearTimeout(hoverTimerRef.current)
}, [])
useEffect(() => {
function handleClickOutside(e: MouseEvent) {
if (menuRef.current && !menuRef.current.contains(e.target as Node)) {
@@ -157,68 +249,89 @@ export function BlockActionMenu({
return () => {
document.removeEventListener('mousedown', handleClickOutside)
document.removeEventListener('keydown', handleKeyDown)
if (hoverTimerRef.current) clearTimeout(hoverTimerRef.current)
}
}, [onClose])
const menuLeft = anchorRect.right + 6
const menuTop = anchorRect.top - 4
const menuStyle: React.CSSProperties = {
position: 'fixed',
left: anchorRect.right + 6,
top: anchorRect.top - 4,
left: menuLeft > window.innerWidth - 230 ? anchorRect.left - 215 : menuLeft,
top: menuTop + 320 > window.innerHeight ? window.innerHeight - 330 : menuTop,
zIndex: 9999,
}
if (Number(menuStyle.left) > window.innerWidth - 220) {
menuStyle.left = anchorRect.left - 210
}
if (Number(menuStyle.top) + 300 > window.innerHeight) {
menuStyle.top = window.innerHeight - 310
}
return createPortal(
<div ref={menuRef} style={menuStyle} className="block-action-menu">
<button type="button" className="block-action-item" onClick={handleDelete}>
<Trash2 size={16} />
<span>{t('blockAction.delete')}</span>
{/* Actions de déplacement */}
<button type="button" className="block-action-item" onClick={handleMoveUp}>
<ArrowUp size={16} />
<span>{t('blockAction.moveUp')}</span>
</button>
<button type="button" className="block-action-item" onClick={handleMoveDown}>
<ArrowDown size={16} />
<span>{t('blockAction.moveDown')}</span>
</button>
<div className="block-action-separator" />
{/* Transformer en */}
<div
className="block-action-submenu-wrap"
onMouseLeave={handleTurnIntoLeave}
>
<button
type="button"
className="block-action-item block-action-submenu-trigger"
onClick={() => setShowTurnInto((v) => !v)}
onMouseEnter={handleTurnIntoEnter}
>
<Repeat size={16} />
<span>{t('blockAction.turnInto')}</span>
<ChevronRight size={14} className="ml-auto" />
</button>
{showTurnInto && (
<div className="block-action-submenu" onMouseEnter={handleSubmenuEnter}>
{TURN_INTO_OPTIONS.map((opt) => (
<button
key={opt.id}
type="button"
className="block-action-item"
onClick={() => handleTurnInto(opt)}
>
<opt.icon size={16} />
<span>{t(`blockAction.turnInto_${opt.id}`)}</span>
</button>
))}
</div>
)}
</div>
<div className="block-action-separator" />
{/* Copier */}
<button type="button" className="block-action-item" onClick={() => { void handleCopyContent() }}>
<ClipboardCopy size={16} />
<span>{t('blockAction.copyContent')}</span>
</button>
<button type="button" className="block-action-item" onClick={() => { void handleCopyRef() }}>
<Link size={16} />
<span>{t('blockAction.copyRef')}</span>
</button>
<div className="block-action-separator" />
{/* Actions destructives */}
<button type="button" className="block-action-item" onClick={handleDuplicate}>
<Copy size={16} />
<span>{t('blockAction.duplicate')}</span>
</button>
<div className="block-action-separator" />
<button
type="button"
className="block-action-item block-action-submenu-trigger"
onClick={() => setShowTurnInto(!showTurnInto)}
onMouseEnter={() => setShowTurnInto(true)}
>
<Repeat size={16} />
<span>{t('blockAction.turnInto')}</span>
<ChevronRight size={14} className="ml-auto" />
</button>
{showTurnInto && (
<div className="block-action-submenu">
{TURN_INTO_OPTIONS.map((opt) => (
<button
key={opt.id}
type="button"
className="block-action-item"
onClick={() => handleTurnInto(opt)}
>
<opt.icon size={16} />
<span>{t(`blockAction.turnInto_${opt.id}`)}</span>
</button>
))}
</div>
)}
<div className="block-action-separator" />
<button type="button" className="block-action-item" onClick={() => { void handleCopyRef() }}>
<Link size={16} />
<span>{t('blockAction.copyRef')}</span>
<button type="button" className="block-action-item block-action-item--danger" onClick={handleDelete}>
<Trash2 size={16} />
<span>{t('blockAction.delete')}</span>
</button>
</div>,
document.body

View File

@@ -9,7 +9,6 @@ import {
ChevronLeft,
ChevronRight,
Calendar,
Plus,
BarChart3,
Loader2,
BookOpen,
@@ -78,8 +77,7 @@ function shuffleCards<T>(items: T[]): T[] {
}
function buildSessionQueue(cards: FlashcardItem[], dueOnly: boolean): FlashcardItem[] {
let toReview = dueOnly ? cards.filter((c) => c.due) : cards
if (toReview.length === 0) toReview = cards
const toReview = dueOnly ? cards.filter((c) => c.due) : cards
return shuffleCards(toReview)
}
@@ -316,8 +314,6 @@ export function RevisionView() {
const [sessionDurationSeconds, setSessionDurationSeconds] = useState(0)
const sessionTimerRef = useRef<ReturnType<typeof setInterval> | null>(null)
const [newDeckName, setNewDeckName] = useState('')
const [creatingDeck, setCreatingDeck] = useState(false)
// Gap 8 — deck deletion state
const [deletingDeckId, setDeletingDeckId] = useState<string | null>(null)
@@ -402,6 +398,17 @@ export function RevisionView() {
return
}
const shuffled = buildSessionQueue(cardsInput, mode === 'due')
// Mode "due" mais aucune carte n'est due → afficher état "à jour" directement
if (shuffled.length === 0) {
setSessionCards([])
setCurrentIndex(0)
setIsFlipped(false)
setSessionGrades({})
setIsSessionActive(true)
setIsSessionFinished(true)
setActiveDeckId(deckId)
return
}
setSessionCards(shuffled)
setCurrentIndex(0)
setIsFlipped(false)
@@ -561,27 +568,6 @@ export function RevisionView() {
}
}
const createDeck = async () => {
const name = newDeckName.trim()
if (!name) return
setCreatingDeck(true)
try {
const res = await fetch('/api/flashcards/decks', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name }),
})
const data = await res.json()
if (res.ok) {
setNewDeckName('')
await loadDecks()
toast.success(t('flashcards.deckCreated'))
if (data.deck?.id) setActiveDeckId(data.deck.id)
}
} finally {
setCreatingDeck(false)
}
}
// Gap 8 — delete a deck
const handleDeleteDeck = async (deckId: string) => {
@@ -910,24 +896,6 @@ export function RevisionView() {
</div>
)}
<div className="flex flex-wrap gap-2 items-center">
<input
value={newDeckName}
onChange={(e) => setNewDeckName(e.target.value)}
onKeyDown={(e) => { if (e.key === 'Enter') void createDeck() }}
placeholder={t('flashcards.newDeckPlaceholder')}
className="flex-1 min-w-[180px] px-3 py-2 rounded-lg border border-border text-sm bg-transparent"
/>
<button
type="button"
onClick={createDeck}
disabled={creatingDeck || !newDeckName.trim()}
className="px-3 py-2 rounded-lg border border-border text-xs font-bold flex items-center gap-1 disabled:opacity-50"
>
{creatingDeck ? <Loader2 size={14} className="animate-spin" /> : <Plus size={14} />}
{t('flashcards.createDeck')}
</button>
</div>
{loadingDecks ? (
<div className="flex justify-center py-16"><Loader2 className="animate-spin text-concrete" /></div>

View File

@@ -173,7 +173,6 @@ export function HomeClient({
const detail = (e as CustomEvent<{ layout?: NotesLayoutMode }>).detail?.layout
if (detail === 'grid' || detail === 'list' || detail === 'table' || detail === 'kanban') {
setLayoutMode(detail)
setViewType('notes')
}
}
window.addEventListener('memento-notes-layout-change', onLayoutChange)
@@ -411,7 +410,6 @@ export function HomeClient({
const selectLayoutMode = useCallback((mode: NotesLayoutMode) => {
if (mode === 'gallery') return
setLayoutMode(mode)
setViewType('notes')
}, [])
const showStructuredIntro =