@liveblocks/react-ui 2.8.0 → 2.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,6 +52,7 @@ const Thread = React.forwardRef(
52
52
  onAuthorClick,
53
53
  onMentionClick,
54
54
  onAttachmentClick,
55
+ onComposerSubmit,
55
56
  overrides: overrides$1,
56
57
  className,
57
58
  ...props
@@ -190,6 +191,7 @@ const Thread = React.forwardRef(
190
191
  threadId: thread.id,
191
192
  defaultCollapsed: showComposer === "collapsed" ? true : void 0,
192
193
  showAttachments,
194
+ onComposerSubmit,
193
195
  overrides: {
194
196
  COMPOSER_PLACEHOLDER: $.THREAD_COMPOSER_PLACEHOLDER,
195
197
  COMPOSER_SEND: $.THREAD_COMPOSER_SEND
@@ -1 +1 @@
1
- {"version":3,"file":"Thread.js","sources":["../../src/components/Thread.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n BaseMetadata,\n CommentData,\n DM,\n ThreadData,\n} from \"@liveblocks/core\";\nimport {\n useMarkThreadAsResolved,\n useMarkThreadAsUnresolved,\n useThreadSubscription,\n} from \"@liveblocks/react\";\nimport * as TogglePrimitive from \"@radix-ui/react-toggle\";\nimport type {\n ComponentPropsWithoutRef,\n ForwardedRef,\n RefAttributes,\n SyntheticEvent,\n} from \"react\";\nimport React, {\n forwardRef,\n Fragment,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\n\nimport { ArrowDownIcon } from \"../icons/ArrowDown\";\nimport { ResolveIcon } from \"../icons/Resolve\";\nimport { ResolvedIcon } from \"../icons/Resolved\";\nimport type {\n CommentOverrides,\n ComposerOverrides,\n GlobalOverrides,\n ThreadOverrides,\n} from \"../overrides\";\nimport { useOverrides } from \"../overrides\";\nimport { classNames } from \"../utils/class-names\";\nimport { findLastIndex } from \"../utils/find-last-index\";\nimport type { CommentProps } from \"./Comment\";\nimport { Comment } from \"./Comment\";\nimport { Composer } from \"./Composer\";\nimport { Button } from \"./internal/Button\";\nimport { Tooltip, TooltipProvider } from \"./internal/Tooltip\";\n\nexport interface ThreadProps<M extends BaseMetadata = DM>\n extends ComponentPropsWithoutRef<\"div\"> {\n /**\n * The thread to display.\n */\n thread: ThreadData<M>;\n\n /**\n * How to show or hide the composer to reply to the thread.\n */\n showComposer?: boolean | \"collapsed\";\n\n /**\n * Whether to show the action to resolve the thread.\n */\n showResolveAction?: boolean;\n\n /**\n * How to show or hide the actions.\n */\n showActions?: CommentProps[\"showActions\"];\n\n /**\n * Whether to show reactions.\n */\n showReactions?: CommentProps[\"showReactions\"];\n\n /**\n * Whether to indent the comments' content.\n */\n indentCommentContent?: CommentProps[\"indentContent\"];\n\n /**\n * Whether to show deleted comments.\n */\n showDeletedComments?: CommentProps[\"showDeleted\"];\n\n /**\n * Whether to show attachments.\n */\n showAttachments?: boolean;\n\n /**\n * The event handler called when changing the resolved status.\n */\n onResolvedChange?: (resolved: boolean) => void;\n\n /**\n * The event handler called when a comment is edited.\n */\n onCommentEdit?: CommentProps[\"onCommentEdit\"];\n\n /**\n * The event handler called when a comment is deleted.\n */\n onCommentDelete?: CommentProps[\"onCommentDelete\"];\n\n /**\n * The event handler called when the thread is deleted.\n * A thread is deleted when all its comments are deleted.\n */\n onThreadDelete?: (thread: ThreadData<M>) => void;\n\n /**\n * The event handler called when clicking on a comment's author.\n */\n onAuthorClick?: CommentProps[\"onAuthorClick\"];\n\n /**\n * The event handler called when clicking on a mention.\n */\n onMentionClick?: CommentProps[\"onMentionClick\"];\n\n /**\n * The event handler called when clicking on a comment's attachment.\n */\n onAttachmentClick?: CommentProps[\"onAttachmentClick\"];\n\n /**\n * Override the component's strings.\n */\n overrides?: Partial<\n GlobalOverrides & ThreadOverrides & CommentOverrides & ComposerOverrides\n >;\n}\n\n/**\n * Displays a thread of comments, with a composer to reply\n * to it.\n *\n * @example\n * <>\n * {threads.map((thread) => (\n * <Thread key={thread.id} thread={thread} />\n * ))}\n * </>\n */\nexport const Thread = forwardRef(\n <M extends BaseMetadata = DM>(\n {\n thread,\n indentCommentContent = true,\n showActions = \"hover\",\n showDeletedComments,\n showResolveAction = true,\n showReactions = true,\n showComposer = \"collapsed\",\n showAttachments = true,\n onResolvedChange,\n onCommentEdit,\n onCommentDelete,\n onThreadDelete,\n onAuthorClick,\n onMentionClick,\n onAttachmentClick,\n overrides,\n className,\n ...props\n }: ThreadProps<M>,\n forwardedRef: ForwardedRef<HTMLDivElement>\n ) => {\n const markThreadAsResolved = useMarkThreadAsResolved();\n const markThreadAsUnresolved = useMarkThreadAsUnresolved();\n const $ = useOverrides(overrides);\n const firstCommentIndex = useMemo(() => {\n return showDeletedComments\n ? 0\n : thread.comments.findIndex((comment) => comment.body);\n }, [showDeletedComments, thread.comments]);\n const lastCommentIndex = useMemo(() => {\n return showDeletedComments\n ? thread.comments.length - 1\n : findLastIndex(thread.comments, (comment) => comment.body);\n }, [showDeletedComments, thread.comments]);\n const { status: subscriptionStatus, unreadSince } = useThreadSubscription(\n thread.id\n );\n const unreadIndex = useMemo(() => {\n // The user is not subscribed to this thread.\n if (subscriptionStatus !== \"subscribed\") {\n return;\n }\n\n // The user hasn't read the thread yet, so all comments are unread.\n if (unreadSince === null) {\n return firstCommentIndex;\n }\n\n // The user has read the thread, so we find the first unread comment.\n const unreadIndex = thread.comments.findIndex(\n (comment) =>\n (showDeletedComments ? true : comment.body) &&\n comment.createdAt > unreadSince\n );\n\n return unreadIndex >= 0 && unreadIndex < thread.comments.length\n ? unreadIndex\n : undefined;\n }, [\n firstCommentIndex,\n showDeletedComments,\n subscriptionStatus,\n thread.comments,\n unreadSince,\n ]);\n const [newIndex, setNewIndex] = useState<number>();\n const newIndicatorIndex = newIndex === undefined ? unreadIndex : newIndex;\n\n useEffect(() => {\n if (unreadIndex) {\n // Keep the \"new\" indicator at the lowest unread index.\n setNewIndex((persistedUnreadIndex) =>\n Math.min(persistedUnreadIndex ?? Infinity, unreadIndex)\n );\n }\n }, [unreadIndex]);\n\n const stopPropagation = useCallback((event: SyntheticEvent) => {\n event.stopPropagation();\n }, []);\n\n const handleResolvedChange = useCallback(\n (resolved: boolean) => {\n onResolvedChange?.(resolved);\n\n if (resolved) {\n markThreadAsResolved(thread.id);\n } else {\n markThreadAsUnresolved(thread.id);\n }\n },\n [\n markThreadAsResolved,\n markThreadAsUnresolved,\n onResolvedChange,\n thread.id,\n ]\n );\n\n const handleCommentDelete = useCallback(\n (comment: CommentData) => {\n onCommentDelete?.(comment);\n\n const filteredComments = thread.comments.filter(\n (comment) => comment.body\n );\n\n if (filteredComments.length <= 1) {\n onThreadDelete?.(thread);\n }\n },\n [onCommentDelete, onThreadDelete, thread]\n );\n\n return (\n <TooltipProvider>\n <div\n className={classNames(\n \"lb-root lb-thread\",\n showActions === \"hover\" && \"lb-thread:show-actions-hover\",\n className\n )}\n data-resolved={thread.resolved ? \"\" : undefined}\n data-unread={unreadIndex !== undefined ? \"\" : undefined}\n dir={$.dir}\n {...props}\n ref={forwardedRef}\n >\n <div className=\"lb-thread-comments\">\n {thread.comments.map((comment, index) => {\n const isFirstComment = index === firstCommentIndex;\n const isUnread =\n unreadIndex !== undefined && index >= unreadIndex;\n\n const children = (\n <Comment\n key={comment.id}\n className=\"lb-thread-comment\"\n data-unread={isUnread ? \"\" : undefined}\n comment={comment}\n indentContent={indentCommentContent}\n showDeleted={showDeletedComments}\n showActions={showActions}\n showReactions={showReactions}\n showAttachments={showAttachments}\n onCommentEdit={onCommentEdit}\n onCommentDelete={handleCommentDelete}\n onAuthorClick={onAuthorClick}\n onMentionClick={onMentionClick}\n onAttachmentClick={onAttachmentClick}\n autoMarkReadThreadId={\n index === lastCommentIndex && isUnread\n ? thread.id\n : undefined\n }\n additionalActionsClassName={\n isFirstComment ? \"lb-thread-actions\" : undefined\n }\n additionalActions={\n isFirstComment && showResolveAction ? (\n <Tooltip\n content={\n thread.resolved\n ? $.THREAD_UNRESOLVE\n : $.THREAD_RESOLVE\n }\n >\n <TogglePrimitive.Root\n pressed={thread.resolved}\n onPressedChange={handleResolvedChange}\n asChild\n >\n <Button\n className=\"lb-comment-action\"\n onClick={stopPropagation}\n aria-label={\n thread.resolved\n ? $.THREAD_UNRESOLVE\n : $.THREAD_RESOLVE\n }\n >\n {thread.resolved ? (\n <ResolvedIcon className=\"lb-button-icon\" />\n ) : (\n <ResolveIcon className=\"lb-button-icon\" />\n )}\n </Button>\n </TogglePrimitive.Root>\n </Tooltip>\n ) : null\n }\n />\n );\n\n return index === newIndicatorIndex &&\n newIndicatorIndex !== firstCommentIndex &&\n newIndicatorIndex <= lastCommentIndex ? (\n <Fragment key={comment.id}>\n <div\n className=\"lb-thread-new-indicator\"\n aria-label={$.THREAD_NEW_INDICATOR_DESCRIPTION}\n >\n <span className=\"lb-thread-new-indicator-label\">\n <ArrowDownIcon className=\"lb-thread-new-indicator-label-icon\" />\n {$.THREAD_NEW_INDICATOR}\n </span>\n </div>\n {children}\n </Fragment>\n ) : (\n children\n );\n })}\n </div>\n {showComposer && (\n <Composer\n className=\"lb-thread-composer\"\n threadId={thread.id}\n defaultCollapsed={showComposer === \"collapsed\" ? true : undefined}\n showAttachments={showAttachments}\n overrides={{\n COMPOSER_PLACEHOLDER: $.THREAD_COMPOSER_PLACEHOLDER,\n COMPOSER_SEND: $.THREAD_COMPOSER_SEND,\n }}\n />\n )}\n </div>\n </TooltipProvider>\n );\n }\n) as <M extends BaseMetadata = DM>(\n props: ThreadProps<M> & RefAttributes<HTMLDivElement>\n) => JSX.Element;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgJO;AAAe;AAElB;AACE;AACuB;AACT;AACd;AACoB;AACJ;AACD;AACG;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACG;AAIL;AACA;AACA;AACA;AACE;AAEuD;AAEzD;AACE;AAE4D;AAE9D;AAAoD;AAC3C;AAET;AAEE;AACE;AAAA;AAIF;AACE;AAAO;AAIT;AAAoC;AAGZ;AAGxB;AAEI;AACH;AACD;AACA;AACA;AACO;AACP;AAEF;AACA;AAEA;AACE;AAEE;AAAA;AACwD;AACxD;AACF;AAGF;AACE;AAAsB;AAGxB;AAA6B;AAEzB;AAEA;AACE;AAA8B;AAE9B;AAAgC;AAClC;AACF;AACA;AACE;AACA;AACA;AACO;AACT;AAGF;AAA4B;AAExB;AAEA;AAAyC;AAClB;AAGvB;AACE;AAAuB;AACzB;AACF;AACwC;AAG1C;AAEK;AACY;AACT;AAC2B;AAC3B;AACF;AACsC;AACQ;AACvC;AACH;AACC;AAEJ;AAAc;AAEX;AACA;AAGA;AACG;AACc;AACH;AACmB;AAC7B;AACe;AACF;AACb;AACA;AACA;AACA;AACiB;AACjB;AACA;AACA;AAIM;AAGmC;AAIpC;AAIS;AAGP;AACiB;AACC;AACV;AAEN;AACW;AACD;AAID;AAIL;AAAuB;AAEvB;AAAsB;AAK7B;AAKV;AAGG;AAAsB;AACpB;AACW;AACI;AAEb;AAAe;AACb;AAAwB;AAO/B;AAKH;AACW;AACO;AACuC;AACxD;AACW;AACe;AACP;AACnB;AAIR;AAGN;;"}
1
+ {"version":3,"file":"Thread.js","sources":["../../src/components/Thread.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n BaseMetadata,\n CommentData,\n DM,\n ThreadData,\n} from \"@liveblocks/core\";\nimport {\n useMarkThreadAsResolved,\n useMarkThreadAsUnresolved,\n useThreadSubscription,\n} from \"@liveblocks/react\";\nimport * as TogglePrimitive from \"@radix-ui/react-toggle\";\nimport type {\n ComponentPropsWithoutRef,\n ForwardedRef,\n RefAttributes,\n SyntheticEvent,\n} from \"react\";\nimport React, {\n forwardRef,\n Fragment,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\n\nimport { ArrowDownIcon } from \"../icons/ArrowDown\";\nimport { ResolveIcon } from \"../icons/Resolve\";\nimport { ResolvedIcon } from \"../icons/Resolved\";\nimport type {\n CommentOverrides,\n ComposerOverrides,\n GlobalOverrides,\n ThreadOverrides,\n} from \"../overrides\";\nimport { useOverrides } from \"../overrides\";\nimport { classNames } from \"../utils/class-names\";\nimport { findLastIndex } from \"../utils/find-last-index\";\nimport type { CommentProps } from \"./Comment\";\nimport { Comment } from \"./Comment\";\nimport type { ComposerProps } from \"./Composer\";\nimport { Composer } from \"./Composer\";\nimport { Button } from \"./internal/Button\";\nimport { Tooltip, TooltipProvider } from \"./internal/Tooltip\";\n\nexport interface ThreadProps<M extends BaseMetadata = DM>\n extends ComponentPropsWithoutRef<\"div\"> {\n /**\n * The thread to display.\n */\n thread: ThreadData<M>;\n\n /**\n * How to show or hide the composer to reply to the thread.\n */\n showComposer?: boolean | \"collapsed\";\n\n /**\n * Whether to show the action to resolve the thread.\n */\n showResolveAction?: boolean;\n\n /**\n * How to show or hide the actions.\n */\n showActions?: CommentProps[\"showActions\"];\n\n /**\n * Whether to show reactions.\n */\n showReactions?: CommentProps[\"showReactions\"];\n\n /**\n * Whether to indent the comments' content.\n */\n indentCommentContent?: CommentProps[\"indentContent\"];\n\n /**\n * Whether to show deleted comments.\n */\n showDeletedComments?: CommentProps[\"showDeleted\"];\n\n /**\n * Whether to show attachments.\n */\n showAttachments?: boolean;\n\n /**\n * The event handler called when changing the resolved status.\n */\n onResolvedChange?: (resolved: boolean) => void;\n\n /**\n * The event handler called when a comment is edited.\n */\n onCommentEdit?: CommentProps[\"onCommentEdit\"];\n\n /**\n * The event handler called when a comment is deleted.\n */\n onCommentDelete?: CommentProps[\"onCommentDelete\"];\n\n /**\n * The event handler called when the thread is deleted.\n * A thread is deleted when all its comments are deleted.\n */\n onThreadDelete?: (thread: ThreadData<M>) => void;\n\n /**\n * The event handler called when clicking on a comment's author.\n */\n onAuthorClick?: CommentProps[\"onAuthorClick\"];\n\n /**\n * The event handler called when clicking on a mention.\n */\n onMentionClick?: CommentProps[\"onMentionClick\"];\n\n /**\n * The event handler called when clicking on a comment's attachment.\n */\n onAttachmentClick?: CommentProps[\"onAttachmentClick\"];\n\n /**\n * The event handler called when the composer is submitted.\n */\n onComposerSubmit?: ComposerProps[\"onComposerSubmit\"];\n\n /**\n * Override the component's strings.\n */\n overrides?: Partial<\n GlobalOverrides & ThreadOverrides & CommentOverrides & ComposerOverrides\n >;\n}\n\n/**\n * Displays a thread of comments, with a composer to reply\n * to it.\n *\n * @example\n * <>\n * {threads.map((thread) => (\n * <Thread key={thread.id} thread={thread} />\n * ))}\n * </>\n */\nexport const Thread = forwardRef(\n <M extends BaseMetadata = DM>(\n {\n thread,\n indentCommentContent = true,\n showActions = \"hover\",\n showDeletedComments,\n showResolveAction = true,\n showReactions = true,\n showComposer = \"collapsed\",\n showAttachments = true,\n onResolvedChange,\n onCommentEdit,\n onCommentDelete,\n onThreadDelete,\n onAuthorClick,\n onMentionClick,\n onAttachmentClick,\n onComposerSubmit,\n overrides,\n className,\n ...props\n }: ThreadProps<M>,\n forwardedRef: ForwardedRef<HTMLDivElement>\n ) => {\n const markThreadAsResolved = useMarkThreadAsResolved();\n const markThreadAsUnresolved = useMarkThreadAsUnresolved();\n const $ = useOverrides(overrides);\n const firstCommentIndex = useMemo(() => {\n return showDeletedComments\n ? 0\n : thread.comments.findIndex((comment) => comment.body);\n }, [showDeletedComments, thread.comments]);\n const lastCommentIndex = useMemo(() => {\n return showDeletedComments\n ? thread.comments.length - 1\n : findLastIndex(thread.comments, (comment) => comment.body);\n }, [showDeletedComments, thread.comments]);\n const { status: subscriptionStatus, unreadSince } = useThreadSubscription(\n thread.id\n );\n const unreadIndex = useMemo(() => {\n // The user is not subscribed to this thread.\n if (subscriptionStatus !== \"subscribed\") {\n return;\n }\n\n // The user hasn't read the thread yet, so all comments are unread.\n if (unreadSince === null) {\n return firstCommentIndex;\n }\n\n // The user has read the thread, so we find the first unread comment.\n const unreadIndex = thread.comments.findIndex(\n (comment) =>\n (showDeletedComments ? true : comment.body) &&\n comment.createdAt > unreadSince\n );\n\n return unreadIndex >= 0 && unreadIndex < thread.comments.length\n ? unreadIndex\n : undefined;\n }, [\n firstCommentIndex,\n showDeletedComments,\n subscriptionStatus,\n thread.comments,\n unreadSince,\n ]);\n const [newIndex, setNewIndex] = useState<number>();\n const newIndicatorIndex = newIndex === undefined ? unreadIndex : newIndex;\n\n useEffect(() => {\n if (unreadIndex) {\n // Keep the \"new\" indicator at the lowest unread index.\n setNewIndex((persistedUnreadIndex) =>\n Math.min(persistedUnreadIndex ?? Infinity, unreadIndex)\n );\n }\n }, [unreadIndex]);\n\n const stopPropagation = useCallback((event: SyntheticEvent) => {\n event.stopPropagation();\n }, []);\n\n const handleResolvedChange = useCallback(\n (resolved: boolean) => {\n onResolvedChange?.(resolved);\n\n if (resolved) {\n markThreadAsResolved(thread.id);\n } else {\n markThreadAsUnresolved(thread.id);\n }\n },\n [\n markThreadAsResolved,\n markThreadAsUnresolved,\n onResolvedChange,\n thread.id,\n ]\n );\n\n const handleCommentDelete = useCallback(\n (comment: CommentData) => {\n onCommentDelete?.(comment);\n\n const filteredComments = thread.comments.filter(\n (comment) => comment.body\n );\n\n if (filteredComments.length <= 1) {\n onThreadDelete?.(thread);\n }\n },\n [onCommentDelete, onThreadDelete, thread]\n );\n\n return (\n <TooltipProvider>\n <div\n className={classNames(\n \"lb-root lb-thread\",\n showActions === \"hover\" && \"lb-thread:show-actions-hover\",\n className\n )}\n data-resolved={thread.resolved ? \"\" : undefined}\n data-unread={unreadIndex !== undefined ? \"\" : undefined}\n dir={$.dir}\n {...props}\n ref={forwardedRef}\n >\n <div className=\"lb-thread-comments\">\n {thread.comments.map((comment, index) => {\n const isFirstComment = index === firstCommentIndex;\n const isUnread =\n unreadIndex !== undefined && index >= unreadIndex;\n\n const children = (\n <Comment\n key={comment.id}\n className=\"lb-thread-comment\"\n data-unread={isUnread ? \"\" : undefined}\n comment={comment}\n indentContent={indentCommentContent}\n showDeleted={showDeletedComments}\n showActions={showActions}\n showReactions={showReactions}\n showAttachments={showAttachments}\n onCommentEdit={onCommentEdit}\n onCommentDelete={handleCommentDelete}\n onAuthorClick={onAuthorClick}\n onMentionClick={onMentionClick}\n onAttachmentClick={onAttachmentClick}\n autoMarkReadThreadId={\n index === lastCommentIndex && isUnread\n ? thread.id\n : undefined\n }\n additionalActionsClassName={\n isFirstComment ? \"lb-thread-actions\" : undefined\n }\n additionalActions={\n isFirstComment && showResolveAction ? (\n <Tooltip\n content={\n thread.resolved\n ? $.THREAD_UNRESOLVE\n : $.THREAD_RESOLVE\n }\n >\n <TogglePrimitive.Root\n pressed={thread.resolved}\n onPressedChange={handleResolvedChange}\n asChild\n >\n <Button\n className=\"lb-comment-action\"\n onClick={stopPropagation}\n aria-label={\n thread.resolved\n ? $.THREAD_UNRESOLVE\n : $.THREAD_RESOLVE\n }\n >\n {thread.resolved ? (\n <ResolvedIcon className=\"lb-button-icon\" />\n ) : (\n <ResolveIcon className=\"lb-button-icon\" />\n )}\n </Button>\n </TogglePrimitive.Root>\n </Tooltip>\n ) : null\n }\n />\n );\n\n return index === newIndicatorIndex &&\n newIndicatorIndex !== firstCommentIndex &&\n newIndicatorIndex <= lastCommentIndex ? (\n <Fragment key={comment.id}>\n <div\n className=\"lb-thread-new-indicator\"\n aria-label={$.THREAD_NEW_INDICATOR_DESCRIPTION}\n >\n <span className=\"lb-thread-new-indicator-label\">\n <ArrowDownIcon className=\"lb-thread-new-indicator-label-icon\" />\n {$.THREAD_NEW_INDICATOR}\n </span>\n </div>\n {children}\n </Fragment>\n ) : (\n children\n );\n })}\n </div>\n {showComposer && (\n <Composer\n className=\"lb-thread-composer\"\n threadId={thread.id}\n defaultCollapsed={showComposer === \"collapsed\" ? true : undefined}\n showAttachments={showAttachments}\n onComposerSubmit={onComposerSubmit}\n overrides={{\n COMPOSER_PLACEHOLDER: $.THREAD_COMPOSER_PLACEHOLDER,\n COMPOSER_SEND: $.THREAD_COMPOSER_SEND,\n }}\n />\n )}\n </div>\n </TooltipProvider>\n );\n }\n) as <M extends BaseMetadata = DM>(\n props: ThreadProps<M> & RefAttributes<HTMLDivElement>\n) => JSX.Element;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsJO;AAAe;AAElB;AACE;AACuB;AACT;AACd;AACoB;AACJ;AACD;AACG;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACG;AAIL;AACA;AACA;AACA;AACE;AAEuD;AAEzD;AACE;AAE4D;AAE9D;AAAoD;AAC3C;AAET;AAEE;AACE;AAAA;AAIF;AACE;AAAO;AAIT;AAAoC;AAGZ;AAGxB;AAEI;AACH;AACD;AACA;AACA;AACO;AACP;AAEF;AACA;AAEA;AACE;AAEE;AAAA;AACwD;AACxD;AACF;AAGF;AACE;AAAsB;AAGxB;AAA6B;AAEzB;AAEA;AACE;AAA8B;AAE9B;AAAgC;AAClC;AACF;AACA;AACE;AACA;AACA;AACO;AACT;AAGF;AAA4B;AAExB;AAEA;AAAyC;AAClB;AAGvB;AACE;AAAuB;AACzB;AACF;AACwC;AAG1C;AAEK;AACY;AACT;AAC2B;AAC3B;AACF;AACsC;AACQ;AACvC;AACH;AACC;AAEJ;AAAc;AAEX;AACA;AAGA;AACG;AACc;AACH;AACmB;AAC7B;AACe;AACF;AACb;AACA;AACA;AACA;AACiB;AACjB;AACA;AACA;AAIM;AAGmC;AAIpC;AAIS;AAGP;AACiB;AACC;AACV;AAEN;AACW;AACD;AAID;AAIL;AAAuB;AAEvB;AAAsB;AAK7B;AAKV;AAGG;AAAsB;AACpB;AACW;AACI;AAEb;AAAe;AACb;AAAwB;AAO/B;AAKH;AACW;AACO;AACuC;AACxD;AACA;AACW;AACe;AACP;AACnB;AAIR;AAGN;;"}
@@ -31,6 +31,7 @@ const Thread = forwardRef(
31
31
  onAuthorClick,
32
32
  onMentionClick,
33
33
  onAttachmentClick,
34
+ onComposerSubmit,
34
35
  overrides,
35
36
  className,
36
37
  ...props
@@ -169,6 +170,7 @@ const Thread = forwardRef(
169
170
  threadId: thread.id,
170
171
  defaultCollapsed: showComposer === "collapsed" ? true : void 0,
171
172
  showAttachments,
173
+ onComposerSubmit,
172
174
  overrides: {
173
175
  COMPOSER_PLACEHOLDER: $.THREAD_COMPOSER_PLACEHOLDER,
174
176
  COMPOSER_SEND: $.THREAD_COMPOSER_SEND
@@ -1 +1 @@
1
- {"version":3,"file":"Thread.mjs","sources":["../../src/components/Thread.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n BaseMetadata,\n CommentData,\n DM,\n ThreadData,\n} from \"@liveblocks/core\";\nimport {\n useMarkThreadAsResolved,\n useMarkThreadAsUnresolved,\n useThreadSubscription,\n} from \"@liveblocks/react\";\nimport * as TogglePrimitive from \"@radix-ui/react-toggle\";\nimport type {\n ComponentPropsWithoutRef,\n ForwardedRef,\n RefAttributes,\n SyntheticEvent,\n} from \"react\";\nimport React, {\n forwardRef,\n Fragment,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\n\nimport { ArrowDownIcon } from \"../icons/ArrowDown\";\nimport { ResolveIcon } from \"../icons/Resolve\";\nimport { ResolvedIcon } from \"../icons/Resolved\";\nimport type {\n CommentOverrides,\n ComposerOverrides,\n GlobalOverrides,\n ThreadOverrides,\n} from \"../overrides\";\nimport { useOverrides } from \"../overrides\";\nimport { classNames } from \"../utils/class-names\";\nimport { findLastIndex } from \"../utils/find-last-index\";\nimport type { CommentProps } from \"./Comment\";\nimport { Comment } from \"./Comment\";\nimport { Composer } from \"./Composer\";\nimport { Button } from \"./internal/Button\";\nimport { Tooltip, TooltipProvider } from \"./internal/Tooltip\";\n\nexport interface ThreadProps<M extends BaseMetadata = DM>\n extends ComponentPropsWithoutRef<\"div\"> {\n /**\n * The thread to display.\n */\n thread: ThreadData<M>;\n\n /**\n * How to show or hide the composer to reply to the thread.\n */\n showComposer?: boolean | \"collapsed\";\n\n /**\n * Whether to show the action to resolve the thread.\n */\n showResolveAction?: boolean;\n\n /**\n * How to show or hide the actions.\n */\n showActions?: CommentProps[\"showActions\"];\n\n /**\n * Whether to show reactions.\n */\n showReactions?: CommentProps[\"showReactions\"];\n\n /**\n * Whether to indent the comments' content.\n */\n indentCommentContent?: CommentProps[\"indentContent\"];\n\n /**\n * Whether to show deleted comments.\n */\n showDeletedComments?: CommentProps[\"showDeleted\"];\n\n /**\n * Whether to show attachments.\n */\n showAttachments?: boolean;\n\n /**\n * The event handler called when changing the resolved status.\n */\n onResolvedChange?: (resolved: boolean) => void;\n\n /**\n * The event handler called when a comment is edited.\n */\n onCommentEdit?: CommentProps[\"onCommentEdit\"];\n\n /**\n * The event handler called when a comment is deleted.\n */\n onCommentDelete?: CommentProps[\"onCommentDelete\"];\n\n /**\n * The event handler called when the thread is deleted.\n * A thread is deleted when all its comments are deleted.\n */\n onThreadDelete?: (thread: ThreadData<M>) => void;\n\n /**\n * The event handler called when clicking on a comment's author.\n */\n onAuthorClick?: CommentProps[\"onAuthorClick\"];\n\n /**\n * The event handler called when clicking on a mention.\n */\n onMentionClick?: CommentProps[\"onMentionClick\"];\n\n /**\n * The event handler called when clicking on a comment's attachment.\n */\n onAttachmentClick?: CommentProps[\"onAttachmentClick\"];\n\n /**\n * Override the component's strings.\n */\n overrides?: Partial<\n GlobalOverrides & ThreadOverrides & CommentOverrides & ComposerOverrides\n >;\n}\n\n/**\n * Displays a thread of comments, with a composer to reply\n * to it.\n *\n * @example\n * <>\n * {threads.map((thread) => (\n * <Thread key={thread.id} thread={thread} />\n * ))}\n * </>\n */\nexport const Thread = forwardRef(\n <M extends BaseMetadata = DM>(\n {\n thread,\n indentCommentContent = true,\n showActions = \"hover\",\n showDeletedComments,\n showResolveAction = true,\n showReactions = true,\n showComposer = \"collapsed\",\n showAttachments = true,\n onResolvedChange,\n onCommentEdit,\n onCommentDelete,\n onThreadDelete,\n onAuthorClick,\n onMentionClick,\n onAttachmentClick,\n overrides,\n className,\n ...props\n }: ThreadProps<M>,\n forwardedRef: ForwardedRef<HTMLDivElement>\n ) => {\n const markThreadAsResolved = useMarkThreadAsResolved();\n const markThreadAsUnresolved = useMarkThreadAsUnresolved();\n const $ = useOverrides(overrides);\n const firstCommentIndex = useMemo(() => {\n return showDeletedComments\n ? 0\n : thread.comments.findIndex((comment) => comment.body);\n }, [showDeletedComments, thread.comments]);\n const lastCommentIndex = useMemo(() => {\n return showDeletedComments\n ? thread.comments.length - 1\n : findLastIndex(thread.comments, (comment) => comment.body);\n }, [showDeletedComments, thread.comments]);\n const { status: subscriptionStatus, unreadSince } = useThreadSubscription(\n thread.id\n );\n const unreadIndex = useMemo(() => {\n // The user is not subscribed to this thread.\n if (subscriptionStatus !== \"subscribed\") {\n return;\n }\n\n // The user hasn't read the thread yet, so all comments are unread.\n if (unreadSince === null) {\n return firstCommentIndex;\n }\n\n // The user has read the thread, so we find the first unread comment.\n const unreadIndex = thread.comments.findIndex(\n (comment) =>\n (showDeletedComments ? true : comment.body) &&\n comment.createdAt > unreadSince\n );\n\n return unreadIndex >= 0 && unreadIndex < thread.comments.length\n ? unreadIndex\n : undefined;\n }, [\n firstCommentIndex,\n showDeletedComments,\n subscriptionStatus,\n thread.comments,\n unreadSince,\n ]);\n const [newIndex, setNewIndex] = useState<number>();\n const newIndicatorIndex = newIndex === undefined ? unreadIndex : newIndex;\n\n useEffect(() => {\n if (unreadIndex) {\n // Keep the \"new\" indicator at the lowest unread index.\n setNewIndex((persistedUnreadIndex) =>\n Math.min(persistedUnreadIndex ?? Infinity, unreadIndex)\n );\n }\n }, [unreadIndex]);\n\n const stopPropagation = useCallback((event: SyntheticEvent) => {\n event.stopPropagation();\n }, []);\n\n const handleResolvedChange = useCallback(\n (resolved: boolean) => {\n onResolvedChange?.(resolved);\n\n if (resolved) {\n markThreadAsResolved(thread.id);\n } else {\n markThreadAsUnresolved(thread.id);\n }\n },\n [\n markThreadAsResolved,\n markThreadAsUnresolved,\n onResolvedChange,\n thread.id,\n ]\n );\n\n const handleCommentDelete = useCallback(\n (comment: CommentData) => {\n onCommentDelete?.(comment);\n\n const filteredComments = thread.comments.filter(\n (comment) => comment.body\n );\n\n if (filteredComments.length <= 1) {\n onThreadDelete?.(thread);\n }\n },\n [onCommentDelete, onThreadDelete, thread]\n );\n\n return (\n <TooltipProvider>\n <div\n className={classNames(\n \"lb-root lb-thread\",\n showActions === \"hover\" && \"lb-thread:show-actions-hover\",\n className\n )}\n data-resolved={thread.resolved ? \"\" : undefined}\n data-unread={unreadIndex !== undefined ? \"\" : undefined}\n dir={$.dir}\n {...props}\n ref={forwardedRef}\n >\n <div className=\"lb-thread-comments\">\n {thread.comments.map((comment, index) => {\n const isFirstComment = index === firstCommentIndex;\n const isUnread =\n unreadIndex !== undefined && index >= unreadIndex;\n\n const children = (\n <Comment\n key={comment.id}\n className=\"lb-thread-comment\"\n data-unread={isUnread ? \"\" : undefined}\n comment={comment}\n indentContent={indentCommentContent}\n showDeleted={showDeletedComments}\n showActions={showActions}\n showReactions={showReactions}\n showAttachments={showAttachments}\n onCommentEdit={onCommentEdit}\n onCommentDelete={handleCommentDelete}\n onAuthorClick={onAuthorClick}\n onMentionClick={onMentionClick}\n onAttachmentClick={onAttachmentClick}\n autoMarkReadThreadId={\n index === lastCommentIndex && isUnread\n ? thread.id\n : undefined\n }\n additionalActionsClassName={\n isFirstComment ? \"lb-thread-actions\" : undefined\n }\n additionalActions={\n isFirstComment && showResolveAction ? (\n <Tooltip\n content={\n thread.resolved\n ? $.THREAD_UNRESOLVE\n : $.THREAD_RESOLVE\n }\n >\n <TogglePrimitive.Root\n pressed={thread.resolved}\n onPressedChange={handleResolvedChange}\n asChild\n >\n <Button\n className=\"lb-comment-action\"\n onClick={stopPropagation}\n aria-label={\n thread.resolved\n ? $.THREAD_UNRESOLVE\n : $.THREAD_RESOLVE\n }\n >\n {thread.resolved ? (\n <ResolvedIcon className=\"lb-button-icon\" />\n ) : (\n <ResolveIcon className=\"lb-button-icon\" />\n )}\n </Button>\n </TogglePrimitive.Root>\n </Tooltip>\n ) : null\n }\n />\n );\n\n return index === newIndicatorIndex &&\n newIndicatorIndex !== firstCommentIndex &&\n newIndicatorIndex <= lastCommentIndex ? (\n <Fragment key={comment.id}>\n <div\n className=\"lb-thread-new-indicator\"\n aria-label={$.THREAD_NEW_INDICATOR_DESCRIPTION}\n >\n <span className=\"lb-thread-new-indicator-label\">\n <ArrowDownIcon className=\"lb-thread-new-indicator-label-icon\" />\n {$.THREAD_NEW_INDICATOR}\n </span>\n </div>\n {children}\n </Fragment>\n ) : (\n children\n );\n })}\n </div>\n {showComposer && (\n <Composer\n className=\"lb-thread-composer\"\n threadId={thread.id}\n defaultCollapsed={showComposer === \"collapsed\" ? true : undefined}\n showAttachments={showAttachments}\n overrides={{\n COMPOSER_PLACEHOLDER: $.THREAD_COMPOSER_PLACEHOLDER,\n COMPOSER_SEND: $.THREAD_COMPOSER_SEND,\n }}\n />\n )}\n </div>\n </TooltipProvider>\n );\n }\n) as <M extends BaseMetadata = DM>(\n props: ThreadProps<M> & RefAttributes<HTMLDivElement>\n) => JSX.Element;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAgJO;AAAe;AAElB;AACE;AACuB;AACT;AACd;AACoB;AACJ;AACD;AACG;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACG;AAIL;AACA;AACA;AACA;AACE;AAEuD;AAEzD;AACE;AAE4D;AAE9D;AAAoD;AAC3C;AAET;AAEE;AACE;AAAA;AAIF;AACE;AAAO;AAIT;AAAoC;AAGZ;AAGxB;AAEI;AACH;AACD;AACA;AACA;AACO;AACP;AAEF;AACA;AAEA;AACE;AAEE;AAAA;AACwD;AACxD;AACF;AAGF;AACE;AAAsB;AAGxB;AAA6B;AAEzB;AAEA;AACE;AAA8B;AAE9B;AAAgC;AAClC;AACF;AACA;AACE;AACA;AACA;AACO;AACT;AAGF;AAA4B;AAExB;AAEA;AAAyC;AAClB;AAGvB;AACE;AAAuB;AACzB;AACF;AACwC;AAG1C;AAEK;AACY;AACT;AAC2B;AAC3B;AACF;AACsC;AACQ;AACvC;AACH;AACC;AAEJ;AAAc;AAEX;AACA;AAGA;AACG;AACc;AACH;AACmB;AAC7B;AACe;AACF;AACb;AACA;AACA;AACA;AACiB;AACjB;AACA;AACA;AAIM;AAGmC;AAIpC;AAIS;AAGP;AACiB;AACC;AACV;AAEN;AACW;AACD;AAID;AAIL;AAAuB;AAEvB;AAAsB;AAK7B;AAKV;AAGG;AAAsB;AACpB;AACW;AACI;AAEb;AAAe;AACb;AAAwB;AAO/B;AAKH;AACW;AACO;AACuC;AACxD;AACW;AACe;AACP;AACnB;AAIR;AAGN;;"}
1
+ {"version":3,"file":"Thread.mjs","sources":["../../src/components/Thread.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n BaseMetadata,\n CommentData,\n DM,\n ThreadData,\n} from \"@liveblocks/core\";\nimport {\n useMarkThreadAsResolved,\n useMarkThreadAsUnresolved,\n useThreadSubscription,\n} from \"@liveblocks/react\";\nimport * as TogglePrimitive from \"@radix-ui/react-toggle\";\nimport type {\n ComponentPropsWithoutRef,\n ForwardedRef,\n RefAttributes,\n SyntheticEvent,\n} from \"react\";\nimport React, {\n forwardRef,\n Fragment,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from \"react\";\n\nimport { ArrowDownIcon } from \"../icons/ArrowDown\";\nimport { ResolveIcon } from \"../icons/Resolve\";\nimport { ResolvedIcon } from \"../icons/Resolved\";\nimport type {\n CommentOverrides,\n ComposerOverrides,\n GlobalOverrides,\n ThreadOverrides,\n} from \"../overrides\";\nimport { useOverrides } from \"../overrides\";\nimport { classNames } from \"../utils/class-names\";\nimport { findLastIndex } from \"../utils/find-last-index\";\nimport type { CommentProps } from \"./Comment\";\nimport { Comment } from \"./Comment\";\nimport type { ComposerProps } from \"./Composer\";\nimport { Composer } from \"./Composer\";\nimport { Button } from \"./internal/Button\";\nimport { Tooltip, TooltipProvider } from \"./internal/Tooltip\";\n\nexport interface ThreadProps<M extends BaseMetadata = DM>\n extends ComponentPropsWithoutRef<\"div\"> {\n /**\n * The thread to display.\n */\n thread: ThreadData<M>;\n\n /**\n * How to show or hide the composer to reply to the thread.\n */\n showComposer?: boolean | \"collapsed\";\n\n /**\n * Whether to show the action to resolve the thread.\n */\n showResolveAction?: boolean;\n\n /**\n * How to show or hide the actions.\n */\n showActions?: CommentProps[\"showActions\"];\n\n /**\n * Whether to show reactions.\n */\n showReactions?: CommentProps[\"showReactions\"];\n\n /**\n * Whether to indent the comments' content.\n */\n indentCommentContent?: CommentProps[\"indentContent\"];\n\n /**\n * Whether to show deleted comments.\n */\n showDeletedComments?: CommentProps[\"showDeleted\"];\n\n /**\n * Whether to show attachments.\n */\n showAttachments?: boolean;\n\n /**\n * The event handler called when changing the resolved status.\n */\n onResolvedChange?: (resolved: boolean) => void;\n\n /**\n * The event handler called when a comment is edited.\n */\n onCommentEdit?: CommentProps[\"onCommentEdit\"];\n\n /**\n * The event handler called when a comment is deleted.\n */\n onCommentDelete?: CommentProps[\"onCommentDelete\"];\n\n /**\n * The event handler called when the thread is deleted.\n * A thread is deleted when all its comments are deleted.\n */\n onThreadDelete?: (thread: ThreadData<M>) => void;\n\n /**\n * The event handler called when clicking on a comment's author.\n */\n onAuthorClick?: CommentProps[\"onAuthorClick\"];\n\n /**\n * The event handler called when clicking on a mention.\n */\n onMentionClick?: CommentProps[\"onMentionClick\"];\n\n /**\n * The event handler called when clicking on a comment's attachment.\n */\n onAttachmentClick?: CommentProps[\"onAttachmentClick\"];\n\n /**\n * The event handler called when the composer is submitted.\n */\n onComposerSubmit?: ComposerProps[\"onComposerSubmit\"];\n\n /**\n * Override the component's strings.\n */\n overrides?: Partial<\n GlobalOverrides & ThreadOverrides & CommentOverrides & ComposerOverrides\n >;\n}\n\n/**\n * Displays a thread of comments, with a composer to reply\n * to it.\n *\n * @example\n * <>\n * {threads.map((thread) => (\n * <Thread key={thread.id} thread={thread} />\n * ))}\n * </>\n */\nexport const Thread = forwardRef(\n <M extends BaseMetadata = DM>(\n {\n thread,\n indentCommentContent = true,\n showActions = \"hover\",\n showDeletedComments,\n showResolveAction = true,\n showReactions = true,\n showComposer = \"collapsed\",\n showAttachments = true,\n onResolvedChange,\n onCommentEdit,\n onCommentDelete,\n onThreadDelete,\n onAuthorClick,\n onMentionClick,\n onAttachmentClick,\n onComposerSubmit,\n overrides,\n className,\n ...props\n }: ThreadProps<M>,\n forwardedRef: ForwardedRef<HTMLDivElement>\n ) => {\n const markThreadAsResolved = useMarkThreadAsResolved();\n const markThreadAsUnresolved = useMarkThreadAsUnresolved();\n const $ = useOverrides(overrides);\n const firstCommentIndex = useMemo(() => {\n return showDeletedComments\n ? 0\n : thread.comments.findIndex((comment) => comment.body);\n }, [showDeletedComments, thread.comments]);\n const lastCommentIndex = useMemo(() => {\n return showDeletedComments\n ? thread.comments.length - 1\n : findLastIndex(thread.comments, (comment) => comment.body);\n }, [showDeletedComments, thread.comments]);\n const { status: subscriptionStatus, unreadSince } = useThreadSubscription(\n thread.id\n );\n const unreadIndex = useMemo(() => {\n // The user is not subscribed to this thread.\n if (subscriptionStatus !== \"subscribed\") {\n return;\n }\n\n // The user hasn't read the thread yet, so all comments are unread.\n if (unreadSince === null) {\n return firstCommentIndex;\n }\n\n // The user has read the thread, so we find the first unread comment.\n const unreadIndex = thread.comments.findIndex(\n (comment) =>\n (showDeletedComments ? true : comment.body) &&\n comment.createdAt > unreadSince\n );\n\n return unreadIndex >= 0 && unreadIndex < thread.comments.length\n ? unreadIndex\n : undefined;\n }, [\n firstCommentIndex,\n showDeletedComments,\n subscriptionStatus,\n thread.comments,\n unreadSince,\n ]);\n const [newIndex, setNewIndex] = useState<number>();\n const newIndicatorIndex = newIndex === undefined ? unreadIndex : newIndex;\n\n useEffect(() => {\n if (unreadIndex) {\n // Keep the \"new\" indicator at the lowest unread index.\n setNewIndex((persistedUnreadIndex) =>\n Math.min(persistedUnreadIndex ?? Infinity, unreadIndex)\n );\n }\n }, [unreadIndex]);\n\n const stopPropagation = useCallback((event: SyntheticEvent) => {\n event.stopPropagation();\n }, []);\n\n const handleResolvedChange = useCallback(\n (resolved: boolean) => {\n onResolvedChange?.(resolved);\n\n if (resolved) {\n markThreadAsResolved(thread.id);\n } else {\n markThreadAsUnresolved(thread.id);\n }\n },\n [\n markThreadAsResolved,\n markThreadAsUnresolved,\n onResolvedChange,\n thread.id,\n ]\n );\n\n const handleCommentDelete = useCallback(\n (comment: CommentData) => {\n onCommentDelete?.(comment);\n\n const filteredComments = thread.comments.filter(\n (comment) => comment.body\n );\n\n if (filteredComments.length <= 1) {\n onThreadDelete?.(thread);\n }\n },\n [onCommentDelete, onThreadDelete, thread]\n );\n\n return (\n <TooltipProvider>\n <div\n className={classNames(\n \"lb-root lb-thread\",\n showActions === \"hover\" && \"lb-thread:show-actions-hover\",\n className\n )}\n data-resolved={thread.resolved ? \"\" : undefined}\n data-unread={unreadIndex !== undefined ? \"\" : undefined}\n dir={$.dir}\n {...props}\n ref={forwardedRef}\n >\n <div className=\"lb-thread-comments\">\n {thread.comments.map((comment, index) => {\n const isFirstComment = index === firstCommentIndex;\n const isUnread =\n unreadIndex !== undefined && index >= unreadIndex;\n\n const children = (\n <Comment\n key={comment.id}\n className=\"lb-thread-comment\"\n data-unread={isUnread ? \"\" : undefined}\n comment={comment}\n indentContent={indentCommentContent}\n showDeleted={showDeletedComments}\n showActions={showActions}\n showReactions={showReactions}\n showAttachments={showAttachments}\n onCommentEdit={onCommentEdit}\n onCommentDelete={handleCommentDelete}\n onAuthorClick={onAuthorClick}\n onMentionClick={onMentionClick}\n onAttachmentClick={onAttachmentClick}\n autoMarkReadThreadId={\n index === lastCommentIndex && isUnread\n ? thread.id\n : undefined\n }\n additionalActionsClassName={\n isFirstComment ? \"lb-thread-actions\" : undefined\n }\n additionalActions={\n isFirstComment && showResolveAction ? (\n <Tooltip\n content={\n thread.resolved\n ? $.THREAD_UNRESOLVE\n : $.THREAD_RESOLVE\n }\n >\n <TogglePrimitive.Root\n pressed={thread.resolved}\n onPressedChange={handleResolvedChange}\n asChild\n >\n <Button\n className=\"lb-comment-action\"\n onClick={stopPropagation}\n aria-label={\n thread.resolved\n ? $.THREAD_UNRESOLVE\n : $.THREAD_RESOLVE\n }\n >\n {thread.resolved ? (\n <ResolvedIcon className=\"lb-button-icon\" />\n ) : (\n <ResolveIcon className=\"lb-button-icon\" />\n )}\n </Button>\n </TogglePrimitive.Root>\n </Tooltip>\n ) : null\n }\n />\n );\n\n return index === newIndicatorIndex &&\n newIndicatorIndex !== firstCommentIndex &&\n newIndicatorIndex <= lastCommentIndex ? (\n <Fragment key={comment.id}>\n <div\n className=\"lb-thread-new-indicator\"\n aria-label={$.THREAD_NEW_INDICATOR_DESCRIPTION}\n >\n <span className=\"lb-thread-new-indicator-label\">\n <ArrowDownIcon className=\"lb-thread-new-indicator-label-icon\" />\n {$.THREAD_NEW_INDICATOR}\n </span>\n </div>\n {children}\n </Fragment>\n ) : (\n children\n );\n })}\n </div>\n {showComposer && (\n <Composer\n className=\"lb-thread-composer\"\n threadId={thread.id}\n defaultCollapsed={showComposer === \"collapsed\" ? true : undefined}\n showAttachments={showAttachments}\n onComposerSubmit={onComposerSubmit}\n overrides={{\n COMPOSER_PLACEHOLDER: $.THREAD_COMPOSER_PLACEHOLDER,\n COMPOSER_SEND: $.THREAD_COMPOSER_SEND,\n }}\n />\n )}\n </div>\n </TooltipProvider>\n );\n }\n) as <M extends BaseMetadata = DM>(\n props: ThreadProps<M> & RefAttributes<HTMLDivElement>\n) => JSX.Element;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAsJO;AAAe;AAElB;AACE;AACuB;AACT;AACd;AACoB;AACJ;AACD;AACG;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACG;AAIL;AACA;AACA;AACA;AACE;AAEuD;AAEzD;AACE;AAE4D;AAE9D;AAAoD;AAC3C;AAET;AAEE;AACE;AAAA;AAIF;AACE;AAAO;AAIT;AAAoC;AAGZ;AAGxB;AAEI;AACH;AACD;AACA;AACA;AACO;AACP;AAEF;AACA;AAEA;AACE;AAEE;AAAA;AACwD;AACxD;AACF;AAGF;AACE;AAAsB;AAGxB;AAA6B;AAEzB;AAEA;AACE;AAA8B;AAE9B;AAAgC;AAClC;AACF;AACA;AACE;AACA;AACA;AACO;AACT;AAGF;AAA4B;AAExB;AAEA;AAAyC;AAClB;AAGvB;AACE;AAAuB;AACzB;AACF;AACwC;AAG1C;AAEK;AACY;AACT;AAC2B;AAC3B;AACF;AACsC;AACQ;AACvC;AACH;AACC;AAEJ;AAAc;AAEX;AACA;AAGA;AACG;AACc;AACH;AACmB;AAC7B;AACe;AACF;AACb;AACA;AACA;AACA;AACiB;AACjB;AACA;AACA;AAIM;AAGmC;AAIpC;AAIS;AAGP;AACiB;AACC;AACV;AAEN;AACW;AACD;AAID;AAIL;AAAuB;AAEvB;AAAsB;AAK7B;AAKV;AAGG;AAAsB;AACpB;AACW;AACI;AAEb;AAAe;AACb;AAAwB;AAO/B;AAKH;AACW;AACO;AACuC;AACxD;AACA;AACW;AACe;AACP;AACnB;AAIR;AAGN;;"}
package/dist/index.d.mts CHANGED
@@ -554,6 +554,10 @@ interface ThreadProps<M extends BaseMetadata = DM> extends ComponentPropsWithout
554
554
  * The event handler called when clicking on a comment's attachment.
555
555
  */
556
556
  onAttachmentClick?: CommentProps["onAttachmentClick"];
557
+ /**
558
+ * The event handler called when the composer is submitted.
559
+ */
560
+ onComposerSubmit?: ComposerProps["onComposerSubmit"];
557
561
  /**
558
562
  * Override the component's strings.
559
563
  */
package/dist/index.d.ts CHANGED
@@ -554,6 +554,10 @@ interface ThreadProps<M extends BaseMetadata = DM> extends ComponentPropsWithout
554
554
  * The event handler called when clicking on a comment's attachment.
555
555
  */
556
556
  onAttachmentClick?: CommentProps["onAttachmentClick"];
557
+ /**
558
+ * The event handler called when the composer is submitted.
559
+ */
560
+ onComposerSubmit?: ComposerProps["onComposerSubmit"];
557
561
  /**
558
562
  * Override the component's strings.
559
563
  */
@@ -290,17 +290,12 @@ function createComposerAttachmentsManager(room, options) {
290
290
  attachments.clear();
291
291
  notifySubscribers();
292
292
  }
293
- function dispose() {
294
- clear();
295
- eventSource.clear();
296
- }
297
293
  return {
298
294
  addAttachments,
299
295
  removeAttachment,
300
296
  getSnapshot,
301
297
  subscribe: eventSource.subscribe,
302
- clear,
303
- dispose
298
+ clear
304
299
  };
305
300
  }
306
301
  function preventBeforeUnloadDefault(event) {
@@ -317,7 +312,7 @@ function useComposerAttachmentsManager(defaultAttachments, options) {
317
312
  }, [frozenDefaultAttachments, frozenAttachmentsManager]);
318
313
  React.useEffect(() => {
319
314
  return () => {
320
- frozenAttachmentsManager.dispose();
315
+ frozenAttachmentsManager.clear();
321
316
  };
322
317
  }, [frozenAttachmentsManager]);
323
318
  const attachments = index_js.useSyncExternalStore(
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../../src/primitives/Composer/utils.ts"],"sourcesContent":["import type { Placement } from \"@floating-ui/react-dom\";\nimport {\n type CommentAttachment,\n type CommentBody,\n type CommentBodyLink,\n type CommentBodyMention,\n type CommentLocalAttachment,\n type CommentMixedAttachment,\n CommentsApiError,\n makeEventSource,\n type OpaqueRoom,\n} from \"@liveblocks/core\";\nimport { useRoom } from \"@liveblocks/react\";\nimport type { DragEvent } from \"react\";\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\n\nimport { isComposerBodyAutoLink } from \"../../slate/plugins/auto-links\";\nimport { isComposerBodyCustomLink } from \"../../slate/plugins/custom-links\";\nimport { isComposerBodyMention } from \"../../slate/plugins/mentions\";\nimport { isText } from \"../../slate/utils/is-text\";\nimport type {\n ComposerBody,\n ComposerBodyAutoLink,\n ComposerBodyCustomLink,\n ComposerBodyMention,\n ComposerBodyText,\n Direction,\n} from \"../../types\";\nimport { getFiles } from \"../../utils/data-transfer\";\nimport { exists } from \"../../utils/exists\";\nimport { useInitial } from \"../../utils/use-initial\";\nimport { useLatest } from \"../../utils/use-latest\";\nimport {\n isCommentBodyLink,\n isCommentBodyMention,\n isCommentBodyText,\n} from \"../Comment/utils\";\nimport { useComposer, useComposerAttachmentsContext } from \"./contexts\";\nimport type { SuggestionsPosition } from \"./types\";\n\nexport function composerBodyMentionToCommentBodyMention(\n mention: ComposerBodyMention\n): CommentBodyMention {\n return {\n type: \"mention\",\n id: mention.id,\n };\n}\n\nexport function composerBodyAutoLinkToCommentBodyLink(\n link: ComposerBodyAutoLink\n): CommentBodyLink {\n return {\n type: \"link\",\n url: link.url,\n };\n}\n\nexport function composerBodyCustomLinkToCommentBodyLink(\n link: ComposerBodyCustomLink\n): CommentBodyLink {\n return {\n type: \"link\",\n url: link.url,\n text: link.children.map((child) => child.text).join(\"\"),\n };\n}\n\nexport function commentBodyMentionToComposerBodyMention(\n mention: CommentBodyMention\n): ComposerBodyMention {\n return {\n type: \"mention\",\n id: mention.id,\n children: [{ text: \"\" }],\n };\n}\n\nexport function commentBodyLinkToComposerBodyLink(\n link: CommentBodyLink\n): ComposerBodyAutoLink | ComposerBodyCustomLink {\n if (link.text) {\n return {\n type: \"custom-link\",\n url: link.url,\n children: [{ text: link.text }],\n };\n } else {\n return {\n type: \"auto-link\",\n url: link.url,\n children: [{ text: link.url }],\n };\n }\n}\n\nexport function composerBodyToCommentBody(body: ComposerBody): CommentBody {\n return {\n version: 1,\n content: body\n .map((block) => {\n // All root blocks are paragraphs at the moment\n if (block.type !== \"paragraph\") {\n return null;\n }\n\n const children = block.children\n .map((inline) => {\n if (isComposerBodyMention(inline)) {\n return composerBodyMentionToCommentBodyMention(inline);\n }\n\n if (isComposerBodyAutoLink(inline)) {\n return composerBodyAutoLinkToCommentBodyLink(inline);\n }\n\n if (isComposerBodyCustomLink(inline)) {\n return composerBodyCustomLinkToCommentBodyLink(inline);\n }\n\n if (isText(inline)) {\n return inline;\n }\n\n return null;\n })\n .filter(exists);\n\n return {\n ...block,\n children,\n };\n })\n .filter(exists),\n };\n}\n\nconst emptyComposerBody: ComposerBody = [];\n\nexport function commentBodyToComposerBody(body: CommentBody): ComposerBody {\n if (!body || !body?.content) {\n return emptyComposerBody;\n }\n\n return body.content\n .map((block) => {\n // All root blocks are paragraphs at the moment\n if (block.type !== \"paragraph\") {\n return null;\n }\n\n const children = block.children\n .map((inline) => {\n if (isCommentBodyMention(inline)) {\n return commentBodyMentionToComposerBodyMention(inline);\n }\n\n if (isCommentBodyLink(inline)) {\n return commentBodyLinkToComposerBodyLink(inline);\n }\n\n if (isCommentBodyText(inline)) {\n return inline as ComposerBodyText;\n }\n\n return null;\n })\n .filter(exists);\n\n return {\n ...block,\n children,\n };\n })\n .filter(exists);\n}\n\nexport function getPlacementFromPosition(\n position: SuggestionsPosition,\n direction: Direction = \"ltr\"\n): Placement {\n return `${position}-${direction === \"rtl\" ? \"end\" : \"start\"}`;\n}\n\nexport function getSideAndAlignFromPlacement(placement: Placement) {\n const [side, align = \"center\"] = placement.split(\"-\");\n\n return [side, align] as const;\n}\n\nexport function useComposerAttachmentsDropArea<\n T extends HTMLElement = HTMLElement,\n>({\n onDragEnter,\n onDragLeave,\n onDragOver,\n onDrop,\n disabled,\n}: {\n onDragEnter?: (event: DragEvent<T>) => void;\n onDragLeave?: (event: DragEvent<T>) => void;\n onDragOver?: (event: DragEvent<T>) => void;\n onDrop?: (event: DragEvent<T>) => void;\n disabled?: boolean;\n}) {\n const { isDisabled: isComposerDisabled } = useComposer();\n const isDisabled = isComposerDisabled || disabled;\n const { createAttachments } = useComposerAttachmentsContext();\n const [isDraggingOver, setDraggingOver] = useState(false);\n const latestIsDraggingOver = useLatest(isDraggingOver);\n\n const handleDragEnter = useCallback(\n (event: DragEvent<T>) => {\n onDragEnter?.(event);\n\n if (\n latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n const dataTransfer = event.dataTransfer;\n\n if (!dataTransfer.types.includes(\"Files\")) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(true);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDragEnter, isDisabled]\n );\n\n const handleDragLeave = useCallback(\n (event: DragEvent<T>) => {\n onDragLeave?.(event);\n\n if (\n !latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n // Ignore drag leave events that are not actually leaving the drop area\n if (\n event.relatedTarget\n ? event.relatedTarget === event.currentTarget ||\n event.currentTarget.contains(event.relatedTarget as HTMLElement)\n : event.currentTarget !== event.target\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(false);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDragLeave, isDisabled]\n );\n\n const handleDragOver = useCallback(\n (event: DragEvent<T>) => {\n onDragOver?.(event);\n\n if (isDisabled || event.isDefaultPrevented()) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n },\n [onDragOver, isDisabled]\n );\n\n const handleDrop = useCallback(\n (event: DragEvent<T>) => {\n onDrop?.(event);\n\n if (\n !latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(false);\n\n const files = getFiles(event.dataTransfer);\n\n createAttachments(files);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDrop, isDisabled, createAttachments]\n );\n\n return [\n isDraggingOver,\n {\n onDragEnter: handleDragEnter,\n onDragLeave: handleDragLeave,\n onDragOver: handleDragOver,\n onDrop: handleDrop,\n \"data-drop\": isDraggingOver ? \"\" : undefined,\n \"data-disabled\": isDisabled ? \"\" : undefined,\n } as const,\n ] as const;\n}\n\ninterface ComposerAttachmentsManagerOptions {\n maxFileSize: number;\n}\n\nexport class AttachmentTooLargeError extends Error {\n origin: \"client\" | \"server\";\n name = \"AttachmentTooLargeError\";\n\n constructor(message: string, origin: \"client\" | \"server\" = \"client\") {\n super(message);\n this.origin = origin;\n }\n}\n\nfunction createComposerAttachmentsManager(\n room: OpaqueRoom,\n options: ComposerAttachmentsManagerOptions\n) {\n const attachments: Map<string, CommentMixedAttachment> = new Map();\n const abortControllers: Map<string, AbortController> = new Map();\n const eventSource = makeEventSource<void>();\n let cachedSnapshot: CommentMixedAttachment[] | null = null;\n\n function notifySubscribers() {\n // Invalidate the cached snapshot\n cachedSnapshot = null;\n eventSource.notify();\n }\n\n function uploadAttachment(attachment: CommentLocalAttachment) {\n const abortController = new AbortController();\n abortControllers.set(attachment.id, abortController);\n\n room\n .uploadAttachment(attachment, {\n signal: abortController.signal,\n })\n .then(() => {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"uploaded\",\n });\n notifySubscribers();\n })\n .catch((error) => {\n if (\n error instanceof Error &&\n error.name !== \"AbortError\" &&\n error.name !== \"TimeoutError\"\n ) {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"error\",\n error:\n error instanceof CommentsApiError && error.status === 413\n ? new AttachmentTooLargeError(\"File is too large.\", \"server\")\n : error,\n });\n notifySubscribers();\n }\n });\n }\n\n function addAttachments(addedAttachments: CommentMixedAttachment[]) {\n if (addedAttachments.length === 0) {\n return;\n }\n\n // Ignore attachments that are already in the manager\n const newAttachments = addedAttachments.filter(\n (attachment) => !attachments.has(attachment.id)\n );\n\n const attachmentsToUpload: CommentLocalAttachment[] = [];\n\n // Add all the new attachments to the manager\n for (const attachment of newAttachments) {\n if (attachment.type === \"localAttachment\") {\n // The file is too large to be uploaded\n if (attachment.file.size > options.maxFileSize) {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"error\",\n error: new AttachmentTooLargeError(\"File is too large.\", \"client\"),\n });\n\n continue;\n }\n\n // Otherwise, mark the attachment to be uploaded\n attachments.set(attachment.id, {\n ...attachment,\n status: \"uploading\",\n });\n attachmentsToUpload.push(attachment);\n } else {\n attachments.set(attachment.id, attachment);\n }\n }\n\n // Notify subscribers about the new attachments that were added\n if (newAttachments.length > 0) {\n notifySubscribers();\n }\n\n // Upload all the new local attachments\n for (const attachment of attachmentsToUpload) {\n uploadAttachment(attachment);\n }\n }\n\n function removeAttachment(attachmentId: string) {\n const abortController = abortControllers.get(attachmentId);\n\n abortController?.abort();\n\n attachments.delete(attachmentId);\n abortControllers.delete(attachmentId);\n\n notifySubscribers();\n }\n\n function getSnapshot() {\n if (!cachedSnapshot) {\n cachedSnapshot = Array.from(attachments.values());\n }\n\n return cachedSnapshot;\n }\n\n // Clear all attachments and abort all ongoing uploads\n function clear() {\n abortControllers.forEach((controller) => controller.abort());\n abortControllers.clear();\n attachments.clear();\n\n notifySubscribers();\n }\n\n function dispose() {\n clear();\n eventSource.clear();\n }\n\n return {\n addAttachments,\n removeAttachment,\n getSnapshot,\n subscribe: eventSource.subscribe,\n clear,\n dispose,\n };\n}\n\nfunction preventBeforeUnloadDefault(event: BeforeUnloadEvent) {\n event.preventDefault();\n}\n\nexport function useComposerAttachmentsManager(\n defaultAttachments: CommentAttachment[],\n options: ComposerAttachmentsManagerOptions\n) {\n const room = useRoom();\n const frozenDefaultAttachments = useInitial(defaultAttachments);\n const frozenAttachmentsManager = useInitial(() =>\n createComposerAttachmentsManager(room, options)\n );\n\n // Initialize default attachments on mount\n useEffect(() => {\n frozenAttachmentsManager.addAttachments(frozenDefaultAttachments);\n }, [frozenDefaultAttachments, frozenAttachmentsManager]);\n\n // Cleanup on unmount\n useEffect(() => {\n return () => {\n frozenAttachmentsManager.dispose();\n };\n }, [frozenAttachmentsManager]);\n\n const attachments = useSyncExternalStore(\n frozenAttachmentsManager.subscribe,\n frozenAttachmentsManager.getSnapshot,\n frozenAttachmentsManager.getSnapshot\n );\n\n const isUploadingAttachments = useMemo(() => {\n return attachments.some(\n (attachment) =>\n attachment.type === \"localAttachment\" &&\n attachment.status === \"uploading\"\n );\n }, [attachments]);\n\n useEffect(() => {\n if (!isUploadingAttachments) {\n return;\n }\n\n window.addEventListener(\"beforeunload\", preventBeforeUnloadDefault);\n\n return () => {\n window.removeEventListener(\"beforeunload\", preventBeforeUnloadDefault);\n };\n }, [isUploadingAttachments]);\n\n return {\n attachments,\n isUploadingAttachments,\n addAttachments: frozenAttachmentsManager.addAttachments,\n removeAttachment: frozenAttachmentsManager.removeAttachment,\n clearAttachments: frozenAttachmentsManager.clear,\n };\n}\n"],"names":["isComposerBodyMention","isComposerBodyAutoLink","isComposerBodyCustomLink","isText","exists","isCommentBodyMention","isCommentBodyLink","isCommentBodyText","useComposer","useComposerAttachmentsContext","useState","useLatest","useCallback","getFiles","makeEventSource","CommentsApiError","useRoom","useInitial","useEffect","useSyncExternalStore","useMemo"],"mappings":";;;;;;;;;;;;;;;;;AAyCO,SAAS,wCACd,OACoB,EAAA;AACpB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,SAAA;AAAA,IACN,IAAI,OAAQ,CAAA,EAAA;AAAA,GACd,CAAA;AACF,CAAA;AAEO,SAAS,sCACd,IACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,KAAK,IAAK,CAAA,GAAA;AAAA,GACZ,CAAA;AACF,CAAA;AAEO,SAAS,wCACd,IACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,KAAK,IAAK,CAAA,GAAA;AAAA,IACV,IAAA,EAAM,IAAK,CAAA,QAAA,CAAS,GAAI,CAAA,CAAC,UAAU,KAAM,CAAA,IAAI,CAAE,CAAA,IAAA,CAAK,EAAE,CAAA;AAAA,GACxD,CAAA;AACF,CAAA;AAEO,SAAS,wCACd,OACqB,EAAA;AACrB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,SAAA;AAAA,IACN,IAAI,OAAQ,CAAA,EAAA;AAAA,IACZ,QAAU,EAAA,CAAC,EAAE,IAAA,EAAM,IAAI,CAAA;AAAA,GACzB,CAAA;AACF,CAAA;AAEO,SAAS,kCACd,IAC+C,EAAA;AAC/C,EAAA,IAAI,KAAK,IAAM,EAAA;AACb,IAAO,OAAA;AAAA,MACL,IAAM,EAAA,aAAA;AAAA,MACN,KAAK,IAAK,CAAA,GAAA;AAAA,MACV,UAAU,CAAC,EAAE,IAAM,EAAA,IAAA,CAAK,MAAM,CAAA;AAAA,KAChC,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,OAAQ,EAAA,CAAA;AAAA,KACnC,CAAA;AAAA,GACF,EAAG,CAAC,wBAAwB,CAAC,CAAA,CAAA;AAE7B,EAAA,MAAM,WAAc,GAAAC,6BAAA;AAAA,IAClB,wBAAyB,CAAA,SAAA;AAAA,IACzB,wBAAyB,CAAA,WAAA;AAAA,IACzB,wBAAyB,CAAA,WAAA;AAAA,GAC3B,CAAA;AAEA,EAAM,MAAA,sBAAA,GAAyBC,cAAQ,MAAM;AAC3C,IAAA,OAAO,WAAY,CAAA,IAAA;AAAA,MACjB,CAAC,UACC,KAAA,UAAA,CAAW,IAAS,KAAA,iBAAA,IACpB,WAAW,MAAW,KAAA,WAAA;AAAA,KAC1B,CAAA;AAAA,GACF,EAAG,CAAC,WAAW,CAAC,CAAA,CAAA;AAEhB,EAAAF,eAAA,CAAU,MAAM;AACd,IAAA,IAAI,CAAC,sBAAwB,EAAA;AAC3B,MAAA,OAAA;AAAA,KACF;AAEA,IAAO,MAAA,CAAA,gBAAA,CAAiB,gBAAgB,0BAA0B,CAAA,CAAA;AAElE,IAAA,OAAO,MAAM;AACX,MAAO,MAAA,CAAA,mBAAA,CAAoB,gBAAgB,0BAA0B,CAAA,CAAA;AAAA,KACvE,CAAA;AAAA,GACF,EAAG,CAAC,sBAAsB,CAAC,CAAA,CAAA;AAE3B,EAAO,OAAA;AAAA,IACL,WAAA;AAAA,IACA,sBAAA;AAAA,IACA,gBAAgB,wBAAyB,CAAA,cAAA;AAAA,IACzC,kBAAkB,wBAAyB,CAAA,gBAAA;AAAA,IAC3C,kBAAkB,wBAAyB,CAAA,KAAA;AAAA,GAC7C,CAAA;AACF;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../../src/primitives/Composer/utils.ts"],"sourcesContent":["import type { Placement } from \"@floating-ui/react-dom\";\nimport {\n type CommentAttachment,\n type CommentBody,\n type CommentBodyLink,\n type CommentBodyMention,\n type CommentLocalAttachment,\n type CommentMixedAttachment,\n CommentsApiError,\n makeEventSource,\n type OpaqueRoom,\n} from \"@liveblocks/core\";\nimport { useRoom } from \"@liveblocks/react\";\nimport type { DragEvent } from \"react\";\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\n\nimport { isComposerBodyAutoLink } from \"../../slate/plugins/auto-links\";\nimport { isComposerBodyCustomLink } from \"../../slate/plugins/custom-links\";\nimport { isComposerBodyMention } from \"../../slate/plugins/mentions\";\nimport { isText } from \"../../slate/utils/is-text\";\nimport type {\n ComposerBody,\n ComposerBodyAutoLink,\n ComposerBodyCustomLink,\n ComposerBodyMention,\n ComposerBodyText,\n Direction,\n} from \"../../types\";\nimport { getFiles } from \"../../utils/data-transfer\";\nimport { exists } from \"../../utils/exists\";\nimport { useInitial } from \"../../utils/use-initial\";\nimport { useLatest } from \"../../utils/use-latest\";\nimport {\n isCommentBodyLink,\n isCommentBodyMention,\n isCommentBodyText,\n} from \"../Comment/utils\";\nimport { useComposer, useComposerAttachmentsContext } from \"./contexts\";\nimport type { SuggestionsPosition } from \"./types\";\n\nexport function composerBodyMentionToCommentBodyMention(\n mention: ComposerBodyMention\n): CommentBodyMention {\n return {\n type: \"mention\",\n id: mention.id,\n };\n}\n\nexport function composerBodyAutoLinkToCommentBodyLink(\n link: ComposerBodyAutoLink\n): CommentBodyLink {\n return {\n type: \"link\",\n url: link.url,\n };\n}\n\nexport function composerBodyCustomLinkToCommentBodyLink(\n link: ComposerBodyCustomLink\n): CommentBodyLink {\n return {\n type: \"link\",\n url: link.url,\n text: link.children.map((child) => child.text).join(\"\"),\n };\n}\n\nexport function commentBodyMentionToComposerBodyMention(\n mention: CommentBodyMention\n): ComposerBodyMention {\n return {\n type: \"mention\",\n id: mention.id,\n children: [{ text: \"\" }],\n };\n}\n\nexport function commentBodyLinkToComposerBodyLink(\n link: CommentBodyLink\n): ComposerBodyAutoLink | ComposerBodyCustomLink {\n if (link.text) {\n return {\n type: \"custom-link\",\n url: link.url,\n children: [{ text: link.text }],\n };\n } else {\n return {\n type: \"auto-link\",\n url: link.url,\n children: [{ text: link.url }],\n };\n }\n}\n\nexport function composerBodyToCommentBody(body: ComposerBody): CommentBody {\n return {\n version: 1,\n content: body\n .map((block) => {\n // All root blocks are paragraphs at the moment\n if (block.type !== \"paragraph\") {\n return null;\n }\n\n const children = block.children\n .map((inline) => {\n if (isComposerBodyMention(inline)) {\n return composerBodyMentionToCommentBodyMention(inline);\n }\n\n if (isComposerBodyAutoLink(inline)) {\n return composerBodyAutoLinkToCommentBodyLink(inline);\n }\n\n if (isComposerBodyCustomLink(inline)) {\n return composerBodyCustomLinkToCommentBodyLink(inline);\n }\n\n if (isText(inline)) {\n return inline;\n }\n\n return null;\n })\n .filter(exists);\n\n return {\n ...block,\n children,\n };\n })\n .filter(exists),\n };\n}\n\nconst emptyComposerBody: ComposerBody = [];\n\nexport function commentBodyToComposerBody(body: CommentBody): ComposerBody {\n if (!body || !body?.content) {\n return emptyComposerBody;\n }\n\n return body.content\n .map((block) => {\n // All root blocks are paragraphs at the moment\n if (block.type !== \"paragraph\") {\n return null;\n }\n\n const children = block.children\n .map((inline) => {\n if (isCommentBodyMention(inline)) {\n return commentBodyMentionToComposerBodyMention(inline);\n }\n\n if (isCommentBodyLink(inline)) {\n return commentBodyLinkToComposerBodyLink(inline);\n }\n\n if (isCommentBodyText(inline)) {\n return inline as ComposerBodyText;\n }\n\n return null;\n })\n .filter(exists);\n\n return {\n ...block,\n children,\n };\n })\n .filter(exists);\n}\n\nexport function getPlacementFromPosition(\n position: SuggestionsPosition,\n direction: Direction = \"ltr\"\n): Placement {\n return `${position}-${direction === \"rtl\" ? \"end\" : \"start\"}`;\n}\n\nexport function getSideAndAlignFromPlacement(placement: Placement) {\n const [side, align = \"center\"] = placement.split(\"-\");\n\n return [side, align] as const;\n}\n\nexport function useComposerAttachmentsDropArea<\n T extends HTMLElement = HTMLElement,\n>({\n onDragEnter,\n onDragLeave,\n onDragOver,\n onDrop,\n disabled,\n}: {\n onDragEnter?: (event: DragEvent<T>) => void;\n onDragLeave?: (event: DragEvent<T>) => void;\n onDragOver?: (event: DragEvent<T>) => void;\n onDrop?: (event: DragEvent<T>) => void;\n disabled?: boolean;\n}) {\n const { isDisabled: isComposerDisabled } = useComposer();\n const isDisabled = isComposerDisabled || disabled;\n const { createAttachments } = useComposerAttachmentsContext();\n const [isDraggingOver, setDraggingOver] = useState(false);\n const latestIsDraggingOver = useLatest(isDraggingOver);\n\n const handleDragEnter = useCallback(\n (event: DragEvent<T>) => {\n onDragEnter?.(event);\n\n if (\n latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n const dataTransfer = event.dataTransfer;\n\n if (!dataTransfer.types.includes(\"Files\")) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(true);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDragEnter, isDisabled]\n );\n\n const handleDragLeave = useCallback(\n (event: DragEvent<T>) => {\n onDragLeave?.(event);\n\n if (\n !latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n // Ignore drag leave events that are not actually leaving the drop area\n if (\n event.relatedTarget\n ? event.relatedTarget === event.currentTarget ||\n event.currentTarget.contains(event.relatedTarget as HTMLElement)\n : event.currentTarget !== event.target\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(false);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDragLeave, isDisabled]\n );\n\n const handleDragOver = useCallback(\n (event: DragEvent<T>) => {\n onDragOver?.(event);\n\n if (isDisabled || event.isDefaultPrevented()) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n },\n [onDragOver, isDisabled]\n );\n\n const handleDrop = useCallback(\n (event: DragEvent<T>) => {\n onDrop?.(event);\n\n if (\n !latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(false);\n\n const files = getFiles(event.dataTransfer);\n\n createAttachments(files);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDrop, isDisabled, createAttachments]\n );\n\n return [\n isDraggingOver,\n {\n onDragEnter: handleDragEnter,\n onDragLeave: handleDragLeave,\n onDragOver: handleDragOver,\n onDrop: handleDrop,\n \"data-drop\": isDraggingOver ? \"\" : undefined,\n \"data-disabled\": isDisabled ? \"\" : undefined,\n } as const,\n ] as const;\n}\n\ninterface ComposerAttachmentsManagerOptions {\n maxFileSize: number;\n}\n\nexport class AttachmentTooLargeError extends Error {\n origin: \"client\" | \"server\";\n name = \"AttachmentTooLargeError\";\n\n constructor(message: string, origin: \"client\" | \"server\" = \"client\") {\n super(message);\n this.origin = origin;\n }\n}\n\nfunction createComposerAttachmentsManager(\n room: OpaqueRoom,\n options: ComposerAttachmentsManagerOptions\n) {\n const attachments: Map<string, CommentMixedAttachment> = new Map();\n const abortControllers: Map<string, AbortController> = new Map();\n const eventSource = makeEventSource<void>();\n let cachedSnapshot: CommentMixedAttachment[] | null = null;\n\n function notifySubscribers() {\n // Invalidate the cached snapshot\n cachedSnapshot = null;\n eventSource.notify();\n }\n\n function uploadAttachment(attachment: CommentLocalAttachment) {\n const abortController = new AbortController();\n abortControllers.set(attachment.id, abortController);\n\n room\n .uploadAttachment(attachment, {\n signal: abortController.signal,\n })\n .then(() => {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"uploaded\",\n });\n notifySubscribers();\n })\n .catch((error) => {\n if (\n error instanceof Error &&\n error.name !== \"AbortError\" &&\n error.name !== \"TimeoutError\"\n ) {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"error\",\n error:\n error instanceof CommentsApiError && error.status === 413\n ? new AttachmentTooLargeError(\"File is too large.\", \"server\")\n : error,\n });\n notifySubscribers();\n }\n });\n }\n\n function addAttachments(addedAttachments: CommentMixedAttachment[]) {\n if (addedAttachments.length === 0) {\n return;\n }\n\n // Ignore attachments that are already in the manager\n const newAttachments = addedAttachments.filter(\n (attachment) => !attachments.has(attachment.id)\n );\n\n const attachmentsToUpload: CommentLocalAttachment[] = [];\n\n // Add all the new attachments to the manager\n for (const attachment of newAttachments) {\n if (attachment.type === \"localAttachment\") {\n // The file is too large to be uploaded\n if (attachment.file.size > options.maxFileSize) {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"error\",\n error: new AttachmentTooLargeError(\"File is too large.\", \"client\"),\n });\n\n continue;\n }\n\n // Otherwise, mark the attachment to be uploaded\n attachments.set(attachment.id, {\n ...attachment,\n status: \"uploading\",\n });\n attachmentsToUpload.push(attachment);\n } else {\n attachments.set(attachment.id, attachment);\n }\n }\n\n // Notify subscribers about the new attachments that were added\n if (newAttachments.length > 0) {\n notifySubscribers();\n }\n\n // Upload all the new local attachments\n for (const attachment of attachmentsToUpload) {\n uploadAttachment(attachment);\n }\n }\n\n function removeAttachment(attachmentId: string) {\n const abortController = abortControllers.get(attachmentId);\n\n abortController?.abort();\n\n attachments.delete(attachmentId);\n abortControllers.delete(attachmentId);\n\n notifySubscribers();\n }\n\n function getSnapshot() {\n if (!cachedSnapshot) {\n cachedSnapshot = Array.from(attachments.values());\n }\n\n return cachedSnapshot;\n }\n\n // Clear all attachments and abort all ongoing uploads\n function clear() {\n abortControllers.forEach((controller) => controller.abort());\n abortControllers.clear();\n attachments.clear();\n\n notifySubscribers();\n }\n\n return {\n addAttachments,\n removeAttachment,\n getSnapshot,\n subscribe: eventSource.subscribe,\n clear,\n };\n}\n\nfunction preventBeforeUnloadDefault(event: BeforeUnloadEvent) {\n event.preventDefault();\n}\n\nexport function useComposerAttachmentsManager(\n defaultAttachments: CommentAttachment[],\n options: ComposerAttachmentsManagerOptions\n) {\n const room = useRoom();\n const frozenDefaultAttachments = useInitial(defaultAttachments);\n const frozenAttachmentsManager = useInitial(() =>\n createComposerAttachmentsManager(room, options)\n );\n\n // Initialize default attachments on mount\n useEffect(() => {\n frozenAttachmentsManager.addAttachments(frozenDefaultAttachments);\n }, [frozenDefaultAttachments, frozenAttachmentsManager]);\n\n // Clear on unmount\n useEffect(() => {\n return () => {\n frozenAttachmentsManager.clear();\n };\n }, [frozenAttachmentsManager]);\n\n const attachments = useSyncExternalStore(\n frozenAttachmentsManager.subscribe,\n frozenAttachmentsManager.getSnapshot,\n frozenAttachmentsManager.getSnapshot\n );\n\n const isUploadingAttachments = useMemo(() => {\n return attachments.some(\n (attachment) =>\n attachment.type === \"localAttachment\" &&\n attachment.status === \"uploading\"\n );\n }, [attachments]);\n\n useEffect(() => {\n if (!isUploadingAttachments) {\n return;\n }\n\n window.addEventListener(\"beforeunload\", preventBeforeUnloadDefault);\n\n return () => {\n window.removeEventListener(\"beforeunload\", preventBeforeUnloadDefault);\n };\n }, [isUploadingAttachments]);\n\n return {\n attachments,\n isUploadingAttachments,\n addAttachments: frozenAttachmentsManager.addAttachments,\n removeAttachment: frozenAttachmentsManager.removeAttachment,\n clearAttachments: frozenAttachmentsManager.clear,\n };\n}\n"],"names":["isComposerBodyMention","isComposerBodyAutoLink","isComposerBodyCustomLink","isText","exists","isCommentBodyMention","isCommentBodyLink","isCommentBodyText","useComposer","useComposerAttachmentsContext","useState","useLatest","useCallback","getFiles","makeEventSource","CommentsApiError","useRoom","useInitial","useEffect","useSyncExternalStore","useMemo"],"mappings":";;;;;;;;;;;;;;;;;AAyCO,SAAS,wCACd,OACoB,EAAA;AACpB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,SAAA;AAAA,IACN,IAAI,OAAQ,CAAA,EAAA;AAAA,GACd,CAAA;AACF,CAAA;AAEO,SAAS,sCACd,IACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,KAAK,IAAK,CAAA,GAAA;AAAA,GACZ,CAAA;AACF,CAAA;AAEO,SAAS,wCACd,IACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,KAAK,IAAK,C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,EAAG,CAAC,sBAAsB,CAAC,CAAA,CAAA;AAE3B,EAAO,OAAA;AAAA,IACL,WAAA;AAAA,IACA,sBAAA;AAAA,IACA,gBAAgB,wBAAyB,CAAA,cAAA;AAAA,IACzC,kBAAkB,wBAAyB,CAAA,gBAAA;AAAA,IAC3C,kBAAkB,wBAAyB,CAAA,KAAA;AAAA,GAC7C,CAAA;AACF;;;;;;;;;;;;;;;"}
@@ -288,17 +288,12 @@ function createComposerAttachmentsManager(room, options) {
288
288
  attachments.clear();
289
289
  notifySubscribers();
290
290
  }
291
- function dispose() {
292
- clear();
293
- eventSource.clear();
294
- }
295
291
  return {
296
292
  addAttachments,
297
293
  removeAttachment,
298
294
  getSnapshot,
299
295
  subscribe: eventSource.subscribe,
300
- clear,
301
- dispose
296
+ clear
302
297
  };
303
298
  }
304
299
  function preventBeforeUnloadDefault(event) {
@@ -315,7 +310,7 @@ function useComposerAttachmentsManager(defaultAttachments, options) {
315
310
  }, [frozenDefaultAttachments, frozenAttachmentsManager]);
316
311
  useEffect(() => {
317
312
  return () => {
318
- frozenAttachmentsManager.dispose();
313
+ frozenAttachmentsManager.clear();
319
314
  };
320
315
  }, [frozenAttachmentsManager]);
321
316
  const attachments = useSyncExternalStore(
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sources":["../../../src/primitives/Composer/utils.ts"],"sourcesContent":["import type { Placement } from \"@floating-ui/react-dom\";\nimport {\n type CommentAttachment,\n type CommentBody,\n type CommentBodyLink,\n type CommentBodyMention,\n type CommentLocalAttachment,\n type CommentMixedAttachment,\n CommentsApiError,\n makeEventSource,\n type OpaqueRoom,\n} from \"@liveblocks/core\";\nimport { useRoom } from \"@liveblocks/react\";\nimport type { DragEvent } from \"react\";\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\n\nimport { isComposerBodyAutoLink } from \"../../slate/plugins/auto-links\";\nimport { isComposerBodyCustomLink } from \"../../slate/plugins/custom-links\";\nimport { isComposerBodyMention } from \"../../slate/plugins/mentions\";\nimport { isText } from \"../../slate/utils/is-text\";\nimport type {\n ComposerBody,\n ComposerBodyAutoLink,\n ComposerBodyCustomLink,\n ComposerBodyMention,\n ComposerBodyText,\n Direction,\n} from \"../../types\";\nimport { getFiles } from \"../../utils/data-transfer\";\nimport { exists } from \"../../utils/exists\";\nimport { useInitial } from \"../../utils/use-initial\";\nimport { useLatest } from \"../../utils/use-latest\";\nimport {\n isCommentBodyLink,\n isCommentBodyMention,\n isCommentBodyText,\n} from \"../Comment/utils\";\nimport { useComposer, useComposerAttachmentsContext } from \"./contexts\";\nimport type { SuggestionsPosition } from \"./types\";\n\nexport function composerBodyMentionToCommentBodyMention(\n mention: ComposerBodyMention\n): CommentBodyMention {\n return {\n type: \"mention\",\n id: mention.id,\n };\n}\n\nexport function composerBodyAutoLinkToCommentBodyLink(\n link: ComposerBodyAutoLink\n): CommentBodyLink {\n return {\n type: \"link\",\n url: link.url,\n };\n}\n\nexport function composerBodyCustomLinkToCommentBodyLink(\n link: ComposerBodyCustomLink\n): CommentBodyLink {\n return {\n type: \"link\",\n url: link.url,\n text: link.children.map((child) => child.text).join(\"\"),\n };\n}\n\nexport function commentBodyMentionToComposerBodyMention(\n mention: CommentBodyMention\n): ComposerBodyMention {\n return {\n type: \"mention\",\n id: mention.id,\n children: [{ text: \"\" }],\n };\n}\n\nexport function commentBodyLinkToComposerBodyLink(\n link: CommentBodyLink\n): ComposerBodyAutoLink | ComposerBodyCustomLink {\n if (link.text) {\n return {\n type: \"custom-link\",\n url: link.url,\n children: [{ text: link.text }],\n };\n } else {\n return {\n type: \"auto-link\",\n url: link.url,\n children: [{ text: link.url }],\n };\n }\n}\n\nexport function composerBodyToCommentBody(body: ComposerBody): CommentBody {\n return {\n version: 1,\n content: body\n .map((block) => {\n // All root blocks are paragraphs at the moment\n if (block.type !== \"paragraph\") {\n return null;\n }\n\n const children = block.children\n .map((inline) => {\n if (isComposerBodyMention(inline)) {\n return composerBodyMentionToCommentBodyMention(inline);\n }\n\n if (isComposerBodyAutoLink(inline)) {\n return composerBodyAutoLinkToCommentBodyLink(inline);\n }\n\n if (isComposerBodyCustomLink(inline)) {\n return composerBodyCustomLinkToCommentBodyLink(inline);\n }\n\n if (isText(inline)) {\n return inline;\n }\n\n return null;\n })\n .filter(exists);\n\n return {\n ...block,\n children,\n };\n })\n .filter(exists),\n };\n}\n\nconst emptyComposerBody: ComposerBody = [];\n\nexport function commentBodyToComposerBody(body: CommentBody): ComposerBody {\n if (!body || !body?.content) {\n return emptyComposerBody;\n }\n\n return body.content\n .map((block) => {\n // All root blocks are paragraphs at the moment\n if (block.type !== \"paragraph\") {\n return null;\n }\n\n const children = block.children\n .map((inline) => {\n if (isCommentBodyMention(inline)) {\n return commentBodyMentionToComposerBodyMention(inline);\n }\n\n if (isCommentBodyLink(inline)) {\n return commentBodyLinkToComposerBodyLink(inline);\n }\n\n if (isCommentBodyText(inline)) {\n return inline as ComposerBodyText;\n }\n\n return null;\n })\n .filter(exists);\n\n return {\n ...block,\n children,\n };\n })\n .filter(exists);\n}\n\nexport function getPlacementFromPosition(\n position: SuggestionsPosition,\n direction: Direction = \"ltr\"\n): Placement {\n return `${position}-${direction === \"rtl\" ? \"end\" : \"start\"}`;\n}\n\nexport function getSideAndAlignFromPlacement(placement: Placement) {\n const [side, align = \"center\"] = placement.split(\"-\");\n\n return [side, align] as const;\n}\n\nexport function useComposerAttachmentsDropArea<\n T extends HTMLElement = HTMLElement,\n>({\n onDragEnter,\n onDragLeave,\n onDragOver,\n onDrop,\n disabled,\n}: {\n onDragEnter?: (event: DragEvent<T>) => void;\n onDragLeave?: (event: DragEvent<T>) => void;\n onDragOver?: (event: DragEvent<T>) => void;\n onDrop?: (event: DragEvent<T>) => void;\n disabled?: boolean;\n}) {\n const { isDisabled: isComposerDisabled } = useComposer();\n const isDisabled = isComposerDisabled || disabled;\n const { createAttachments } = useComposerAttachmentsContext();\n const [isDraggingOver, setDraggingOver] = useState(false);\n const latestIsDraggingOver = useLatest(isDraggingOver);\n\n const handleDragEnter = useCallback(\n (event: DragEvent<T>) => {\n onDragEnter?.(event);\n\n if (\n latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n const dataTransfer = event.dataTransfer;\n\n if (!dataTransfer.types.includes(\"Files\")) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(true);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDragEnter, isDisabled]\n );\n\n const handleDragLeave = useCallback(\n (event: DragEvent<T>) => {\n onDragLeave?.(event);\n\n if (\n !latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n // Ignore drag leave events that are not actually leaving the drop area\n if (\n event.relatedTarget\n ? event.relatedTarget === event.currentTarget ||\n event.currentTarget.contains(event.relatedTarget as HTMLElement)\n : event.currentTarget !== event.target\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(false);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDragLeave, isDisabled]\n );\n\n const handleDragOver = useCallback(\n (event: DragEvent<T>) => {\n onDragOver?.(event);\n\n if (isDisabled || event.isDefaultPrevented()) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n },\n [onDragOver, isDisabled]\n );\n\n const handleDrop = useCallback(\n (event: DragEvent<T>) => {\n onDrop?.(event);\n\n if (\n !latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(false);\n\n const files = getFiles(event.dataTransfer);\n\n createAttachments(files);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDrop, isDisabled, createAttachments]\n );\n\n return [\n isDraggingOver,\n {\n onDragEnter: handleDragEnter,\n onDragLeave: handleDragLeave,\n onDragOver: handleDragOver,\n onDrop: handleDrop,\n \"data-drop\": isDraggingOver ? \"\" : undefined,\n \"data-disabled\": isDisabled ? \"\" : undefined,\n } as const,\n ] as const;\n}\n\ninterface ComposerAttachmentsManagerOptions {\n maxFileSize: number;\n}\n\nexport class AttachmentTooLargeError extends Error {\n origin: \"client\" | \"server\";\n name = \"AttachmentTooLargeError\";\n\n constructor(message: string, origin: \"client\" | \"server\" = \"client\") {\n super(message);\n this.origin = origin;\n }\n}\n\nfunction createComposerAttachmentsManager(\n room: OpaqueRoom,\n options: ComposerAttachmentsManagerOptions\n) {\n const attachments: Map<string, CommentMixedAttachment> = new Map();\n const abortControllers: Map<string, AbortController> = new Map();\n const eventSource = makeEventSource<void>();\n let cachedSnapshot: CommentMixedAttachment[] | null = null;\n\n function notifySubscribers() {\n // Invalidate the cached snapshot\n cachedSnapshot = null;\n eventSource.notify();\n }\n\n function uploadAttachment(attachment: CommentLocalAttachment) {\n const abortController = new AbortController();\n abortControllers.set(attachment.id, abortController);\n\n room\n .uploadAttachment(attachment, {\n signal: abortController.signal,\n })\n .then(() => {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"uploaded\",\n });\n notifySubscribers();\n })\n .catch((error) => {\n if (\n error instanceof Error &&\n error.name !== \"AbortError\" &&\n error.name !== \"TimeoutError\"\n ) {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"error\",\n error:\n error instanceof CommentsApiError && error.status === 413\n ? new AttachmentTooLargeError(\"File is too large.\", \"server\")\n : error,\n });\n notifySubscribers();\n }\n });\n }\n\n function addAttachments(addedAttachments: CommentMixedAttachment[]) {\n if (addedAttachments.length === 0) {\n return;\n }\n\n // Ignore attachments that are already in the manager\n const newAttachments = addedAttachments.filter(\n (attachment) => !attachments.has(attachment.id)\n );\n\n const attachmentsToUpload: CommentLocalAttachment[] = [];\n\n // Add all the new attachments to the manager\n for (const attachment of newAttachments) {\n if (attachment.type === \"localAttachment\") {\n // The file is too large to be uploaded\n if (attachment.file.size > options.maxFileSize) {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"error\",\n error: new AttachmentTooLargeError(\"File is too large.\", \"client\"),\n });\n\n continue;\n }\n\n // Otherwise, mark the attachment to be uploaded\n attachments.set(attachment.id, {\n ...attachment,\n status: \"uploading\",\n });\n attachmentsToUpload.push(attachment);\n } else {\n attachments.set(attachment.id, attachment);\n }\n }\n\n // Notify subscribers about the new attachments that were added\n if (newAttachments.length > 0) {\n notifySubscribers();\n }\n\n // Upload all the new local attachments\n for (const attachment of attachmentsToUpload) {\n uploadAttachment(attachment);\n }\n }\n\n function removeAttachment(attachmentId: string) {\n const abortController = abortControllers.get(attachmentId);\n\n abortController?.abort();\n\n attachments.delete(attachmentId);\n abortControllers.delete(attachmentId);\n\n notifySubscribers();\n }\n\n function getSnapshot() {\n if (!cachedSnapshot) {\n cachedSnapshot = Array.from(attachments.values());\n }\n\n return cachedSnapshot;\n }\n\n // Clear all attachments and abort all ongoing uploads\n function clear() {\n abortControllers.forEach((controller) => controller.abort());\n abortControllers.clear();\n attachments.clear();\n\n notifySubscribers();\n }\n\n function dispose() {\n clear();\n eventSource.clear();\n }\n\n return {\n addAttachments,\n removeAttachment,\n getSnapshot,\n subscribe: eventSource.subscribe,\n clear,\n dispose,\n };\n}\n\nfunction preventBeforeUnloadDefault(event: BeforeUnloadEvent) {\n event.preventDefault();\n}\n\nexport function useComposerAttachmentsManager(\n defaultAttachments: CommentAttachment[],\n options: ComposerAttachmentsManagerOptions\n) {\n const room = useRoom();\n const frozenDefaultAttachments = useInitial(defaultAttachments);\n const frozenAttachmentsManager = useInitial(() =>\n createComposerAttachmentsManager(room, options)\n );\n\n // Initialize default attachments on mount\n useEffect(() => {\n frozenAttachmentsManager.addAttachments(frozenDefaultAttachments);\n }, [frozenDefaultAttachments, frozenAttachmentsManager]);\n\n // Cleanup on unmount\n useEffect(() => {\n return () => {\n frozenAttachmentsManager.dispose();\n };\n }, [frozenAttachmentsManager]);\n\n const attachments = useSyncExternalStore(\n frozenAttachmentsManager.subscribe,\n frozenAttachmentsManager.getSnapshot,\n frozenAttachmentsManager.getSnapshot\n );\n\n const isUploadingAttachments = useMemo(() => {\n return attachments.some(\n (attachment) =>\n attachment.type === \"localAttachment\" &&\n attachment.status === \"uploading\"\n );\n }, [attachments]);\n\n useEffect(() => {\n if (!isUploadingAttachments) {\n return;\n }\n\n window.addEventListener(\"beforeunload\", preventBeforeUnloadDefault);\n\n return () => {\n window.removeEventListener(\"beforeunload\", preventBeforeUnloadDefault);\n };\n }, [isUploadingAttachments]);\n\n return {\n attachments,\n isUploadingAttachments,\n addAttachments: frozenAttachmentsManager.addAttachments,\n removeAttachment: frozenAttachmentsManager.removeAttachment,\n clearAttachments: frozenAttachmentsManager.clear,\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAyCO,SAAS,wCACd,OACoB,EAAA;AACpB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,SAAA;AAAA,IACN,IAAI,OAAQ,CAAA,EAAA;AAAA,GACd,CAAA;AACF,CAAA;AAEO,SAAS,sCACd,IACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,KAAK,IAAK,CAAA,GAAA;AAAA,GACZ,CAAA;AACF,CAAA;AAEO,SAAS,wCACd,IACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,KAAK,IAAK,CAAA,GAAA;AAAA,IACV,IAAA,EAAM,IAAK,CAAA,QAAA,CAAS,GAAI,CAAA,CAAC,UAAU,KAAM,CAAA,IAAI,CAAE,CAAA,IAAA,CAAK,EAAE,CAAA;AAAA,GACxD,CAAA;AACF,CAAA;AAEO,SAAS,wCACd,OACqB,EAAA;AACrB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,SAAA;AAAA,IACN,IAAI,OAAQ,CAAA,EAAA;AAAA,IACZ,QAAU,EAAA,CAAC,EAAE,IAAA,EAAM,IAAI,CAAA;AAAA,GACzB,CAAA;AACF,CAAA;AAEO,SAAS,kCACd,IAC+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sourcesContent":["import type { Placement } from \"@floating-ui/react-dom\";\nimport {\n type CommentAttachment,\n type CommentBody,\n type CommentBodyLink,\n type CommentBodyMention,\n type CommentLocalAttachment,\n type CommentMixedAttachment,\n CommentsApiError,\n makeEventSource,\n type OpaqueRoom,\n} from \"@liveblocks/core\";\nimport { useRoom } from \"@liveblocks/react\";\nimport type { DragEvent } from \"react\";\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\n\nimport { isComposerBodyAutoLink } from \"../../slate/plugins/auto-links\";\nimport { isComposerBodyCustomLink } from \"../../slate/plugins/custom-links\";\nimport { isComposerBodyMention } from \"../../slate/plugins/mentions\";\nimport { isText } from \"../../slate/utils/is-text\";\nimport type {\n ComposerBody,\n ComposerBodyAutoLink,\n ComposerBodyCustomLink,\n ComposerBodyMention,\n ComposerBodyText,\n Direction,\n} from \"../../types\";\nimport { getFiles } from \"../../utils/data-transfer\";\nimport { exists } from \"../../utils/exists\";\nimport { useInitial } from \"../../utils/use-initial\";\nimport { useLatest } from \"../../utils/use-latest\";\nimport {\n isCommentBodyLink,\n isCommentBodyMention,\n isCommentBodyText,\n} from \"../Comment/utils\";\nimport { useComposer, useComposerAttachmentsContext } from \"./contexts\";\nimport type { SuggestionsPosition } from \"./types\";\n\nexport function composerBodyMentionToCommentBodyMention(\n mention: ComposerBodyMention\n): CommentBodyMention {\n return {\n type: \"mention\",\n id: mention.id,\n };\n}\n\nexport function composerBodyAutoLinkToCommentBodyLink(\n link: ComposerBodyAutoLink\n): CommentBodyLink {\n return {\n type: \"link\",\n url: link.url,\n };\n}\n\nexport function composerBodyCustomLinkToCommentBodyLink(\n link: ComposerBodyCustomLink\n): CommentBodyLink {\n return {\n type: \"link\",\n url: link.url,\n text: link.children.map((child) => child.text).join(\"\"),\n };\n}\n\nexport function commentBodyMentionToComposerBodyMention(\n mention: CommentBodyMention\n): ComposerBodyMention {\n return {\n type: \"mention\",\n id: mention.id,\n children: [{ text: \"\" }],\n };\n}\n\nexport function commentBodyLinkToComposerBodyLink(\n link: CommentBodyLink\n): ComposerBodyAutoLink | ComposerBodyCustomLink {\n if (link.text) {\n return {\n type: \"custom-link\",\n url: link.url,\n children: [{ text: link.text }],\n };\n } else {\n return {\n type: \"auto-link\",\n url: link.url,\n children: [{ text: link.url }],\n };\n }\n}\n\nexport function composerBodyToCommentBody(body: ComposerBody): CommentBody {\n return {\n version: 1,\n content: body\n .map((block) => {\n // All root blocks are paragraphs at the moment\n if (block.type !== \"paragraph\") {\n return null;\n }\n\n const children = block.children\n .map((inline) => {\n if (isComposerBodyMention(inline)) {\n return composerBodyMentionToCommentBodyMention(inline);\n }\n\n if (isComposerBodyAutoLink(inline)) {\n return composerBodyAutoLinkToCommentBodyLink(inline);\n }\n\n if (isComposerBodyCustomLink(inline)) {\n return composerBodyCustomLinkToCommentBodyLink(inline);\n }\n\n if (isText(inline)) {\n return inline;\n }\n\n return null;\n })\n .filter(exists);\n\n return {\n ...block,\n children,\n };\n })\n .filter(exists),\n };\n}\n\nconst emptyComposerBody: ComposerBody = [];\n\nexport function commentBodyToComposerBody(body: CommentBody): ComposerBody {\n if (!body || !body?.content) {\n return emptyComposerBody;\n }\n\n return body.content\n .map((block) => {\n // All root blocks are paragraphs at the moment\n if (block.type !== \"paragraph\") {\n return null;\n }\n\n const children = block.children\n .map((inline) => {\n if (isCommentBodyMention(inline)) {\n return commentBodyMentionToComposerBodyMention(inline);\n }\n\n if (isCommentBodyLink(inline)) {\n return commentBodyLinkToComposerBodyLink(inline);\n }\n\n if (isCommentBodyText(inline)) {\n return inline as ComposerBodyText;\n }\n\n return null;\n })\n .filter(exists);\n\n return {\n ...block,\n children,\n };\n })\n .filter(exists);\n}\n\nexport function getPlacementFromPosition(\n position: SuggestionsPosition,\n direction: Direction = \"ltr\"\n): Placement {\n return `${position}-${direction === \"rtl\" ? \"end\" : \"start\"}`;\n}\n\nexport function getSideAndAlignFromPlacement(placement: Placement) {\n const [side, align = \"center\"] = placement.split(\"-\");\n\n return [side, align] as const;\n}\n\nexport function useComposerAttachmentsDropArea<\n T extends HTMLElement = HTMLElement,\n>({\n onDragEnter,\n onDragLeave,\n onDragOver,\n onDrop,\n disabled,\n}: {\n onDragEnter?: (event: DragEvent<T>) => void;\n onDragLeave?: (event: DragEvent<T>) => void;\n onDragOver?: (event: DragEvent<T>) => void;\n onDrop?: (event: DragEvent<T>) => void;\n disabled?: boolean;\n}) {\n const { isDisabled: isComposerDisabled } = useComposer();\n const isDisabled = isComposerDisabled || disabled;\n const { createAttachments } = useComposerAttachmentsContext();\n const [isDraggingOver, setDraggingOver] = useState(false);\n const latestIsDraggingOver = useLatest(isDraggingOver);\n\n const handleDragEnter = useCallback(\n (event: DragEvent<T>) => {\n onDragEnter?.(event);\n\n if (\n latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n const dataTransfer = event.dataTransfer;\n\n if (!dataTransfer.types.includes(\"Files\")) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(true);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDragEnter, isDisabled]\n );\n\n const handleDragLeave = useCallback(\n (event: DragEvent<T>) => {\n onDragLeave?.(event);\n\n if (\n !latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n // Ignore drag leave events that are not actually leaving the drop area\n if (\n event.relatedTarget\n ? event.relatedTarget === event.currentTarget ||\n event.currentTarget.contains(event.relatedTarget as HTMLElement)\n : event.currentTarget !== event.target\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(false);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDragLeave, isDisabled]\n );\n\n const handleDragOver = useCallback(\n (event: DragEvent<T>) => {\n onDragOver?.(event);\n\n if (isDisabled || event.isDefaultPrevented()) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n },\n [onDragOver, isDisabled]\n );\n\n const handleDrop = useCallback(\n (event: DragEvent<T>) => {\n onDrop?.(event);\n\n if (\n !latestIsDraggingOver.current ||\n isDisabled ||\n event.isDefaultPrevented()\n ) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n setDraggingOver(false);\n\n const files = getFiles(event.dataTransfer);\n\n createAttachments(files);\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onDrop, isDisabled, createAttachments]\n );\n\n return [\n isDraggingOver,\n {\n onDragEnter: handleDragEnter,\n onDragLeave: handleDragLeave,\n onDragOver: handleDragOver,\n onDrop: handleDrop,\n \"data-drop\": isDraggingOver ? \"\" : undefined,\n \"data-disabled\": isDisabled ? \"\" : undefined,\n } as const,\n ] as const;\n}\n\ninterface ComposerAttachmentsManagerOptions {\n maxFileSize: number;\n}\n\nexport class AttachmentTooLargeError extends Error {\n origin: \"client\" | \"server\";\n name = \"AttachmentTooLargeError\";\n\n constructor(message: string, origin: \"client\" | \"server\" = \"client\") {\n super(message);\n this.origin = origin;\n }\n}\n\nfunction createComposerAttachmentsManager(\n room: OpaqueRoom,\n options: ComposerAttachmentsManagerOptions\n) {\n const attachments: Map<string, CommentMixedAttachment> = new Map();\n const abortControllers: Map<string, AbortController> = new Map();\n const eventSource = makeEventSource<void>();\n let cachedSnapshot: CommentMixedAttachment[] | null = null;\n\n function notifySubscribers() {\n // Invalidate the cached snapshot\n cachedSnapshot = null;\n eventSource.notify();\n }\n\n function uploadAttachment(attachment: CommentLocalAttachment) {\n const abortController = new AbortController();\n abortControllers.set(attachment.id, abortController);\n\n room\n .uploadAttachment(attachment, {\n signal: abortController.signal,\n })\n .then(() => {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"uploaded\",\n });\n notifySubscribers();\n })\n .catch((error) => {\n if (\n error instanceof Error &&\n error.name !== \"AbortError\" &&\n error.name !== \"TimeoutError\"\n ) {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"error\",\n error:\n error instanceof CommentsApiError && error.status === 413\n ? new AttachmentTooLargeError(\"File is too large.\", \"server\")\n : error,\n });\n notifySubscribers();\n }\n });\n }\n\n function addAttachments(addedAttachments: CommentMixedAttachment[]) {\n if (addedAttachments.length === 0) {\n return;\n }\n\n // Ignore attachments that are already in the manager\n const newAttachments = addedAttachments.filter(\n (attachment) => !attachments.has(attachment.id)\n );\n\n const attachmentsToUpload: CommentLocalAttachment[] = [];\n\n // Add all the new attachments to the manager\n for (const attachment of newAttachments) {\n if (attachment.type === \"localAttachment\") {\n // The file is too large to be uploaded\n if (attachment.file.size > options.maxFileSize) {\n attachments.set(attachment.id, {\n ...attachment,\n status: \"error\",\n error: new AttachmentTooLargeError(\"File is too large.\", \"client\"),\n });\n\n continue;\n }\n\n // Otherwise, mark the attachment to be uploaded\n attachments.set(attachment.id, {\n ...attachment,\n status: \"uploading\",\n });\n attachmentsToUpload.push(attachment);\n } else {\n attachments.set(attachment.id, attachment);\n }\n }\n\n // Notify subscribers about the new attachments that were added\n if (newAttachments.length > 0) {\n notifySubscribers();\n }\n\n // Upload all the new local attachments\n for (const attachment of attachmentsToUpload) {\n uploadAttachment(attachment);\n }\n }\n\n function removeAttachment(attachmentId: string) {\n const abortController = abortControllers.get(attachmentId);\n\n abortController?.abort();\n\n attachments.delete(attachmentId);\n abortControllers.delete(attachmentId);\n\n notifySubscribers();\n }\n\n function getSnapshot() {\n if (!cachedSnapshot) {\n cachedSnapshot = Array.from(attachments.values());\n }\n\n return cachedSnapshot;\n }\n\n // Clear all attachments and abort all ongoing uploads\n function clear() {\n abortControllers.forEach((controller) => controller.abort());\n abortControllers.clear();\n attachments.clear();\n\n notifySubscribers();\n }\n\n return {\n addAttachments,\n removeAttachment,\n getSnapshot,\n subscribe: eventSource.subscribe,\n clear,\n };\n}\n\nfunction preventBeforeUnloadDefault(event: BeforeUnloadEvent) {\n event.preventDefault();\n}\n\nexport function useComposerAttachmentsManager(\n defaultAttachments: CommentAttachment[],\n options: ComposerAttachmentsManagerOptions\n) {\n const room = useRoom();\n const frozenDefaultAttachments = useInitial(defaultAttachments);\n const frozenAttachmentsManager = useInitial(() =>\n createComposerAttachmentsManager(room, options)\n );\n\n // Initialize default attachments on mount\n useEffect(() => {\n frozenAttachmentsManager.addAttachments(frozenDefaultAttachments);\n }, [frozenDefaultAttachments, frozenAttachmentsManager]);\n\n // Clear on unmount\n useEffect(() => {\n return () => {\n frozenAttachmentsManager.clear();\n };\n }, [frozenAttachmentsManager]);\n\n const attachments = useSyncExternalStore(\n frozenAttachmentsManager.subscribe,\n frozenAttachmentsManager.getSnapshot,\n frozenAttachmentsManager.getSnapshot\n );\n\n const isUploadingAttachments = useMemo(() => {\n return attachments.some(\n (attachment) =>\n attachment.type === \"localAttachment\" &&\n attachment.status === \"uploading\"\n );\n }, [attachments]);\n\n useEffect(() => {\n if (!isUploadingAttachments) {\n return;\n }\n\n window.addEventListener(\"beforeunload\", preventBeforeUnloadDefault);\n\n return () => {\n window.removeEventListener(\"beforeunload\", preventBeforeUnloadDefault);\n };\n }, [isUploadingAttachments]);\n\n return {\n attachments,\n isUploadingAttachments,\n addAttachments: frozenAttachmentsManager.addAttachments,\n removeAttachment: frozenAttachmentsManager.removeAttachment,\n clearAttachments: frozenAttachmentsManager.clear,\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAyCO,SAAS,wCACd,OACoB,EAAA;AACpB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,SAAA;AAAA,IACN,IAAI,OAAQ,CAAA,EAAA;AAAA,GACd,CAAA;AACF,CAAA;AAEO,SAAS,sCACd,IACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,KAAK,IAAK,CAAA,GAAA;AAAA,GACZ,CAAA;AACF,CAAA;AAEO,SAAS,wCACd,IACiB,EAAA;AACjB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,KAAK,IAAK,CAAA,GAAA;AAAA,IACV,IAAA,EAAM,IAAK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A,sBAAA;AAAA,IACA,gBAAgB,wBAAyB,CAAA,cAAA;AAAA,IACzC,kBAAkB,wBAAyB,CAAA,gBAAA;AAAA,IAC3C,kBAAkB,wBAAyB,CAAA,KAAA;AAAA,GAC7C,CAAA;AACF;;;;"}
package/dist/version.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const PKG_NAME = "@liveblocks/react-ui";
4
- const PKG_VERSION = "2.8.0";
4
+ const PKG_VERSION = "2.8.2";
5
5
  const PKG_FORMAT = "cjs";
6
6
 
7
7
  exports.PKG_FORMAT = PKG_FORMAT;
package/dist/version.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  const PKG_NAME = "@liveblocks/react-ui";
2
- const PKG_VERSION = "2.8.0";
2
+ const PKG_VERSION = "2.8.2";
3
3
  const PKG_FORMAT = "esm";
4
4
 
5
5
  export { PKG_FORMAT, PKG_NAME, PKG_VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/react-ui",
3
- "version": "2.8.0",
3
+ "version": "2.8.2",
4
4
  "description": "A set of React pre-built components for the Liveblocks products. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "commonjs",
@@ -75,9 +75,9 @@
75
75
  },
76
76
  "dependencies": {
77
77
  "@floating-ui/react-dom": "^2.1.1",
78
- "@liveblocks/client": "2.8.0",
79
- "@liveblocks/core": "2.8.0",
80
- "@liveblocks/react": "2.8.0",
78
+ "@liveblocks/client": "2.8.2",
79
+ "@liveblocks/core": "2.8.2",
80
+ "@liveblocks/react": "2.8.2",
81
81
  "@radix-ui/react-dropdown-menu": "^2.0.6",
82
82
  "@radix-ui/react-popover": "^1.0.7",
83
83
  "@radix-ui/react-slot": "^1.0.2",