Block Discussion
plate/block-discussionFreeComponent
A popover interface for managing discussions: comments, replies, suggestions.
Live preview
live · rendered by the registry
Rendered by plate on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://platejs.org/r/block-discussion.jsonSource
1'use client';23import * as React from 'react';45import type { PlateElementProps, RenderNodeWrapper } from 'platejs/react';67import { getDraftCommentKey } from '@platejs/comment';8import { CommentPlugin } from '@platejs/comment/react';9import { getTransientSuggestionKey } from '@platejs/suggestion';10import { SuggestionPlugin } from '@platejs/suggestion/react';11import {12 MessageSquareTextIcon,13 MessagesSquareIcon,14 PencilLineIcon,15} from 'lucide-react';16import { type AnyPluginConfig, type NodeEntry, PathApi } from 'platejs';17import { useEditorRef, usePluginOption } from 'platejs/react';1819import { Button } from '@/components/ui/button';20import {21 Popover,22 PopoverAnchor,23 PopoverContent,24 PopoverTrigger,25} from '@/components/ui/popover';26import { commentPlugin } from '@/registry/components/editor/plugins/comment-kit';27import type { TDiscussion } from '@/registry/components/editor/plugins/discussion-kit';28import { useBlockDiscussionItems } from '@/registry/lib/block-discussion-index';29import { suggestionPlugin } from '@/registry/components/editor/plugins/suggestion-kit';3031import { BlockSuggestionCard, isResolvedSuggestion } from './block-suggestion';32import { Comment, CommentCreateForm } from './comment';3334export const BlockDiscussion: RenderNodeWrapper<AnyPluginConfig> =35 (_props) => (props) => <BlockCommentContent {...props} />;3637const BlockCommentContent = ({ children, element }: PlateElementProps) => {38 const editor = useEditorRef();39 const commentsApi = editor.getApi(CommentPlugin).comment;40 const blockPath = editor.api.findPath(element) ?? [];41 const isTopLevelBlock = blockPath.length === 1;42 const draftCommentNode = isTopLevelBlock43 ? commentsApi.node({ at: blockPath, isDraft: true })44 : undefined;45 const commentNodes = isTopLevelBlock46 ? [...commentsApi.nodes({ at: blockPath })]47 : [];48 const suggestionNodes = isTopLevelBlock49 ? [50 ...editor.getApi(SuggestionPlugin).suggestion.nodes({ at: blockPath }),51 ].filter(([node]) => !node[getTransientSuggestionKey()])52 : [];53 const { resolvedDiscussions, resolvedSuggestions } =54 useBlockDiscussionItems(blockPath);5556 const suggestionsCount = resolvedSuggestions.length;57 const discussionsCount = resolvedDiscussions.length;58 const totalCount = suggestionsCount + discussionsCount;5960 const activeSuggestionId = usePluginOption(suggestionPlugin, 'activeId');61 const activeSuggestion =62 activeSuggestionId &&63// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from plate
All 324 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-kitai-kit | plate | Components | Free | 1 dep | |
| AI Menuai-menu | plate | Components | Free | 5 deps · 2 files | |
| AI Leafai-node | plate | Components | Free | no deps | |
| AI Toolbar Buttonai-toolbar-button | plate | Components | Free | 1 dep | |
| align-base-kitalign-base-kit | plate | Components | Free | 1 dep | |
| align-kitalign-kit | plate | Components | Free | 1 dep | |
| Align Toolbar Buttonalign-toolbar-button | plate | Components | Free | 1 dep | |
| autoformat-classic-kitautoformat-classic-kit | plate | Components | Free | 2 deps |
