Files
Momento/memento-note/lib/editor/parse-block-reference.ts
Antigravity f46654f574 feat: editor improvements and architectural grid prototype
Multiple feature additions and improvements across the application:

- NextGen Editor: drag handles, smart paste, block actions
- Structured views: Kanban and table layouts for notes
- Architectural Grid: new brainstorming/agent interface prototype
- Flashcards: SM-2 revision algorithm with AI generation
- MCP server: robustness improvements
- Graph/PDF chat: fix click propagation and copy behavior
- Various UI/UX enhancements and bug fixes

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 19:45:15 +00:00

68 lines
1.9 KiB
TypeScript

export type ParsedBlockReference = {
sourceNoteId: string
blockId: string
raw: string
}
export type StoredBlockReference = ParsedBlockReference & {
blockContent?: string
sourceNoteTitle?: string
}
export const LAST_BLOCK_REF_SESSION_KEY = 'memento:lastBlockRef'
/** Référence bloc copiée via « Copier la référence » : /home?openNote=…#block-… */
export function parseBlockReferenceFromText(text: string): ParsedBlockReference | null {
const trimmed = text.trim()
if (!trimmed || trimmed.includes('\n')) return null
const match = trimmed.match(/openNote=([^&#\s]+)(?:[^#]*?)#block-([a-zA-Z0-9_-]+)/i)
if (!match) return null
try {
return {
sourceNoteId: decodeURIComponent(match[1]),
blockId: match[2],
raw: trimmed,
}
} catch {
return null
}
}
export function rememberBlockReference(
raw: string,
extras?: { blockContent?: string; sourceNoteTitle?: string },
) {
if (typeof sessionStorage === 'undefined') return
const parsed = parseBlockReferenceFromText(raw)
if (!parsed) return
const payload: StoredBlockReference = {
...parsed,
...(extras?.blockContent ? { blockContent: extras.blockContent } : {}),
...(extras?.sourceNoteTitle ? { sourceNoteTitle: extras.sourceNoteTitle } : {}),
}
try {
sessionStorage.setItem(LAST_BLOCK_REF_SESSION_KEY, JSON.stringify(payload))
} catch {
// quota / private mode
}
}
export function recallLastBlockReference(): StoredBlockReference | null {
if (typeof sessionStorage === 'undefined') return null
try {
const stored = sessionStorage.getItem(LAST_BLOCK_REF_SESSION_KEY)
if (!stored) return null
if (stored.startsWith('{')) {
const payload = JSON.parse(stored) as StoredBlockReference
if (payload?.sourceNoteId && payload?.blockId && payload?.raw) return payload
return null
}
const parsed = parseBlockReferenceFromText(stored)
return parsed ?? null
} catch {
return null
}
}