@solexllc/usx-react 0.11.0 → 0.12.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 (181) hide show
  1. package/README.md +16 -0
  2. package/dist/Popover-BzDCTuQM.cjs +984 -0
  3. package/dist/Popover-LToVWsWc.js +985 -0
  4. package/dist/chat.cjs +1391 -0
  5. package/dist/chat.js +1391 -0
  6. package/dist/index.cjs +4428 -5290
  7. package/dist/index.js +58 -917
  8. package/package.json +7 -3
  9. package/src/chat.js +15 -0
  10. package/src/components/avatar/Avatar.tsx +54 -16
  11. package/src/components/avatar/avatar.django-snapshot.html +112 -0
  12. package/src/components/avatar/avatar.django.html +2 -2
  13. package/src/components/avatar/avatar.html +25 -0
  14. package/src/components/avatar/avatar.react-snapshot.html +104 -0
  15. package/src/components/avatar/config.json +13 -15
  16. package/src/components/avatar-group/AvatarGroup.tsx +17 -15
  17. package/src/components/avatar-group/avatar-group.django-snapshot.html +22 -0
  18. package/src/components/avatar-group/avatar-group.django.html +1 -1
  19. package/src/components/avatar-group/avatar-group.react-snapshot.html +20 -0
  20. package/src/components/avatar-group/config.json +2 -2
  21. package/src/components/back-to-top/BackToTop.tsx +21 -57
  22. package/src/components/back-to-top/back-to-top.django-snapshot.html +101 -202
  23. package/src/components/back-to-top/back-to-top.django.html +11 -38
  24. package/src/components/back-to-top/back-to-top.html +22 -106
  25. package/src/components/back-to-top/back-to-top.react-snapshot.html +94 -148
  26. package/src/components/back-to-top/config.json +41 -10
  27. package/src/components/button/Button.tsx +12 -3
  28. package/src/components/button/button.django-snapshot.html +18 -0
  29. package/src/components/button/button.django.html +3 -2
  30. package/src/components/button/button.react-snapshot.html +16 -0
  31. package/src/components/button/config.json +11 -2
  32. package/src/components/callout/callout.django.html +1 -1
  33. package/src/components/callout/config.json +7 -16
  34. package/src/components/character-count/CharacterCount.tsx +2 -0
  35. package/src/components/character-count/character-count.react-snapshot.html +7 -0
  36. package/src/components/chat/Chat.tsx +575 -0
  37. package/src/components/chat/README.md +174 -0
  38. package/src/components/chat/avatarProps.ts +32 -0
  39. package/src/components/chat/chat.django-snapshot.html +23515 -0
  40. package/src/components/chat/chat.django.html +75 -0
  41. package/src/components/chat/chat.html +116 -0
  42. package/src/components/chat/chat.react-snapshot.html +16895 -0
  43. package/src/components/chat/config.json +1241 -0
  44. package/src/components/chat-attachment/ChatAttachment.tsx +39 -0
  45. package/src/components/chat-attachment/chat-attachment.django.html +24 -0
  46. package/src/components/chat-attachment/chat-attachment.html +10 -0
  47. package/src/components/chat-attachment/config.json +27 -0
  48. package/src/components/chat-attachments/ChatAttachments.tsx +17 -0
  49. package/src/components/chat-attachments/chat-attachments.django-snapshot.html +58 -0
  50. package/src/components/chat-attachments/chat-attachments.django.html +10 -0
  51. package/src/components/chat-attachments/chat-attachments.html +14 -0
  52. package/src/components/chat-attachments/chat-attachments.react-snapshot.html +46 -0
  53. package/src/components/chat-attachments/config.json +25 -0
  54. package/src/components/chat-bubble/ChatBubble.tsx +39 -0
  55. package/src/components/chat-bubble/ChatFormattedText.tsx +138 -0
  56. package/src/components/chat-bubble/chat-bubble.django-snapshot.html +128 -0
  57. package/src/components/chat-bubble/chat-bubble.django.html +19 -0
  58. package/src/components/chat-bubble/chat-bubble.html +1 -0
  59. package/src/components/chat-bubble/chat-bubble.react-snapshot.html +118 -0
  60. package/src/components/chat-bubble/config.json +70 -0
  61. package/src/components/chat-composer/ChatComposer.tsx +210 -0
  62. package/src/components/chat-composer/README.md +15 -0
  63. package/src/components/chat-composer/chat-composer.django-snapshot.html +575 -0
  64. package/src/components/chat-composer/chat-composer.django.html +77 -0
  65. package/src/components/chat-composer/chat-composer.html +44 -0
  66. package/src/components/chat-composer/chat-composer.react-snapshot.html +519 -0
  67. package/src/components/chat-composer/chat-formatting.django.html +59 -0
  68. package/src/components/chat-composer/config.json +137 -0
  69. package/src/components/chat-context/ChatContext.tsx +46 -0
  70. package/src/components/chat-context/chat-context.django-snapshot.html +35 -0
  71. package/src/components/chat-context/chat-context.django.html +20 -0
  72. package/src/components/chat-context/chat-context.html +9 -0
  73. package/src/components/chat-context/chat-context.react-snapshot.html +30 -0
  74. package/src/components/chat-context/config.json +36 -0
  75. package/src/components/chat-controls/ChatControls.tsx +67 -0
  76. package/src/components/chat-controls/chat-controls.django-snapshot.html +114 -0
  77. package/src/components/chat-controls/chat-controls.django.html +36 -0
  78. package/src/components/chat-controls/chat-controls.html +11 -0
  79. package/src/components/chat-controls/chat-controls.react-snapshot.html +107 -0
  80. package/src/components/chat-controls/config.json +67 -0
  81. package/src/components/chat-directory/ChatDirectory.tsx +168 -0
  82. package/src/components/chat-directory/chat-directory.django-snapshot.html +546 -0
  83. package/src/components/chat-directory/chat-directory.django.html +14 -0
  84. package/src/components/chat-directory/chat-directory.html +4 -0
  85. package/src/components/chat-directory/chat-directory.react-snapshot.html +471 -0
  86. package/src/components/chat-directory/config.json +242 -0
  87. package/src/components/chat-directory-item/ChatDirectoryItem.tsx +150 -0
  88. package/src/components/chat-directory-item/chat-directory-item.django-snapshot.html +281 -0
  89. package/src/components/chat-directory-item/chat-directory-item.django.html +38 -0
  90. package/src/components/chat-directory-item/chat-directory-item.html +9 -0
  91. package/src/components/chat-directory-item/chat-directory-item.react-snapshot.html +249 -0
  92. package/src/components/chat-directory-item/config.json +103 -0
  93. package/src/components/chat-history/ChatHistory.tsx +30 -0
  94. package/src/components/chat-history/chat-history.django-snapshot.html +113 -0
  95. package/src/components/chat-history/chat-history.django.html +20 -0
  96. package/src/components/chat-history/chat-history.html +9 -0
  97. package/src/components/chat-history/chat-history.react-snapshot.html +111 -0
  98. package/src/components/chat-history/config.json +24 -0
  99. package/src/components/chat-message/ChatMessage.tsx +148 -0
  100. package/src/components/chat-message/chat-message.django-snapshot.html +758 -0
  101. package/src/components/chat-message/chat-message.django.html +56 -0
  102. package/src/components/chat-message/chat-message.html +12 -0
  103. package/src/components/chat-message/chat-message.react-snapshot.html +627 -0
  104. package/src/components/chat-message/config.json +278 -0
  105. package/src/components/chat-message-actions/ChatMessageActions.tsx +133 -0
  106. package/src/components/chat-message-actions/chat-message-actions.django-snapshot.html +345 -0
  107. package/src/components/chat-message-actions/chat-message-actions.django.html +29 -0
  108. package/src/components/chat-message-actions/chat-message-actions.html +53 -0
  109. package/src/components/chat-message-actions/chat-message-actions.react-snapshot.html +295 -0
  110. package/src/components/chat-message-actions/config.json +121 -0
  111. package/src/components/chat-window/ChatWindow.tsx +133 -0
  112. package/src/components/chat-window/chat-window.django-snapshot.html +448 -0
  113. package/src/components/chat-window/chat-window.django.html +39 -0
  114. package/src/components/chat-window/chat-window.html +26 -0
  115. package/src/components/chat-window/chat-window.react-snapshot.html +286 -0
  116. package/src/components/chat-window/config.json +123 -0
  117. package/src/components/clickable/Clickable.tsx +19 -5
  118. package/src/components/clickable/clickable.django-snapshot.html +11 -2
  119. package/src/components/clickable/clickable.django.html +2 -0
  120. package/src/components/clickable/clickable.react-snapshot.html +10 -2
  121. package/src/components/clickable/config.json +4 -0
  122. package/src/components/code/code.django-snapshot.html +25 -18
  123. package/src/components/code/code.react-snapshot.html +41 -4
  124. package/src/components/copy-to-clipboard/CopyToClipboard.tsx +2 -7
  125. package/src/components/copy-to-clipboard/copy-to-clipboard.django-snapshot.html +6 -4
  126. package/src/components/copy-to-clipboard/copy-to-clipboard.django.html +3 -2
  127. package/src/components/copy-to-clipboard/copy-to-clipboard.react-snapshot.html +14 -2
  128. package/src/components/file-list/FileList.tsx +3 -2
  129. package/src/components/file-list/config.json +5 -0
  130. package/src/components/file-list/file-list.django-snapshot.html +63 -0
  131. package/src/components/file-list/file-list.django.html +1 -1
  132. package/src/components/file-list/file-list.react-snapshot.html +53 -0
  133. package/src/components/footer/footer.django-snapshot.html +0 -3
  134. package/src/components/header/header.django-snapshot.html +0 -160
  135. package/src/components/header/header.django.html +2 -2
  136. package/src/components/hero/hero.django-snapshot.html +0 -20
  137. package/src/components/hero/hero.django.html +3 -3
  138. package/src/components/image/image.django.html +4 -4
  139. package/src/components/input/Input.tsx +1 -1
  140. package/src/components/input/config.json +2 -3
  141. package/src/components/input/input.django-snapshot.html +4 -21
  142. package/src/components/input/input.django.html +2 -2
  143. package/src/components/link/Link.tsx +7 -4
  144. package/src/components/link/config.json +2 -3
  145. package/src/components/link/link.django-snapshot.html +8 -0
  146. package/src/components/link/link.django.html +2 -2
  147. package/src/components/link/link.html +4 -1
  148. package/src/components/link/link.react-snapshot.html +8 -0
  149. package/src/components/memorable-date/memorable-date.django-snapshot.html +0 -8
  150. package/src/components/memorable-date/memorable-date.django.html +2 -2
  151. package/src/components/misc-banner/misc-banner.django-snapshot.html +12 -12
  152. package/src/components/misc-banner/misc-banner.django.html +4 -2
  153. package/src/components/popover/Popover.tsx +60 -9
  154. package/src/components/popover/PopoverMenu.tsx +33 -15
  155. package/src/components/popover/config.json +88 -14
  156. package/src/components/popover/popover-menu.django.html +13 -2
  157. package/src/components/popover/popover.django-snapshot.html +229 -7
  158. package/src/components/popover/popover.django.html +3 -2
  159. package/src/components/popover/popover.react-snapshot.html +127 -4
  160. package/src/components/process-list/config.json +41 -3
  161. package/src/components/quote/Quote.tsx +9 -2
  162. package/src/components/search/Search.tsx +1 -1
  163. package/src/components/search/config.json +3 -4
  164. package/src/components/search/search.django-snapshot.html +262 -1684
  165. package/src/components/search/search.django.html +1 -20
  166. package/src/components/select/select.django-snapshot.html +7 -7
  167. package/src/components/select/select.react-snapshot.html +7 -7
  168. package/src/components/summary/Summary.tsx +4 -2
  169. package/src/components/summary/config.json +4 -0
  170. package/src/components/summary/summary.django.html +4 -4
  171. package/src/components/table/Table.tsx +58 -25
  172. package/src/components/table/config.json +61 -13
  173. package/src/components/tag/Tag.tsx +40 -7
  174. package/src/components/tag/config.json +18 -2
  175. package/src/components/tag/tag.django-snapshot.html +16 -1
  176. package/src/components/tag/tag.django.html +12 -6
  177. package/src/components/tag/tag.html +4 -0
  178. package/src/components/tag/tag.react-snapshot.html +16 -1
  179. package/src/components/tag-group/TagGroup.tsx +6 -9
  180. package/src/components/tag-group/config.json +4 -0
  181. package/src/components/tag-group/tag-group.django.html +1 -1
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import Button from '../button/Button';
3
+ import Image from '../image/Image';
4
+ import Icon from '../icon/Icon';
5
+ export interface ChatAttachmentProps {
6
+ name: string;
7
+ url?: string;
8
+ imageUrl?: string;
9
+ alt?: string;
10
+ }
11
+ export default function ChatAttachment({ name, url, imageUrl, alt }: ChatAttachmentProps) {
12
+ const content = (
13
+ <>
14
+ {imageUrl ? (
15
+ <Image
16
+ src={imageUrl}
17
+ alt={alt ?? name}
18
+ className="usx-chat__attachment-image maxw-card"
19
+ objectFit="cover"
20
+ rounded
21
+ />
22
+ ) : (
23
+ <Icon name="attach_file" />
24
+ )}
25
+ <span>{name}</span>
26
+ </>
27
+ );
28
+ return (
29
+ <li>
30
+ {url ? (
31
+ <Button href={url} download={name} variant="unstyled">
32
+ {content}
33
+ </Button>
34
+ ) : (
35
+ <div>{content}</div>
36
+ )}
37
+ </li>
38
+ );
39
+ }
@@ -0,0 +1,24 @@
1
+ {% load usx_components %}
2
+ {% fragment as content %}
3
+ {% if imageUrl %}
4
+ {% if alt == None %}
5
+ {% image src=imageUrl alt=name className='usx-chat__attachment-image maxw-card' objectFit='cover' rounded=True %}{% endimage %}
6
+ {% else %}
7
+ {% image src=imageUrl alt=alt className='usx-chat__attachment-image maxw-card' objectFit='cover' rounded=True %}{% endimage %}
8
+ {% endif %}
9
+ {% else %}
10
+ {% icon name='attach_file' %}{% endicon %}
11
+ {% endif %}
12
+ <span>{{ name }}</span>
13
+ {% endfragment %}
14
+ <li>
15
+ {% if url %}
16
+ {% button href=url download=name variant='unstyled' %}
17
+ {{ content }}
18
+ {% endbutton %}
19
+ {% else %}
20
+ <div>
21
+ {{ content }}
22
+ </div>
23
+ {% endif %}
24
+ </li>
@@ -0,0 +1,10 @@
1
+ <li>
2
+ <a
3
+ class="usa-button usx-button usa-button--unstyled"
4
+ href="/notes.txt"
5
+ download="Notes.txt"
6
+ ><svg class="usa-icon usx-icon" aria-hidden="true" focusable="false" role="img">
7
+ <use href="/img/sprite.svg#attach_file"></use></svg
8
+ ><span>Notes.txt</span></a
9
+ >
10
+ </li>
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "chat-attachment",
3
+ "template": "chat-attachment/chat-attachment.django.html",
4
+ "version": 1,
5
+ "default": {
6
+ "name": "Notes.txt",
7
+ "url": "/notes.txt"
8
+ },
9
+ "props": {
10
+ "name": {
11
+ "type": "string",
12
+ "description": "File name."
13
+ },
14
+ "url": {
15
+ "type": "string",
16
+ "description": "Download URL."
17
+ },
18
+ "imageUrl": {
19
+ "type": "string",
20
+ "description": "Optional preview image."
21
+ },
22
+ "alt": {
23
+ "type": "string",
24
+ "description": "Preview alternative text; defaults to name."
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import ChatAttachment, { type ChatAttachmentProps } from '../chat-attachment/ChatAttachment';
3
+
4
+ export interface ChatAttachmentsProps {
5
+ items?: ChatAttachmentProps[];
6
+ }
7
+
8
+ export default function ChatAttachments({ items = [] }: ChatAttachmentsProps) {
9
+ if (!items.length) return null;
10
+ return (
11
+ <ul className="usx-chat__attachments">
12
+ {items.map((item, index) => (
13
+ <ChatAttachment key={index} {...item} />
14
+ ))}
15
+ </ul>
16
+ );
17
+ }
@@ -0,0 +1,58 @@
1
+ <h3 class="site-preview-heading">Attachments</h3>
2
+ <ul class="usx-chat__attachments">
3
+ <li>
4
+ <a
5
+ href="/liberty-island-notes.txt"
6
+ download="Notes.txt"
7
+ class="usa-button usx-button usa-button--unstyled"
8
+ >
9
+ <svg class="usa-icon usx-icon" aria-hidden="true" focusable="false" role="img">
10
+ <use href="img/sprite.svg#attach_file"></use>
11
+ </svg>
12
+
13
+ <span>Notes.txt</span>
14
+ </a>
15
+ </li>
16
+
17
+ <li>
18
+ <a
19
+ href="/marketplace-bicycle.svg"
20
+ download="Bicycle.svg"
21
+ class="usa-button usx-button usa-button--unstyled"
22
+ >
23
+ <div
24
+ class="usx-image usx-image--rounded usx-object-fit-cover usx-chat__attachment-image maxw-card"
25
+ >
26
+ <img src="marketplace-bicycle.svg" alt="Blue bicycle offered for sale" />
27
+ </div>
28
+
29
+ <span>Bicycle.svg</span>
30
+ </a>
31
+ </li>
32
+
33
+ <li>
34
+ <div>
35
+ <svg class="usa-icon usx-icon" aria-hidden="true" focusable="false" role="img">
36
+ <use href="img/sprite.svg#attach_file"></use>
37
+ </svg>
38
+
39
+ <span>Document awaiting upload.pdf</span>
40
+ </div>
41
+ </li>
42
+
43
+ <li>
44
+ <a
45
+ href="/marketplace-bicycle.svg"
46
+ download="Bicycle thumbnail.svg"
47
+ class="usa-button usx-button usa-button--unstyled"
48
+ >
49
+ <div
50
+ class="usx-image usx-image--rounded usx-object-fit-cover usx-chat__attachment-image maxw-card"
51
+ >
52
+ <img src="marketplace-bicycle.svg" alt="" />
53
+ </div>
54
+
55
+ <span>Bicycle thumbnail.svg</span>
56
+ </a>
57
+ </li>
58
+ </ul>
@@ -0,0 +1,10 @@
1
+ {% load usx_components %}
2
+ {% if items %}
3
+ <ul class="usx-chat__attachments">
4
+ {% for item in items %}
5
+ {% chat_attachment name=item.name url=item.url imageUrl=item.imageUrl
6
+ alt=item|get_optional:'alt' %}
7
+ {% endchat_attachment %}
8
+ {% endfor %}
9
+ </ul>
10
+ {% endif %}
@@ -0,0 +1,14 @@
1
+ <ul class="usx-chat__attachments">
2
+ <li>
3
+ <a
4
+ class="usa-button usx-button usa-button--unstyled"
5
+ href="/liberty-island-notes.txt"
6
+ download="Notes.txt"
7
+ >
8
+ <svg class="usa-icon usx-icon" aria-hidden="true" focusable="false" role="img">
9
+ <use href="/img/sprite.svg#attach_file"></use>
10
+ </svg>
11
+ <span>Notes.txt</span>
12
+ </a>
13
+ </li>
14
+ </ul>
@@ -0,0 +1,46 @@
1
+ <h3 class="site-preview-heading">Attachments</h3>
2
+ <ul class="usx-chat__attachments">
3
+ <li>
4
+ <a
5
+ class="usa-button usx-button usa-button--unstyled"
6
+ href="/liberty-island-notes.txt"
7
+ download="Notes.txt"
8
+ ><svg class="usa-icon usx-icon" aria-hidden="true" focusable="false" role="img">
9
+ <use href="/img/sprite.svg#attach_file"></use></svg
10
+ ><span>Notes.txt</span></a
11
+ >
12
+ </li>
13
+ <li>
14
+ <a
15
+ class="usa-button usx-button usa-button--unstyled"
16
+ href="/marketplace-bicycle.svg"
17
+ download="Bicycle.svg"
18
+ ><div
19
+ class="usx-image usx-image--rounded usx-object-fit-cover usx-chat__attachment-image maxw-card"
20
+ >
21
+ <img src="/marketplace-bicycle.svg" alt="Blue bicycle offered for sale" />
22
+ </div>
23
+ <span>Bicycle.svg</span></a
24
+ >
25
+ </li>
26
+ <li>
27
+ <div>
28
+ <svg class="usa-icon usx-icon" aria-hidden="true" focusable="false" role="img">
29
+ <use href="/img/sprite.svg#attach_file"></use></svg
30
+ ><span>Document awaiting upload.pdf</span>
31
+ </div>
32
+ </li>
33
+ <li>
34
+ <a
35
+ class="usa-button usx-button usa-button--unstyled"
36
+ href="/marketplace-bicycle.svg"
37
+ download="Bicycle thumbnail.svg"
38
+ ><div
39
+ class="usx-image usx-image--rounded usx-object-fit-cover usx-chat__attachment-image maxw-card"
40
+ >
41
+ <img src="/marketplace-bicycle.svg" alt="" />
42
+ </div>
43
+ <span>Bicycle thumbnail.svg</span></a
44
+ >
45
+ </li>
46
+ </ul>
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "chat-attachments",
3
+ "template": "chat-attachments/chat-attachments.django.html",
4
+ "version": 1,
5
+ "default": {
6
+ "items": [
7
+ {
8
+ "name": "Notes.txt",
9
+ "url": "/liberty-island-notes.txt"
10
+ }
11
+ ]
12
+ },
13
+ "props": {
14
+ "items": {
15
+ "type": "array",
16
+ "description": "Files and image previews rendered as ChatAttachment items inside ul.usx-chat__attachments. An empty array renders nothing.",
17
+ "default": [],
18
+ "items": {
19
+ "type": "object",
20
+ "component": "chat-attachment",
21
+ "description": "Props for one ChatAttachment list item."
22
+ }
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import ChatAttachments from '../chat-attachments/ChatAttachments';
3
+ import ChatFormattedText from './ChatFormattedText';
4
+ import Button from '../button/Button';
5
+ import TagGroup from '../tag-group/TagGroup';
6
+ import type { ChatAttachment as Attachment, ChatReaction } from '../chat/Chat';
7
+ export interface ChatBubbleProps {
8
+ text?: string;
9
+ content?: React.ReactNode;
10
+ attachments?: Attachment[];
11
+ reactions?: ChatReaction[];
12
+ }
13
+ export default function ChatBubble({ text, content, attachments, reactions }: ChatBubbleProps) {
14
+ return (
15
+ <div className="usx-chat__bubble">
16
+ {content ?? (text && <ChatFormattedText text={text} />)}
17
+ <ChatAttachments items={attachments} />
18
+ {reactions?.length ? (
19
+ <TagGroup
20
+ className="usx-chat__reactions"
21
+ extraAttributes={{ role: 'group', 'aria-label': 'Reactions' }}
22
+ >
23
+ {reactions.map((reaction) => (
24
+ <Button
25
+ key={reaction.label}
26
+ variant="unstyled"
27
+ className="usa-tag usx-tag usx-tag--outline usx-tag--interactive usa-link usx-link usx-no-visited usx-chat__reaction"
28
+ extraAttributes={{ 'data-usx-chat-reaction': reaction.label }}
29
+ aria-pressed={Boolean(reaction.selected)}
30
+ aria-label={`${reaction.label}, ${reaction.count}`}
31
+ >
32
+ {reaction.emoji} {reaction.count}
33
+ </Button>
34
+ ))}
35
+ </TagGroup>
36
+ ) : null}
37
+ </div>
38
+ );
39
+ }
@@ -0,0 +1,138 @@
1
+ import React from 'react';
2
+
3
+ /** The composer uses a small, predictable Markdown subset; host rich content still takes precedence. */
4
+ function inline(value: string): React.ReactNode[] {
5
+ const pattern = /(\*\*([^*\n]+)\*\*|\*([^*\n]+)\*|<u>([^<\n]+)<\/u>|~~([^~\n]+)~~|`([^`\n]+)`)/g;
6
+ const parts: React.ReactNode[] = [];
7
+ let cursor = 0;
8
+ for (const match of value.matchAll(pattern)) {
9
+ const at = match.index ?? 0;
10
+ if (at > cursor) parts.push(value.slice(cursor, at));
11
+ const key = parts.length;
12
+ if (match[2]) parts.push(<strong key={key}>{match[2]}</strong>);
13
+ else if (match[3]) parts.push(<em key={key}>{match[3]}</em>);
14
+ else if (match[4]) parts.push(<u key={key}>{match[4]}</u>);
15
+ else if (match[5]) parts.push(<s key={key}>{match[5]}</s>);
16
+ else parts.push(<code key={key}>{match[6]}</code>);
17
+ cursor = at + match[0].length;
18
+ }
19
+ if (cursor < value.length) parts.push(value.slice(cursor));
20
+ return parts;
21
+ }
22
+
23
+ function quotePrefix(line: string) {
24
+ let offset = 0;
25
+ let depth = 0;
26
+ while (line[offset] === '>') {
27
+ depth += 1;
28
+ offset += 1;
29
+ while (line[offset] === ' ' || line[offset] === '\t') offset += 1;
30
+ }
31
+ return { depth, content: line.slice(offset) };
32
+ }
33
+
34
+ type QuoteNode = { children: Array<QuoteNode | string> };
35
+
36
+ function quotedBlock(lines: string[]) {
37
+ const root: QuoteNode = { children: [] };
38
+ const stack = [root];
39
+ for (const line of lines) {
40
+ const { depth, content } = quotePrefix(line);
41
+ while (stack.length - 1 > depth) stack.pop();
42
+ while (stack.length - 1 < depth) {
43
+ const child: QuoteNode = { children: [] };
44
+ stack[stack.length - 1].children.push(child);
45
+ stack.push(child);
46
+ }
47
+ stack[stack.length - 1].children.push(content);
48
+ }
49
+ const rendered = new WeakMap<QuoteNode, React.ReactNode>();
50
+ const pending: Array<{ node: QuoteNode; ready: boolean }> = [{ node: root, ready: false }];
51
+ while (pending.length) {
52
+ const item = pending.pop()!;
53
+ if (!item.ready) {
54
+ pending.push({ node: item.node, ready: true });
55
+ for (let index = item.node.children.length - 1; index >= 0; index -= 1) {
56
+ const child = item.node.children[index];
57
+ if (typeof child !== 'string') pending.push({ node: child, ready: false });
58
+ }
59
+ continue;
60
+ }
61
+ rendered.set(
62
+ item.node,
63
+ <blockquote>
64
+ {item.node.children.map((child, index) =>
65
+ typeof child === 'string' ? (
66
+ <p key={index}>{inline(child)}</p>
67
+ ) : (
68
+ <React.Fragment key={index}>{rendered.get(child)}</React.Fragment>
69
+ )
70
+ )}
71
+ </blockquote>
72
+ );
73
+ }
74
+ return root.children.map((child, index) => (
75
+ <React.Fragment key={index}>{rendered.get(child as QuoteNode)}</React.Fragment>
76
+ ));
77
+ }
78
+
79
+ export default function ChatFormattedText({ text }: { text: string }) {
80
+ const lines = text.split('\n');
81
+ const blocks: React.ReactNode[] = [];
82
+ let index = 0;
83
+ while (index < lines.length) {
84
+ const line = lines[index];
85
+ if (!line.trim()) {
86
+ index += 1;
87
+ continue;
88
+ }
89
+ const key = blocks.length;
90
+ if (/^```/.test(line)) {
91
+ const code: string[] = [];
92
+ index += 1;
93
+ while (index < lines.length && !/^```\s*$/.test(lines[index])) code.push(lines[index++]);
94
+ if (index < lines.length) index += 1;
95
+ blocks.push(
96
+ <pre key={key}>
97
+ <code>{code.join('\n')}</code>
98
+ </pre>
99
+ );
100
+ continue;
101
+ }
102
+ if (quotePrefix(line).depth) {
103
+ const quoted: string[] = [];
104
+ while (index < lines.length && quotePrefix(lines[index]).depth) quoted.push(lines[index++]);
105
+ blocks.push(<React.Fragment key={key}>{quotedBlock(quoted)}</React.Fragment>);
106
+ continue;
107
+ }
108
+ const ordered = /^\d+\. /.test(line);
109
+ const unordered = /^[-*] /.test(line);
110
+ if (ordered || unordered) {
111
+ const items: React.ReactNode[] = [];
112
+ const itemPattern = ordered ? /^\d+\. / : /^[-*] /;
113
+ while (index < lines.length && itemPattern.test(lines[index])) {
114
+ items.push(<li key={items.length}>{inline(lines[index++].replace(itemPattern, ''))}</li>);
115
+ }
116
+ blocks.push(ordered ? <ol key={key}>{items}</ol> : <ul key={key}>{items}</ul>);
117
+ continue;
118
+ }
119
+ const paragraph: string[] = [];
120
+ while (
121
+ index < lines.length &&
122
+ lines[index].trim() &&
123
+ !/^(?:```|> ?|\d+\. |[-*] )/.test(lines[index])
124
+ )
125
+ paragraph.push(lines[index++]);
126
+ blocks.push(
127
+ <p key={key}>
128
+ {paragraph.map((part, partIndex) => (
129
+ <React.Fragment key={partIndex}>
130
+ {partIndex > 0 && <br />}
131
+ {inline(part)}
132
+ </React.Fragment>
133
+ ))}
134
+ </p>
135
+ );
136
+ }
137
+ return <>{blocks}</>;
138
+ }
@@ -0,0 +1,128 @@
1
+ <h3 class="site-preview-heading">Default</h3>
2
+ <div>
3
+ <section id="django-example-bubble-default" class="usx-chat" style="max-width: 28rem">
4
+ <div data-chat-view="conversation" class="usx-chat__window" style="height: auto">
5
+ <span class="usx-chat__copy-status usa-sr-only" role="status"></span>
6
+ <ol class="usx-chat__messages">
7
+ <li data-message-id="example-message" data-sender-name="Avery">
8
+ <div class="usx-chat__bubble">
9
+ <p>Your appointment is confirmed.</p>
10
+ </div>
11
+ </li>
12
+ </ol>
13
+ </div>
14
+ </section>
15
+ </div>
16
+
17
+ <h3 class="site-preview-heading">Formatted</h3>
18
+ <div>
19
+ <section id="django-example-bubble-formatted" class="usx-chat" style="max-width: 28rem">
20
+ <div data-chat-view="conversation" class="usx-chat__window" style="height: auto">
21
+ <span class="usx-chat__copy-status usa-sr-only" role="status"></span>
22
+ <ol class="usx-chat__messages">
23
+ <li data-message-id="example-message" data-sender-name="Avery">
24
+ <div class="usx-chat__bubble">
25
+ <p><strong>Bring with you:</strong></p>
26
+ <ul>
27
+ <li>Photo identification</li>
28
+ <li>Your appointment letter</li>
29
+ </ul>
30
+ <blockquote><p>Arrive ten minutes early.</p></blockquote>
31
+ </div>
32
+ </li>
33
+ </ol>
34
+ </div>
35
+ </section>
36
+ </div>
37
+
38
+ <h3 class="site-preview-heading">Attachments</h3>
39
+ <div>
40
+ <section id="django-example-bubble-attachments" class="usx-chat" style="max-width: 28rem">
41
+ <div data-chat-view="conversation" class="usx-chat__window" style="height: auto">
42
+ <span class="usx-chat__copy-status usa-sr-only" role="status"></span>
43
+ <ol class="usx-chat__messages">
44
+ <li data-message-id="example-message" data-sender-name="Avery">
45
+ <div class="usx-chat__bubble">
46
+ <p>Here are your notes.</p>
47
+
48
+ <ul class="usx-chat__attachments">
49
+ <li>
50
+ <a
51
+ href="/liberty-island-notes.txt"
52
+ download="Appointment notes.txt"
53
+ class="usa-button usx-button usa-button--unstyled"
54
+ >
55
+ <svg class="usa-icon usx-icon" aria-hidden="true" focusable="false" role="img">
56
+ <use href="img/sprite.svg#attach_file"></use>
57
+ </svg>
58
+
59
+ <span>Appointment notes.txt</span>
60
+ </a>
61
+ </li>
62
+ </ul>
63
+ </div>
64
+ </li>
65
+ </ol>
66
+ </div>
67
+ </section>
68
+ </div>
69
+
70
+ <h3 class="site-preview-heading">Reactions</h3>
71
+ <div>
72
+ <section id="django-example-bubble-reactions" class="usx-chat" style="max-width: 28rem">
73
+ <div data-chat-view="conversation" class="usx-chat__window" style="height: auto">
74
+ <span class="usx-chat__copy-status usa-sr-only" role="status"></span>
75
+ <ol class="usx-chat__messages">
76
+ <li data-message-id="example-message" data-sender-name="Avery">
77
+ <div class="usx-chat__bubble">
78
+ <p>Thank you for the update.</p>
79
+
80
+ <div class="usx-tag-group usx-chat__reactions" role="group" aria-label="Reactions">
81
+ <button
82
+ type="button"
83
+ class="usa-button usx-button usa-button--unstyled usa-tag usx-tag usx-tag--outline usx-tag--interactive usa-link usx-link usx-no-visited usx-chat__reaction"
84
+ data-usx-chat-reaction="Helpful"
85
+ aria-label="Helpful, 2"
86
+ aria-pressed="true"
87
+ >
88
+ 👍 2
89
+ </button>
90
+ </div>
91
+ </div>
92
+ </li>
93
+ </ol>
94
+ </div>
95
+ </section>
96
+ </div>
97
+
98
+ <h3 class="site-preview-heading">Rich Content</h3>
99
+ <div>
100
+ <section id="django-example-bubble-richcontent" class="usx-chat" style="max-width: 28rem">
101
+ <div data-chat-view="conversation" class="usx-chat__window" style="height: auto">
102
+ <span class="usx-chat__copy-status usa-sr-only" role="status"></span>
103
+ <ol class="usx-chat__messages">
104
+ <li data-message-id="example-message" data-sender-name="Avery">
105
+ <div class="usx-chat__bubble">
106
+ <p>Review package: application_AR2048_supporting_documents_2026_11_18_final.pdf</p>
107
+
108
+ <ul class="usa-button-group usx-button-group">
109
+ <li class="usa-button-group__item">
110
+ <a href="#review" class="usa-button usx-button usa-button--primary"> Review </a>
111
+ </li>
112
+
113
+ <li class="usa-button-group__item">
114
+ <a
115
+ href="/liberty-island-notes.txt"
116
+ download
117
+ class="usa-button usx-button usa-button--outline"
118
+ >
119
+ Download
120
+ </a>
121
+ </li>
122
+ </ul>
123
+ </div>
124
+ </li>
125
+ </ol>
126
+ </div>
127
+ </section>
128
+ </div>
@@ -0,0 +1,19 @@
1
+ {% load usx_components %}
2
+ <div class="usx-chat__bubble">
3
+ {% if content != None %}
4
+ {% if content is not True and content is not False %}{{ content|safe }}{% endif %}
5
+ {% elif text %}
6
+ {{ formattedText }}
7
+ {% endif %}
8
+ {% chat_attachments items=attachments %}{% endchat_attachments %}
9
+ {% if reactions %}
10
+ {% dict role='group' aria_label='Reactions' as reactionGroupAttrs %}
11
+ {% tag_group className='usx-chat__reactions' extraAttributes=reactionGroupAttrs %}
12
+ {% for reaction in reactionButtons %}
13
+ {% button variant='unstyled' className='usa-tag usx-tag usx-tag--outline usx-tag--interactive usa-link usx-link usx-no-visited usx-chat__reaction' extraAttributes=reaction.attributes %}
14
+ {{ reaction.emoji }} {{ reaction.count }}
15
+ {% endbutton %}
16
+ {% endfor %}
17
+ {% endtag_group %}
18
+ {% endif %}
19
+ </div>
@@ -0,0 +1 @@
1
+ <div class="usx-chat__bubble"><p>Your appointment is confirmed.</p></div>