@pega/cosmos-react-social 4.0.0-dev.9.1 → 4.0.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.
Files changed (197) hide show
  1. package/lib/components/Chat/Chat.d.ts +10 -12
  2. package/lib/components/Chat/Chat.d.ts.map +1 -1
  3. package/lib/components/Chat/Chat.js +10 -13
  4. package/lib/components/Chat/Chat.js.map +1 -1
  5. package/lib/components/Chat/Chat.types.d.ts +106 -4
  6. package/lib/components/Chat/Chat.types.d.ts.map +1 -1
  7. package/lib/components/Chat/Chat.types.js +9 -1
  8. package/lib/components/Chat/Chat.types.js.map +1 -1
  9. package/lib/components/Chat/ChatBody.d.ts +3 -8
  10. package/lib/components/Chat/ChatBody.d.ts.map +1 -1
  11. package/lib/components/Chat/ChatBody.js +289 -15
  12. package/lib/components/Chat/ChatBody.js.map +1 -1
  13. package/lib/components/Chat/ChatComposer.d.ts +3 -4
  14. package/lib/components/Chat/ChatComposer.d.ts.map +1 -1
  15. package/lib/components/Chat/ChatComposer.js +41 -31
  16. package/lib/components/Chat/ChatComposer.js.map +1 -1
  17. package/lib/components/Chat/ChatHeader.d.ts +2 -2
  18. package/lib/components/Chat/ChatHeader.d.ts.map +1 -1
  19. package/lib/components/Chat/ChatHeader.js +3 -3
  20. package/lib/components/Chat/ChatHeader.js.map +1 -1
  21. package/lib/components/Chat/ChatSettingsPanel.styles.js +1 -1
  22. package/lib/components/Chat/ChatSettingsPanel.styles.js.map +1 -1
  23. package/lib/components/Chat/Message.d.ts +3 -43
  24. package/lib/components/Chat/Message.d.ts.map +1 -1
  25. package/lib/components/Chat/Message.js +68 -28
  26. package/lib/components/Chat/Message.js.map +1 -1
  27. package/lib/components/Chat/Message.styles.d.ts +32 -21
  28. package/lib/components/Chat/Message.styles.d.ts.map +1 -1
  29. package/lib/components/Chat/Message.styles.js +92 -20
  30. package/lib/components/Chat/Message.styles.js.map +1 -1
  31. package/lib/components/Chat/SuggestedReplyPicker.d.ts +20 -4
  32. package/lib/components/Chat/SuggestedReplyPicker.d.ts.map +1 -1
  33. package/lib/components/Chat/SuggestedReplyPicker.js +115 -51
  34. package/lib/components/Chat/SuggestedReplyPicker.js.map +1 -1
  35. package/lib/components/Chat/SystemMessage.d.ts +4 -15
  36. package/lib/components/Chat/SystemMessage.d.ts.map +1 -1
  37. package/lib/components/Chat/SystemMessage.js +33 -23
  38. package/lib/components/Chat/SystemMessage.js.map +1 -1
  39. package/lib/components/Chat/TypeIndicator.d.ts +3 -10
  40. package/lib/components/Chat/TypeIndicator.d.ts.map +1 -1
  41. package/lib/components/Chat/TypeIndicator.js +6 -3
  42. package/lib/components/Chat/TypeIndicator.js.map +1 -1
  43. package/lib/components/Chat/index.d.ts +13 -13
  44. package/lib/components/Chat/index.d.ts.map +1 -1
  45. package/lib/components/Chat/index.js +1 -5
  46. package/lib/components/Chat/index.js.map +1 -1
  47. package/lib/components/Email/ContextMenuPopover.js +1 -1
  48. package/lib/components/Email/ContextMenuPopover.js.map +1 -1
  49. package/lib/components/Email/Email.d.ts.map +1 -1
  50. package/lib/components/Email/Email.js +1 -1
  51. package/lib/components/Email/Email.js.map +1 -1
  52. package/lib/components/Email/Email.styles.d.ts +12 -4
  53. package/lib/components/Email/Email.styles.d.ts.map +1 -1
  54. package/lib/components/Email/Email.styles.js +11 -4
  55. package/lib/components/Email/Email.styles.js.map +1 -1
  56. package/lib/components/Email/Email.types.d.ts +9 -7
  57. package/lib/components/Email/Email.types.d.ts.map +1 -1
  58. package/lib/components/Email/Email.types.js.map +1 -1
  59. package/lib/components/Email/EmailCaseView.d.ts.map +1 -1
  60. package/lib/components/Email/EmailCaseView.js +2 -2
  61. package/lib/components/Email/EmailCaseView.js.map +1 -1
  62. package/lib/components/Email/EmailComposer.d.ts.map +1 -1
  63. package/lib/components/Email/EmailComposer.js +71 -93
  64. package/lib/components/Email/EmailComposer.js.map +1 -1
  65. package/lib/components/Email/EmailConversation.d.ts.map +1 -1
  66. package/lib/components/Email/EmailConversation.js +77 -82
  67. package/lib/components/Email/EmailConversation.js.map +1 -1
  68. package/lib/components/Email/EmailEntity.d.ts.map +1 -1
  69. package/lib/components/Email/EmailEntity.js +1 -1
  70. package/lib/components/Email/EmailEntity.js.map +1 -1
  71. package/lib/components/Email/EmailManager.js +2 -2
  72. package/lib/components/Email/EmailManager.js.map +1 -1
  73. package/lib/components/Email/EmailShell.js +1 -1
  74. package/lib/components/Email/EmailShell.js.map +1 -1
  75. package/lib/components/Email/EmailSummaryItem.d.ts +1 -0
  76. package/lib/components/Email/EmailSummaryItem.d.ts.map +1 -1
  77. package/lib/components/Email/EmailSummaryItem.js +4 -5
  78. package/lib/components/Email/EmailSummaryItem.js.map +1 -1
  79. package/lib/components/Email/EmailSummaryList.js +2 -2
  80. package/lib/components/Email/EmailSummaryList.js.map +1 -1
  81. package/lib/components/Email/EntityList.js +2 -2
  82. package/lib/components/Email/EntityList.js.map +1 -1
  83. package/lib/components/Email/index.d.ts +1 -1
  84. package/lib/components/Email/index.d.ts.map +1 -1
  85. package/lib/components/Email/index.js.map +1 -1
  86. package/lib/components/Email/utils/EntityHighlighter.d.ts.map +1 -1
  87. package/lib/components/Email/utils/EntityHighlighter.js +4 -10
  88. package/lib/components/Email/utils/EntityHighlighter.js.map +1 -1
  89. package/lib/components/Feed/Feed.context.d.ts +5 -1
  90. package/lib/components/Feed/Feed.context.d.ts.map +1 -1
  91. package/lib/components/Feed/Feed.context.js.map +1 -1
  92. package/lib/components/Feed/Feed.d.ts +3 -53
  93. package/lib/components/Feed/Feed.d.ts.map +1 -1
  94. package/lib/components/Feed/Feed.js +52 -32
  95. package/lib/components/Feed/Feed.js.map +1 -1
  96. package/lib/components/Feed/Feed.types.d.ts +330 -0
  97. package/lib/components/Feed/Feed.types.d.ts.map +1 -0
  98. package/lib/components/Feed/Feed.types.js +2 -0
  99. package/lib/components/Feed/Feed.types.js.map +1 -0
  100. package/lib/components/Feed/FeedAnnouncer.d.ts +2 -3
  101. package/lib/components/Feed/FeedAnnouncer.d.ts.map +1 -1
  102. package/lib/components/Feed/FeedAnnouncer.js.map +1 -1
  103. package/lib/components/Feed/FeedAttachments.d.ts +3 -9
  104. package/lib/components/Feed/FeedAttachments.d.ts.map +1 -1
  105. package/lib/components/Feed/FeedAttachments.js +20 -18
  106. package/lib/components/Feed/FeedAttachments.js.map +1 -1
  107. package/lib/components/Feed/FeedButton.d.ts +0 -1
  108. package/lib/components/Feed/FeedButton.d.ts.map +1 -1
  109. package/lib/components/Feed/FeedButton.js +2 -10
  110. package/lib/components/Feed/FeedButton.js.map +1 -1
  111. package/lib/components/Feed/FeedContent.d.ts +2 -10
  112. package/lib/components/Feed/FeedContent.d.ts.map +1 -1
  113. package/lib/components/Feed/FeedContent.js +9 -2
  114. package/lib/components/Feed/FeedContent.js.map +1 -1
  115. package/lib/components/Feed/FeedContentFooter.d.ts +5 -0
  116. package/lib/components/Feed/FeedContentFooter.d.ts.map +1 -0
  117. package/lib/components/Feed/FeedContentFooter.js +34 -0
  118. package/lib/components/Feed/FeedContentFooter.js.map +1 -0
  119. package/lib/components/Feed/FeedContentHeader.d.ts +5 -0
  120. package/lib/components/Feed/FeedContentHeader.d.ts.map +1 -0
  121. package/lib/components/Feed/FeedContentHeader.js +101 -0
  122. package/lib/components/Feed/FeedContentHeader.js.map +1 -0
  123. package/lib/components/Feed/FeedEditRegion.d.ts +6 -0
  124. package/lib/components/Feed/FeedEditRegion.d.ts.map +1 -0
  125. package/lib/components/Feed/FeedEditRegion.js +57 -0
  126. package/lib/components/Feed/FeedEditRegion.js.map +1 -0
  127. package/lib/components/Feed/FeedInputRegion.d.ts +8 -0
  128. package/lib/components/Feed/FeedInputRegion.d.ts.map +1 -0
  129. package/lib/components/Feed/FeedInputRegion.js +86 -0
  130. package/lib/components/Feed/FeedInputRegion.js.map +1 -0
  131. package/lib/components/Feed/FeedLikeButton.d.ts +5 -17
  132. package/lib/components/Feed/FeedLikeButton.d.ts.map +1 -1
  133. package/lib/components/Feed/FeedLikeButton.js +54 -42
  134. package/lib/components/Feed/FeedLikeButton.js.map +1 -1
  135. package/lib/components/Feed/FeedModalList.d.ts +1 -13
  136. package/lib/components/Feed/FeedModalList.d.ts.map +1 -1
  137. package/lib/components/Feed/FeedModalList.js +6 -3
  138. package/lib/components/Feed/FeedModalList.js.map +1 -1
  139. package/lib/components/Feed/FeedNewPost.d.ts +1 -30
  140. package/lib/components/Feed/FeedNewPost.d.ts.map +1 -1
  141. package/lib/components/Feed/FeedNewPost.js +7 -85
  142. package/lib/components/Feed/FeedNewPost.js.map +1 -1
  143. package/lib/components/Feed/FeedNewPostTypeMenu.d.ts +1 -30
  144. package/lib/components/Feed/FeedNewPostTypeMenu.d.ts.map +1 -1
  145. package/lib/components/Feed/FeedNewPostTypeMenu.js +38 -50
  146. package/lib/components/Feed/FeedNewPostTypeMenu.js.map +1 -1
  147. package/lib/components/Feed/FeedPost.d.ts +2 -4
  148. package/lib/components/Feed/FeedPost.d.ts.map +1 -1
  149. package/lib/components/Feed/FeedPost.js +97 -170
  150. package/lib/components/Feed/FeedPost.js.map +1 -1
  151. package/lib/components/Feed/FeedReply.d.ts +1 -4
  152. package/lib/components/Feed/FeedReply.d.ts.map +1 -1
  153. package/lib/components/Feed/FeedReply.js +56 -138
  154. package/lib/components/Feed/FeedReply.js.map +1 -1
  155. package/lib/components/Feed/FeedReplyInput.d.ts +2 -27
  156. package/lib/components/Feed/FeedReplyInput.d.ts.map +1 -1
  157. package/lib/components/Feed/FeedReplyInput.js +9 -96
  158. package/lib/components/Feed/FeedReplyInput.js.map +1 -1
  159. package/lib/components/Feed/FeedRichText.d.ts +1 -4
  160. package/lib/components/Feed/FeedRichText.d.ts.map +1 -1
  161. package/lib/components/Feed/FeedRichText.js +4 -9
  162. package/lib/components/Feed/FeedRichText.js.map +1 -1
  163. package/lib/components/Feed/index.d.ts +4 -7
  164. package/lib/components/Feed/index.d.ts.map +1 -1
  165. package/lib/components/Feed/index.js.map +1 -1
  166. package/lib/components/HashtagButton/HashtagButton.d.ts.map +1 -1
  167. package/lib/components/HashtagButton/HashtagButton.js +3 -3
  168. package/lib/components/HashtagButton/HashtagButton.js.map +1 -1
  169. package/lib/components/MentionButton/MentionButton.d.ts +1 -1
  170. package/lib/components/MentionButton/MentionButton.d.ts.map +1 -1
  171. package/lib/components/MentionButton/MentionButton.js +12 -14
  172. package/lib/components/MentionButton/MentionButton.js.map +1 -1
  173. package/package.json +17 -19
  174. package/lib/components/Chat/ChatTranscript.d.ts +0 -23
  175. package/lib/components/Chat/ChatTranscript.d.ts.map +0 -1
  176. package/lib/components/Chat/ChatTranscript.js +0 -45
  177. package/lib/components/Chat/ChatTranscript.js.map +0 -1
  178. package/lib/components/Chat/MessageList.d.ts +0 -35
  179. package/lib/components/Chat/MessageList.d.ts.map +0 -1
  180. package/lib/components/Chat/MessageList.js +0 -134
  181. package/lib/components/Chat/MessageList.js.map +0 -1
  182. package/lib/components/Chat/RepeatingView.d.ts +0 -31
  183. package/lib/components/Chat/RepeatingView.d.ts.map +0 -1
  184. package/lib/components/Chat/RepeatingView.js +0 -47
  185. package/lib/components/Chat/RepeatingView.js.map +0 -1
  186. package/lib/components/Chat/TranscriptMessage.d.ts +0 -25
  187. package/lib/components/Chat/TranscriptMessage.d.ts.map +0 -1
  188. package/lib/components/Chat/TranscriptMessage.js +0 -48
  189. package/lib/components/Chat/TranscriptMessage.js.map +0 -1
  190. package/lib/components/Feed/FeedPost.types.d.ts +0 -107
  191. package/lib/components/Feed/FeedPost.types.d.ts.map +0 -1
  192. package/lib/components/Feed/FeedPost.types.js +0 -2
  193. package/lib/components/Feed/FeedPost.types.js.map +0 -1
  194. package/lib/components/Feed/FeedReply.types.d.ts +0 -72
  195. package/lib/components/Feed/FeedReply.types.d.ts.map +0 -1
  196. package/lib/components/Feed/FeedReply.types.js +0 -2
  197. package/lib/components/Feed/FeedReply.types.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"HashtagButton.d.ts","sourceRoot":"","sources":["../../../src/components/HashtagButton/HashtagButton.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAGjB,YAAY,EAGb,MAAM,OAAO,CAAC;AAGf,OAAO,EAAO,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAK5D,UAAU,kBAAkB;IAC1B,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC;IAChD,qBAAqB;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAQD,QAAA,MAAM,aAAa,EAAE,iBAAiB,CAAC,kBAAkB,GAAG,YAAY,CAwBvE,CAAC;AAEF,eAAO,MAAM,mBAAmB;;;;;;aAKL,MAAM;;uBAQZ,MAAM;;;CAM1B,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"HashtagButton.d.ts","sourceRoot":"","sources":["../../../src/components/HashtagButton/HashtagButton.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAGjB,YAAY,EAGb,MAAM,OAAO,CAAC;AAGf,OAAO,EAAO,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAK5D,UAAU,kBAAkB;IAC1B,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC;IAChD,qBAAqB;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAQD,QAAA,MAAM,aAAa,EAAE,iBAAiB,CAAC,kBAAkB,GAAG,YAAY,CAsBvE,CAAC;AAEF,eAAO,MAAM,mBAAmB;;;;;;aAKL,MAAM;;uBAQZ,MAAM;;;CAM1B,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { forwardRef, isValidElement, useContext } from 'react';
3
3
  import styled from 'styled-components';
4
4
  import { Tag } from '@pega/cosmos-react-core';
@@ -8,7 +8,7 @@ const StyledTag = styled(Tag) `
8
8
  cursor: pointer;
9
9
  `;
10
10
  const serializer = new XMLSerializer();
11
- const HashtagButton = forwardRef(({ children, tag: tagProp = '', ...restProps }, ref) => {
11
+ const HashtagButton = forwardRef(function HashtagButton({ children, tag: tagProp = '', ...restProps }, ref) {
12
12
  const { onTagClick } = useContext(FeedContext);
13
13
  let tag = '';
14
14
  if (!isValidElement(children)) {
@@ -19,7 +19,7 @@ const HashtagButton = forwardRef(({ children, tag: tagProp = '', ...restProps },
19
19
  else {
20
20
  tag = tagProp;
21
21
  }
22
- return (_jsx(_Fragment, { children: _jsx(StyledTag, { ...restProps, ref: ref, onClick: () => onTagClick?.(tag), spellCheck: false, children: isValidElement(children) ? children : tag }) }));
22
+ return (_jsx(StyledTag, { ...restProps, ref: ref, onClick: () => onTagClick?.(tag), spellCheck: false, children: isValidElement(children) ? children : tag }));
23
23
  });
24
24
  export const HashtagButtonConfig = {
25
25
  type: 'tag',
@@ -1 +1 @@
1
- {"version":3,"file":"HashtagButton.js","sourceRoot":"","sources":["../../../src/components/HashtagButton/HashtagButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAEV,cAAc,EAId,UAAU,EACX,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EAAE,GAAG,EAAgB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AASnD,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;;CAE5B,CAAC;AAEF,MAAM,UAAU,GAAG,IAAI,aAAa,EAAE,CAAC;AAEvC,MAAM,aAAa,GAAyD,UAAU,CACpF,CACE,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,GAAG,EAAE,EAAE,GAAG,SAAS,EAAuC,EACl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AG;YAAE,OAAO,SAAS,CAAC;QACrD,OAAO,EAAE,GAAG,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC;IACjC,CAAC;CACF,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n isValidElement,\n PropsWithoutRef,\n ReactElement,\n Ref,\n useContext\n} from 'react';\nimport styled from 'styled-components';\n\nimport { Tag, ForwardProps } from '@pega/cosmos-react-core';\nimport { getXMLAttributes } from '@pega/cosmos-react-rte';\n\nimport { FeedContext } from '../Feed/Feed.context';\n\ninterface HashtagButtonProps {\n /** Text for the button, or an object containing all necessary props. */\n children: Record<string, string> | ReactElement;\n /** The tag value. */\n tag?: string;\n}\n\nconst StyledTag = styled(Tag)`\n cursor: pointer;\n`;\n\nconst serializer = new XMLSerializer();\n\nconst HashtagButton: FunctionComponent<HashtagButtonProps & ForwardProps> = forwardRef(\n (\n { children, tag: tagProp = '', ...restProps }: PropsWithoutRef<HashtagButtonProps>,\n ref: Ref<HTMLButtonElement>\n ) => {\n const { onTagClick } = useContext(FeedContext);\n\n let tag = '';\n\n if (!isValidElement(children)) {\n if (!children.tag) return <span>{children.rawText}</span>;\n tag = children.tag;\n } else {\n tag = tagProp;\n }\n\n return (\n <>\n <StyledTag {...restProps} ref={ref} onClick={() => onTagClick?.(tag)} spellCheck={false}>\n {isValidElement(children) ? children : tag}\n </StyledTag>\n </>\n );\n }\n);\n\nexport const HashtagButtonConfig = {\n type: 'tag',\n xmlElement: 'pega-tag',\n regexPattern: /(?:^|)<pega-tag (?:[^\\n/]|\\/(?!>))+\\/>/gm,\n component: HashtagButton,\n inject: ({ tag }: { tag: string }) => {\n if (!tag) return;\n\n const element = document.createElementNS(null, 'pega-tag');\n element.setAttribute('tag', tag);\n\n return serializer.serializeToString(element);\n },\n extract: (element: string) => {\n const attributes = getXMLAttributes(element);\n\n if (!attributes || !attributes.tag) return undefined;\n return { tag: attributes.tag };\n }\n};\n\nexport default HashtagButton;\n"]}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M,CAAC,MAAM,mBAAmB,GAAG;IACjC,IAAI,EAAE,KAAK;IACX,UAAU,EAAE,UAAU;IACtB,YAAY,EAAE,0CAA0C;IACxD,SAAS,EAAE,aAAa;IACxB,MAAM,EAAE,CAAC,EAAE,GAAG,EAAmB,EAAE,EAAE;QACnC,IAAI,CAAC,GAAG;YAAE,OAAO;QAEjB,MAAM,OAAO,GAAG,QAAQ,CAAC,eAAe,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAC3D,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAEjC,OAAO,UAAU,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,EAAE,CAAC,OAAe,EAAE,EAAE;QAC3B,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAE7C,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,CAAC,GAAG;YAAE,OAAO,SAAS,CAAC;QACrD,OAAO,EAAE,GAAG,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC;IACjC,CAAC;CACF,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n isValidElement,\n PropsWithoutRef,\n ReactElement,\n Ref,\n useContext\n} from 'react';\nimport styled from 'styled-components';\n\nimport { Tag, ForwardProps } from '@pega/cosmos-react-core';\nimport { getXMLAttributes } from '@pega/cosmos-react-rte';\n\nimport { FeedContext } from '../Feed/Feed.context';\n\ninterface HashtagButtonProps {\n /** Text for the button, or an object containing all necessary props. */\n children: Record<string, string> | ReactElement;\n /** The tag value. */\n tag?: string;\n}\n\nconst StyledTag = styled(Tag)`\n cursor: pointer;\n`;\n\nconst serializer = new XMLSerializer();\n\nconst HashtagButton: FunctionComponent<HashtagButtonProps & ForwardProps> = forwardRef(\n function HashtagButton(\n { children, tag: tagProp = '', ...restProps }: PropsWithoutRef<HashtagButtonProps>,\n ref: Ref<HTMLButtonElement>\n ) {\n const { onTagClick } = useContext(FeedContext);\n\n let tag = '';\n\n if (!isValidElement<any>(children)) {\n if (!children.tag) return <span>{children.rawText}</span>;\n tag = children.tag;\n } else {\n tag = tagProp;\n }\n\n return (\n <StyledTag {...restProps} ref={ref} onClick={() => onTagClick?.(tag)} spellCheck={false}>\n {isValidElement(children) ? children : tag}\n </StyledTag>\n );\n }\n);\n\nexport const HashtagButtonConfig = {\n type: 'tag',\n xmlElement: 'pega-tag',\n regexPattern: /(?:^|)<pega-tag (?:[^\\n/]|\\/(?!>))+\\/>/gm,\n component: HashtagButton,\n inject: ({ tag }: { tag: string }) => {\n if (!tag) return;\n\n const element = document.createElementNS(null, 'pega-tag');\n element.setAttribute('tag', tag);\n\n return serializer.serializeToString(element);\n },\n extract: (element: string) => {\n const attributes = getXMLAttributes(element);\n\n if (!attributes || !attributes.tag) return undefined;\n return { tag: attributes.tag };\n }\n};\n\nexport default HashtagButton;\n"]}
@@ -3,7 +3,7 @@ import { ForwardProps } from '@pega/cosmos-react-core';
3
3
  interface MentionButtonProps {
4
4
  /** Text for the button, or an object containing all necessary props. */
5
5
  children: Record<string, string> | ReactElement;
6
- /** The id of the mention. */
6
+ /** The id of the mention. */
7
7
  id?: string;
8
8
  /** The text of the mention button. */
9
9
  text?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"MentionButton.d.ts","sourceRoot":"","sources":["../../../src/components/MentionButton/MentionButton.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAGjB,YAAY,EAKb,MAAM,OAAO,CAAC;AAGf,OAAO,EAEL,YAAY,EAKb,MAAM,yBAAyB,CAAC;AAKjC,UAAU,kBAAkB;IAC1B,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC;IAChD,8BAA8B;IAC9B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,sCAAsC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAoBD,QAAA,MAAM,aAAa,EAAE,iBAAiB,CAAC,kBAAkB,GAAG,YAAY,CAiGvE,CAAC;AAEF,eAAO,MAAM,mBAAmB;;;;;;YAKW,MAAM;cAAQ,MAAM;cAAQ,MAAM;;;uBAWxD,MAAM;;;;;;CAW1B,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"MentionButton.d.ts","sourceRoot":"","sources":["../../../src/components/MentionButton/MentionButton.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAGjB,YAAY,EAKb,MAAM,OAAO,CAAC;AAGf,OAAO,EAEL,YAAY,EAIb,MAAM,yBAAyB,CAAC;AAKjC,UAAU,kBAAkB;IAC1B,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC;IAChD,6BAA6B;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,sCAAsC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAoBD,QAAA,MAAM,aAAa,EAAE,iBAAiB,CAAC,kBAAkB,GAAG,YAAY,CAoFvE,CAAC;AAEF,eAAO,MAAM,mBAAmB;;;;;;YAKW,MAAM;cAAQ,MAAM;cAAQ,MAAM;;;uBAWxD,MAAM;;;;;;CAW1B,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef, isValidElement, useContext, useRef, useState } from 'react';
2
+ import { forwardRef, isValidElement, useContext, useState } from 'react';
3
3
  import styled from 'styled-components';
4
- import { Button, Link, Popover, useConsolidatedRef, useOuterEvent } from '@pega/cosmos-react-core';
4
+ import { Button, Link, useConsolidatedRef, useElement } from '@pega/cosmos-react-core';
5
5
  import { getXMLAttributes } from '@pega/cosmos-react-rte';
6
6
  import { FeedContext } from '../Feed/Feed.context';
7
7
  const StyledButton = styled(Button) `
@@ -19,15 +19,11 @@ const StyledLink = styled(Link) `
19
19
  }
20
20
  `;
21
21
  const serializer = new XMLSerializer();
22
- const MentionButton = forwardRef(({ children, id: idProp = '', text: textProp = '', type: typeProp = '', href: hrefProp = '', ...restProps }, ref) => {
23
- const { feedRef, onMentionClick, onMentionPreview } = useContext(FeedContext);
24
- const [showPopover, setShowPopover] = useState(false);
22
+ const MentionButton = forwardRef(function MentionButton({ children, id: idProp = '', text: textProp = '', type: typeProp = '', href: hrefProp = '', ...restProps }, ref) {
23
+ const { onMentionClick, onMentionPreview } = useContext(FeedContext);
25
24
  const [mentionContent, setMentionContent] = useState();
25
+ const [target, setTarget] = useElement(null);
26
26
  const mentionRef = useConsolidatedRef(ref);
27
- const popoverRef = useRef(null);
28
- useOuterEvent(['click', 'focusin'], [mentionRef, popoverRef], () => {
29
- setShowPopover(false);
30
- });
31
27
  let id = '';
32
28
  let text = '';
33
29
  let type = '';
@@ -46,15 +42,17 @@ const MentionButton = forwardRef(({ children, id: idProp = '', text: textProp =
46
42
  type = typeProp;
47
43
  href = hrefProp;
48
44
  }
49
- const handleClick = () => {
45
+ const handleClick = (e) => {
46
+ setTarget(e.currentTarget);
50
47
  const comp = onMentionClick?.({
51
48
  id,
52
49
  text,
53
- type
50
+ type,
51
+ target: e.currentTarget,
52
+ closeGlimpse: () => setTarget(null)
54
53
  });
55
54
  if (comp)
56
- setShowPopover(true);
57
- setMentionContent(comp);
55
+ setMentionContent(comp);
58
56
  };
59
57
  return (_jsxs(_Fragment, { children: [href ? (_jsx(StyledLink, { ...restProps, ref: mentionRef, href: href, previewable: !!onMentionPreview, onPreview: onMentionPreview
60
58
  ? () => onMentionPreview({
@@ -62,7 +60,7 @@ const MentionButton = forwardRef(({ children, id: idProp = '', text: textProp =
62
60
  text,
63
61
  type
64
62
  })
65
- : undefined, spellCheck: false, children: isValidElement(children) ? children : text })) : (_jsx(StyledButton, { ...restProps, ref: mentionRef, variant: 'link', onClick: handleClick, spellCheck: false, children: isValidElement(children) ? children : text })), _jsx(Popover, { ref: popoverRef, show: showPopover, target: mentionRef.current, placement: 'bottom-start', portal: feedRef?.current ?? undefined, hideOnTargetHidden: true, arrow: true, children: mentionContent })] }));
63
+ : undefined, spellCheck: false, children: isValidElement(children) ? children : text })) : (_jsx(StyledButton, { ...restProps, ref: mentionRef, variant: 'link', onClick: handleClick, spellCheck: false, children: isValidElement(children) ? children : text })), target && mentionContent] }));
66
64
  });
67
65
  export const MentionButtonConfig = {
68
66
  type: 'mention',
@@ -1 +1 @@
1
- {"version":3,"file":"MentionButton.js","sourceRoot":"","sources":["../../../src/components/MentionButton/MentionButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAEV,cAAc,EAId,UAAU,EACV,MAAM,EACN,QAAQ,EACT,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EACL,MAAM,EAEN,IAAI,EACJ,OAAO,EACP,kBAAkB,EAClB,aAAa,EACd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAenD,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;;;;;;CAMlC,CAAC;AAEF,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;;;;;;CAM9B,CAAC;AAEF,MAAM,UAAU,GAAG,IAAI,aAAa,EAAE,CAAC;AAEvC,MAAM,aAAa,GAAyD,UAAU,CACpF,CACE,EACE,QAAQ,EACR,EAAE,EAAE,MAAM,GAAG,EAAE,EACf,IAAI,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ponent,\n isValidElement,\n PropsWithoutRef,\n ReactElement,\n Ref,\n useContext,\n useRef,\n useState\n} from 'react';\nimport styled from 'styled-components';\n\nimport {\n Button,\n ForwardProps,\n Link,\n Popover,\n useConsolidatedRef,\n useOuterEvent\n} from '@pega/cosmos-react-core';\nimport { getXMLAttributes } from '@pega/cosmos-react-rte';\n\nimport { FeedContext } from '../Feed/Feed.context';\n\ninterface MentionButtonProps {\n /** Text for the button, or an object containing all necessary props. */\n children: Record<string, string> | ReactElement;\n /** The id of the mention. */\n id?: string;\n /** The text of the mention button. */\n text?: string;\n /** Designates the type of the mention for proper handling on click. */\n type?: string;\n /** If an href is provided, render a link. Otherwise, render a button. */\n href?: string;\n}\n\nconst StyledButton = styled(Button)`\n &:enabled:focus,\n &:not([disabled]):focus {\n box-shadow: none;\n text-decoration: underline;\n }\n`;\n\nconst StyledLink = styled(Link)`\n &:enabled:focus,\n &:not([disabled]):focus {\n box-shadow: none;\n text-decoration: underline;\n }\n`;\n\nconst serializer = new XMLSerializer();\n\nconst MentionButton: FunctionComponent<MentionButtonProps & ForwardProps> = forwardRef(\n (\n {\n children,\n id: idProp = '',\n text: textProp = '',\n type: typeProp = '',\n href: hrefProp = '',\n ...restProps\n }: PropsWithoutRef<MentionButtonProps>,\n ref: Ref<HTMLButtonElement>\n ) => {\n const { feedRef, onMentionClick, onMentionPreview } = useContext(FeedContext);\n const [showPopover, setShowPopover] = useState(false);\n const [mentionContent, setMentionContent] = useState<JSX.Element | undefined>();\n const mentionRef = useConsolidatedRef(ref);\n const popoverRef = useRef(null);\n\n useOuterEvent(['click', 'focusin'], [mentionRef, popoverRef], () => {\n setShowPopover(false);\n });\n\n let id = '';\n let text = '';\n let type = '';\n let href = '';\n\n if (!isValidElement(children)) {\n if (!children.id || !children.text || !children.type) return <span>{children.rawText}</span>;\n id = children.id;\n text = children.text;\n type = children.type;\n href = children.href || '';\n } else {\n id = idProp;\n text = textProp;\n type = typeProp;\n href = hrefProp;\n }\n\n const handleClick = () => {\n const comp = onMentionClick?.({\n id,\n text,\n type\n });\n if (comp) setShowPopover(true);\n setMentionContent(comp);\n };\n\n return (\n <>\n {href ? (\n <StyledLink\n {...restProps}\n ref={mentionRef}\n href={href}\n previewable={!!onMentionPreview}\n onPreview={\n onMentionPreview\n ? () =>\n onMentionPreview({\n id,\n text,\n type\n })\n : undefined\n }\n spellCheck={false}\n >\n {isValidElement(children) ? children : text}\n </StyledLink>\n ) : (\n <StyledButton\n {...restProps}\n ref={mentionRef}\n variant='link'\n onClick={handleClick}\n spellCheck={false}\n >\n {isValidElement(children) ? children : text}\n </StyledButton>\n )}\n <Popover\n ref={popoverRef}\n show={showPopover}\n target={mentionRef.current}\n placement='bottom-start'\n portal={feedRef?.current ?? undefined}\n hideOnTargetHidden\n arrow\n >\n {mentionContent}\n </Popover>\n </>\n );\n }\n);\n\nexport const MentionButtonConfig = {\n type: 'mention',\n xmlElement: 'pega-mention',\n regexPattern: /(?:^|)<pega-mention (?:[^\\n/]|\\/(?!>))+\\/>/g,\n component: MentionButton,\n inject: ({ id, type, text, href }: { id: string; type: string; text: string; href?: string }) => {\n if (!id || !type || !text) return;\n\n const element = document.createElementNS(null, 'pega-mention');\n element.setAttribute('id', id);\n element.setAttribute('text', text);\n element.setAttribute('type', type);\n if (href) element.setAttribute('href', href);\n\n return serializer.serializeToString(element);\n },\n extract: (element: string) => {\n const attributes = getXMLAttributes(element);\n\n if (!attributes || !attributes.id || !attributes.text || !attributes.type) return undefined;\n return {\n id: attributes.id,\n text: attributes.text,\n type: attributes.type,\n href: attributes.href\n };\n }\n};\n\nexport default MentionButton;\n"]}
1
+ {"version":3,"file":"MentionButton.js","sourceRoot":"","sources":["../../../src/components/MentionButton/MentionButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAEV,cAAc,EAId,UAAU,EACV,QAAQ,EAET,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EACL,MAAM,EAEN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B,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,IAAI,EAAE,UAAU,CAAC,IAAI;SACtB,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n isValidElement,\n PropsWithoutRef,\n ReactElement,\n Ref,\n useContext,\n useState,\n MouseEvent\n} from 'react';\nimport styled from 'styled-components';\n\nimport {\n Button,\n ForwardProps,\n Link,\n useConsolidatedRef,\n useElement\n} from '@pega/cosmos-react-core';\nimport { getXMLAttributes } from '@pega/cosmos-react-rte';\n\nimport { FeedContext } from '../Feed/Feed.context';\n\ninterface MentionButtonProps {\n /** Text for the button, or an object containing all necessary props. */\n children: Record<string, string> | ReactElement;\n /** The id of the mention. */\n id?: string;\n /** The text of the mention button. */\n text?: string;\n /** Designates the type of the mention for proper handling on click. */\n type?: string;\n /** If an href is provided, render a link. Otherwise, render a button. */\n href?: string;\n}\n\nconst StyledButton = styled(Button)`\n &:enabled:focus,\n &:not([disabled]):focus {\n box-shadow: none;\n text-decoration: underline;\n }\n`;\n\nconst StyledLink = styled(Link)`\n &:enabled:focus,\n &:not([disabled]):focus {\n box-shadow: none;\n text-decoration: underline;\n }\n`;\n\nconst serializer = new XMLSerializer();\n\nconst MentionButton: FunctionComponent<MentionButtonProps & ForwardProps> = forwardRef(\n function MentionButton(\n {\n children,\n id: idProp = '',\n text: textProp = '',\n type: typeProp = '',\n href: hrefProp = '',\n ...restProps\n }: PropsWithoutRef<MentionButtonProps>,\n ref: Ref<HTMLButtonElement>\n ) {\n const { onMentionClick, onMentionPreview } = useContext(FeedContext);\n const [mentionContent, setMentionContent] = useState<JSX.Element | undefined>();\n const [target, setTarget] = useElement<HTMLButtonElement>(null);\n const mentionRef = useConsolidatedRef(ref);\n\n let id = '';\n let text = '';\n let type = '';\n let href = '';\n\n if (!isValidElement<any>(children)) {\n if (!children.id || !children.text || !children.type) return <span>{children.rawText}</span>;\n id = children.id;\n text = children.text;\n type = children.type;\n href = children.href || '';\n } else {\n id = idProp;\n text = textProp;\n type = typeProp;\n href = hrefProp;\n }\n\n const handleClick = (e: MouseEvent<HTMLButtonElement>) => {\n setTarget(e.currentTarget);\n const comp = onMentionClick?.({\n id,\n text,\n type,\n target: e.currentTarget,\n closeGlimpse: () => setTarget(null)\n });\n if (comp) setMentionContent(comp);\n };\n\n return (\n <>\n {href ? (\n <StyledLink\n {...restProps}\n ref={mentionRef}\n href={href}\n previewable={!!onMentionPreview}\n onPreview={\n onMentionPreview\n ? () =>\n onMentionPreview({\n id,\n text,\n type\n })\n : undefined\n }\n spellCheck={false}\n >\n {isValidElement(children) ? children : text}\n </StyledLink>\n ) : (\n <StyledButton\n {...restProps}\n ref={mentionRef}\n variant='link'\n onClick={handleClick}\n spellCheck={false}\n >\n {isValidElement(children) ? children : text}\n </StyledButton>\n )}\n {target && mentionContent}\n </>\n );\n }\n);\n\nexport const MentionButtonConfig = {\n type: 'mention',\n xmlElement: 'pega-mention',\n regexPattern: /(?:^|)<pega-mention (?:[^\\n/]|\\/(?!>))+\\/>/g,\n component: MentionButton,\n inject: ({ id, type, text, href }: { id: string; type: string; text: string; href?: string }) => {\n if (!id || !type || !text) return;\n\n const element = document.createElementNS(null, 'pega-mention');\n element.setAttribute('id', id);\n element.setAttribute('text', text);\n element.setAttribute('type', type);\n if (href) element.setAttribute('href', href);\n\n return serializer.serializeToString(element);\n },\n extract: (element: string) => {\n const attributes = getXMLAttributes(element);\n\n if (!attributes || !attributes.id || !attributes.text || !attributes.type) return undefined;\n return {\n id: attributes.id,\n text: attributes.text,\n type: attributes.type,\n href: attributes.href\n };\n }\n};\n\nexport default MentionButton;\n"]}
package/package.json CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "@pega/cosmos-react-social",
3
- "version": "4.0.0-dev.9.1",
4
- "author": "Pegasystems",
5
- "license": "SEE LICENSE IN LICENSE",
3
+ "version": "4.0.0",
6
4
  "repository": {
7
5
  "type": "git",
8
6
  "url": "https://github.com/pegasystems/cosmos-react.git",
9
7
  "directory": "packages/cosmos-social"
10
8
  },
9
+ "license": "SEE LICENSE IN LICENSE",
10
+ "author": "Pegasystems",
11
+ "sideEffects": [
12
+ "./src/components/Email/EmailEntity.tsx",
13
+ "./lib/components/Email/EmailEntity.js"
14
+ ],
11
15
  "main": "lib/index.js",
12
16
  "types": "lib/index.d.ts",
13
17
  "files": [
@@ -15,17 +19,13 @@
15
19
  "README.md",
16
20
  "lib"
17
21
  ],
18
- "sideEffects": [
19
- "./src/components/Email/EmailEntity.tsx",
20
- "./lib/components/Email/EmailEntity.js"
21
- ],
22
22
  "scripts": {
23
23
  "build": "tsc -b"
24
24
  },
25
25
  "dependencies": {
26
- "@pega/cosmos-react-core": "4.0.0-dev.9.1",
27
- "@pega/cosmos-react-rte": "4.0.0-dev.9.1",
28
- "@pega/cosmos-react-work": "4.0.0-dev.9.1",
26
+ "@pega/cosmos-react-core": "4.0.0",
27
+ "@pega/cosmos-react-rte": "4.0.0",
28
+ "@pega/cosmos-react-work": "4.0.0",
29
29
  "@types/parse5": "^6.0.0",
30
30
  "@types/react": "^16.14.24 || ^17.0.38",
31
31
  "@types/react-dom": "^16.9.14 || ^17.0.11",
@@ -37,16 +37,14 @@
37
37
  "styled-components": "^5.2.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@storybook/addon-a11y": "^6.4.19",
41
- "@storybook/addon-actions": "^6.4.19",
42
- "@storybook/addon-storysource": "^6.4.19",
43
- "@storybook/addon-toolbars": "^6.4.19",
44
- "@storybook/addons": "^6.4.19",
45
- "@storybook/react": "^6.4.19",
46
- "@storybook/testing-react": "^1.2.4",
47
- "@storybook/theming": "^6.4.19",
40
+ "@storybook/addon-a11y": "^7.0.24",
41
+ "@storybook/addon-actions": "^7.0.24",
42
+ "@storybook/addon-storysource": "^7.0.24",
43
+ "@storybook/addon-toolbars": "^7.0.24",
44
+ "@storybook/react": "^7.0.24",
45
+ "@storybook/theming": "^7.0.24",
48
46
  "@testing-library/react": "^12.1.3",
49
47
  "@testing-library/user-event": "^13.5.0",
50
- "typescript": "~4.7.2"
48
+ "typescript": "~5.0.2"
51
49
  }
52
50
  }
@@ -1,23 +0,0 @@
1
- import { FunctionComponent, Ref } from 'react';
2
- import { ForwardProps } from '@pega/cosmos-react-core';
3
- import { RepeatingViewRow } from './RepeatingView';
4
- import { TranscriptMessageProps } from './TranscriptMessage';
5
- import { SystemMessageProps } from './SystemMessage';
6
- export declare type ChatTranscriptItem = (TranscriptMessageProps & {
7
- type: 'transcript';
8
- id: RepeatingViewRow['id'];
9
- }) | (SystemMessageProps & {
10
- type: 'system';
11
- id: RepeatingViewRow['id'];
12
- });
13
- export interface ChatTranscriptProps {
14
- /** ref to the element */
15
- ref?: Ref<HTMLDivElement>;
16
- /** Title for transcript's body */
17
- title?: string;
18
- /** Transcript messages array */
19
- transcript: ChatTranscriptItem[];
20
- }
21
- declare const ChatTranscript: FunctionComponent<ChatTranscriptProps & ForwardProps>;
22
- export default ChatTranscript;
23
- //# sourceMappingURL=ChatTranscript.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ChatTranscript.d.ts","sourceRoot":"","sources":["../../../src/components/Chat/ChatTranscript.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAmB,GAAG,EAAE,MAAM,OAAO,CAAC;AAG5E,OAAO,EAA0B,YAAY,EAAQ,MAAM,yBAAyB,CAAC;AAErF,OAAsB,EAAE,gBAAgB,EAA2B,MAAM,iBAAiB,CAAC;AAC3F,OAA0B,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAsB,EAAE,kBAAkB,EAAuB,MAAM,iBAAiB,CAAC;AAEzF,oBAAY,kBAAkB,GAC1B,CAAC,sBAAsB,GAAG;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,EAAE,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,GAC7E,CAAC,kBAAkB,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,EAAE,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,CAAC;AAE1E,MAAM,WAAW,mBAAmB;IAClC,yBAAyB;IACzB,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;IAC1B,kCAAkC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gCAAgC;IAChC,UAAU,EAAE,kBAAkB,EAAE,CAAC;CAClC;AAgCD,QAAA,MAAM,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,YAAY,CAwCzE,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -1,45 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef } from 'react';
3
- import styled, { css } from 'styled-components';
4
- import { Flex, defaultThemeProp, Text } from '@pega/cosmos-react-core';
5
- import RepeatingView, { StyledRepeatingViewItem } from './RepeatingView';
6
- import TranscriptMessage from './TranscriptMessage';
7
- import SystemMessage, { StyledSystemMessage } from './SystemMessage';
8
- const StyledChatTranscriptHeading = styled.h4 ``;
9
- const StyledChatTranscriptContainer = styled.div(props => {
10
- const { theme: { base: { shadow: { focus: shadowFocus }, spacing } } } = props;
11
- return css `
12
- width: 100%;
13
- outline: none;
14
- padding: 0 0.75rem 0.5rem;
15
- &:focus {
16
- box-shadow: ${shadowFocus};
17
- }
18
- ${StyledChatTranscriptHeading}, ${StyledRepeatingViewItem}, ${StyledSystemMessage} {
19
- margin: calc(0.25 * ${spacing});
20
- padding: calc(0.25 * ${spacing});
21
- }
22
- ${StyledSystemMessage} {
23
- padding: 0;
24
- }
25
- `;
26
- });
27
- StyledChatTranscriptContainer.defaultProps = defaultThemeProp;
28
- const ChatTranscript = forwardRef((props, ref) => {
29
- const { transcript: transcriptItems = [], title, ...restProps } = props;
30
- return (_jsxs(Flex, { ref: ref, as: StyledChatTranscriptContainer, container: {
31
- direction: 'column',
32
- gap: 0.5
33
- }, ...restProps, children: [title && (_jsx(Text, { variant: 'h4', as: StyledChatTranscriptHeading, children: title })), _jsx(RepeatingView, { rows: transcriptItems, children: item => {
34
- const { id, type, ...transcriptItemRestProps } = item;
35
- if (type === 'transcript') {
36
- return (_jsx(TranscriptMessage, { ...transcriptItemRestProps }, id));
37
- }
38
- if (type === 'system') {
39
- return (_jsx(SystemMessage, { ...transcriptItemRestProps }, id));
40
- }
41
- return _jsx(_Fragment, {});
42
- } })] }));
43
- });
44
- export default ChatTranscript;
45
- //# sourceMappingURL=ChatTranscript.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ChatTranscript.js","sourceRoot":"","sources":["../../../src/components/Chat/ChatTranscript.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAA2C,MAAM,OAAO,CAAC;AAC5E,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAgB,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAErF,OAAO,aAAa,EAAE,EAAoB,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC3F,OAAO,iBAA6C,MAAM,qBAAqB,CAAC;AAChF,OAAO,aAAa,EAAE,EAAsB,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAezF,MAAM,2BAA2B,GAAG,MAAM,CAAC,EAAE,CAAA,EAAE,CAAC;AAEhD,MAAM,6BAA6B,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;IACvD,MAAM,EACJ,KAAK,EAAE,EACL,IAAI,EAAE,EACJ,MAAM,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,EAC9B,OAAO,EACR,EACF,EACF,GAAG,KAAK,CAAC;IACV,OAAO,GAAG,CAAA;;;;;oBAKQ,WAAW;;MAEzB,2BAA2B,KAAK,uBAAuB,KAAK,mBAAmB;4BACzD,OAAO;6BACN,OAAO;;MAE9B,mBAAmB;;;GAGtB,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,6BAA6B,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE9D,MAAM,cAAc,GAA0D,UAAU,CACtF,CAAC,KAA2C,EAAE,GAA+B,EAAE,EAAE;IAC/E,MAAM,EAAE,UAAU,EAAE,eAAe,GAAG,EAAE,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IACxE,OAAO,CACL,MAAC,IAAI,IACH,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,6BAA6B,EACjC,SAAS,EAAE;YACT,SAAS,EAAE,QAAQ;YACnB,GAAG,EAAE,GAAG;SACT,KACG,SAAS,aAEZ,KAAK,IAAI,CACR,KAAC,IAAI,IAAC,OAAO,EAAC,IAAI,EAAC,EAAE,EAAE,2BAA2B,YAC/C,KAAK,GACD,CACR,EACD,KAAC,aAAa,IAAC,IAAI,EAAE,eAAe,YACjC,IAAI,CAAC,EAAE;oBACN,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,uBAAuB,EAAE,GAAG,IAA0B,CAAC;oBAC5E,IAAI,IAAI,KAAK,YAAY,EAAE;wBACzB,OAAO,CACL,KAAC,iBAAiB,OAEX,uBAAkD,IADlD,EAAE,CAEP,CACH,CAAC;qBACH;oBACD,IAAI,IAAI,KAAK,QAAQ,EAAE;wBACrB,OAAO,CACL,KAAC,aAAa,OAAe,uBAA8C,IAAvD,EAAE,CAAyD,CAChF,CAAC;qBACH;oBACD,OAAO,mBAAK,CAAC;gBACf,CAAC,GACa,IACX,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import { forwardRef, FunctionComponent, PropsWithoutRef, Ref } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport { Flex, defaultThemeProp, ForwardProps, Text } from '@pega/cosmos-react-core';\n\nimport RepeatingView, { RepeatingViewRow, StyledRepeatingViewItem } from './RepeatingView';\nimport TranscriptMessage, { TranscriptMessageProps } from './TranscriptMessage';\nimport SystemMessage, { SystemMessageProps, StyledSystemMessage } from './SystemMessage';\n\nexport type ChatTranscriptItem =\n | (TranscriptMessageProps & { type: 'transcript'; id: RepeatingViewRow['id'] })\n | (SystemMessageProps & { type: 'system'; id: RepeatingViewRow['id'] });\n\nexport interface ChatTranscriptProps {\n /** ref to the element */\n ref?: Ref<HTMLDivElement>;\n /** Title for transcript's body */\n title?: string;\n /** Transcript messages array */\n transcript: ChatTranscriptItem[];\n}\n\nconst StyledChatTranscriptHeading = styled.h4``;\n\nconst StyledChatTranscriptContainer = styled.div(props => {\n const {\n theme: {\n base: {\n shadow: { focus: shadowFocus },\n spacing\n }\n }\n } = props;\n return css`\n width: 100%;\n outline: none;\n padding: 0 0.75rem 0.5rem;\n &:focus {\n box-shadow: ${shadowFocus};\n }\n ${StyledChatTranscriptHeading}, ${StyledRepeatingViewItem}, ${StyledSystemMessage} {\n margin: calc(0.25 * ${spacing});\n padding: calc(0.25 * ${spacing});\n }\n ${StyledSystemMessage} {\n padding: 0;\n }\n `;\n});\n\nStyledChatTranscriptContainer.defaultProps = defaultThemeProp;\n\nconst ChatTranscript: FunctionComponent<ChatTranscriptProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<ChatTranscriptProps>, ref: ChatTranscriptProps['ref']) => {\n const { transcript: transcriptItems = [], title, ...restProps } = props;\n return (\n <Flex\n ref={ref}\n as={StyledChatTranscriptContainer}\n container={{\n direction: 'column',\n gap: 0.5\n }}\n {...restProps}\n >\n {title && (\n <Text variant='h4' as={StyledChatTranscriptHeading}>\n {title}\n </Text>\n )}\n <RepeatingView rows={transcriptItems}>\n {item => {\n const { id, type, ...transcriptItemRestProps } = item as ChatTranscriptItem;\n if (type === 'transcript') {\n return (\n <TranscriptMessage\n key={id}\n {...(transcriptItemRestProps as TranscriptMessageProps)}\n />\n );\n }\n if (type === 'system') {\n return (\n <SystemMessage key={id} {...(transcriptItemRestProps as SystemMessageProps)} />\n );\n }\n return <></>;\n }}\n </RepeatingView>\n </Flex>\n );\n }\n);\n\nexport default ChatTranscript;\n"]}
@@ -1,35 +0,0 @@
1
- import { FunctionComponent, Ref } from 'react';
2
- import { ForwardProps, OmitStrict } from '@pega/cosmos-react-core';
3
- import { RepeatingViewProps, RepeatingViewRow } from './RepeatingView';
4
- import { MessageProps } from './Message';
5
- import { SystemMessageProps } from './SystemMessage';
6
- import { TypeIndicatorProps } from './TypeIndicator';
7
- export interface MessageListImperativeHandleProps {
8
- isScrolledToLatest: () => boolean;
9
- scrollToLatestMessage: () => void;
10
- scrollToNewMessage: () => void;
11
- }
12
- export declare type MessageListItemProps = (MessageProps & {
13
- type: 'message';
14
- id: RepeatingViewRow['id'];
15
- }) | (SystemMessageProps & {
16
- type: 'system';
17
- id: RepeatingViewRow['id'];
18
- }) | (TypeIndicatorProps & {
19
- type: 'typing';
20
- id: RepeatingViewRow['id'];
21
- });
22
- export interface MessageListProps extends OmitStrict<RepeatingViewProps, 'children' | 'rows' | 'ref'> {
23
- /** Messages Data array */
24
- messages: MessageListItemProps[];
25
- /** ref to the message list */
26
- ref?: Ref<MessageListImperativeHandleProps>;
27
- /** Total unread messages */
28
- unReadMessageCount?: number;
29
- /** on scroll to button */
30
- onScrollToButtonClick?: () => void;
31
- }
32
- export declare const NewMessageSeparatorId = "new-message-separator";
33
- declare const MessageList: FunctionComponent<MessageListProps & ForwardProps>;
34
- export default MessageList;
35
- //# sourceMappingURL=MessageList.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MessageList.d.ts","sourceRoot":"","sources":["../../../src/components/Chat/MessageList.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAGjB,GAAG,EAOJ,MAAM,OAAO,CAAC;AAGf,OAAO,EASL,YAAY,EACZ,UAAU,EACX,MAAM,yBAAyB,CAAC;AAGjC,OAAsB,EACpB,kBAAkB,EAClB,gBAAgB,EAIjB,MAAM,iBAAiB,CAAC;AACzB,OAAgB,EAAE,YAAY,EAAE,MA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- import { forwardRef, useImperativeHandle, useRef, useCallback, useState, useLayoutEffect } from 'react';
3
- import styled, { css } from 'styled-components';
4
- import { Button, Flex, Icon, registerIcon, StyledButton, useI18n, debounce, defaultThemeProp } from '@pega/cosmos-react-core';
5
- import * as caretDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/caret-down.icon';
6
- import RepeatingView, { StyledRepeatingView, StyledRepeatingViewItem, StyledRepeatingViewUL } from './RepeatingView';
7
- import Message from './Message';
8
- import SystemMessage from './SystemMessage';
9
- import TypeIndicator from './TypeIndicator';
10
- registerIcon(caretDownIcon);
11
- const StyledMessageList = styled.div ``;
12
- export const NewMessageSeparatorId = 'new-message-separator';
13
- const StyledMessageListContainer = styled.div(props => {
14
- const { theme: { base: { shadow: { high: shadowHigh }, colors: { white } } } } = props;
15
- return css `
16
- position: relative;
17
- overflow-y: hidden;
18
- > ${StyledMessageList} {
19
- overflow-y: auto;
20
- }
21
- > ${StyledButton} {
22
- position: absolute;
23
- bottom: 0;
24
- left: 50%;
25
- transform: translate(-50%, -50%);
26
- box-shadow: ${shadowHigh};
27
- z-index: 1;
28
- background-color: ${white};
29
- }
30
- ${StyledRepeatingView} {
31
- overflow-y: hidden;
32
- }
33
- ${StyledRepeatingViewUL} {
34
- padding: 1rem;
35
- }
36
-
37
- ${StyledRepeatingViewItem} {
38
- padding: 0.125rem 0;
39
- }
40
- `;
41
- });
42
- StyledMessageListContainer.defaultProps = defaultThemeProp;
43
- const ScrollToLatest = props => {
44
- const { scrollContainerRef } = props;
45
- useLayoutEffect(() => {
46
- if (scrollContainerRef.current) {
47
- scrollContainerRef.current.scrollTop =
48
- scrollContainerRef.current.scrollHeight - scrollContainerRef.current.offsetHeight;
49
- }
50
- });
51
- return _jsx(_Fragment, {});
52
- };
53
- const MessageList = forwardRef((props, ref) => {
54
- const { messages, unReadMessageCount = 0, onScrollToButtonClick, ...restProps } = props;
55
- const t = useI18n();
56
- const conversationRef = useRef(null);
57
- const scrollRef = useRef(false);
58
- const isScrolledToLatest = useCallback(() => {
59
- return conversationRef.current
60
- ? conversationRef.current.scrollHeight -
61
- conversationRef.current.scrollTop -
62
- conversationRef.current.offsetHeight <=
63
- 30
64
- : true;
65
- }, [conversationRef.current]);
66
- const scrollToLatestMessage = useCallback(() => {
67
- if (conversationRef.current) {
68
- conversationRef.current.scrollTop = conversationRef.current.scrollHeight;
69
- }
70
- }, [conversationRef.current]);
71
- const [displayScrollLatest, setDisplayScrollToLatest] = useState(false);
72
- const onMessageListScroll = useCallback(() => {
73
- const isScrolled = isScrolledToLatest();
74
- if (scrollRef.current && isScrolled) {
75
- scrollRef.current = false;
76
- if (unReadMessageCount) {
77
- onScrollToButtonClick?.();
78
- }
79
- }
80
- if (!scrollRef.current && !isScrolled) {
81
- scrollRef.current = true;
82
- }
83
- setDisplayScrollToLatest(!isScrolled);
84
- }, [isScrolledToLatest(), unReadMessageCount]);
85
- const scrollToNewMessage = useCallback(() => {
86
- if (conversationRef.current) {
87
- setDisplayScrollToLatest(false);
88
- const newMessageIndicatorEle = conversationRef.current.querySelector('[data-new-message-separator]');
89
- if (newMessageIndicatorEle) {
90
- conversationRef.current.scrollTop = newMessageIndicatorEle.offsetTop;
91
- }
92
- else {
93
- conversationRef.current.scrollTop = conversationRef.current.scrollHeight;
94
- }
95
- }
96
- }, [conversationRef.current]);
97
- useImperativeHandle(ref, () => ({
98
- isScrolledToLatest,
99
- scrollToLatestMessage,
100
- scrollToNewMessage
101
- }), [isScrolledToLatest, scrollToLatestMessage, scrollToNewMessage]);
102
- return (_jsxs(_Fragment, { children: [_jsxs(Flex, { as: StyledMessageListContainer, item: {
103
- grow: 1
104
- }, container: {
105
- direction: 'column'
106
- }, ...restProps, children: [(unReadMessageCount > 0 || displayScrollLatest) && (_jsxs(Button, { "aria-label": unReadMessageCount > 0
107
- ? t('scroll_to_unread_messages')
108
- : t('scroll_to_latest_message'), onClick: () => {
109
- if (unReadMessageCount > 0) {
110
- scrollToNewMessage();
111
- }
112
- else {
113
- scrollToLatestMessage();
114
- }
115
- onScrollToButtonClick?.();
116
- }, icon: unReadMessageCount === 0, children: [_jsx(Icon, { name: 'caret-down' }), unReadMessageCount > 0 && _jsxs(_Fragment, { children: ["\u00A0 ", t('new_messages')] })] })), _jsx(RepeatingView, { as: StyledMessageList, container: { direction: 'column' }, ref: conversationRef, rows: messages, onScroll: debounce(onMessageListScroll, 100), ...restProps, children: (item) => {
117
- const { id, type, ...messageListItemRestProps } = item;
118
- if (type === 'message') {
119
- return _jsx(Message, { ...messageListItemRestProps }, id);
120
- }
121
- if (type === 'system') {
122
- const extraProps = {};
123
- if (id === NewMessageSeparatorId) {
124
- extraProps['data-new-message-separator'] = NewMessageSeparatorId;
125
- }
126
- return (_jsx(SystemMessage, { ...messageListItemRestProps, ...extraProps }, id));
127
- }
128
- if (type === 'typing') {
129
- return (_jsx(TypeIndicator, { ...messageListItemRestProps }, id));
130
- }
131
- } })] }), isScrolledToLatest() && _jsx(ScrollToLatest, { scrollContainerRef: conversationRef })] }));
132
- });
133
- export default MessageList;
134
- //# sourceMappingURL=MessageList.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MessageList.js","sourceRoot":"","sources":["../../../src/components/Chat/MessageList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAGL,UAAU,EAEV,mBAAmB,EACnB,MAAM,EACN,WAAW,EACX,QAAQ,EACR,eAAe,EAEhB,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,gBAAgB,EAGjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,aAAa,MAAM,mEAAmE,CAAC;AAEnG,OAAO,aAAa,EAAE,EAGpB,mBAAmB,EACnB,uBAAuB,EACvB,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,OA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wardRef,\n Ref,\n useImperativeHandle,\n useRef,\n useCallback,\n useState,\n useLayoutEffect,\n RefObject\n} from 'react';\nimport styled, { css } from 'styled-components';\n\nimport {\n Button,\n Flex,\n Icon,\n registerIcon,\n StyledButton,\n useI18n,\n debounce,\n defaultThemeProp,\n ForwardProps,\n OmitStrict\n} from '@pega/cosmos-react-core';\nimport * as caretDownIcon from '@pega/cosmos-react-core/lib/components/Icon/icons/caret-down.icon';\n\nimport RepeatingView, {\n RepeatingViewProps,\n RepeatingViewRow,\n StyledRepeatingView,\n StyledRepeatingViewItem,\n StyledRepeatingViewUL\n} from './RepeatingView';\nimport Message, { MessageProps } from './Message';\nimport SystemMessage, { SystemMessageProps } from './SystemMessage';\nimport TypeIndicator, { TypeIndicatorProps } from './TypeIndicator';\n\nregisterIcon(caretDownIcon);\n\nexport interface MessageListImperativeHandleProps {\n isScrolledToLatest: () => boolean;\n scrollToLatestMessage: () => void;\n scrollToNewMessage: () => void;\n}\n\nexport type MessageListItemProps =\n | (MessageProps & { type: 'message'; id: RepeatingViewRow['id'] })\n | (SystemMessageProps & { type: 'system'; id: RepeatingViewRow['id'] })\n | (TypeIndicatorProps & { type: 'typing'; id: RepeatingViewRow['id'] });\n\nexport interface MessageListProps\n extends OmitStrict<RepeatingViewProps, 'children' | 'rows' | 'ref'> {\n /** Messages Data array */\n messages: MessageListItemProps[];\n /** ref to the message list */\n ref?: Ref<MessageListImperativeHandleProps>;\n /** Total unread messages */\n unReadMessageCount?: number;\n /** on scroll to button */\n onScrollToButtonClick?: () => void;\n}\n\nconst StyledMessageList = styled.div``;\n\nexport const NewMessageSeparatorId = 'new-message-separator';\n\nconst StyledMessageListContainer = styled.div(props => {\n const {\n theme: {\n base: {\n shadow: { high: shadowHigh },\n colors: { white }\n }\n }\n } = props;\n return css`\n position: relative;\n overflow-y: hidden;\n > ${StyledMessageList} {\n overflow-y: auto;\n }\n > ${StyledButton} {\n position: absolute;\n bottom: 0;\n left: 50%;\n transform: translate(-50%, -50%);\n box-shadow: ${shadowHigh};\n z-index: 1;\n background-color: ${white};\n }\n ${StyledRepeatingView} {\n overflow-y: hidden;\n }\n ${StyledRepeatingViewUL} {\n padding: 1rem;\n }\n\n ${StyledRepeatingViewItem} {\n padding: 0.125rem 0;\n }\n `;\n});\n\nStyledMessageListContainer.defaultProps = defaultThemeProp;\n\nconst ScrollToLatest: FunctionComponent<{\n scrollContainerRef: RefObject<HTMLUListElement>;\n}> = props => {\n const { scrollContainerRef } = props;\n useLayoutEffect(() => {\n if (scrollContainerRef.current) {\n scrollContainerRef.current.scrollTop =\n scrollContainerRef.current.scrollHeight - scrollContainerRef.current.offsetHeight;\n }\n });\n return <></>;\n};\n\nconst MessageList: FunctionComponent<MessageListProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<MessageListProps>, ref: MessageListProps['ref']) => {\n const { messages, unReadMessageCount = 0, onScrollToButtonClick, ...restProps } = props;\n\n const t = useI18n();\n const conversationRef = useRef<HTMLUListElement>(null);\n const scrollRef = useRef(false);\n\n const isScrolledToLatest: MessageListImperativeHandleProps['isScrolledToLatest'] =\n useCallback(() => {\n return conversationRef.current\n ? conversationRef.current.scrollHeight -\n conversationRef.current.scrollTop -\n conversationRef.current.offsetHeight <=\n 30\n : true;\n }, [conversationRef.current]);\n\n const scrollToLatestMessage: MessageListImperativeHandleProps['scrollToLatestMessage'] =\n useCallback(() => {\n if (conversationRef.current) {\n conversationRef.current.scrollTop = conversationRef.current.scrollHeight;\n }\n }, [conversationRef.current]);\n\n const [displayScrollLatest, setDisplayScrollToLatest] = useState(false);\n\n const onMessageListScroll = useCallback(() => {\n const isScrolled = isScrolledToLatest();\n if (scrollRef.current && isScrolled) {\n scrollRef.current = false;\n if (unReadMessageCount) {\n onScrollToButtonClick?.();\n }\n }\n\n if (!scrollRef.current && !isScrolled) {\n scrollRef.current = true;\n }\n\n setDisplayScrollToLatest(!isScrolled);\n }, [isScrolledToLatest(), unReadMessageCount]);\n\n const scrollToNewMessage: MessageListImperativeHandleProps['scrollToNewMessage'] =\n useCallback(() => {\n if (conversationRef.current) {\n setDisplayScrollToLatest(false);\n const newMessageIndicatorEle = conversationRef.current.querySelector<HTMLElement>(\n '[data-new-message-separator]'\n );\n if (newMessageIndicatorEle) {\n conversationRef.current.scrollTop = newMessageIndicatorEle.offsetTop;\n } else {\n conversationRef.current.scrollTop = conversationRef.current.scrollHeight;\n }\n }\n }, [conversationRef.current]);\n\n useImperativeHandle<MessageListImperativeHandleProps, MessageListImperativeHandleProps>(\n ref,\n () => ({\n isScrolledToLatest,\n scrollToLatestMessage,\n scrollToNewMessage\n }),\n [isScrolledToLatest, scrollToLatestMessage, scrollToNewMessage]\n );\n\n return (\n <>\n <Flex\n as={StyledMessageListContainer}\n item={{\n grow: 1\n }}\n container={{\n direction: 'column'\n }}\n {...restProps}\n >\n {(unReadMessageCount > 0 || displayScrollLatest) && (\n <Button\n aria-label={\n unReadMessageCount > 0\n ? t('scroll_to_unread_messages')\n : t('scroll_to_latest_message')\n }\n onClick={() => {\n if (unReadMessageCount > 0) {\n scrollToNewMessage();\n } else {\n scrollToLatestMessage();\n }\n onScrollToButtonClick?.();\n }}\n icon={unReadMessageCount === 0}\n >\n <Icon name='caret-down' />\n {unReadMessageCount > 0 && <>&nbsp; {t('new_messages')}</>}\n </Button>\n )}\n <RepeatingView\n as={StyledMessageList}\n container={{ direction: 'column' }}\n ref={conversationRef}\n rows={messages}\n onScroll={debounce(onMessageListScroll, 100)}\n {...restProps}\n >\n {(item: RepeatingViewRow) => {\n const { id, type, ...messageListItemRestProps } = item as MessageListItemProps;\n if (type === 'message') {\n return <Message key={id} {...(messageListItemRestProps as MessageProps)} />;\n }\n\n if (type === 'system') {\n const extraProps: Record<string, string> = {};\n if (id === NewMessageSeparatorId) {\n extraProps['data-new-message-separator'] = NewMessageSeparatorId;\n }\n return (\n <SystemMessage\n key={id}\n {...(messageListItemRestProps as SystemMessageProps)}\n {...extraProps}\n />\n );\n }\n if (type === 'typing') {\n return (\n <TypeIndicator key={id} {...(messageListItemRestProps as TypeIndicatorProps)} />\n );\n }\n }}\n </RepeatingView>\n </Flex>\n {isScrolledToLatest() && <ScrollToLatest scrollContainerRef={conversationRef} />}\n </>\n );\n }\n);\n\nexport default MessageList;\n"]}
@@ -1,31 +0,0 @@
1
- import { FunctionComponent, Ref, ReactNode } from 'react';
2
- import { ForwardProps } from '@pega/cosmos-react-core';
3
- export interface RepeatingViewRow {
4
- id: string | number;
5
- ariaLabel?: string;
6
- }
7
- export interface RepeatingViewProps {
8
- /** ref to the list element */
9
- ref?: Ref<HTMLUListElement>;
10
- /** Callback to render the view */
11
- children: (row: RepeatingViewRow) => ReactNode;
12
- /** Data rows */
13
- rows?: RepeatingViewRow[];
14
- /** Indicates if the data is being currently loading */
15
- loading?: boolean;
16
- /** Offset of the row item that need to trigger the load more callback */
17
- offset?: number;
18
- /** Callback to fetch more rows */
19
- loadMore?: () => void;
20
- /** UI that needs to be shown when list is empty */
21
- emptyView?: ReactNode;
22
- /** Scroll direction */
23
- scrollDirection?: 'top-to-bottom' | 'bottom-to-top';
24
- }
25
- export declare const StyledRepeatingViewItem: import("styled-components").StyledComponent<"li", import("styled-components").DefaultTheme, {}, never>;
26
- export declare const StyledRepeatingViewUL: import("styled-components").StyledComponent<"ul", import("styled-components").DefaultTheme, {}, never>;
27
- export declare const StyledRepeatingView: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
28
- export declare const StyledEmptyView: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
29
- declare const RepeatingView: FunctionComponent<RepeatingViewProps & ForwardProps>;
30
- export default RepeatingView;
31
- //# sourceMappingURL=RepeatingView.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RepeatingView.d.ts","sourceRoot":"","sources":["../../../src/components/Chat/RepeatingView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA+B,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvF,OAAO,EAML,YAAY,EACb,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,8BAA8B;IAC9B,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC5B,kCAAkC;IAClC,QAAQ,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,SAAS,CAAC;IAC/C,gBAAgB;IAChB,IAAI,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC1B,uDAAuD;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yEAAyE;IACzE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,mDAAmD;IACnD,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,uBAAuB;IACvB,eAAe,CAAC,EAAE,eAAe,GAAG,eAAe,CAAC;CACrD;AACD,eAAO,MAAM,uBAAuB,wGAOlC,CAAC;AAGH,eAAO,MAAM,qBAAqB,wGAKjC,CAAC;AAEF,eAAO,MAAM,mBAAmB,yGAE/B,CAAC;AAEF,eAAO,MAAM,eAAe,yGAM3B,CAAC;AAEF,QAAA,MAAM,aAAa,EAAE,iBAAiB,CAAC,kBAAkB,GAAG,YAAY,CA4DvE,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -1,47 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef } from 'react';
3
- import styled, { css } from 'styled-components';
4
- import { Flex, Progress, useItemIntersection, useConsolidatedRef, defaultThemeProp } from '@pega/cosmos-react-core';
5
- export const StyledRepeatingViewItem = styled.li(({ theme }) => {
6
- return css `
7
- outline: none;
8
- &:focus {
9
- box-shadow: ${theme.base.shadow.focus};
10
- }
11
- `;
12
- });
13
- StyledRepeatingViewItem.defaultProps = defaultThemeProp;
14
- export const StyledRepeatingViewUL = styled.ul `
15
- list-style-type: none;
16
- overflow-y: auto;
17
- height: 100%;
18
- width: 100%;
19
- `;
20
- export const StyledRepeatingView = styled.div `
21
- position: relative;
22
- `;
23
- export const StyledEmptyView = styled.div `
24
- position: absolute;
25
- bottom: 50%;
26
- left: 50%;
27
- transform: translate(-50%, -50%);
28
- z-index: 1;
29
- `;
30
- const RepeatingView = forwardRef((props, ref) => {
31
- const { children: renderer, offset = -1, loadMore, loading: isLoading = false, rows = [], emptyView, scrollDirection = 'top-to-bottom', ...restProps } = props;
32
- const listRef = useConsolidatedRef(ref);
33
- useItemIntersection(listRef, offset, () => {
34
- loadMore?.();
35
- }, ':scope > li');
36
- return (_jsxs(Flex, { container: {
37
- alignItems: 'center',
38
- justify: 'center'
39
- }, as: StyledRepeatingView, ...restProps, children: [_jsxs(Flex, { ...restProps, container: {
40
- direction: scrollDirection === 'top-to-bottom' ? 'column' : 'column-reverse'
41
- }, as: StyledRepeatingViewUL, ref: listRef, children: [rows.map(row => {
42
- const { ariaLabel, ...rowRestProps } = row;
43
- return (_jsx(StyledRepeatingViewItem, { "aria-label": ariaLabel, children: renderer(rowRestProps) }, row.id));
44
- }), isLoading && (_jsx(StyledRepeatingViewItem, { children: _jsx(Progress, { placement: 'inline' }) }, 'loader'))] }), !isLoading && rows.length === 0 && emptyView && (_jsx(StyledEmptyView, { children: emptyView }))] }));
45
- });
46
- export default RepeatingView;
47
- //# sourceMappingURL=RepeatingView.js.map