dorfteich/packages/shared/src/editor-schema/mentions.ts
Claude Fable 5 7471fc70f7 #150: @-Mentions — Inline-Node, instanzweite User-Suche, Autocomplete
Neuer Inline-Atom mention {userId, username}: Markdown-Regel @username
(E-Mail-sicher über Wortgrenzen), Serializer, HTML-Span dt-mention,
Plain-Text für die Suche, Extraktor extractMentionUserIds. Neue
Endpoints GET /users/search (auth, min. 2 Zeichen, Limit 10,
Rate-Limit) und GET /users/brief (Batch-Auflösung für live
Anzeigenamen; gelöschte Nutzer → toter Chip). Editor: MentionView mit
Live-displayName, MentionAutocomplete (Klon des Wikilink-Musters),
Chip-CSS. 5 Unit-Tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0155v2aT8AG1kZDQEZiCLBWC
2026-07-20 00:56:07 +02:00

19 lines
591 B
TypeScript

import { Node } from 'prosemirror-model';
/**
* The distinct user ids mentioned in a document (issue #150) — the input for
* the derived `page_mentions` rows and the mention notifications (#151).
* Mentions without a resolved user id (e.g. from a Markdown import) are
* purely visual and excluded.
*/
export function extractMentionUserIds(doc: Node): string[] {
const ids = new Set<string>();
doc.descendants((node) => {
if (node.type.name === 'mention') {
const userId = node.attrs.userId as string;
if (userId) ids.add(userId);
}
});
return [...ids];
}