Files
DeepTutor/web/features/notes/model/concept-map.ts
Bingxi Zhao (Frank) 857a82e74a feat(notes): add block notebooks with inline reviews and linked favorites
Add rich text and learning blocks, media uploads, page trees, and revisioned notebook storage. Present AI suggestions at their target blocks with durable accept and dismiss actions.

Unify saved outputs as Favorites with typed expandable blocks, stable source links, atomic batch insertion, nesting, dragging, and undo/redo.

Validation: 99 frontend tests and 99 backend tests pass in an isolated snapshot, along with TypeScript, scoped ESLint, dependency architecture, and locale parity checks.
2026-10-17 23:15:23 +08:00

28 lines
1.2 KiB
TypeScript

/** Accept both notebook (source/target) and book (src/dst) graph payloads. */
export function noteConceptMap(payload: Record<string, unknown>): string {
const graph =
payload.graph && typeof payload.graph === 'object'
? (payload.graph as Record<string, unknown>)
: payload
const nodes = Array.isArray(graph.nodes) ? (graph.nodes as Record<string, unknown>[]) : []
const edges = Array.isArray(graph.edges) ? (graph.edges as Record<string, unknown>[]) : []
const label = (text: unknown) =>
String(text || '')
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/[\r\n]/g, ' ')
const ids = new Map(nodes.map((node, i) => [String(node.id), `n${i}`]))
const lines = [
'flowchart TD',
...nodes.map((node, i) => ` n${i}["${label(node.label || node.title || node.id)}"]`),
]
for (const edge of edges) {
const from = ids.get(String(edge.source || edge.src || edge.from))
const to = ids.get(String(edge.target || edge.dst || edge.to))
if (from && to) lines.push(` ${from} -->${edge.label ? `|"${label(edge.label)}"|` : ''} ${to}`)
}
return nodes.length ? '```mermaid\n' + lines.join('\n') + '\n```' : ''
}