import { observer } from "mobx-react"; import { DocumentIcon, EmailIcon, CollectionIcon } from "outline-icons"; import { Node } from "prosemirror-model"; import * as React from "react"; import { Link } from "react-router-dom"; import Icon from "../../components/Icon"; import useStores from "../../hooks/useStores"; import { cn } from "../styles/utils"; import { ComponentProps } from "../types"; const getAttributesFromNode = (node: Node) => { const spec = node.type.spec.toDOM?.(node) as any as Record[]; const { class: className, ...attrs } = spec[1]; return { className, ...attrs }; }; export const MentionUser = observer(function MentionUser_( props: ComponentProps ) { const { isSelected, node } = props; const { users } = useStores(); const user = users.get(node.attrs.modelId); const { className, ...attrs } = getAttributesFromNode(node); return ( {user?.name || node.attrs.label} ); }); export const MentionDocument = observer(function MentionDocument_( props: ComponentProps ) { const { isSelected, node } = props; const { documents } = useStores(); const doc = documents.get(node.attrs.modelId); const modelId = node.attrs.modelId; const { className, ...attrs } = getAttributesFromNode(node); React.useEffect(() => { if (modelId) { void documents.prefetchDocument(modelId); } }, [modelId, documents]); return ( {doc?.icon ? ( ) : ( )} {doc?.title || node.attrs.label} ); }); export const MentionCollection = observer(function MentionCollection_( props: ComponentProps ) { const { isSelected, node } = props; const { collections } = useStores(); const collection = collections.get(node.attrs.modelId); const modelId = node.attrs.modelId; const { className, ...attrs } = getAttributesFromNode(node); React.useEffect(() => { if (modelId) { void collections.fetch(modelId); } }, [modelId, collections]); return ( {collection?.icon ? ( ) : ( )} {collection?.title || node.attrs.label} ); });