feat: RTL/i18n, AI translate+undo, no-refresh saves, settings perf
- RTL: force dir=rtl on LabelFilter, NotesViewToggle, LabelManagementDialog - i18n: add missing keys (notifications, privacy, edit/preview, AI translate/undo) - Settings pages: convert to Server Components (general, appearance) + loading skeleton - AI menu: add Translate option (10 languages) + Undo AI button in toolbar - Fix: saveInline uses REST API instead of Server Action → eliminates all implicit refreshes in list mode - Fix: NotesTabsView notes sync effect preserves selected note on content changes - Fix: auto-tag suggestions now filter already-assigned labels - Fix: color change in card view uses local state (no refresh) - Fix: nav links use <Link> for prefetching (Settings, Admin) - Fix: suppress duplicate label suggestions already on note - Route: add /api/ai/translate endpoint
This commit is contained in:
@@ -15,24 +15,40 @@ export class OllamaProvider implements AIProvider {
|
||||
this.embeddingModelName = embeddingModelName || modelName;
|
||||
}
|
||||
|
||||
async generateTags(content: string): Promise<TagSuggestion[]> {
|
||||
async generateTags(content: string, language: string = "en"): Promise<TagSuggestion[]> {
|
||||
try {
|
||||
const promptText = language === 'fa'
|
||||
? `متن زیر را تحلیل کن و مفاهیم کلیدی را به عنوان برچسب استخراج کن (حداکثر ۱-۳ کلمه).
|
||||
قوانین:
|
||||
- کلمات ربط را حذف کن.
|
||||
- عبارات ترکیبی را حفظ کن.
|
||||
- حداکثر ۵ برچسب.
|
||||
پاسخ فقط به صورت لیست JSON با فرمت [{"tag": "string", "confidence": number}]
|
||||
متن: "${content}"`
|
||||
: language === 'fr'
|
||||
? `Analyse la note suivante et extrais les concepts clés sous forme de tags courts (1-3 mots max).
|
||||
Règles:
|
||||
- Pas de mots de liaison.
|
||||
- Garde les expressions composées ensemble.
|
||||
- Normalise en minuscules sauf noms propres.
|
||||
- Maximum 5 tags.
|
||||
Réponds UNIQUEMENT sous forme de liste JSON d'objets : [{"tag": "string", "confidence": number}].
|
||||
Contenu de la note: "${content}"`
|
||||
: `Analyze the following note and extract key concepts as short tags (1-3 words max).
|
||||
Rules:
|
||||
- No stop words.
|
||||
- Keep compound expressions together.
|
||||
- Lowercase unless proper noun.
|
||||
- Max 5 tags.
|
||||
Respond ONLY as a JSON list of objects: [{"tag": "string", "confidence": number}].
|
||||
Note content: "${content}"`;
|
||||
|
||||
const response = await fetch(`${this.baseUrl}/generate`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
model: this.modelName,
|
||||
prompt: `Analyse la note suivante et extrais les concepts clés sous forme de tags courts (1-3 mots max).
|
||||
|
||||
Règles:
|
||||
- Pas de mots de liaison (le, la, pour, et...).
|
||||
- Garde les expressions composées ensemble (ex: "semaine prochaine", "New York").
|
||||
- Normalise en minuscules sauf noms propres.
|
||||
- Maximum 5 tags.
|
||||
|
||||
Réponds UNIQUEMENT sous forme de liste JSON d'objets : [{"tag": "string", "confidence": number}].
|
||||
|
||||
Contenu de la note: "${content}"`,
|
||||
prompt: promptText,
|
||||
stream: false,
|
||||
}),
|
||||
});
|
||||
@@ -88,9 +104,7 @@ export class OllamaProvider implements AIProvider {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
model: this.modelName,
|
||||
prompt: `${prompt}
|
||||
|
||||
Réponds UNIQUEMENT sous forme de tableau JSON : [{"title": "string", "confidence": number}]`,
|
||||
prompt: `${prompt}\n\nRéponds UNIQUEMENT sous forme de tableau JSON : [{"title": "string", "confidence": number}]`,
|
||||
stream: false,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -12,7 +12,7 @@ export interface AIProvider {
|
||||
/**
|
||||
* Analyse le contenu et suggère des tags pertinents.
|
||||
*/
|
||||
generateTags(content: string): Promise<TagSuggestion[]>;
|
||||
generateTags(content: string, language?: string): Promise<TagSuggestion[]>;
|
||||
|
||||
/**
|
||||
* Génère un vecteur d'embeddings pour la recherche sémantique.
|
||||
|
||||
@@ -41,6 +41,8 @@ export interface Translations {
|
||||
editLabels: string
|
||||
archive: string
|
||||
trash: string
|
||||
newNoteTabs: string
|
||||
newNoteTabsHint: string
|
||||
}
|
||||
notes: {
|
||||
title: string
|
||||
@@ -103,6 +105,7 @@ export interface Translations {
|
||||
noNotes: string
|
||||
noNotesFound: string
|
||||
createFirstNote: string
|
||||
emptyStateTabs: string
|
||||
size: string
|
||||
small: string
|
||||
medium: string
|
||||
@@ -126,6 +129,12 @@ export interface Translations {
|
||||
markdownOff: string
|
||||
undo: string
|
||||
redo: string
|
||||
viewCards: string
|
||||
viewTabs: string
|
||||
viewCardsTooltip: string
|
||||
viewTabsTooltip: string
|
||||
viewModeGroup: string
|
||||
reorderTabs: string
|
||||
}
|
||||
pagination: {
|
||||
previous: string
|
||||
@@ -782,6 +791,10 @@ export interface Translations {
|
||||
appearance: {
|
||||
title: string
|
||||
description: string
|
||||
notesViewDescription: string
|
||||
notesViewLabel: string
|
||||
notesViewTabs: string
|
||||
notesViewMasonry: string
|
||||
}
|
||||
generalSettings: {
|
||||
title: string
|
||||
|
||||
33
keep-notes/lib/note-preview.ts
Normal file
33
keep-notes/lib/note-preview.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Plain-text preview for list view (light markdown stripping).
|
||||
*/
|
||||
export function stripMarkdownPreview(raw: string, maxLen = 180): string {
|
||||
if (!raw?.trim()) return ''
|
||||
let t = raw
|
||||
.replace(/^#{1,6}\s+/gm, '')
|
||||
.replace(/```[\s\S]*?```/g, ' ')
|
||||
.replace(/\*\*([^*]+)\*\*/g, '$1')
|
||||
.replace(/\*([^*]+)\*/g, '$1')
|
||||
.replace(/`([^`]+)`/g, '$1')
|
||||
.replace(/\[(.+?)]\([^)]+\)/g, '$1')
|
||||
.replace(/^\s*[-*+]\s+/gm, '')
|
||||
.replace(/^\s*\d+\.\s+/gm, '')
|
||||
.replace(/\n+/g, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim()
|
||||
if (t.length > maxLen) {
|
||||
return `${t.slice(0, maxLen).trim()}…`
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
export function getNoteDisplayTitle(note: { title: string | null; content: string; type: string }, untitled: string): string {
|
||||
const title = note.title?.trim()
|
||||
if (title) return title
|
||||
if (note.type === 'checklist') {
|
||||
const line = note.content?.split('\n').find((l) => l.trim())
|
||||
if (line) return stripMarkdownPreview(line, 80) || untitled
|
||||
}
|
||||
const preview = stripMarkdownPreview(note.content || '', 100)
|
||||
return preview || untitled
|
||||
}
|
||||
Reference in New Issue
Block a user