@liveblocks/react-ui 2.1.1-test1 → 2.2.0
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.
- package/dist/components/Comment.js +23 -11
- package/dist/components/Comment.js.map +1 -1
- package/dist/components/Comment.mjs +23 -11
- package/dist/components/Comment.mjs.map +1 -1
- package/dist/components/Composer.js.map +1 -1
- package/dist/components/Composer.mjs.map +1 -1
- package/dist/components/InboxNotification.js.map +1 -1
- package/dist/components/InboxNotification.mjs.map +1 -1
- package/dist/components/InboxNotificationList.js.map +1 -1
- package/dist/components/InboxNotificationList.mjs.map +1 -1
- package/dist/components/Thread.js +19 -9
- package/dist/components/Thread.js.map +1 -1
- package/dist/components/Thread.mjs +20 -10
- package/dist/components/Thread.mjs.map +1 -1
- package/dist/index.d.mts +5 -12
- package/dist/index.d.ts +5 -12
- package/dist/primitives/Comment/index.js +5 -3
- package/dist/primitives/Comment/index.js.map +1 -1
- package/dist/primitives/Comment/index.mjs +5 -3
- package/dist/primitives/Comment/index.mjs.map +1 -1
- package/dist/primitives/Comment/utils.js +1 -1
- package/dist/primitives/Comment/utils.js.map +1 -1
- package/dist/primitives/Comment/utils.mjs +1 -1
- package/dist/primitives/Comment/utils.mjs.map +1 -1
- package/dist/primitives/Composer/index.js +14 -11
- package/dist/primitives/Composer/index.js.map +1 -1
- package/dist/primitives/Composer/index.mjs +14 -11
- package/dist/primitives/Composer/index.mjs.map +1 -1
- package/dist/primitives/Composer/utils.js +35 -13
- package/dist/primitives/Composer/utils.js.map +1 -1
- package/dist/primitives/Composer/utils.mjs +35 -14
- package/dist/primitives/Composer/utils.mjs.map +1 -1
- package/dist/slate/plugins/auto-links.js +16 -5
- package/dist/slate/plugins/auto-links.js.map +1 -1
- package/dist/slate/plugins/auto-links.mjs +17 -6
- package/dist/slate/plugins/auto-links.mjs.map +1 -1
- package/dist/slate/plugins/custom-links.js +71 -0
- package/dist/slate/plugins/custom-links.js.map +1 -0
- package/dist/slate/plugins/custom-links.mjs +68 -0
- package/dist/slate/plugins/custom-links.mjs.map +1 -0
- package/dist/slate/plugins/paste-html.js +105 -0
- package/dist/slate/plugins/paste-html.js.map +1 -0
- package/dist/slate/plugins/paste-html.mjs +103 -0
- package/dist/slate/plugins/paste-html.mjs.map +1 -0
- package/dist/slate/utils/is-empty.js +3 -2
- package/dist/slate/utils/is-empty.js.map +1 -1
- package/dist/slate/utils/is-empty.mjs +4 -3
- package/dist/slate/utils/is-empty.mjs.map +1 -1
- package/dist/slate/utils/is-text.js +12 -0
- package/dist/slate/utils/is-text.js.map +1 -0
- package/dist/slate/utils/is-text.mjs +9 -0
- package/dist/slate/utils/is-text.mjs.map +1 -0
- package/dist/slate/utils/selection-contains-inlines.js +36 -0
- package/dist/slate/utils/selection-contains-inlines.js.map +1 -0
- package/dist/slate/utils/selection-contains-inlines.mjs +34 -0
- package/dist/slate/utils/selection-contains-inlines.mjs.map +1 -0
- package/dist/utils/use-transition.js +6 -2
- package/dist/utils/use-transition.js.map +1 -1
- package/dist/utils/use-transition.mjs +7 -3
- package/dist/utils/use-transition.mjs.map +1 -1
- package/dist/utils/use-window-focus.js +24 -0
- package/dist/utils/use-window-focus.js.map +1 -0
- package/dist/utils/use-window-focus.mjs +22 -0
- package/dist/utils/use-window-focus.mjs.map +1 -0
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/package.json +5 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommentData, CommentBody, BaseMetadata, InboxNotificationData, InboxNotificationThreadData, InboxNotificationTextMentionData, InboxNotificationCustomData, KDAD, ThreadData } from '@liveblocks/core';
|
|
1
|
+
import { CommentData, CommentBody, BaseMetadata, DM, InboxNotificationData, InboxNotificationThreadData, InboxNotificationTextMentionData, InboxNotificationCustomData, KDAD, ThreadData } from '@liveblocks/core';
|
|
2
2
|
import React, { ReactNode, ComponentPropsWithoutRef, MouseEvent, ComponentType, FormEvent, RefAttributes, ComponentProps, PropsWithChildren } from 'react';
|
|
3
3
|
|
|
4
4
|
declare type Direction = "ltr" | "rtl";
|
|
@@ -8,9 +8,6 @@ declare type SlotProp = {
|
|
|
8
8
|
*/
|
|
9
9
|
asChild?: boolean;
|
|
10
10
|
};
|
|
11
|
-
declare type ThreadMetadata = {
|
|
12
|
-
resolved?: boolean;
|
|
13
|
-
};
|
|
14
11
|
|
|
15
12
|
interface LocalizationOverrides {
|
|
16
13
|
locale: string;
|
|
@@ -225,7 +222,7 @@ declare type ComposerEditCommentProps = {
|
|
|
225
222
|
commentId: string;
|
|
226
223
|
metadata?: never;
|
|
227
224
|
};
|
|
228
|
-
declare type ComposerProps<M extends BaseMetadata =
|
|
225
|
+
declare type ComposerProps<M extends BaseMetadata = DM> = Omit<ComponentPropsWithoutRef<"form">, "defaultValue"> & (ComposerCreateThreadProps<M> | ComposerCreateCommentProps | ComposerEditCommentProps) & {
|
|
229
226
|
/**
|
|
230
227
|
* The event handler called when the composer is submitted.
|
|
231
228
|
*/
|
|
@@ -265,7 +262,7 @@ declare type ComposerProps<M extends BaseMetadata = ThreadMetadata> = Omit<Compo
|
|
|
265
262
|
* @example
|
|
266
263
|
* <Composer />
|
|
267
264
|
*/
|
|
268
|
-
declare const Composer: <M extends BaseMetadata =
|
|
265
|
+
declare const Composer: <M extends BaseMetadata = BaseMetadata>(props: ComposerProps<M> & RefAttributes<HTMLFormElement>) => JSX.Element;
|
|
269
266
|
|
|
270
267
|
interface GlobalComponents {
|
|
271
268
|
Anchor: ComponentType<ComponentPropsWithoutRef<"a">> | "a";
|
|
@@ -367,8 +364,6 @@ declare type InboxNotificationAvatarProps = AvatarProps;
|
|
|
367
364
|
declare function InboxNotificationIcon({ className, ...props }: InboxNotificationIconProps): React.JSX.Element;
|
|
368
365
|
declare function InboxNotificationAvatar({ className, ...props }: InboxNotificationAvatarProps): React.JSX.Element;
|
|
369
366
|
/**
|
|
370
|
-
* @beta
|
|
371
|
-
*
|
|
372
367
|
* Displays a single inbox notification.
|
|
373
368
|
*
|
|
374
369
|
* @example
|
|
@@ -392,8 +387,6 @@ declare const InboxNotification: React.ForwardRefExoticComponent<InboxNotificati
|
|
|
392
387
|
|
|
393
388
|
declare type InboxNotificationListProps = ComponentPropsWithoutRef<"ol">;
|
|
394
389
|
/**
|
|
395
|
-
* @beta
|
|
396
|
-
*
|
|
397
390
|
* Displays inbox notifications as a list.
|
|
398
391
|
*
|
|
399
392
|
* @example
|
|
@@ -405,7 +398,7 @@ declare type InboxNotificationListProps = ComponentPropsWithoutRef<"ol">;
|
|
|
405
398
|
*/
|
|
406
399
|
declare const InboxNotificationList: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.OlHTMLAttributes<HTMLOListElement>, HTMLOListElement>, "ref"> & React.RefAttributes<HTMLOListElement>>;
|
|
407
400
|
|
|
408
|
-
interface ThreadProps<M extends BaseMetadata =
|
|
401
|
+
interface ThreadProps<M extends BaseMetadata = DM> extends ComponentPropsWithoutRef<"div"> {
|
|
409
402
|
/**
|
|
410
403
|
* The thread to display.
|
|
411
404
|
*/
|
|
@@ -475,7 +468,7 @@ interface ThreadProps<M extends BaseMetadata = ThreadMetadata> extends Component
|
|
|
475
468
|
* ))}
|
|
476
469
|
* </>
|
|
477
470
|
*/
|
|
478
|
-
declare const Thread: <M extends BaseMetadata =
|
|
471
|
+
declare const Thread: <M extends BaseMetadata = BaseMetadata>(props: ThreadProps<M> & RefAttributes<HTMLDivElement>) => JSX.Element;
|
|
479
472
|
|
|
480
473
|
declare type LiveblocksUIConfigProps = PropsWithChildren<{
|
|
481
474
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommentData, CommentBody, BaseMetadata, InboxNotificationData, InboxNotificationThreadData, InboxNotificationTextMentionData, InboxNotificationCustomData, KDAD, ThreadData } from '@liveblocks/core';
|
|
1
|
+
import { CommentData, CommentBody, BaseMetadata, DM, InboxNotificationData, InboxNotificationThreadData, InboxNotificationTextMentionData, InboxNotificationCustomData, KDAD, ThreadData } from '@liveblocks/core';
|
|
2
2
|
import React, { ReactNode, ComponentPropsWithoutRef, MouseEvent, ComponentType, FormEvent, RefAttributes, ComponentProps, PropsWithChildren } from 'react';
|
|
3
3
|
|
|
4
4
|
declare type Direction = "ltr" | "rtl";
|
|
@@ -8,9 +8,6 @@ declare type SlotProp = {
|
|
|
8
8
|
*/
|
|
9
9
|
asChild?: boolean;
|
|
10
10
|
};
|
|
11
|
-
declare type ThreadMetadata = {
|
|
12
|
-
resolved?: boolean;
|
|
13
|
-
};
|
|
14
11
|
|
|
15
12
|
interface LocalizationOverrides {
|
|
16
13
|
locale: string;
|
|
@@ -225,7 +222,7 @@ declare type ComposerEditCommentProps = {
|
|
|
225
222
|
commentId: string;
|
|
226
223
|
metadata?: never;
|
|
227
224
|
};
|
|
228
|
-
declare type ComposerProps<M extends BaseMetadata =
|
|
225
|
+
declare type ComposerProps<M extends BaseMetadata = DM> = Omit<ComponentPropsWithoutRef<"form">, "defaultValue"> & (ComposerCreateThreadProps<M> | ComposerCreateCommentProps | ComposerEditCommentProps) & {
|
|
229
226
|
/**
|
|
230
227
|
* The event handler called when the composer is submitted.
|
|
231
228
|
*/
|
|
@@ -265,7 +262,7 @@ declare type ComposerProps<M extends BaseMetadata = ThreadMetadata> = Omit<Compo
|
|
|
265
262
|
* @example
|
|
266
263
|
* <Composer />
|
|
267
264
|
*/
|
|
268
|
-
declare const Composer: <M extends BaseMetadata =
|
|
265
|
+
declare const Composer: <M extends BaseMetadata = BaseMetadata>(props: ComposerProps<M> & RefAttributes<HTMLFormElement>) => JSX.Element;
|
|
269
266
|
|
|
270
267
|
interface GlobalComponents {
|
|
271
268
|
Anchor: ComponentType<ComponentPropsWithoutRef<"a">> | "a";
|
|
@@ -367,8 +364,6 @@ declare type InboxNotificationAvatarProps = AvatarProps;
|
|
|
367
364
|
declare function InboxNotificationIcon({ className, ...props }: InboxNotificationIconProps): React.JSX.Element;
|
|
368
365
|
declare function InboxNotificationAvatar({ className, ...props }: InboxNotificationAvatarProps): React.JSX.Element;
|
|
369
366
|
/**
|
|
370
|
-
* @beta
|
|
371
|
-
*
|
|
372
367
|
* Displays a single inbox notification.
|
|
373
368
|
*
|
|
374
369
|
* @example
|
|
@@ -392,8 +387,6 @@ declare const InboxNotification: React.ForwardRefExoticComponent<InboxNotificati
|
|
|
392
387
|
|
|
393
388
|
declare type InboxNotificationListProps = ComponentPropsWithoutRef<"ol">;
|
|
394
389
|
/**
|
|
395
|
-
* @beta
|
|
396
|
-
*
|
|
397
390
|
* Displays inbox notifications as a list.
|
|
398
391
|
*
|
|
399
392
|
* @example
|
|
@@ -405,7 +398,7 @@ declare type InboxNotificationListProps = ComponentPropsWithoutRef<"ol">;
|
|
|
405
398
|
*/
|
|
406
399
|
declare const InboxNotificationList: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.OlHTMLAttributes<HTMLOListElement>, HTMLOListElement>, "ref"> & React.RefAttributes<HTMLOListElement>>;
|
|
407
400
|
|
|
408
|
-
interface ThreadProps<M extends BaseMetadata =
|
|
401
|
+
interface ThreadProps<M extends BaseMetadata = DM> extends ComponentPropsWithoutRef<"div"> {
|
|
409
402
|
/**
|
|
410
403
|
* The thread to display.
|
|
411
404
|
*/
|
|
@@ -475,7 +468,7 @@ interface ThreadProps<M extends BaseMetadata = ThreadMetadata> extends Component
|
|
|
475
468
|
* ))}
|
|
476
469
|
* </>
|
|
477
470
|
*/
|
|
478
|
-
declare const Thread: <M extends BaseMetadata =
|
|
471
|
+
declare const Thread: <M extends BaseMetadata = BaseMetadata>(props: ThreadProps<M> & RefAttributes<HTMLDivElement>) => JSX.Element;
|
|
479
472
|
|
|
480
473
|
declare type LiveblocksUIConfigProps = PropsWithChildren<{
|
|
481
474
|
/**
|
|
@@ -39,7 +39,7 @@ const defaultBodyComponents = {
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
const CommentBody = React.forwardRef(
|
|
42
|
-
({ body, components, asChild, ...props }, forwardedRef) => {
|
|
42
|
+
({ body, components, style, asChild, ...props }, forwardedRef) => {
|
|
43
43
|
const Component = asChild ? reactSlot.Slot : "div";
|
|
44
44
|
const { Mention, Link } = React.useMemo(
|
|
45
45
|
() => ({ ...defaultBodyComponents, ...components }),
|
|
@@ -50,12 +50,14 @@ const CommentBody = React.forwardRef(
|
|
|
50
50
|
}
|
|
51
51
|
return /* @__PURE__ */ React.createElement(Component, {
|
|
52
52
|
...props,
|
|
53
|
+
style: { whiteSpace: "break-spaces", ...style },
|
|
53
54
|
ref: forwardedRef
|
|
54
55
|
}, body.content.map((block, index) => {
|
|
55
56
|
switch (block.type) {
|
|
56
57
|
case "paragraph":
|
|
57
58
|
return /* @__PURE__ */ React.createElement("p", {
|
|
58
|
-
key: index
|
|
59
|
+
key: index,
|
|
60
|
+
style: { minHeight: "1lh" }
|
|
59
61
|
}, block.children.map((inline, index2) => {
|
|
60
62
|
if (utils.isCommentBodyMention(inline)) {
|
|
61
63
|
return inline.id ? /* @__PURE__ */ React.createElement(Mention, {
|
|
@@ -68,7 +70,7 @@ const CommentBody = React.forwardRef(
|
|
|
68
70
|
return /* @__PURE__ */ React.createElement(Link, {
|
|
69
71
|
href,
|
|
70
72
|
key: index2
|
|
71
|
-
}, inline.url);
|
|
73
|
+
}, inline.text ?? inline.url);
|
|
72
74
|
}
|
|
73
75
|
let children = inline.text;
|
|
74
76
|
if (inline.bold) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/primitives/Comment/index.tsx"],"sourcesContent":["import { Slot } from \"@radix-ui/react-slot\";\nimport type { ReactNode } from \"react\";\nimport React, { forwardRef, useMemo } from \"react\";\n\nimport { MENTION_CHARACTER } from \"../../slate/plugins/mentions\";\nimport type {\n CommentBodyComponents,\n CommentBodyProps,\n CommentLinkProps,\n CommentMentionProps,\n} from \"./types\";\nimport {\n isCommentBodyLink,\n isCommentBodyMention,\n toAbsoluteUrl,\n} from \"./utils\";\n\nconst COMMENT_MENTION_NAME = \"CommentMention\";\nconst COMMENT_BODY_NAME = \"CommentBody\";\nconst COMMENT_LINK_NAME = \"CommentLink\";\n\n/**\n * Displays mentions within `Comment.Body`.\n *\n * @example\n * <Comment.Mention>@{userId}</Comment.Mention>\n */\nconst CommentMention = forwardRef<HTMLSpanElement, CommentMentionProps>(\n ({ children, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"span\";\n\n return (\n <Component {...props} ref={forwardedRef}>\n {children}\n </Component>\n );\n }\n);\n\n/**\n * Displays links within `Comment.Body`.\n *\n * @example\n * <Comment.Link href={href}>{children}</Comment.Link>\n */\nconst CommentLink = forwardRef<HTMLAnchorElement, CommentLinkProps>(\n ({ children, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"a\";\n\n return (\n <Component\n target=\"_blank\"\n rel=\"noopener noreferrer nofollow\"\n {...props}\n ref={forwardedRef}\n >\n {children}\n </Component>\n );\n }\n);\n\nconst defaultBodyComponents: CommentBodyComponents = {\n Mention: ({ userId }) => {\n return (\n <CommentMention>\n {MENTION_CHARACTER}\n {userId}\n </CommentMention>\n );\n },\n Link: ({ href, children }) => {\n return <CommentLink href={href}>{children}</CommentLink>;\n },\n};\n\n/**\n * Displays a comment body.\n *\n * @example\n * <Comment.Body body={comment.body} />\n */\nconst CommentBody = forwardRef<HTMLDivElement, CommentBodyProps>(\n ({ body, components, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"div\";\n const { Mention, Link } = useMemo(\n () => ({ ...defaultBodyComponents, ...components }),\n [components]\n );\n\n if (!body || !body?.content) {\n return null;\n }\n\n return (\n <Component
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/primitives/Comment/index.tsx"],"sourcesContent":["import { Slot } from \"@radix-ui/react-slot\";\nimport type { ReactNode } from \"react\";\nimport React, { forwardRef, useMemo } from \"react\";\n\nimport { MENTION_CHARACTER } from \"../../slate/plugins/mentions\";\nimport type {\n CommentBodyComponents,\n CommentBodyProps,\n CommentLinkProps,\n CommentMentionProps,\n} from \"./types\";\nimport {\n isCommentBodyLink,\n isCommentBodyMention,\n toAbsoluteUrl,\n} from \"./utils\";\n\nconst COMMENT_MENTION_NAME = \"CommentMention\";\nconst COMMENT_BODY_NAME = \"CommentBody\";\nconst COMMENT_LINK_NAME = \"CommentLink\";\n\n/**\n * Displays mentions within `Comment.Body`.\n *\n * @example\n * <Comment.Mention>@{userId}</Comment.Mention>\n */\nconst CommentMention = forwardRef<HTMLSpanElement, CommentMentionProps>(\n ({ children, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"span\";\n\n return (\n <Component {...props} ref={forwardedRef}>\n {children}\n </Component>\n );\n }\n);\n\n/**\n * Displays links within `Comment.Body`.\n *\n * @example\n * <Comment.Link href={href}>{children}</Comment.Link>\n */\nconst CommentLink = forwardRef<HTMLAnchorElement, CommentLinkProps>(\n ({ children, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"a\";\n\n return (\n <Component\n target=\"_blank\"\n rel=\"noopener noreferrer nofollow\"\n {...props}\n ref={forwardedRef}\n >\n {children}\n </Component>\n );\n }\n);\n\nconst defaultBodyComponents: CommentBodyComponents = {\n Mention: ({ userId }) => {\n return (\n <CommentMention>\n {MENTION_CHARACTER}\n {userId}\n </CommentMention>\n );\n },\n Link: ({ href, children }) => {\n return <CommentLink href={href}>{children}</CommentLink>;\n },\n};\n\n/**\n * Displays a comment body.\n *\n * @example\n * <Comment.Body body={comment.body} />\n */\nconst CommentBody = forwardRef<HTMLDivElement, CommentBodyProps>(\n ({ body, components, style, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"div\";\n const { Mention, Link } = useMemo(\n () => ({ ...defaultBodyComponents, ...components }),\n [components]\n );\n\n if (!body || !body?.content) {\n return null;\n }\n\n return (\n <Component\n {...props}\n style={{ whiteSpace: \"break-spaces\", ...style }}\n ref={forwardedRef}\n >\n {body.content.map((block, index) => {\n switch (block.type) {\n case \"paragraph\":\n return (\n <p key={index} style={{ minHeight: \"1lh\" }}>\n {block.children.map((inline, index) => {\n if (isCommentBodyMention(inline)) {\n return inline.id ? (\n <Mention userId={inline.id} key={index} />\n ) : null;\n }\n\n if (isCommentBodyLink(inline)) {\n const href = toAbsoluteUrl(inline.url) ?? inline.url;\n\n return (\n <Link href={href} key={index}>\n {inline.text ?? inline.url}\n </Link>\n );\n }\n\n // <code><s><em><strong>text</strong></s></em></code>\n let children: ReactNode = inline.text;\n\n if (inline.bold) {\n children = <strong key={index}>{children}</strong>;\n }\n\n if (inline.italic) {\n children = <em key={index}>{children}</em>;\n }\n\n if (inline.strikethrough) {\n children = <s key={index}>{children}</s>;\n }\n\n if (inline.code) {\n children = <code key={index}>{children}</code>;\n }\n\n return <span key={index}>{children}</span>;\n })}\n </p>\n );\n default:\n return null;\n }\n })}\n </Component>\n );\n }\n);\n\nif (process.env.NODE_ENV !== \"production\") {\n CommentBody.displayName = COMMENT_BODY_NAME;\n CommentMention.displayName = COMMENT_MENTION_NAME;\n CommentLink.displayName = COMMENT_LINK_NAME;\n}\n\n// NOTE: Every export from this file will be available publicly as Comment.*\nexport { CommentBody as Body, CommentLink as Link, CommentMention as Mention };\n"],"names":["forwardRef","Slot","MENTION_CHARACTER","useMemo","index","isCommentBodyMention","isCommentBodyLink","toAbsoluteUrl"],"mappings":";;;;;;;AAiBA,MAAM,oBAAuB,GAAA,gBAAA,CAAA;AAC7B,MAAM,iBAAoB,GAAA,aAAA,CAAA;AAC1B,MAAM,iBAAoB,GAAA,aAAA,CAAA;AAQ1B,MAAM,cAAiB,GAAAA,gBAAA;AAAA,EACrB,CAAC,EAAE,QAAA,EAAU,OAAY,EAAA,GAAA,KAAA,IAAS,YAAiB,KAAA;AACjD,IAAM,MAAA,SAAA,GAAY,UAAUC,cAAO,GAAA,MAAA,CAAA;AAEnC,IAAA,uBACG,KAAA,CAAA,aAAA,CAA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,GAAA,oBAAA,CAAA;AAC7B,EAAA,WAAA,CAAY,WAAc,GAAA,iBAAA,CAAA;AAC5B;;;;;;"}
|
|
@@ -37,7 +37,7 @@ const defaultBodyComponents = {
|
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
const CommentBody = forwardRef(
|
|
40
|
-
({ body, components, asChild, ...props }, forwardedRef) => {
|
|
40
|
+
({ body, components, style, asChild, ...props }, forwardedRef) => {
|
|
41
41
|
const Component = asChild ? Slot : "div";
|
|
42
42
|
const { Mention, Link } = useMemo(
|
|
43
43
|
() => ({ ...defaultBodyComponents, ...components }),
|
|
@@ -48,12 +48,14 @@ const CommentBody = forwardRef(
|
|
|
48
48
|
}
|
|
49
49
|
return /* @__PURE__ */ React__default.createElement(Component, {
|
|
50
50
|
...props,
|
|
51
|
+
style: { whiteSpace: "break-spaces", ...style },
|
|
51
52
|
ref: forwardedRef
|
|
52
53
|
}, body.content.map((block, index) => {
|
|
53
54
|
switch (block.type) {
|
|
54
55
|
case "paragraph":
|
|
55
56
|
return /* @__PURE__ */ React__default.createElement("p", {
|
|
56
|
-
key: index
|
|
57
|
+
key: index,
|
|
58
|
+
style: { minHeight: "1lh" }
|
|
57
59
|
}, block.children.map((inline, index2) => {
|
|
58
60
|
if (isCommentBodyMention(inline)) {
|
|
59
61
|
return inline.id ? /* @__PURE__ */ React__default.createElement(Mention, {
|
|
@@ -66,7 +68,7 @@ const CommentBody = forwardRef(
|
|
|
66
68
|
return /* @__PURE__ */ React__default.createElement(Link, {
|
|
67
69
|
href,
|
|
68
70
|
key: index2
|
|
69
|
-
}, inline.url);
|
|
71
|
+
}, inline.text ?? inline.url);
|
|
70
72
|
}
|
|
71
73
|
let children = inline.text;
|
|
72
74
|
if (inline.bold) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/primitives/Comment/index.tsx"],"sourcesContent":["import { Slot } from \"@radix-ui/react-slot\";\nimport type { ReactNode } from \"react\";\nimport React, { forwardRef, useMemo } from \"react\";\n\nimport { MENTION_CHARACTER } from \"../../slate/plugins/mentions\";\nimport type {\n CommentBodyComponents,\n CommentBodyProps,\n CommentLinkProps,\n CommentMentionProps,\n} from \"./types\";\nimport {\n isCommentBodyLink,\n isCommentBodyMention,\n toAbsoluteUrl,\n} from \"./utils\";\n\nconst COMMENT_MENTION_NAME = \"CommentMention\";\nconst COMMENT_BODY_NAME = \"CommentBody\";\nconst COMMENT_LINK_NAME = \"CommentLink\";\n\n/**\n * Displays mentions within `Comment.Body`.\n *\n * @example\n * <Comment.Mention>@{userId}</Comment.Mention>\n */\nconst CommentMention = forwardRef<HTMLSpanElement, CommentMentionProps>(\n ({ children, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"span\";\n\n return (\n <Component {...props} ref={forwardedRef}>\n {children}\n </Component>\n );\n }\n);\n\n/**\n * Displays links within `Comment.Body`.\n *\n * @example\n * <Comment.Link href={href}>{children}</Comment.Link>\n */\nconst CommentLink = forwardRef<HTMLAnchorElement, CommentLinkProps>(\n ({ children, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"a\";\n\n return (\n <Component\n target=\"_blank\"\n rel=\"noopener noreferrer nofollow\"\n {...props}\n ref={forwardedRef}\n >\n {children}\n </Component>\n );\n }\n);\n\nconst defaultBodyComponents: CommentBodyComponents = {\n Mention: ({ userId }) => {\n return (\n <CommentMention>\n {MENTION_CHARACTER}\n {userId}\n </CommentMention>\n );\n },\n Link: ({ href, children }) => {\n return <CommentLink href={href}>{children}</CommentLink>;\n },\n};\n\n/**\n * Displays a comment body.\n *\n * @example\n * <Comment.Body body={comment.body} />\n */\nconst CommentBody = forwardRef<HTMLDivElement, CommentBodyProps>(\n ({ body, components, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"div\";\n const { Mention, Link } = useMemo(\n () => ({ ...defaultBodyComponents, ...components }),\n [components]\n );\n\n if (!body || !body?.content) {\n return null;\n }\n\n return (\n <Component
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/primitives/Comment/index.tsx"],"sourcesContent":["import { Slot } from \"@radix-ui/react-slot\";\nimport type { ReactNode } from \"react\";\nimport React, { forwardRef, useMemo } from \"react\";\n\nimport { MENTION_CHARACTER } from \"../../slate/plugins/mentions\";\nimport type {\n CommentBodyComponents,\n CommentBodyProps,\n CommentLinkProps,\n CommentMentionProps,\n} from \"./types\";\nimport {\n isCommentBodyLink,\n isCommentBodyMention,\n toAbsoluteUrl,\n} from \"./utils\";\n\nconst COMMENT_MENTION_NAME = \"CommentMention\";\nconst COMMENT_BODY_NAME = \"CommentBody\";\nconst COMMENT_LINK_NAME = \"CommentLink\";\n\n/**\n * Displays mentions within `Comment.Body`.\n *\n * @example\n * <Comment.Mention>@{userId}</Comment.Mention>\n */\nconst CommentMention = forwardRef<HTMLSpanElement, CommentMentionProps>(\n ({ children, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"span\";\n\n return (\n <Component {...props} ref={forwardedRef}>\n {children}\n </Component>\n );\n }\n);\n\n/**\n * Displays links within `Comment.Body`.\n *\n * @example\n * <Comment.Link href={href}>{children}</Comment.Link>\n */\nconst CommentLink = forwardRef<HTMLAnchorElement, CommentLinkProps>(\n ({ children, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"a\";\n\n return (\n <Component\n target=\"_blank\"\n rel=\"noopener noreferrer nofollow\"\n {...props}\n ref={forwardedRef}\n >\n {children}\n </Component>\n );\n }\n);\n\nconst defaultBodyComponents: CommentBodyComponents = {\n Mention: ({ userId }) => {\n return (\n <CommentMention>\n {MENTION_CHARACTER}\n {userId}\n </CommentMention>\n );\n },\n Link: ({ href, children }) => {\n return <CommentLink href={href}>{children}</CommentLink>;\n },\n};\n\n/**\n * Displays a comment body.\n *\n * @example\n * <Comment.Body body={comment.body} />\n */\nconst CommentBody = forwardRef<HTMLDivElement, CommentBodyProps>(\n ({ body, components, style, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"div\";\n const { Mention, Link } = useMemo(\n () => ({ ...defaultBodyComponents, ...components }),\n [components]\n );\n\n if (!body || !body?.content) {\n return null;\n }\n\n return (\n <Component\n {...props}\n style={{ whiteSpace: \"break-spaces\", ...style }}\n ref={forwardedRef}\n >\n {body.content.map((block, index) => {\n switch (block.type) {\n case \"paragraph\":\n return (\n <p key={index} style={{ minHeight: \"1lh\" }}>\n {block.children.map((inline, index) => {\n if (isCommentBodyMention(inline)) {\n return inline.id ? (\n <Mention userId={inline.id} key={index} />\n ) : null;\n }\n\n if (isCommentBodyLink(inline)) {\n const href = toAbsoluteUrl(inline.url) ?? inline.url;\n\n return (\n <Link href={href} key={index}>\n {inline.text ?? inline.url}\n </Link>\n );\n }\n\n // <code><s><em><strong>text</strong></s></em></code>\n let children: ReactNode = inline.text;\n\n if (inline.bold) {\n children = <strong key={index}>{children}</strong>;\n }\n\n if (inline.italic) {\n children = <em key={index}>{children}</em>;\n }\n\n if (inline.strikethrough) {\n children = <s key={index}>{children}</s>;\n }\n\n if (inline.code) {\n children = <code key={index}>{children}</code>;\n }\n\n return <span key={index}>{children}</span>;\n })}\n </p>\n );\n default:\n return null;\n }\n })}\n </Component>\n );\n }\n);\n\nif (process.env.NODE_ENV !== \"production\") {\n CommentBody.displayName = COMMENT_BODY_NAME;\n CommentMention.displayName = COMMENT_MENTION_NAME;\n CommentLink.displayName = COMMENT_LINK_NAME;\n}\n\n// NOTE: Every export from this file will be available publicly as Comment.*\nexport { CommentBody as Body, CommentLink as Link, CommentMention as Mention };\n"],"names":["React","index"],"mappings":";;;;;AAiBA,MAAM,oBAAuB,GAAA,gBAAA,CAAA;AAC7B,MAAM,iBAAoB,GAAA,aAAA,CAAA;AAC1B,MAAM,iBAAoB,GAAA,aAAA,CAAA;AAQ1B,MAAM,cAAiB,GAAA,UAAA;AAAA,EACrB,CAAC,EAAE,QAAA,EAAU,OAAY,EAAA,GAAA,KAAA,IAAS,YAAiB,KAAA;AACjD,IAAM,MAAA,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A;AACzC,EAAA,WAAA,CAAY,WAAc,GAAA,iBAAA,CAAA;AAC1B,EAAA,cAAA,CAAe,WAAc,GAAA,oBAAA,CAAA;AAC7B,EAAA,WAAA,CAAY,WAAc,GAAA,iBAAA,CAAA;AAC5B;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
function isCommentBodyText(element) {
|
|
4
|
-
return "text" in element && typeof element.text === "string";
|
|
4
|
+
return !("type" in element) && "text" in element && typeof element.text === "string";
|
|
5
5
|
}
|
|
6
6
|
function isCommentBodyMention(element) {
|
|
7
7
|
return "type" in element && element.type === "mention";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/primitives/Comment/utils.ts"],"sourcesContent":["import type {\n CommentBodyElement,\n CommentBodyLink,\n CommentBodyMention,\n CommentBodyText,\n} from \"@liveblocks/core\";\n\nexport function isCommentBodyText(\n element: CommentBodyElement\n): element is CommentBodyText {\n return \"text\" in element
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/primitives/Comment/utils.ts"],"sourcesContent":["import type {\n CommentBodyElement,\n CommentBodyLink,\n CommentBodyMention,\n CommentBodyText,\n} from \"@liveblocks/core\";\n\nexport function isCommentBodyText(\n element: CommentBodyElement\n): element is CommentBodyText {\n return (\n !(\"type\" in element) &&\n \"text\" in element &&\n typeof element.text === \"string\"\n );\n}\n\nexport function isCommentBodyMention(\n element: CommentBodyElement\n): element is CommentBodyMention {\n return \"type\" in element && element.type === \"mention\";\n}\n\nexport function isCommentBodyLink(\n element: CommentBodyElement\n): element is CommentBodyLink {\n return \"type\" in element && element.type === \"link\";\n}\n\n/**\n * Helper function to convert a URL (relative or absolute) to an absolute URL.\n *\n * @param url The URL to convert to an absolute URL (relative or absolute).\n * @returns The absolute URL or undefined if the URL is invalid.\n */\nexport function toAbsoluteUrl(url: string): string | undefined {\n // Check if the URL already contains a scheme\n if (url.startsWith(\"http://\") || url.startsWith(\"https://\")) {\n return url;\n } else if (url.startsWith(\"www.\")) {\n // If the URL starts with \"www.\", prepend \"https://\"\n return \"https://\" + url;\n }\n\n return;\n}\n"],"names":[],"mappings":";;AAOO,SAAS,kBACd,OAC4B,EAAA;AAC5B,EAAA,OACE,EAAE,MAAU,IAAA,OAAA,CAAA,IACZ,UAAU,OACV,IAAA,OAAO,QAAQ,IAAS,KAAA,QAAA,CAAA;AAE5B,CAAA;AAEO,SAAS,qBACd,OAC+B,EAAA;AAC/B,EAAO,OAAA,MAAA,IAAU,OAAW,IAAA,OAAA,CAAQ,IAAS,KAAA,SAAA,CAAA;AAC/C,CAAA;AAEO,SAAS,kBACd,OAC4B,EAAA;AAC5B,EAAO,OAAA,MAAA,IAAU,OAAW,IAAA,OAAA,CAAQ,IAAS,KAAA,MAAA,CAAA;AAC/C,CAAA;AAQO,SAAS,cAAc,GAAiC,EAAA;AAE7D,EAAA,IAAI,IAAI,UAAW,CAAA,SAAS,KAAK,GAAI,CAAA,UAAA,CAAW,UAAU,CAAG,EAAA;AAC3D,IAAO,OAAA,GAAA,CAAA;AAAA,GACE,MAAA,IAAA,GAAA,CAAI,UAAW,CAAA,MAAM,CAAG,EAAA;AAEjC,IAAA,OAAO,UAAa,GAAA,GAAA,CAAA;AAAA,GACtB;AAEA,EAAA,OAAA;AACF;;;;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function isCommentBodyText(element) {
|
|
2
|
-
return "text" in element && typeof element.text === "string";
|
|
2
|
+
return !("type" in element) && "text" in element && typeof element.text === "string";
|
|
3
3
|
}
|
|
4
4
|
function isCommentBodyMention(element) {
|
|
5
5
|
return "type" in element && element.type === "mention";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../../src/primitives/Comment/utils.ts"],"sourcesContent":["import type {\n CommentBodyElement,\n CommentBodyLink,\n CommentBodyMention,\n CommentBodyText,\n} from \"@liveblocks/core\";\n\nexport function isCommentBodyText(\n element: CommentBodyElement\n): element is CommentBodyText {\n return \"text\" in element
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../../src/primitives/Comment/utils.ts"],"sourcesContent":["import type {\n CommentBodyElement,\n CommentBodyLink,\n CommentBodyMention,\n CommentBodyText,\n} from \"@liveblocks/core\";\n\nexport function isCommentBodyText(\n element: CommentBodyElement\n): element is CommentBodyText {\n return (\n !(\"type\" in element) &&\n \"text\" in element &&\n typeof element.text === \"string\"\n );\n}\n\nexport function isCommentBodyMention(\n element: CommentBodyElement\n): element is CommentBodyMention {\n return \"type\" in element && element.type === \"mention\";\n}\n\nexport function isCommentBodyLink(\n element: CommentBodyElement\n): element is CommentBodyLink {\n return \"type\" in element && element.type === \"link\";\n}\n\n/**\n * Helper function to convert a URL (relative or absolute) to an absolute URL.\n *\n * @param url The URL to convert to an absolute URL (relative or absolute).\n * @returns The absolute URL or undefined if the URL is invalid.\n */\nexport function toAbsoluteUrl(url: string): string | undefined {\n // Check if the URL already contains a scheme\n if (url.startsWith(\"http://\") || url.startsWith(\"https://\")) {\n return url;\n } else if (url.startsWith(\"www.\")) {\n // If the URL starts with \"www.\", prepend \"https://\"\n return \"https://\" + url;\n }\n\n return;\n}\n"],"names":[],"mappings":"AAOO,SAAS,kBACd,OAC4B,EAAA;AAC5B,EAAA,OACE,EAAE,MAAU,IAAA,OAAA,CAAA,IACZ,UAAU,OACV,IAAA,OAAO,QAAQ,IAAS,KAAA,QAAA,CAAA;AAE5B,CAAA;AAEO,SAAS,qBACd,OAC+B,EAAA;AAC/B,EAAO,OAAA,MAAA,IAAU,OAAW,IAAA,OAAA,CAAQ,IAAS,KAAA,SAAA,CAAA;AAC/C,CAAA;AAEO,SAAS,kBACd,OAC4B,EAAA;AAC5B,EAAO,OAAA,MAAA,IAAU,OAAW,IAAA,OAAA,CAAQ,IAAS,KAAA,MAAA,CAAA;AAC/C,CAAA;AAQO,SAAS,cAAc,GAAiC,EAAA;AAE7D,EAAA,IAAI,IAAI,UAAW,CAAA,SAAS,KAAK,GAAI,CAAA,UAAA,CAAW,UAAU,CAAG,EAAA;AAC3D,IAAO,OAAA,GAAA,CAAA;AAAA,GACE,MAAA,IAAA,GAAA,CAAI,UAAW,CAAA,MAAM,CAAG,EAAA;AAEjC,IAAA,OAAO,UAAa,GAAA,GAAA,CAAA;AAAA,GACtB;AAEA,EAAA,OAAA;AACF;;;;"}
|
|
@@ -13,8 +13,10 @@ var constants = require('../../constants.js');
|
|
|
13
13
|
var shared = require('../../shared.js');
|
|
14
14
|
var autoFormatting = require('../../slate/plugins/auto-formatting.js');
|
|
15
15
|
var autoLinks = require('../../slate/plugins/auto-links.js');
|
|
16
|
+
var customLinks = require('../../slate/plugins/custom-links.js');
|
|
16
17
|
var emptyClearFormatting = require('../../slate/plugins/empty-clear-formatting.js');
|
|
17
18
|
var mentions = require('../../slate/plugins/mentions.js');
|
|
19
|
+
var pasteHtml = require('../../slate/plugins/paste-html.js');
|
|
18
20
|
var getDomRange = require('../../slate/utils/get-dom-range.js');
|
|
19
21
|
var isEmpty = require('../../slate/utils/is-empty.js');
|
|
20
22
|
var marks = require('../../slate/utils/marks.js');
|
|
@@ -45,10 +47,14 @@ const emptyCommentBody = {
|
|
|
45
47
|
content: [{ type: "paragraph", children: [{ text: "" }] }]
|
|
46
48
|
};
|
|
47
49
|
function createComposerEditor() {
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
autoFormatting.withAutoFormatting(
|
|
50
|
+
return mentions.withMentions(
|
|
51
|
+
customLinks.withCustomLinks(
|
|
52
|
+
autoLinks.withAutoLinks(
|
|
53
|
+
autoFormatting.withAutoFormatting(
|
|
54
|
+
emptyClearFormatting.withEmptyClearFormatting(
|
|
55
|
+
pasteHtml.withPasteHtml(slateHistory.withHistory(slateReact.withReact(slate.createEditor())))
|
|
56
|
+
)
|
|
57
|
+
)
|
|
52
58
|
)
|
|
53
59
|
)
|
|
54
60
|
);
|
|
@@ -197,6 +203,7 @@ function ComposerEditorElement({
|
|
|
197
203
|
...props
|
|
198
204
|
});
|
|
199
205
|
case "auto-link":
|
|
206
|
+
case "custom-link":
|
|
200
207
|
return /* @__PURE__ */ React.createElement(ComposerEditorLinkWrapper, {
|
|
201
208
|
Link,
|
|
202
209
|
...props
|
|
@@ -568,13 +575,9 @@ const ComposerEditor = React.forwardRef(
|
|
|
568
575
|
selectedMentionSuggestionUserId
|
|
569
576
|
]
|
|
570
577
|
);
|
|
571
|
-
React.useImperativeHandle(
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
return slateReact.ReactEditor.toDOMNode(editor, editor);
|
|
575
|
-
},
|
|
576
|
-
[editor]
|
|
577
|
-
);
|
|
578
|
+
React.useImperativeHandle(forwardedRef, () => {
|
|
579
|
+
return slateReact.ReactEditor.toDOMNode(editor, editor);
|
|
580
|
+
}, [editor]);
|
|
578
581
|
React.useEffect(() => {
|
|
579
582
|
if (autoFocus) {
|
|
580
583
|
focus();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/primitives/Composer/index.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n DetectOverflowOptions,\n UseFloatingOptions,\n} from \"@floating-ui/react-dom\";\nimport {\n autoUpdate,\n flip,\n hide,\n limitShift,\n shift,\n size,\n useFloating,\n} from \"@floating-ui/react-dom\";\nimport type { CommentBody } from \"@liveblocks/core\";\nimport { useSelf } from \"@liveblocks/react\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport type {\n AriaAttributes,\n FocusEvent,\n FormEvent,\n KeyboardEvent,\n PointerEvent,\n} from \"react\";\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type {\n Descendant as SlateDescendant,\n Element as SlateElement,\n} from \"slate\";\nimport {\n createEditor,\n Editor as SlateEditor,\n insertText as insertSlateText,\n Transforms as SlateTransforms,\n} from \"slate\";\nimport { withHistory } from \"slate-history\";\nimport type {\n RenderElementProps,\n RenderElementSpecificProps,\n RenderLeafProps,\n RenderPlaceholderProps,\n} from \"slate-react\";\nimport {\n Editable,\n ReactEditor,\n Slate,\n useSelected,\n useSlateStatic,\n withReact,\n} from \"slate-react\";\n\nimport { useLiveblocksUIConfig } from \"../../config\";\nimport { FLOATING_ELEMENT_COLLISION_PADDING } from \"../../constants\";\nimport { useMentionSuggestions } from \"../../shared\";\nimport { withAutoFormatting } from \"../../slate/plugins/auto-formatting\";\nimport { withAutoLinks } from \"../../slate/plugins/auto-links\";\nimport { withEmptyClearFormatting } from \"../../slate/plugins/empty-clear-formatting\";\nimport type { MentionDraft } from \"../../slate/plugins/mentions\";\nimport {\n getMentionDraftAtSelection,\n insertMention,\n insertMentionCharacter,\n MENTION_CHARACTER,\n withMentions,\n} from \"../../slate/plugins/mentions\";\nimport { getDOMRange } from \"../../slate/utils/get-dom-range\";\nimport { isEmpty as isEditorEmpty } from \"../../slate/utils/is-empty\";\nimport { leaveMarkEdge, toggleMark } from \"../../slate/utils/marks\";\nimport type {\n ComposerBody as ComposerBodyData,\n ComposerBodyAutoLink,\n ComposerBodyMention,\n} from \"../../types\";\nimport { isKey } from \"../../utils/is-key\";\nimport { Persist, useAnimationPersist, usePersist } from \"../../utils/Persist\";\nimport { Portal } from \"../../utils/Portal\";\nimport { requestSubmit } from \"../../utils/request-submit\";\nimport { useId } from \"../../utils/use-id\";\nimport { useIndex } from \"../../utils/use-index\";\nimport { useInitial } from \"../../utils/use-initial\";\nimport { useLayoutEffect } from \"../../utils/use-layout-effect\";\nimport { useRefs } from \"../../utils/use-refs\";\nimport { toAbsoluteUrl } from \"../Comment/utils\";\nimport {\n ComposerContext,\n ComposerEditorContext,\n ComposerSuggestionsContext,\n useComposer,\n useComposerEditorContext,\n useComposerSuggestionsContext,\n} from \"./contexts\";\nimport type {\n ComposerEditorComponents,\n ComposerEditorElementProps,\n ComposerEditorLinkWrapperProps,\n ComposerEditorMentionSuggestionsWrapperProps,\n ComposerEditorMentionWrapperProps,\n ComposerEditorProps,\n ComposerFormProps,\n ComposerLinkProps,\n ComposerMentionProps,\n ComposerSubmitProps,\n ComposerSuggestionsListItemProps,\n ComposerSuggestionsListProps,\n ComposerSuggestionsProps,\n SuggestionsPosition,\n} from \"./types\";\nimport {\n commentBodyToComposerBody,\n composerBodyToCommentBody,\n getPlacementFromPosition,\n getSideAndAlignFromPlacement,\n} from \"./utils\";\n\nconst MENTION_SUGGESTIONS_POSITION: SuggestionsPosition = \"top\";\n\nconst COMPOSER_MENTION_NAME = \"ComposerMention\";\nconst COMPOSER_LINK_NAME = \"ComposerLink\";\nconst COMPOSER_SUGGESTIONS_NAME = \"ComposerSuggestions\";\nconst COMPOSER_SUGGESTIONS_LIST_NAME = \"ComposerSuggestionsList\";\nconst COMPOSER_SUGGESTIONS_LIST_ITEM_NAME = \"ComposerSuggestionsListItem\";\nconst COMPOSER_SUBMIT_NAME = \"ComposerSubmit\";\nconst COMPOSER_EDITOR_NAME = \"ComposerEditor\";\nconst COMPOSER_FORM_NAME = \"ComposerForm\";\n\nconst emptyCommentBody: CommentBody = {\n version: 1,\n content: [{ type: \"paragraph\", children: [{ text: \"\" }] }],\n};\n\nfunction createComposerEditor() {\n return withAutoLinks(\n withMentions(\n withEmptyClearFormatting(\n withAutoFormatting(withHistory(withReact(createEditor())))\n )\n )\n );\n}\n\nfunction ComposerEditorMentionWrapper({\n Mention,\n attributes,\n children,\n element,\n}: ComposerEditorMentionWrapperProps) {\n const isSelected = useSelected();\n\n return (\n <span {...attributes}>\n {element.id ? (\n <Mention userId={element.id} isSelected={isSelected} />\n ) : null}\n {children}\n </span>\n );\n}\n\nfunction ComposerEditorLinkWrapper({\n Link,\n attributes,\n element,\n children,\n}: ComposerEditorLinkWrapperProps) {\n const href = useMemo(\n () => toAbsoluteUrl(element.url) ?? element.url,\n [element.url]\n );\n\n return (\n <span {...attributes}>\n <Link href={href}>{children}</Link>\n </span>\n );\n}\n\nfunction ComposerEditorMentionSuggestionsWrapper({\n id,\n itemId,\n userIds,\n selectedUserId,\n setSelectedUserId,\n mentionDraft,\n onItemSelect,\n position = MENTION_SUGGESTIONS_POSITION,\n dir,\n MentionSuggestions,\n}: ComposerEditorMentionSuggestionsWrapperProps) {\n const editor = useSlateStatic();\n const { isFocused } = useComposer();\n const [content, setContent] = useState<HTMLDivElement | null>(null);\n const [contentZIndex, setContentZIndex] = useState<string>();\n const contentRef = useCallback(setContent, [setContent]);\n const { portalContainer } = useLiveblocksUIConfig();\n const floatingOptions: UseFloatingOptions = useMemo(() => {\n const detectOverflowOptions: DetectOverflowOptions = {\n padding: FLOATING_ELEMENT_COLLISION_PADDING,\n };\n\n return {\n strategy: \"fixed\",\n placement: getPlacementFromPosition(position, dir),\n middleware: [\n flip({ ...detectOverflowOptions, crossAxis: false }),\n hide(detectOverflowOptions),\n shift({\n ...detectOverflowOptions,\n limiter: limitShift(),\n }),\n size({\n ...detectOverflowOptions,\n apply({ availableWidth, availableHeight, elements }) {\n elements.floating.style.setProperty(\n \"--lb-composer-suggestions-available-width\",\n `${availableWidth}px`\n );\n elements.floating.style.setProperty(\n \"--lb-composer-suggestions-available-height\",\n `${availableHeight}px`\n );\n },\n }),\n ],\n whileElementsMounted: autoUpdate,\n };\n }, [position, dir]);\n const {\n refs: { setReference, setFloating },\n strategy,\n isPositioned,\n placement,\n x,\n y,\n } = useFloating(floatingOptions);\n\n // Copy `z-index` from content to wrapper.\n // Inspired by https://github.com/radix-ui/primitives/blob/main/packages/react/popper/src/Popper.tsx\n useLayoutEffect(() => {\n if (content) {\n setContentZIndex(window.getComputedStyle(content).zIndex);\n }\n }, [content]);\n\n useLayoutEffect(() => {\n if (!mentionDraft) {\n return;\n }\n\n const domRange = getDOMRange(editor, mentionDraft.range);\n\n if (domRange) {\n setReference({\n getBoundingClientRect: () => domRange.getBoundingClientRect(),\n getClientRects: () => domRange.getClientRects(),\n });\n }\n }, [setReference, editor, mentionDraft]);\n\n return (\n <Persist>\n {mentionDraft?.range && isFocused && userIds ? (\n <ComposerSuggestionsContext.Provider\n value={{\n id,\n itemId,\n selectedValue: selectedUserId,\n setSelectedValue: setSelectedUserId,\n onItemSelect,\n placement,\n dir,\n ref: contentRef,\n }}\n >\n <Portal\n ref={setFloating}\n container={portalContainer}\n style={{\n position: strategy,\n top: 0,\n left: 0,\n transform: isPositioned\n ? `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`\n : \"translate3d(0, -200%, 0)\",\n minWidth: \"max-content\",\n zIndex: contentZIndex,\n }}\n >\n <MentionSuggestions\n userIds={userIds}\n selectedUserId={selectedUserId}\n />\n </Portal>\n </ComposerSuggestionsContext.Provider>\n ) : null}\n </Persist>\n );\n}\n\nfunction ComposerEditorElement({\n Mention,\n Link,\n ...props\n}: ComposerEditorElementProps) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const { attributes, children, element } = props;\n\n switch (element.type) {\n case \"mention\":\n return (\n <ComposerEditorMentionWrapper\n Mention={Mention}\n {...(props as RenderElementSpecificProps<ComposerBodyMention>)}\n />\n );\n case \"auto-link\":\n return (\n <ComposerEditorLinkWrapper\n Link={Link}\n {...(props as RenderElementSpecificProps<ComposerBodyAutoLink>)}\n />\n );\n case \"paragraph\":\n return (\n <p {...attributes} style={{ position: \"relative\" }}>\n {children}\n </p>\n );\n default:\n return null;\n }\n}\n\n// <code><s><em><strong>text</strong></s></em></code>\nfunction ComposerEditorLeaf({ attributes, children, leaf }: RenderLeafProps) {\n if (leaf.bold) {\n children = <strong>{children}</strong>;\n }\n\n if (leaf.italic) {\n children = <em>{children}</em>;\n }\n\n if (leaf.strikethrough) {\n children = <s>{children}</s>;\n }\n\n if (leaf.code) {\n children = <code>{children}</code>;\n }\n\n return <span {...attributes}>{children}</span>;\n}\n\nfunction ComposerEditorPlaceholder({\n attributes,\n children,\n}: RenderPlaceholderProps) {\n const { opacity: _opacity, ...style } = attributes.style;\n\n return (\n <span {...attributes} style={style} data-placeholder=\"\">\n {children}\n </span>\n );\n}\n\n/**\n * Displays mentions within `Composer.Editor`.\n *\n * @example\n * <Composer.Mention>@{userId}</Composer.Mention>\n */\nconst ComposerMention = forwardRef<HTMLSpanElement, ComposerMentionProps>(\n ({ children, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"span\";\n const isSelected = useSelected();\n\n return (\n <Component\n data-selected={isSelected || undefined}\n {...props}\n ref={forwardedRef}\n >\n {children}\n </Component>\n );\n }\n);\n\n/**\n * Displays links within `Composer.Editor`.\n *\n * @example\n * <Composer.Link href={href}>{children}</Composer.Link>\n */\nconst ComposerLink = forwardRef<HTMLAnchorElement, ComposerLinkProps>(\n ({ children, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"a\";\n\n return (\n <Component\n target=\"_blank\"\n rel=\"noopener noreferrer nofollow\"\n {...props}\n ref={forwardedRef}\n >\n {children}\n </Component>\n );\n }\n);\n\n/**\n * Contains suggestions within `Composer.Editor`.\n */\nconst ComposerSuggestions = forwardRef<\n HTMLDivElement,\n ComposerSuggestionsProps\n>(({ children, style, asChild, ...props }, forwardedRef) => {\n const [isPresent] = usePersist();\n const ref = useRef<HTMLDivElement>(null);\n const {\n ref: contentRef,\n placement,\n dir,\n } = useComposerSuggestionsContext(COMPOSER_SUGGESTIONS_NAME);\n const mergedRefs = useRefs(forwardedRef, contentRef, ref);\n const [side, align] = useMemo(\n () => getSideAndAlignFromPlacement(placement),\n [placement]\n );\n const Component = asChild ? Slot : \"div\";\n useAnimationPersist(ref);\n\n return (\n <Component\n dir={dir}\n {...props}\n data-state={isPresent ? \"open\" : \"closed\"}\n data-side={side}\n data-align={align}\n style={{\n display: \"flex\",\n flexDirection: \"column\",\n maxHeight: \"var(--lb-composer-suggestions-available-height)\",\n overflowY: \"auto\",\n ...style,\n }}\n ref={mergedRefs}\n >\n {children}\n </Component>\n );\n});\n\n/**\n * Displays a list of suggestions within `Composer.Editor`.\n *\n * @example\n * <Composer.SuggestionsList>\n * {userIds.map((userId) => (\n * <Composer.SuggestionsListItem key={userId} value={userId}>\n * @{userId}\n * </Composer.SuggestionsListItem>\n * ))}\n * </Composer.SuggestionsList>\n */\nconst ComposerSuggestionsList = forwardRef<\n HTMLUListElement,\n ComposerSuggestionsListProps\n>(({ children, asChild, ...props }, forwardedRef) => {\n const { id } = useComposerSuggestionsContext(COMPOSER_SUGGESTIONS_LIST_NAME);\n const Component = asChild ? Slot : \"ul\";\n\n return (\n <Component\n role=\"listbox\"\n id={id}\n aria-label=\"Suggestions list\"\n {...props}\n ref={forwardedRef}\n >\n {children}\n </Component>\n );\n});\n\n/**\n * Displays a suggestion within `Composer.SuggestionsList`.\n *\n * @example\n * <Composer.SuggestionsListItem key={userId} value={userId}>\n * @{userId}\n * </Composer.SuggestionsListItem>\n */\nconst ComposerSuggestionsListItem = forwardRef<\n HTMLLIElement,\n ComposerSuggestionsListItemProps\n>(\n (\n { value, children, onPointerMove, onPointerDown, asChild, ...props },\n forwardedRef\n ) => {\n const ref = useRef<HTMLLIElement>(null);\n const mergedRefs = useRefs(forwardedRef, ref);\n const { selectedValue, setSelectedValue, itemId, onItemSelect } =\n useComposerSuggestionsContext(COMPOSER_SUGGESTIONS_LIST_ITEM_NAME);\n const Component = asChild ? Slot : \"li\";\n const isSelected = useMemo(\n () => selectedValue === value,\n [selectedValue, value]\n );\n // TODO: Support props.id if provided, it will need to be sent up to Composer.Editor to use it in aria-activedescendant\n const id = useMemo(() => itemId(value), [itemId, value]);\n\n useEffect(() => {\n if (ref?.current && isSelected) {\n ref.current.scrollIntoView({ block: \"nearest\" });\n }\n }, [isSelected]);\n\n const handlePointerMove = useCallback(\n (event: PointerEvent<HTMLLIElement>) => {\n onPointerMove?.(event);\n\n if (!event.isDefaultPrevented()) {\n setSelectedValue(value);\n }\n },\n [onPointerMove, setSelectedValue, value]\n );\n\n const handlePointerDown = useCallback(\n (event: PointerEvent<HTMLLIElement>) => {\n onPointerDown?.(event);\n\n if (!event.isDefaultPrevented()) {\n const target = event.target as HTMLElement;\n\n if (target.hasPointerCapture(event.pointerId)) {\n target.releasePointerCapture(event.pointerId);\n }\n\n if (event.button === 0 && event.ctrlKey === false) {\n onItemSelect(value);\n\n event.preventDefault();\n }\n }\n },\n [onItemSelect, onPointerDown, value]\n );\n\n return (\n <Component\n role=\"option\"\n id={id}\n data-selected={isSelected || undefined}\n aria-selected={isSelected || undefined}\n onPointerMove={handlePointerMove}\n onPointerDown={handlePointerDown}\n {...props}\n ref={mergedRefs}\n >\n {children}\n </Component>\n );\n }\n);\n\nconst defaultEditorComponents: ComposerEditorComponents = {\n Link: ({ href, children }) => {\n return <ComposerLink href={href}>{children}</ComposerLink>;\n },\n Mention: ({ userId }) => {\n return (\n <ComposerMention>\n {MENTION_CHARACTER}\n {userId}\n </ComposerMention>\n );\n },\n MentionSuggestions: ({ userIds }) => {\n return userIds.length > 0 ? (\n <ComposerSuggestions>\n <ComposerSuggestionsList>\n {userIds.map((userId) => (\n <ComposerSuggestionsListItem key={userId} value={userId}>\n {userId}\n </ComposerSuggestionsListItem>\n ))}\n </ComposerSuggestionsList>\n </ComposerSuggestions>\n ) : null;\n },\n};\n\n/**\n * Displays the composer's editor.\n *\n * @example\n * <Composer.Editor placeholder=\"Write a comment…\" />\n */\nconst ComposerEditor = forwardRef<HTMLDivElement, ComposerEditorProps>(\n (\n {\n defaultValue,\n onKeyDown,\n onFocus,\n onBlur,\n disabled,\n autoFocus,\n components,\n dir,\n ...props\n },\n forwardedRef\n ) => {\n const self = useSelf();\n const isDisabled = useMemo(\n () => disabled || !self?.canComment,\n [disabled, self?.canComment]\n );\n const { editor, validate, setFocused } = useComposerEditorContext();\n const { submit, focus, select, isEmpty, isFocused } = useComposer();\n const initialBody = useInitial(defaultValue ?? emptyCommentBody);\n const initialEditorValue = useMemo(() => {\n return commentBodyToComposerBody(initialBody);\n }, [initialBody]);\n const { Link, Mention, MentionSuggestions } = useMemo(\n () => ({ ...defaultEditorComponents, ...components }),\n [components]\n );\n\n const [mentionDraft, setMentionDraft] = useState<MentionDraft>();\n const mentionSuggestions = useMentionSuggestions(mentionDraft?.text);\n const [\n selectedMentionSuggestionIndex,\n setPreviousSelectedMentionSuggestionIndex,\n setNextSelectedMentionSuggestionIndex,\n setSelectedMentionSuggestionIndex,\n ] = useIndex(0, mentionSuggestions?.length ?? 0);\n const id = useId();\n const suggestionsListId = useMemo(\n () => `liveblocks-suggestions-list-${id}`,\n [id]\n );\n const suggestionsListItemId = useCallback(\n (userId?: string) =>\n userId ? `liveblocks-suggestions-list-item-${id}-${userId}` : undefined,\n [id]\n );\n const renderElement = useCallback(\n (props: RenderElementProps) => {\n return (\n <ComposerEditorElement Mention={Mention} Link={Link} {...props} />\n );\n },\n [Link, Mention]\n );\n\n const handleChange = useCallback(\n (value: SlateDescendant[]) => {\n validate(value as SlateElement[]);\n\n setMentionDraft(getMentionDraftAtSelection(editor));\n },\n [editor, validate]\n );\n\n const createMention = useCallback(\n (userId?: string) => {\n if (!mentionDraft || !userId) {\n return;\n }\n\n SlateTransforms.select(editor, mentionDraft.range);\n insertMention(editor, userId);\n setMentionDraft(undefined);\n setSelectedMentionSuggestionIndex(0);\n },\n [editor, mentionDraft, setSelectedMentionSuggestionIndex]\n );\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n\n if (event.isDefaultPrevented()) {\n return;\n }\n\n // Allow leaving marks with ArrowLeft\n if (isKey(event, \"ArrowLeft\")) {\n leaveMarkEdge(editor, \"start\");\n }\n\n // Allow leaving marks with ArrowRight\n if (isKey(event, \"ArrowRight\")) {\n leaveMarkEdge(editor, \"end\");\n }\n\n if (mentionDraft && mentionSuggestions?.length) {\n // Select the next mention suggestion on ArrowDown\n if (isKey(event, \"ArrowDown\")) {\n event.preventDefault();\n setNextSelectedMentionSuggestionIndex();\n }\n\n // Select the previous mention suggestion on ArrowUp\n if (isKey(event, \"ArrowUp\")) {\n event.preventDefault();\n setPreviousSelectedMentionSuggestionIndex();\n }\n\n // Create a mention on Enter/Tab\n if (isKey(event, \"Enter\") || isKey(event, \"Tab\")) {\n event.preventDefault();\n\n const userId = mentionSuggestions?.[selectedMentionSuggestionIndex];\n createMention(userId);\n }\n\n // Close the suggestions on Escape\n if (isKey(event, \"Escape\")) {\n event.preventDefault();\n setMentionDraft(undefined);\n setSelectedMentionSuggestionIndex(0);\n }\n } else {\n // Blur the editor on Escape\n if (isKey(event, \"Escape\")) {\n event.preventDefault();\n ReactEditor.blur(editor);\n }\n\n // Submit the editor on Enter\n if (isKey(event, \"Enter\", { shift: false }) && !isEmpty) {\n event.preventDefault();\n submit();\n }\n\n // Create a new line on Shift + Enter\n if (isKey(event, \"Enter\", { shift: true })) {\n event.preventDefault();\n editor.insertBreak();\n }\n\n // Toggle bold on Command/Control + B\n if (isKey(event, \"b\", { mod: true })) {\n event.preventDefault();\n toggleMark(editor, \"bold\");\n }\n\n // Toggle italic on Command/Control + I\n if (isKey(event, \"i\", { mod: true })) {\n event.preventDefault();\n toggleMark(editor, \"italic\");\n }\n\n // Toggle strikethrough on Command/Control + Shift + S\n if (isKey(event, \"s\", { mod: true, shift: true })) {\n event.preventDefault();\n toggleMark(editor, \"strikethrough\");\n }\n\n // Toggle code on Command/Control + E\n if (isKey(event, \"e\", { mod: true })) {\n event.preventDefault();\n toggleMark(editor, \"code\");\n }\n }\n },\n [\n createMention,\n editor,\n isEmpty,\n mentionDraft,\n mentionSuggestions,\n selectedMentionSuggestionIndex,\n onKeyDown,\n setNextSelectedMentionSuggestionIndex,\n setPreviousSelectedMentionSuggestionIndex,\n setSelectedMentionSuggestionIndex,\n submit,\n ]\n );\n\n const handleFocus = useCallback(\n (event: FocusEvent<HTMLDivElement>) => {\n onFocus?.(event);\n\n if (!event.isDefaultPrevented()) {\n setFocused(true);\n }\n },\n [onFocus, setFocused]\n );\n\n const handleBlur = useCallback(\n (event: FocusEvent<HTMLDivElement>) => {\n onBlur?.(event);\n\n if (!event.isDefaultPrevented()) {\n setFocused(false);\n }\n },\n [onBlur, setFocused]\n );\n\n const selectedMentionSuggestionUserId = useMemo(\n () => mentionSuggestions?.[selectedMentionSuggestionIndex],\n [selectedMentionSuggestionIndex, mentionSuggestions]\n );\n const setSelectedMentionSuggestionUserId = useCallback(\n (userId: string) => {\n const index = mentionSuggestions?.indexOf(userId);\n\n if (index !== undefined && index >= 0) {\n setSelectedMentionSuggestionIndex(index);\n }\n },\n [setSelectedMentionSuggestionIndex, mentionSuggestions]\n );\n\n const propsWhileSuggesting: AriaAttributes = useMemo(\n () =>\n mentionDraft\n ? {\n role: \"combobox\",\n \"aria-autocomplete\": \"list\",\n \"aria-expanded\": true,\n \"aria-controls\": suggestionsListId,\n \"aria-activedescendant\": suggestionsListItemId(\n selectedMentionSuggestionUserId\n ),\n }\n : {},\n [\n mentionDraft,\n suggestionsListId,\n suggestionsListItemId,\n selectedMentionSuggestionUserId,\n ]\n );\n\n useImperativeHandle(\n forwardedRef,\n () => {\n return ReactEditor.toDOMNode(editor, editor) as HTMLDivElement;\n },\n [editor]\n );\n\n // Manually focus the editor when `autoFocus` is true\n useEffect(() => {\n if (autoFocus) {\n focus();\n }\n }, [autoFocus, editor, focus]);\n\n // Manually add a selection in the editor if the selection\n // is still empty after being focused\n useEffect(() => {\n if (isFocused && editor.selection === null) {\n select();\n }\n }, [editor, select, isFocused]);\n\n return (\n <Slate\n editor={editor}\n initialValue={initialEditorValue}\n onChange={handleChange}\n >\n <Editable\n dir={dir}\n enterKeyHint={mentionDraft ? \"enter\" : \"send\"}\n autoCapitalize=\"sentences\"\n aria-label=\"Composer editor\"\n data-focused={isFocused || undefined}\n data-disabled={isDisabled || undefined}\n {...propsWhileSuggesting}\n {...props}\n readOnly={isDisabled}\n disabled={isDisabled}\n onKeyDown={handleKeyDown}\n onFocus={handleFocus}\n onBlur={handleBlur}\n renderElement={renderElement}\n renderLeaf={ComposerEditorLeaf}\n renderPlaceholder={ComposerEditorPlaceholder}\n />\n <ComposerEditorMentionSuggestionsWrapper\n dir={dir}\n mentionDraft={mentionDraft}\n selectedUserId={selectedMentionSuggestionUserId}\n setSelectedUserId={setSelectedMentionSuggestionUserId}\n userIds={mentionSuggestions}\n id={suggestionsListId}\n itemId={suggestionsListItemId}\n onItemSelect={createMention}\n MentionSuggestions={MentionSuggestions}\n />\n </Slate>\n );\n }\n);\n\n/**\n * Surrounds the composer's content and handles submissions.\n *\n * @example\n * <Composer.Form onComposerSubmit={({ body }) => {}}>\n *\t <Composer.Editor />\n * <Composer.Submit />\n * </Composer.Form>\n */\nconst ComposerForm = forwardRef<HTMLFormElement, ComposerFormProps>(\n (\n { children, onSubmit, onComposerSubmit, asChild, ...props },\n forwardedRef\n ) => {\n const Component = asChild ? Slot : \"form\";\n const editor = useInitial(createComposerEditor);\n const [isEmpty, setEmpty] = useState(true);\n const [isFocused, setFocused] = useState(false);\n const ref = useRef<HTMLFormElement>(null);\n const mergedRefs = useRefs(forwardedRef, ref);\n\n const validate = useCallback(\n (value: SlateElement[]) => {\n setEmpty(isEditorEmpty(editor, value));\n },\n [editor]\n );\n\n const submit = useCallback(() => {\n // We need to wait for the next frame in some cases like when composing diacritics,\n // we want any native handling to be done first while still being handled on `keydown`.\n requestAnimationFrame(() => {\n if (ref.current) {\n requestSubmit(ref.current);\n }\n });\n }, []);\n\n const clear = useCallback(() => {\n SlateTransforms.delete(editor, {\n at: {\n anchor: SlateEditor.start(editor, []),\n focus: SlateEditor.end(editor, []),\n },\n });\n }, [editor]);\n\n const select = useCallback(() => {\n SlateTransforms.select(editor, {\n anchor: SlateEditor.end(editor, []),\n focus: SlateEditor.end(editor, []),\n });\n }, [editor]);\n\n const focus = useCallback(\n (resetSelection = true) => {\n if (!ReactEditor.isFocused(editor)) {\n SlateTransforms.select(\n editor,\n resetSelection || !editor.selection\n ? SlateEditor.end(editor, [])\n : editor.selection\n );\n ReactEditor.focus(editor);\n }\n },\n [editor]\n );\n\n const blur = useCallback(() => {\n ReactEditor.blur(editor);\n }, [editor]);\n\n const onSubmitEnd = useCallback(() => {\n clear();\n blur();\n }, [blur, clear]);\n\n const createMention = useCallback(() => {\n focus();\n insertMentionCharacter(editor);\n }, [editor, focus]);\n\n const insertText = useCallback(\n (text: string) => {\n focus(false);\n insertSlateText(editor, text);\n },\n [editor, focus]\n );\n\n const handleSubmit = useCallback(\n (event: FormEvent<HTMLFormElement>) => {\n // In some situations (e.g. pressing Enter while composing diacritics), it's possible\n // for the form to be submitted as empty even though we already checked whether the\n // editor was empty when handling the key press.\n const isEmpty = isEditorEmpty(editor, editor.children);\n\n // We even prevent the user's `onSubmit` handler from being called if the editor is empty.\n if (isEmpty) {\n event.preventDefault();\n\n return;\n }\n\n onSubmit?.(event);\n\n if (!onComposerSubmit || event.isDefaultPrevented()) {\n event.preventDefault();\n\n return;\n }\n\n const body = composerBodyToCommentBody(\n editor.children as ComposerBodyData\n );\n const comment = { body };\n\n const promise = onComposerSubmit(comment, event);\n\n event.preventDefault();\n\n if (promise) {\n promise.then(onSubmitEnd);\n } else {\n onSubmitEnd();\n }\n },\n [editor, onComposerSubmit, onSubmit, onSubmitEnd]\n );\n\n return (\n <ComposerEditorContext.Provider\n value={{\n editor,\n validate,\n setFocused,\n }}\n >\n <ComposerContext.Provider\n value={{\n isFocused,\n isEmpty,\n submit,\n clear,\n select,\n focus,\n blur,\n createMention,\n insertText,\n }}\n >\n <Component {...props} onSubmit={handleSubmit} ref={mergedRefs}>\n {children}\n </Component>\n </ComposerContext.Provider>\n </ComposerEditorContext.Provider>\n );\n }\n);\n\n/**\n * A button to submit the composer.\n *\n * @example\n * <Composer.Submit>Send</Composer.Submit>\n */\nconst ComposerSubmit = forwardRef<HTMLButtonElement, ComposerSubmitProps>(\n ({ children, disabled, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"button\";\n const { isEmpty } = useComposer();\n const self = useSelf();\n const isDisabled = useMemo(\n () => disabled || isEmpty || !self?.canComment,\n [disabled, isEmpty, self?.canComment]\n );\n\n return (\n <Component\n type=\"submit\"\n {...props}\n ref={forwardedRef}\n disabled={isDisabled}\n >\n {children}\n </Component>\n );\n }\n);\n\nif (process.env.NODE_ENV !== \"production\") {\n ComposerEditor.displayName = COMPOSER_EDITOR_NAME;\n ComposerForm.displayName = COMPOSER_FORM_NAME;\n ComposerMention.displayName = COMPOSER_MENTION_NAME;\n ComposerLink.displayName = COMPOSER_LINK_NAME;\n ComposerSubmit.displayName = COMPOSER_SUBMIT_NAME;\n ComposerSuggestions.displayName = COMPOSER_SUGGESTIONS_NAME;\n ComposerSuggestionsList.displayName = COMPOSER_SUGGESTIONS_LIST_NAME;\n ComposerSuggestionsListItem.displayName = COMPOSER_SUGGESTIONS_LIST_ITEM_NAME;\n}\n\n// NOTE: Every export from this file will be available publicly as Composer.*\nexport {\n ComposerEditor as Editor,\n ComposerForm as Form,\n ComposerLink as Link,\n ComposerMention as Mention,\n ComposerSubmit as Submit,\n ComposerSuggestions as Suggestions,\n ComposerSuggestionsList as SuggestionsList,\n ComposerSuggestionsListItem as SuggestionsListItem,\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2HA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAAsC;AAC3B;AAEX;AAEA;AACE;AAAO;AACL;AACE;AAC2D;AAC3D;AACF;AAEJ;AAEA;AAAsC;AACpC;AACA;AACA;AAEF;AACE;AAEA;AACG;AAAS;AAEL;AAAwB;AAAI;AAKrC;AAEA;AAAmC;AACjC;AACA;AACA;AAEF;AACE;AAAa;AACiC;AAChC;AAGd;AACG;AAAS;AACP;AAAK;AAGZ;AAEA;AAAiD;AAC/C;AACA;AACA;AACA;AACA;AACA;AACA;AACW;AACX;AAEF;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACE;AAAqD;AAC1C;AAGX;AAAO;AACK;AACuC;AACrC;AACyC;AACzB;AACpB;AACD;AACiB;AACrB;AACI;AACA;AAED;AAAwB;AACtB;AACG;AAEL;AAAwB;AACtB;AACG;AACL;AACF;AACD;AACH;AACsB;AACxB;AAEF;AAAM;AAC8B;AAClC;AACA;AACA;AACA;AACA;AAKF;AACE;AACE;AAAwD;AAC1D;AAGF;AACE;AACE;AAAA;AAGF;AAEA;AACE;AAAa;AACiD;AACd;AAC/C;AACH;AAGF;AAGO;AACQ;AACL;AACA;AACe;AACG;AAClB;AACA;AACA;AACK;AACP;AAEC;AACM;AACM;AACJ;AACK;AACL;AACC;AAGF;AACM;AACF;AACV;AAEC;AACC;AACA;AAOd;AAEA;AAA+B;AAC7B;AACA;AAEF;AAEE;AAEA;AAAsB;AAElB;AACG;AACC;AACK;AACP;AAGF;AACG;AACC;AACK;AACP;AAGF;AACG;AAAM;AAA0C;AAEjD;AAGF;AAAO;AAEb;AAGA;AACE;AACE;AAA6B;AAG/B;AACE;AAAyB;AAG3B;AACE;AAAwB;AAG1B;AACE;AAA2B;AAG7B;AAAQ;AAAS;AACnB;AAEA;AAAmC;AACjC;AAEF;AACE;AAEA;AACG;AAAS;AAAY;AAA+B;AAIzD;AAQA;AAAwB;AAEpB;AACA;AAEA;AACG;AAC8B;AACzB;AACC;AAGP;AAGN;AAQA;AAAqB;AAEjB;AAEA;AACG;AACQ;AACH;AACA;AACC;AAGP;AAGN;AAKM;AAIJ;AACA;AACA;AAAM;AACC;AACL;AACA;AAEF;AACA;AAAsB;AACwB;AAClC;AAEZ;AACA;AAEA;AACG;AACC;AACI;AAC6B;AACtB;AACC;AACL;AACI;AACM;AACJ;AACA;AACR;AACL;AACK;AAKX;AAcM;AAIJ;AACA;AAEA;AACG;AACM;AACL;AACW;AACP;AACC;AAKX;AAUA;AAAoC;AAQhC;AACA;AACA;AAEA;AACA;AAAmB;AACO;AACH;AAGvB;AAEA;AACE;AACE;AAA+C;AACjD;AAGF;AAA0B;AAEtB;AAEA;AACE;AAAsB;AACxB;AACF;AACuC;AAGzC;AAA0B;AAEtB;AAEA;AACE;AAEA;AACE;AAA4C;AAG9C;AACE;AAEA;AAAqB;AACvB;AACF;AACF;AACmC;AAGrC;AACG;A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GrC;AACQ;AACe;AACJ;AACA;AACQ;AACvB;AACF;AAED;AACP;AACE;AACA;AACA;AACA;AACF;AAGF;AAAA;AACE;AAEE;AAA2C;AAC7C;AACO;AAIT;AACE;AACE;AAAM;AACR;AAKF;AACE;AACE;AAAO;AACT;AAGF;AACG;AACC;AACc;AACJ;AAET;AACC;AACuC;AACxB;AACJ;AACgB;AACE;AACzB;AACA;AACM;AACA;AACC;AACF;AACD;AACR;AACY;AACO;AAEpB;AACC;AACA;AACgB;AACG;AACV;AACL;AACI;AACM;AACd;AAEJ;AAGN;AAWA;AAAqB;AAKjB;AACA;AACA;AACA;AACA;AACA;AAEA;AAAiB;AAEb;AAAqC;AACvC;AACO;AAGT;AAGE;AACE;AACE;AAAyB;AAC3B;AACD;AAGH;AACE;AAA+B;AACzB;AACkC;AACH;AACnC;AACD;AAGH;AACE;AAA+B;AACK;AACD;AAClC;AAGH;AAAc;AAEV;AACE;AAAgB;AACd;AAGW;AAEb;AAAwB;AAC1B;AACF;AACO;AAGT;AACE;AAAuB;AAGzB;AACE;AACA;AAAK;AAGP;AACE;AACA;AAA6B;AAG/B;AAAmB;AAEf;AACA;AAA4B;AAC9B;AACc;AAGhB;AAAqB;AAKjB;AAGA;AACE;AAEA;AAAA;AAGF;AAEA;AACE;AAEA;AAAA;AAGF;AAAa;AACJ;AAET;AAEA;AAEA;AAEA;AACE;AAAwB;AAExB;AAAY;AACd;AACF;AACgD;AAGlD;AACG;AACQ;AACL;AACA;AACA;AACF;AAEC;AACQ;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF;AAEC;AAAc;AAAiB;AAAmB;AAIvD;AAGN;AAQA;AAAuB;AAEnB;AACA;AACA;AACA;AAAmB;AACmB;AACA;AAGtC;AACG;AACM;AACD;AACC;AACK;AAGZ;AAGN;AAEA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/primitives/Composer/index.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n DetectOverflowOptions,\n UseFloatingOptions,\n} from \"@floating-ui/react-dom\";\nimport {\n autoUpdate,\n flip,\n hide,\n limitShift,\n shift,\n size,\n useFloating,\n} from \"@floating-ui/react-dom\";\nimport type { CommentBody } from \"@liveblocks/core\";\nimport { useSelf } from \"@liveblocks/react\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport type {\n AriaAttributes,\n FocusEvent,\n FormEvent,\n KeyboardEvent,\n PointerEvent,\n} from \"react\";\nimport React, {\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type {\n Descendant as SlateDescendant,\n Element as SlateElement,\n} from \"slate\";\nimport {\n createEditor,\n Editor as SlateEditor,\n insertText as insertSlateText,\n Transforms as SlateTransforms,\n} from \"slate\";\nimport { withHistory } from \"slate-history\";\nimport type {\n RenderElementProps,\n RenderElementSpecificProps,\n RenderLeafProps,\n RenderPlaceholderProps,\n} from \"slate-react\";\nimport {\n Editable,\n ReactEditor,\n Slate,\n useSelected,\n useSlateStatic,\n withReact,\n} from \"slate-react\";\n\nimport { useLiveblocksUIConfig } from \"../../config\";\nimport { FLOATING_ELEMENT_COLLISION_PADDING } from \"../../constants\";\nimport { useMentionSuggestions } from \"../../shared\";\nimport { withAutoFormatting } from \"../../slate/plugins/auto-formatting\";\nimport { withAutoLinks } from \"../../slate/plugins/auto-links\";\nimport { withCustomLinks } from \"../../slate/plugins/custom-links\";\nimport { withEmptyClearFormatting } from \"../../slate/plugins/empty-clear-formatting\";\nimport type { MentionDraft } from \"../../slate/plugins/mentions\";\nimport {\n getMentionDraftAtSelection,\n insertMention,\n insertMentionCharacter,\n MENTION_CHARACTER,\n withMentions,\n} from \"../../slate/plugins/mentions\";\nimport { withPasteHtml } from \"../../slate/plugins/paste-html\";\nimport { getDOMRange } from \"../../slate/utils/get-dom-range\";\nimport { isEmpty as isEditorEmpty } from \"../../slate/utils/is-empty\";\nimport { leaveMarkEdge, toggleMark } from \"../../slate/utils/marks\";\nimport type {\n ComposerBody as ComposerBodyData,\n ComposerBodyAutoLink,\n ComposerBodyCustomLink,\n ComposerBodyMention,\n} from \"../../types\";\nimport { isKey } from \"../../utils/is-key\";\nimport { Persist, useAnimationPersist, usePersist } from \"../../utils/Persist\";\nimport { Portal } from \"../../utils/Portal\";\nimport { requestSubmit } from \"../../utils/request-submit\";\nimport { useId } from \"../../utils/use-id\";\nimport { useIndex } from \"../../utils/use-index\";\nimport { useInitial } from \"../../utils/use-initial\";\nimport { useLayoutEffect } from \"../../utils/use-layout-effect\";\nimport { useRefs } from \"../../utils/use-refs\";\nimport { toAbsoluteUrl } from \"../Comment/utils\";\nimport {\n ComposerContext,\n ComposerEditorContext,\n ComposerSuggestionsContext,\n useComposer,\n useComposerEditorContext,\n useComposerSuggestionsContext,\n} from \"./contexts\";\nimport type {\n ComposerEditorComponents,\n ComposerEditorElementProps,\n ComposerEditorLinkWrapperProps,\n ComposerEditorMentionSuggestionsWrapperProps,\n ComposerEditorMentionWrapperProps,\n ComposerEditorProps,\n ComposerFormProps,\n ComposerLinkProps,\n ComposerMentionProps,\n ComposerSubmitProps,\n ComposerSuggestionsListItemProps,\n ComposerSuggestionsListProps,\n ComposerSuggestionsProps,\n SuggestionsPosition,\n} from \"./types\";\nimport {\n commentBodyToComposerBody,\n composerBodyToCommentBody,\n getPlacementFromPosition,\n getSideAndAlignFromPlacement,\n} from \"./utils\";\n\nconst MENTION_SUGGESTIONS_POSITION: SuggestionsPosition = \"top\";\n\nconst COMPOSER_MENTION_NAME = \"ComposerMention\";\nconst COMPOSER_LINK_NAME = \"ComposerLink\";\nconst COMPOSER_SUGGESTIONS_NAME = \"ComposerSuggestions\";\nconst COMPOSER_SUGGESTIONS_LIST_NAME = \"ComposerSuggestionsList\";\nconst COMPOSER_SUGGESTIONS_LIST_ITEM_NAME = \"ComposerSuggestionsListItem\";\nconst COMPOSER_SUBMIT_NAME = \"ComposerSubmit\";\nconst COMPOSER_EDITOR_NAME = \"ComposerEditor\";\nconst COMPOSER_FORM_NAME = \"ComposerForm\";\n\nconst emptyCommentBody: CommentBody = {\n version: 1,\n content: [{ type: \"paragraph\", children: [{ text: \"\" }] }],\n};\n\nfunction createComposerEditor() {\n return withMentions(\n withCustomLinks(\n withAutoLinks(\n withAutoFormatting(\n withEmptyClearFormatting(\n withPasteHtml(withHistory(withReact(createEditor())))\n )\n )\n )\n )\n );\n}\n\nfunction ComposerEditorMentionWrapper({\n Mention,\n attributes,\n children,\n element,\n}: ComposerEditorMentionWrapperProps) {\n const isSelected = useSelected();\n\n return (\n <span {...attributes}>\n {element.id ? (\n <Mention userId={element.id} isSelected={isSelected} />\n ) : null}\n {children}\n </span>\n );\n}\n\nfunction ComposerEditorLinkWrapper({\n Link,\n attributes,\n element,\n children,\n}: ComposerEditorLinkWrapperProps) {\n const href = useMemo(\n () => toAbsoluteUrl(element.url) ?? element.url,\n [element.url]\n );\n\n return (\n <span {...attributes}>\n <Link href={href}>{children}</Link>\n </span>\n );\n}\n\nfunction ComposerEditorMentionSuggestionsWrapper({\n id,\n itemId,\n userIds,\n selectedUserId,\n setSelectedUserId,\n mentionDraft,\n onItemSelect,\n position = MENTION_SUGGESTIONS_POSITION,\n dir,\n MentionSuggestions,\n}: ComposerEditorMentionSuggestionsWrapperProps) {\n const editor = useSlateStatic();\n const { isFocused } = useComposer();\n const [content, setContent] = useState<HTMLDivElement | null>(null);\n const [contentZIndex, setContentZIndex] = useState<string>();\n const contentRef = useCallback(setContent, [setContent]);\n const { portalContainer } = useLiveblocksUIConfig();\n const floatingOptions: UseFloatingOptions = useMemo(() => {\n const detectOverflowOptions: DetectOverflowOptions = {\n padding: FLOATING_ELEMENT_COLLISION_PADDING,\n };\n\n return {\n strategy: \"fixed\",\n placement: getPlacementFromPosition(position, dir),\n middleware: [\n flip({ ...detectOverflowOptions, crossAxis: false }),\n hide(detectOverflowOptions),\n shift({\n ...detectOverflowOptions,\n limiter: limitShift(),\n }),\n size({\n ...detectOverflowOptions,\n apply({ availableWidth, availableHeight, elements }) {\n elements.floating.style.setProperty(\n \"--lb-composer-suggestions-available-width\",\n `${availableWidth}px`\n );\n elements.floating.style.setProperty(\n \"--lb-composer-suggestions-available-height\",\n `${availableHeight}px`\n );\n },\n }),\n ],\n whileElementsMounted: autoUpdate,\n };\n }, [position, dir]);\n const {\n refs: { setReference, setFloating },\n strategy,\n isPositioned,\n placement,\n x,\n y,\n } = useFloating(floatingOptions);\n\n // Copy `z-index` from content to wrapper.\n // Inspired by https://github.com/radix-ui/primitives/blob/main/packages/react/popper/src/Popper.tsx\n useLayoutEffect(() => {\n if (content) {\n setContentZIndex(window.getComputedStyle(content).zIndex);\n }\n }, [content]);\n\n useLayoutEffect(() => {\n if (!mentionDraft) {\n return;\n }\n\n const domRange = getDOMRange(editor, mentionDraft.range);\n\n if (domRange) {\n setReference({\n getBoundingClientRect: () => domRange.getBoundingClientRect(),\n getClientRects: () => domRange.getClientRects(),\n });\n }\n }, [setReference, editor, mentionDraft]);\n\n return (\n <Persist>\n {mentionDraft?.range && isFocused && userIds ? (\n <ComposerSuggestionsContext.Provider\n value={{\n id,\n itemId,\n selectedValue: selectedUserId,\n setSelectedValue: setSelectedUserId,\n onItemSelect,\n placement,\n dir,\n ref: contentRef,\n }}\n >\n <Portal\n ref={setFloating}\n container={portalContainer}\n style={{\n position: strategy,\n top: 0,\n left: 0,\n transform: isPositioned\n ? `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`\n : \"translate3d(0, -200%, 0)\",\n minWidth: \"max-content\",\n zIndex: contentZIndex,\n }}\n >\n <MentionSuggestions\n userIds={userIds}\n selectedUserId={selectedUserId}\n />\n </Portal>\n </ComposerSuggestionsContext.Provider>\n ) : null}\n </Persist>\n );\n}\n\nfunction ComposerEditorElement({\n Mention,\n Link,\n ...props\n}: ComposerEditorElementProps) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const { attributes, children, element } = props;\n\n switch (element.type) {\n case \"mention\":\n return (\n <ComposerEditorMentionWrapper\n Mention={Mention}\n {...(props as RenderElementSpecificProps<ComposerBodyMention>)}\n />\n );\n case \"auto-link\":\n case \"custom-link\":\n return (\n <ComposerEditorLinkWrapper\n Link={Link}\n {...(props as RenderElementSpecificProps<\n ComposerBodyAutoLink | ComposerBodyCustomLink\n >)}\n />\n );\n case \"paragraph\":\n return (\n <p {...attributes} style={{ position: \"relative\" }}>\n {children}\n </p>\n );\n default:\n return null;\n }\n}\n\n// <code><s><em><strong>text</strong></s></em></code>\nfunction ComposerEditorLeaf({ attributes, children, leaf }: RenderLeafProps) {\n if (leaf.bold) {\n children = <strong>{children}</strong>;\n }\n\n if (leaf.italic) {\n children = <em>{children}</em>;\n }\n\n if (leaf.strikethrough) {\n children = <s>{children}</s>;\n }\n\n if (leaf.code) {\n children = <code>{children}</code>;\n }\n\n return <span {...attributes}>{children}</span>;\n}\n\nfunction ComposerEditorPlaceholder({\n attributes,\n children,\n}: RenderPlaceholderProps) {\n const { opacity: _opacity, ...style } = attributes.style;\n\n return (\n <span {...attributes} style={style} data-placeholder=\"\">\n {children}\n </span>\n );\n}\n\n/**\n * Displays mentions within `Composer.Editor`.\n *\n * @example\n * <Composer.Mention>@{userId}</Composer.Mention>\n */\nconst ComposerMention = forwardRef<HTMLSpanElement, ComposerMentionProps>(\n ({ children, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"span\";\n const isSelected = useSelected();\n\n return (\n <Component\n data-selected={isSelected || undefined}\n {...props}\n ref={forwardedRef}\n >\n {children}\n </Component>\n );\n }\n);\n\n/**\n * Displays links within `Composer.Editor`.\n *\n * @example\n * <Composer.Link href={href}>{children}</Composer.Link>\n */\nconst ComposerLink = forwardRef<HTMLAnchorElement, ComposerLinkProps>(\n ({ children, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"a\";\n\n return (\n <Component\n target=\"_blank\"\n rel=\"noopener noreferrer nofollow\"\n {...props}\n ref={forwardedRef}\n >\n {children}\n </Component>\n );\n }\n);\n\n/**\n * Contains suggestions within `Composer.Editor`.\n */\nconst ComposerSuggestions = forwardRef<\n HTMLDivElement,\n ComposerSuggestionsProps\n>(({ children, style, asChild, ...props }, forwardedRef) => {\n const [isPresent] = usePersist();\n const ref = useRef<HTMLDivElement>(null);\n const {\n ref: contentRef,\n placement,\n dir,\n } = useComposerSuggestionsContext(COMPOSER_SUGGESTIONS_NAME);\n const mergedRefs = useRefs(forwardedRef, contentRef, ref);\n const [side, align] = useMemo(\n () => getSideAndAlignFromPlacement(placement),\n [placement]\n );\n const Component = asChild ? Slot : \"div\";\n useAnimationPersist(ref);\n\n return (\n <Component\n dir={dir}\n {...props}\n data-state={isPresent ? \"open\" : \"closed\"}\n data-side={side}\n data-align={align}\n style={{\n display: \"flex\",\n flexDirection: \"column\",\n maxHeight: \"var(--lb-composer-suggestions-available-height)\",\n overflowY: \"auto\",\n ...style,\n }}\n ref={mergedRefs}\n >\n {children}\n </Component>\n );\n});\n\n/**\n * Displays a list of suggestions within `Composer.Editor`.\n *\n * @example\n * <Composer.SuggestionsList>\n * {userIds.map((userId) => (\n * <Composer.SuggestionsListItem key={userId} value={userId}>\n * @{userId}\n * </Composer.SuggestionsListItem>\n * ))}\n * </Composer.SuggestionsList>\n */\nconst ComposerSuggestionsList = forwardRef<\n HTMLUListElement,\n ComposerSuggestionsListProps\n>(({ children, asChild, ...props }, forwardedRef) => {\n const { id } = useComposerSuggestionsContext(COMPOSER_SUGGESTIONS_LIST_NAME);\n const Component = asChild ? Slot : \"ul\";\n\n return (\n <Component\n role=\"listbox\"\n id={id}\n aria-label=\"Suggestions list\"\n {...props}\n ref={forwardedRef}\n >\n {children}\n </Component>\n );\n});\n\n/**\n * Displays a suggestion within `Composer.SuggestionsList`.\n *\n * @example\n * <Composer.SuggestionsListItem key={userId} value={userId}>\n * @{userId}\n * </Composer.SuggestionsListItem>\n */\nconst ComposerSuggestionsListItem = forwardRef<\n HTMLLIElement,\n ComposerSuggestionsListItemProps\n>(\n (\n { value, children, onPointerMove, onPointerDown, asChild, ...props },\n forwardedRef\n ) => {\n const ref = useRef<HTMLLIElement>(null);\n const mergedRefs = useRefs(forwardedRef, ref);\n const { selectedValue, setSelectedValue, itemId, onItemSelect } =\n useComposerSuggestionsContext(COMPOSER_SUGGESTIONS_LIST_ITEM_NAME);\n const Component = asChild ? Slot : \"li\";\n const isSelected = useMemo(\n () => selectedValue === value,\n [selectedValue, value]\n );\n // TODO: Support props.id if provided, it will need to be sent up to Composer.Editor to use it in aria-activedescendant\n const id = useMemo(() => itemId(value), [itemId, value]);\n\n useEffect(() => {\n if (ref?.current && isSelected) {\n ref.current.scrollIntoView({ block: \"nearest\" });\n }\n }, [isSelected]);\n\n const handlePointerMove = useCallback(\n (event: PointerEvent<HTMLLIElement>) => {\n onPointerMove?.(event);\n\n if (!event.isDefaultPrevented()) {\n setSelectedValue(value);\n }\n },\n [onPointerMove, setSelectedValue, value]\n );\n\n const handlePointerDown = useCallback(\n (event: PointerEvent<HTMLLIElement>) => {\n onPointerDown?.(event);\n\n if (!event.isDefaultPrevented()) {\n const target = event.target as HTMLElement;\n\n if (target.hasPointerCapture(event.pointerId)) {\n target.releasePointerCapture(event.pointerId);\n }\n\n if (event.button === 0 && event.ctrlKey === false) {\n onItemSelect(value);\n\n event.preventDefault();\n }\n }\n },\n [onItemSelect, onPointerDown, value]\n );\n\n return (\n <Component\n role=\"option\"\n id={id}\n data-selected={isSelected || undefined}\n aria-selected={isSelected || undefined}\n onPointerMove={handlePointerMove}\n onPointerDown={handlePointerDown}\n {...props}\n ref={mergedRefs}\n >\n {children}\n </Component>\n );\n }\n);\n\nconst defaultEditorComponents: ComposerEditorComponents = {\n Link: ({ href, children }) => {\n return <ComposerLink href={href}>{children}</ComposerLink>;\n },\n Mention: ({ userId }) => {\n return (\n <ComposerMention>\n {MENTION_CHARACTER}\n {userId}\n </ComposerMention>\n );\n },\n MentionSuggestions: ({ userIds }) => {\n return userIds.length > 0 ? (\n <ComposerSuggestions>\n <ComposerSuggestionsList>\n {userIds.map((userId) => (\n <ComposerSuggestionsListItem key={userId} value={userId}>\n {userId}\n </ComposerSuggestionsListItem>\n ))}\n </ComposerSuggestionsList>\n </ComposerSuggestions>\n ) : null;\n },\n};\n\n/**\n * Displays the composer's editor.\n *\n * @example\n * <Composer.Editor placeholder=\"Write a comment…\" />\n */\nconst ComposerEditor = forwardRef<HTMLDivElement, ComposerEditorProps>(\n (\n {\n defaultValue,\n onKeyDown,\n onFocus,\n onBlur,\n disabled,\n autoFocus,\n components,\n dir,\n ...props\n },\n forwardedRef\n ) => {\n const self = useSelf();\n const isDisabled = useMemo(\n () => disabled || !self?.canComment,\n [disabled, self?.canComment]\n );\n const { editor, validate, setFocused } = useComposerEditorContext();\n const { submit, focus, select, isEmpty, isFocused } = useComposer();\n const initialBody = useInitial(defaultValue ?? emptyCommentBody);\n const initialEditorValue = useMemo(() => {\n return commentBodyToComposerBody(initialBody);\n }, [initialBody]);\n const { Link, Mention, MentionSuggestions } = useMemo(\n () => ({ ...defaultEditorComponents, ...components }),\n [components]\n );\n\n const [mentionDraft, setMentionDraft] = useState<MentionDraft>();\n const mentionSuggestions = useMentionSuggestions(mentionDraft?.text);\n const [\n selectedMentionSuggestionIndex,\n setPreviousSelectedMentionSuggestionIndex,\n setNextSelectedMentionSuggestionIndex,\n setSelectedMentionSuggestionIndex,\n ] = useIndex(0, mentionSuggestions?.length ?? 0);\n const id = useId();\n const suggestionsListId = useMemo(\n () => `liveblocks-suggestions-list-${id}`,\n [id]\n );\n const suggestionsListItemId = useCallback(\n (userId?: string) =>\n userId ? `liveblocks-suggestions-list-item-${id}-${userId}` : undefined,\n [id]\n );\n const renderElement = useCallback(\n (props: RenderElementProps) => {\n return (\n <ComposerEditorElement Mention={Mention} Link={Link} {...props} />\n );\n },\n [Link, Mention]\n );\n\n const handleChange = useCallback(\n (value: SlateDescendant[]) => {\n validate(value as SlateElement[]);\n\n setMentionDraft(getMentionDraftAtSelection(editor));\n },\n [editor, validate]\n );\n\n const createMention = useCallback(\n (userId?: string) => {\n if (!mentionDraft || !userId) {\n return;\n }\n\n SlateTransforms.select(editor, mentionDraft.range);\n insertMention(editor, userId);\n setMentionDraft(undefined);\n setSelectedMentionSuggestionIndex(0);\n },\n [editor, mentionDraft, setSelectedMentionSuggestionIndex]\n );\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n\n if (event.isDefaultPrevented()) {\n return;\n }\n\n // Allow leaving marks with ArrowLeft\n if (isKey(event, \"ArrowLeft\")) {\n leaveMarkEdge(editor, \"start\");\n }\n\n // Allow leaving marks with ArrowRight\n if (isKey(event, \"ArrowRight\")) {\n leaveMarkEdge(editor, \"end\");\n }\n\n if (mentionDraft && mentionSuggestions?.length) {\n // Select the next mention suggestion on ArrowDown\n if (isKey(event, \"ArrowDown\")) {\n event.preventDefault();\n setNextSelectedMentionSuggestionIndex();\n }\n\n // Select the previous mention suggestion on ArrowUp\n if (isKey(event, \"ArrowUp\")) {\n event.preventDefault();\n setPreviousSelectedMentionSuggestionIndex();\n }\n\n // Create a mention on Enter/Tab\n if (isKey(event, \"Enter\") || isKey(event, \"Tab\")) {\n event.preventDefault();\n\n const userId = mentionSuggestions?.[selectedMentionSuggestionIndex];\n createMention(userId);\n }\n\n // Close the suggestions on Escape\n if (isKey(event, \"Escape\")) {\n event.preventDefault();\n setMentionDraft(undefined);\n setSelectedMentionSuggestionIndex(0);\n }\n } else {\n // Blur the editor on Escape\n if (isKey(event, \"Escape\")) {\n event.preventDefault();\n ReactEditor.blur(editor);\n }\n\n // Submit the editor on Enter\n if (isKey(event, \"Enter\", { shift: false }) && !isEmpty) {\n event.preventDefault();\n submit();\n }\n\n // Create a new line on Shift + Enter\n if (isKey(event, \"Enter\", { shift: true })) {\n event.preventDefault();\n editor.insertBreak();\n }\n\n // Toggle bold on Command/Control + B\n if (isKey(event, \"b\", { mod: true })) {\n event.preventDefault();\n toggleMark(editor, \"bold\");\n }\n\n // Toggle italic on Command/Control + I\n if (isKey(event, \"i\", { mod: true })) {\n event.preventDefault();\n toggleMark(editor, \"italic\");\n }\n\n // Toggle strikethrough on Command/Control + Shift + S\n if (isKey(event, \"s\", { mod: true, shift: true })) {\n event.preventDefault();\n toggleMark(editor, \"strikethrough\");\n }\n\n // Toggle code on Command/Control + E\n if (isKey(event, \"e\", { mod: true })) {\n event.preventDefault();\n toggleMark(editor, \"code\");\n }\n }\n },\n [\n createMention,\n editor,\n isEmpty,\n mentionDraft,\n mentionSuggestions,\n selectedMentionSuggestionIndex,\n onKeyDown,\n setNextSelectedMentionSuggestionIndex,\n setPreviousSelectedMentionSuggestionIndex,\n setSelectedMentionSuggestionIndex,\n submit,\n ]\n );\n\n const handleFocus = useCallback(\n (event: FocusEvent<HTMLDivElement>) => {\n onFocus?.(event);\n\n if (!event.isDefaultPrevented()) {\n setFocused(true);\n }\n },\n [onFocus, setFocused]\n );\n\n const handleBlur = useCallback(\n (event: FocusEvent<HTMLDivElement>) => {\n onBlur?.(event);\n\n if (!event.isDefaultPrevented()) {\n setFocused(false);\n }\n },\n [onBlur, setFocused]\n );\n\n const selectedMentionSuggestionUserId = useMemo(\n () => mentionSuggestions?.[selectedMentionSuggestionIndex],\n [selectedMentionSuggestionIndex, mentionSuggestions]\n );\n const setSelectedMentionSuggestionUserId = useCallback(\n (userId: string) => {\n const index = mentionSuggestions?.indexOf(userId);\n\n if (index !== undefined && index >= 0) {\n setSelectedMentionSuggestionIndex(index);\n }\n },\n [setSelectedMentionSuggestionIndex, mentionSuggestions]\n );\n\n const propsWhileSuggesting: AriaAttributes = useMemo(\n () =>\n mentionDraft\n ? {\n role: \"combobox\",\n \"aria-autocomplete\": \"list\",\n \"aria-expanded\": true,\n \"aria-controls\": suggestionsListId,\n \"aria-activedescendant\": suggestionsListItemId(\n selectedMentionSuggestionUserId\n ),\n }\n : {},\n [\n mentionDraft,\n suggestionsListId,\n suggestionsListItemId,\n selectedMentionSuggestionUserId,\n ]\n );\n\n useImperativeHandle(forwardedRef, () => {\n return ReactEditor.toDOMNode(editor, editor) as HTMLDivElement;\n }, [editor]);\n\n // Manually focus the editor when `autoFocus` is true\n useEffect(() => {\n if (autoFocus) {\n focus();\n }\n }, [autoFocus, editor, focus]);\n\n // Manually add a selection in the editor if the selection\n // is still empty after being focused\n useEffect(() => {\n if (isFocused && editor.selection === null) {\n select();\n }\n }, [editor, select, isFocused]);\n\n return (\n <Slate\n editor={editor}\n initialValue={initialEditorValue}\n onChange={handleChange}\n >\n <Editable\n dir={dir}\n enterKeyHint={mentionDraft ? \"enter\" : \"send\"}\n autoCapitalize=\"sentences\"\n aria-label=\"Composer editor\"\n data-focused={isFocused || undefined}\n data-disabled={isDisabled || undefined}\n {...propsWhileSuggesting}\n {...props}\n readOnly={isDisabled}\n disabled={isDisabled}\n onKeyDown={handleKeyDown}\n onFocus={handleFocus}\n onBlur={handleBlur}\n renderElement={renderElement}\n renderLeaf={ComposerEditorLeaf}\n renderPlaceholder={ComposerEditorPlaceholder}\n />\n <ComposerEditorMentionSuggestionsWrapper\n dir={dir}\n mentionDraft={mentionDraft}\n selectedUserId={selectedMentionSuggestionUserId}\n setSelectedUserId={setSelectedMentionSuggestionUserId}\n userIds={mentionSuggestions}\n id={suggestionsListId}\n itemId={suggestionsListItemId}\n onItemSelect={createMention}\n MentionSuggestions={MentionSuggestions}\n />\n </Slate>\n );\n }\n);\n\n/**\n * Surrounds the composer's content and handles submissions.\n *\n * @example\n * <Composer.Form onComposerSubmit={({ body }) => {}}>\n *\t <Composer.Editor />\n * <Composer.Submit />\n * </Composer.Form>\n */\nconst ComposerForm = forwardRef<HTMLFormElement, ComposerFormProps>(\n (\n { children, onSubmit, onComposerSubmit, asChild, ...props },\n forwardedRef\n ) => {\n const Component = asChild ? Slot : \"form\";\n const editor = useInitial(createComposerEditor);\n const [isEmpty, setEmpty] = useState(true);\n const [isFocused, setFocused] = useState(false);\n const ref = useRef<HTMLFormElement>(null);\n const mergedRefs = useRefs(forwardedRef, ref);\n\n const validate = useCallback(\n (value: SlateElement[]) => {\n setEmpty(isEditorEmpty(editor, value));\n },\n [editor]\n );\n\n const submit = useCallback(() => {\n // We need to wait for the next frame in some cases like when composing diacritics,\n // we want any native handling to be done first while still being handled on `keydown`.\n requestAnimationFrame(() => {\n if (ref.current) {\n requestSubmit(ref.current);\n }\n });\n }, []);\n\n const clear = useCallback(() => {\n SlateTransforms.delete(editor, {\n at: {\n anchor: SlateEditor.start(editor, []),\n focus: SlateEditor.end(editor, []),\n },\n });\n }, [editor]);\n\n const select = useCallback(() => {\n SlateTransforms.select(editor, {\n anchor: SlateEditor.end(editor, []),\n focus: SlateEditor.end(editor, []),\n });\n }, [editor]);\n\n const focus = useCallback(\n (resetSelection = true) => {\n if (!ReactEditor.isFocused(editor)) {\n SlateTransforms.select(\n editor,\n resetSelection || !editor.selection\n ? SlateEditor.end(editor, [])\n : editor.selection\n );\n ReactEditor.focus(editor);\n }\n },\n [editor]\n );\n\n const blur = useCallback(() => {\n ReactEditor.blur(editor);\n }, [editor]);\n\n const onSubmitEnd = useCallback(() => {\n clear();\n blur();\n }, [blur, clear]);\n\n const createMention = useCallback(() => {\n focus();\n insertMentionCharacter(editor);\n }, [editor, focus]);\n\n const insertText = useCallback(\n (text: string) => {\n focus(false);\n insertSlateText(editor, text);\n },\n [editor, focus]\n );\n\n const handleSubmit = useCallback(\n (event: FormEvent<HTMLFormElement>) => {\n // In some situations (e.g. pressing Enter while composing diacritics), it's possible\n // for the form to be submitted as empty even though we already checked whether the\n // editor was empty when handling the key press.\n const isEmpty = isEditorEmpty(editor, editor.children);\n\n // We even prevent the user's `onSubmit` handler from being called if the editor is empty.\n if (isEmpty) {\n event.preventDefault();\n\n return;\n }\n\n onSubmit?.(event);\n\n if (!onComposerSubmit || event.isDefaultPrevented()) {\n event.preventDefault();\n\n return;\n }\n\n const body = composerBodyToCommentBody(\n editor.children as ComposerBodyData\n );\n const comment = { body };\n\n const promise = onComposerSubmit(comment, event);\n\n event.preventDefault();\n\n if (promise) {\n promise.then(onSubmitEnd);\n } else {\n onSubmitEnd();\n }\n },\n [editor, onComposerSubmit, onSubmit, onSubmitEnd]\n );\n\n return (\n <ComposerEditorContext.Provider\n value={{\n editor,\n validate,\n setFocused,\n }}\n >\n <ComposerContext.Provider\n value={{\n isFocused,\n isEmpty,\n submit,\n clear,\n select,\n focus,\n blur,\n createMention,\n insertText,\n }}\n >\n <Component {...props} onSubmit={handleSubmit} ref={mergedRefs}>\n {children}\n </Component>\n </ComposerContext.Provider>\n </ComposerEditorContext.Provider>\n );\n }\n);\n\n/**\n * A button to submit the composer.\n *\n * @example\n * <Composer.Submit>Send</Composer.Submit>\n */\nconst ComposerSubmit = forwardRef<HTMLButtonElement, ComposerSubmitProps>(\n ({ children, disabled, asChild, ...props }, forwardedRef) => {\n const Component = asChild ? Slot : \"button\";\n const { isEmpty } = useComposer();\n const self = useSelf();\n const isDisabled = useMemo(\n () => disabled || isEmpty || !self?.canComment,\n [disabled, isEmpty, self?.canComment]\n );\n\n return (\n <Component\n type=\"submit\"\n {...props}\n ref={forwardedRef}\n disabled={isDisabled}\n >\n {children}\n </Component>\n );\n }\n);\n\nif (process.env.NODE_ENV !== \"production\") {\n ComposerEditor.displayName = COMPOSER_EDITOR_NAME;\n ComposerForm.displayName = COMPOSER_FORM_NAME;\n ComposerMention.displayName = COMPOSER_MENTION_NAME;\n ComposerLink.displayName = COMPOSER_LINK_NAME;\n ComposerSubmit.displayName = COMPOSER_SUBMIT_NAME;\n ComposerSuggestions.displayName = COMPOSER_SUGGESTIONS_NAME;\n ComposerSuggestionsList.displayName = COMPOSER_SUGGESTIONS_LIST_NAME;\n ComposerSuggestionsListItem.displayName = COMPOSER_SUGGESTIONS_LIST_ITEM_NAME;\n}\n\n// NOTE: Every export from this file will be available publicly as Composer.*\nexport {\n ComposerEditor as Editor,\n ComposerForm as Form,\n ComposerLink as Link,\n ComposerMention as Mention,\n ComposerSubmit as Submit,\n ComposerSuggestions as Suggestions,\n ComposerSuggestionsList as SuggestionsList,\n ComposerSuggestionsListItem as SuggestionsListItem,\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8HA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAAsC;AAC3B;AAEX;AAEA;AACE;AAAO;AACL;AACE;AACE;AACE;AACsD;AACtD;AACF;AACF;AACF;AAEJ;AAEA;AAAsC;AACpC;AACA;AACA;AAEF;AACE;AAEA;AACG;AAAS;AAEL;AAAwB;AAAI;AAKrC;AAEA;AAAmC;AACjC;AACA;AACA;AAEF;AACE;AAAa;AACiC;AAChC;AAGd;AACG;AAAS;AACP;AAAK;AAGZ;AAEA;AAAiD;AAC/C;AACA;AACA;AACA;AACA;AACA;AACA;AACW;AACX;AAEF;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACE;AAAqD;AAC1C;AAGX;AAAO;AACK;AACuC;AACrC;AACyC;AACzB;AACpB;AACD;AACiB;AACrB;AACI;AACA;AAED;AAAwB;AACtB;AACG;AAEL;AAAwB;AACtB;AACG;AACL;AACF;AACD;AACH;AACsB;AACxB;AAEF;AAAM;AAC8B;AAClC;AACA;AACA;AACA;AACA;AAKF;AACE;AACE;AAAwD;AAC1D;AAGF;AACE;AACE;AAAA;AAGF;AAEA;AACE;AAAa;AACiD;AACd;AAC/C;AACH;AAGF;AAGO;AACQ;AACL;AACA;AACe;AACG;AAClB;AACA;AACA;AACK;AACP;AAEC;AACM;AACM;AACJ;AACK;AACL;AACC;AAGF;AACM;AACF;AACV;AAEC;AACC;AACA;AAOd;AAEA;AAA+B;AAC7B;AACA;AAEF;AAEE;AAEA;AAAsB;AAElB;AACG;AACC;AACK;AACP;AAEC;AAEH;AACG;AACC;AACK;AAGP;AAGF;AACG;AAAM;AAA0C;AAEjD;AAGF;AAAO;AAEb;AAGA;AACE;AACE;AAA6B;AAG/B;AACE;AAAyB;AAG3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AEjB;AAEA;AAAkD;AACpD;AACiB;AAGnB;AAAsB;AAElB;AACE;AAAA;AAGF;AACA;AACA;AACA;AAAmC;AACrC;AACwD;AAG1D;AAAsB;AAElB;AAEA;AACE;AAAA;AAIF;AACE;AAA6B;AAI/B;AACE;AAA2B;AAG7B;AAEE;AACE;AACA;AAAsC;AAIxC;AACE;AACA;AAA0C;AAI5C;AACE;AAEA;AACA;AAAoB;AAItB;AACE;AACA;AACA;AAAmC;AACrC;AAGA;AACE;AACA;AAAuB;AAIzB;AACE;AACA;AAAO;AAIT;AACE;AACA;AAAmB;AAIrB;AACE;AACA;AAAyB;AAI3B;AACE;AACA;AAA2B;AAI7B;AACE;AACA;AAAkC;AAIpC;AACE;AACA;AAAyB;AAC3B;AACF;AACF;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF;AAGF;AAAoB;AAEhB;AAEA;AACE;AAAe;AACjB;AACF;AACoB;AAGtB;AAAmB;AAEf;AAEA;AACE;AAAgB;AAClB;AACF;AACmB;AAGrB;AAAwC;AACX;AACwB;AAErD;AAA2C;AAEvC;AAEA;AACE;AAAuC;AACzC;AACF;AACsD;AAGxD;AAA6C;AAGrC;AACQ;AACe;AACJ;AACA;AACQ;AACvB;AACF;AAED;AACP;AACE;AACA;AACA;AACA;AACF;AAGF;AACE;AAA2C;AAI7C;AACE;AACE;AAAM;AACR;AAKF;AACE;AACE;AAAO;AACT;AAGF;AACG;AACC;AACc;AACJ;AAET;AACC;AACuC;AACxB;AACJ;AACgB;AACE;AACzB;AACA;AACM;AACA;AACC;AACF;AACD;AACR;AACY;AACO;AAEpB;AACC;AACA;AACgB;AACG;AACV;AACL;AACI;AACM;AACd;AAEJ;AAGN;AAWA;AAAqB;AAKjB;AACA;AACA;AACA;AACA;AACA;AAEA;AAAiB;AAEb;AAAqC;AACvC;AACO;AAGT;AAGE;AACE;AACE;AAAyB;AAC3B;AACD;AAGH;AACE;AAA+B;AACzB;AACkC;AACH;AACnC;AACD;AAGH;AACE;AAA+B;AACK;AACD;AAClC;AAGH;AAAc;AAEV;AACE;AAAgB;AACd;AAGW;AAEb;AAAwB;AAC1B;AACF;AACO;AAGT;AACE;AAAuB;AAGzB;AACE;AACA;AAAK;AAGP;AACE;AACA;AAA6B;AAG/B;AAAmB;AAEf;AACA;AAA4B;AAC9B;AACc;AAGhB;AAAqB;AAKjB;AAGA;AACE;AAEA;AAAA;AAGF;AAEA;AACE;AAEA;AAAA;AAGF;AAAa;AACJ;AAET;AAEA;AAEA;AAEA;AACE;AAAwB;AAExB;AAAY;AACd;AACF;AACgD;AAGlD;AACG;AACQ;AACL;AACA;AACA;AACF;AAEC;AACQ;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF;AAEC;AAAc;AAAiB;AAAmB;AAIvD;AAGN;AAQA;AAAuB;AAEnB;AACA;AACA;AACA;AAAmB;AACmB;AACA;AAGtC;AACG;AACM;AACD;AACC;AACK;AAGZ;AAGN;AAEA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF;;;;;;;;;"}
|