UNPKG

@liveblocks/react-blocknote

Version:

An integration of BlockNote + React to enable collaboration, comments, live cursors, and more with Liveblocks.

74 lines (71 loc) 1.8 kB
import { createInlineContentSpecFromTipTapNode, BlockNoteSchema } from '@blocknote/core'; import { MentionNode, GroupMentionNode } from '@liveblocks/react-tiptap'; const mentionSpec = createInlineContentSpecFromTipTapNode( MentionNode, { id: { default: "" }, notificationId: { default: "" } }, { render(inlineContent) { const el = document.createElement("liveblocks-mention"); el.setAttribute("data-id", inlineContent.props.id); el.setAttribute( "data-notification-id", inlineContent.props.notificationId ); return { dom: el }; } } ); const groupMentionSpec = createInlineContentSpecFromTipTapNode( GroupMentionNode, { id: { default: "" }, userIds: { default: "" }, notificationId: { default: "" } }, { render(inlineContent) { const el = document.createElement("liveblocks-group-mention"); el.setAttribute("data-id", inlineContent.props.id); el.setAttribute("data-user-ids", inlineContent.props.userIds); el.setAttribute( "data-notification-id", inlineContent.props.notificationId ); return { dom: el }; } } ); const withLiveblocksSchema = (schema, liveblocksOptions = {}) => { const optionalSchema = schema || BlockNoteSchema.create(); if (!liveblocksOptions.mentions) { return optionalSchema; } return BlockNoteSchema.create({ blockSpecs: optionalSchema.blockSpecs, inlineContentSpecs: { ...optionalSchema.inlineContentSpecs, liveblocksMention: mentionSpec, liveblocksGroupMention: groupMentionSpec }, styleSpecs: optionalSchema.styleSpecs }); }; export { withLiveblocksSchema }; //# sourceMappingURL=schema.js.map