onSelect(items.find((i) => i.id === id))}>
{items.map((item, index) => (
@{item.user?.name || item.user?.email}
))}
);
};
// Function to insert a mention at the current selection
export const insertMention = (editor, member) => {
const mention = {
type: 'mention',
member,
children: [{ text: '' }],
};
Transforms.insertNodes(editor, mention);
Transforms.move(editor);
};
// Custom plugin to handle mentions in the editor
export const withMentions = editor => {
const { isInline, isVoid } = editor;
// Override isInline to treat mentions as inline elements
editor.isInline = element => {
return element.type === 'mention' ? true : isInline(element);
};
// Override isVoid to treat mentions as void elements
editor.isVoid = element => {
return element.type === 'mention' ? true : isVoid(element);
};
return editor;
};
/**
* export default mention
*/
export default Mention;