blockcn

Mention source

Load @ mentions from your directory.

fetchMentions receives the text after @ and returns { id, label }. It may be async. Without it, a dev build warns once and the list stays empty. Each person gets a stable color from their id, in the document and in the suggestion list.

This page's code block is examples/recipes/mentions.ts. pnpm --dir docs typecheck compiles that file and fails if this block drifts.

import { createBlockcnEditor } from "@/components/editor/preset";
import { mentions } from "@/components/editor/addons/mentionsAddon";

export const kit = createBlockcnEditor({
  addons: [
    mentions({
      fetchMentions: async (query) => {
        const response = await fetch(`/api/people?q=${encodeURIComponent(query)}`);
        const people = (await response.json()) as { id: string; label: string }[];
        return people;
      },
    }),
  ],
});