diff --git a/memento-note/app/actions/notes.ts b/memento-note/app/actions/notes.ts index 32f4f4e..a221394 100644 --- a/memento-note/app/actions/notes.ts +++ b/memento-note/app/actions/notes.ts @@ -8,6 +8,7 @@ import { getAIProvider } from '@/lib/ai/factory' import { parseNote, getHashColor } from '@/lib/utils' import { upsertNoteEmbedding } from '@/lib/embeddings' import { embeddingService } from '@/lib/ai/services/embedding.service' +import { chunkIndexingService } from '@/lib/ai/services/chunk-indexing.service' import { syncNoteLinksForNote } from '@/lib/notes/sync-note-links' import { getSystemConfig, getConfigNumber, getConfigBoolean, SEARCH_DEFAULTS } from '@/lib/config' import { contextualAutoTagService } from '@/lib/ai/services/contextual-auto-tag.service' @@ -458,6 +459,12 @@ export async function createNote(data: { console.error('[BG] Embedding generation failed:', e) } + try { + await chunkIndexingService.indexNote(noteId, data.title, content) + } catch (e) { + console.error('[BG] Chunk indexing failed:', e) + } + // Background task 2: Auto-labeling (only if no user labels and has notebook) if (!hasUserLabels && notebookId) { try { @@ -596,6 +603,12 @@ export async function updateNote(id: string, data: { } catch (e) { console.error('[BG] Embedding regeneration failed:', e); } + + try { + await chunkIndexingService.indexNote(noteId, title, content); + } catch (e) { + console.error('[BG] Chunk indexing failed:', e); + } })(); } diff --git a/memento-note/app/api/clip/save/route.ts b/memento-note/app/api/clip/save/route.ts index 7cf496d..c1b1858 100644 --- a/memento-note/app/api/clip/save/route.ts +++ b/memento-note/app/api/clip/save/route.ts @@ -6,6 +6,7 @@ import { createNotification } from '@/app/actions/notifications' import { buildClipSourceFooter, clipFooterLocaleTag } from '@/lib/clip/extract-article' import { resolveClipLocale, wrapClipArticleHtml, applyRtlToHtmlBlocks } from '@/lib/clip/rtl-content' import { embeddingService } from '@/lib/ai/services/embedding.service' +import { chunkIndexingService } from '@/lib/ai/services/chunk-indexing.service' import { upsertNoteEmbedding } from '@/lib/embeddings' import DOMPurify from 'isomorphic-dompurify' @@ -92,6 +93,8 @@ export async function POST(request: NextRequest) { if (embedding?.length) { await upsertNoteEmbedding(note.id, embedding) } + + await chunkIndexingService.indexNote(note.id, title || domain, fullContent) } catch (error) { console.error('[clip/save] embedding generation failed:', error) } diff --git a/memento-note/components/block-action-menu.tsx b/memento-note/components/block-action-menu.tsx index 8856608..b0e2c0d 100644 --- a/memento-note/components/block-action-menu.tsx +++ b/memento-note/components/block-action-menu.tsx @@ -14,8 +14,10 @@ import { Heading1, Heading2, Heading3, List, ListOrdered, CheckSquare, Quote, CodeXml, Database, ArrowUp, ArrowDown, AlignLeft, ClipboardCopy, Sparkles, + ChevronsRightLeft, } from 'lucide-react' import { replaceBlockWithStructuredView } from '@/components/tiptap-structured-view-block-extension' +import { insertToggleBlock, turnIntoToggleBlock } from '@/components/tiptap-toggle-extension' interface BlockActionMenuProps { editor: Editor @@ -369,6 +371,14 @@ export function BlockActionMenu({
+ {/* Section repliable */} + + +
+ {/* Création de diagramme */} + + {opened ? t('richTextEditor.toggleOpened') : t('richTextEditor.toggleClosed')} + + + +
+ +
+ +
+ + ) +} + +export const ToggleExtension = Node.create({ + name: 'toggleBlock', + + group: 'block', + + content: 'block+', + + defining: true, + + addAttributes() { + return { + opened: { + default: true, + parseHTML: (element) => element.getAttribute('data-opened') !== 'false', + renderHTML: (attributes) => ({ + 'data-opened': attributes.opened, + }), + }, + } + }, + + parseHTML() { + return [ + { + tag: 'div[data-type="toggle-block"]', + }, + { + tag: 'details', + getAttrs: (element) => { + if (typeof element === 'string') return false + return { opened: !(element as HTMLElement).hasAttribute('closed') } + }, + }, + ] + }, + + renderHTML({ HTMLAttributes }) { + return [ + 'div', + mergeAttributes(HTMLAttributes, { + 'data-type': 'toggle-block', + class: 'toggle-block', + }), + 0, + ] + }, + + addNodeView() { + return ReactNodeViewRenderer(ToggleView) + }, + + addKeyboardShortcuts() { + return { + 'Mod-Shift-T': () => this.editor.commands.insertContent({ + type: this.name, + attrs: { opened: true }, + content: [{ type: 'paragraph' }], + }), + } + }, +}) + +export function insertToggleBlock(editor: any) { + editor.chain().focus().insertContent({ + type: 'toggleBlock', + attrs: { opened: true }, + content: [ + { type: 'paragraph' }, + ], + }).run() +} + +/** + * Transforme un bloc existant en section repliable. + * Le contenu du bloc original est déplacé dans le toggle. + */ +export function turnIntoToggleBlock(editor: any, blockPos: number, blockNode: any) { + if (!blockNode || blockPos < 0) return + + const nodeJson = blockNode.toJSON() + + editor.chain().focus().deleteRange({ + from: blockPos, + to: blockPos + blockNode.nodeSize, + }).insertContentAt(blockPos, { + type: 'toggleBlock', + attrs: { opened: true }, + content: [nodeJson], + }).setTextSelection(blockPos + 2).run() +} diff --git a/memento-note/locales/en.json b/memento-note/locales/en.json index 02e68c6..db974e9 100644 --- a/memento-note/locales/en.json +++ b/memento-note/locales/en.json @@ -2407,6 +2407,13 @@ "slashTableDesc": "Insert a simple grid", "slashDatabase": "Structured View", "slashDatabaseDesc": "Embed your notebook's structured data", + "slashToggle": "Toggle Section", + "slashToggleDesc": "Create a collapsible section", + "toggleOpened": "Expanded section — click to collapse", + "toggleClosed": "Collapsed section — click to expand", + "toggleDelete": "Delete section", + "toggleUnwrap": "Disable toggle section", + "blockActionInsertToggle": "Turn into toggle section", "slashDiagram": "Diagram", "slashDiagramDesc": "Generate a flow or mindmap", "slashSlides": "Presentation", diff --git a/memento-note/locales/fr.json b/memento-note/locales/fr.json index 0cf8074..940004f 100644 --- a/memento-note/locales/fr.json +++ b/memento-note/locales/fr.json @@ -2411,6 +2411,13 @@ "slashTableDesc": "Insérer un tableau simple", "slashDatabase": "Vue structurée", "slashDatabaseDesc": "Intégrer les données structurées de votre carnet", + "slashToggle": "Section repliable", + "slashToggleDesc": "Créer une section dépliable", + "toggleOpened": "Section dépliée — cliquer pour replier", + "toggleClosed": "Section repliée — cliquer pour déplier", + "toggleDelete": "Supprimer la section", + "toggleUnwrap": "Désactiver la section repliable", + "blockActionInsertToggle": "Transformer en section repliable", "slashDiagram": "Diagramme", "slashDiagramDesc": "Générer un flux ou une carte mentale", "slashSlides": "Présentation",