@qoretechnologies/reqraft 0.10.13-pr.74.gccefa54 → 0.10.13

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 (125) hide show
  1. package/.claude/CLAUDE.md +8 -11
  2. package/dist/components/form/engine/FormEngine.d.ts +1 -1
  3. package/dist/helpers/common.d.ts +0 -5
  4. package/dist/helpers/common.d.ts.map +1 -1
  5. package/dist/helpers/common.js +1 -20
  6. package/dist/helpers/common.js.map +1 -1
  7. package/dist/index.d.ts +0 -5
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +1 -7
  10. package/dist/index.js.map +1 -1
  11. package/dist/providers/StorageProvider.d.ts +13 -0
  12. package/dist/providers/StorageProvider.d.ts.map +1 -1
  13. package/dist/providers/StorageProvider.js +29 -5
  14. package/dist/providers/StorageProvider.js.map +1 -1
  15. package/package.json +3 -3
  16. package/src/helpers/common.ts +0 -19
  17. package/src/hooks/useStorage/useStorage.stories.tsx +52 -0
  18. package/src/index.tsx +0 -5
  19. package/src/providers/StorageProvider.tsx +30 -4
  20. package/dist/components/composer/Composer.d.ts +0 -108
  21. package/dist/components/composer/Composer.d.ts.map +0 -1
  22. package/dist/components/composer/Composer.js +0 -238
  23. package/dist/components/composer/Composer.js.map +0 -1
  24. package/dist/components/composer/helpers.d.ts +0 -21
  25. package/dist/components/composer/helpers.d.ts.map +0 -1
  26. package/dist/components/composer/helpers.js +0 -75
  27. package/dist/components/composer/helpers.js.map +0 -1
  28. package/dist/components/composer/index.d.ts +0 -3
  29. package/dist/components/composer/index.d.ts.map +0 -1
  30. package/dist/components/composer/index.js +0 -19
  31. package/dist/components/composer/index.js.map +0 -1
  32. package/dist/components/imageLightbox/ImageLightbox.d.ts +0 -17
  33. package/dist/components/imageLightbox/ImageLightbox.d.ts.map +0 -1
  34. package/dist/components/imageLightbox/ImageLightbox.js +0 -129
  35. package/dist/components/imageLightbox/ImageLightbox.js.map +0 -1
  36. package/dist/components/imageLightbox/index.d.ts +0 -2
  37. package/dist/components/imageLightbox/index.d.ts.map +0 -1
  38. package/dist/components/imageLightbox/index.js +0 -18
  39. package/dist/components/imageLightbox/index.js.map +0 -1
  40. package/dist/components/supportTicket/AttachmentChips.d.ts +0 -10
  41. package/dist/components/supportTicket/AttachmentChips.d.ts.map +0 -1
  42. package/dist/components/supportTicket/AttachmentChips.js +0 -119
  43. package/dist/components/supportTicket/AttachmentChips.js.map +0 -1
  44. package/dist/components/supportTicket/InterfaceReferenceTags.d.ts +0 -35
  45. package/dist/components/supportTicket/InterfaceReferenceTags.d.ts.map +0 -1
  46. package/dist/components/supportTicket/InterfaceReferenceTags.js +0 -31
  47. package/dist/components/supportTicket/InterfaceReferenceTags.js.map +0 -1
  48. package/dist/components/supportTicket/ReferencePicker.d.ts +0 -41
  49. package/dist/components/supportTicket/ReferencePicker.d.ts.map +0 -1
  50. package/dist/components/supportTicket/ReferencePicker.js +0 -86
  51. package/dist/components/supportTicket/ReferencePicker.js.map +0 -1
  52. package/dist/components/supportTicket/TicketHeader.d.ts +0 -86
  53. package/dist/components/supportTicket/TicketHeader.d.ts.map +0 -1
  54. package/dist/components/supportTicket/TicketHeader.js +0 -149
  55. package/dist/components/supportTicket/TicketHeader.js.map +0 -1
  56. package/dist/components/supportTicket/TicketMetaTags.d.ts +0 -32
  57. package/dist/components/supportTicket/TicketMetaTags.d.ts.map +0 -1
  58. package/dist/components/supportTicket/TicketMetaTags.js +0 -21
  59. package/dist/components/supportTicket/TicketMetaTags.js.map +0 -1
  60. package/dist/components/supportTicket/TicketReplyBox.d.ts +0 -63
  61. package/dist/components/supportTicket/TicketReplyBox.d.ts.map +0 -1
  62. package/dist/components/supportTicket/TicketReplyBox.js +0 -115
  63. package/dist/components/supportTicket/TicketReplyBox.js.map +0 -1
  64. package/dist/components/supportTicket/fileToAttachment.d.ts +0 -9
  65. package/dist/components/supportTicket/fileToAttachment.d.ts.map +0 -1
  66. package/dist/components/supportTicket/fileToAttachment.js +0 -28
  67. package/dist/components/supportTicket/fileToAttachment.js.map +0 -1
  68. package/dist/components/supportTicket/index.d.ts +0 -9
  69. package/dist/components/supportTicket/index.d.ts.map +0 -1
  70. package/dist/components/supportTicket/index.js +0 -25
  71. package/dist/components/supportTicket/index.js.map +0 -1
  72. package/dist/components/supportTicket/meta.d.ts +0 -63
  73. package/dist/components/supportTicket/meta.d.ts.map +0 -1
  74. package/dist/components/supportTicket/meta.js +0 -79
  75. package/dist/components/supportTicket/meta.js.map +0 -1
  76. package/dist/components/ticketReferences/TicketReferences.d.ts +0 -52
  77. package/dist/components/ticketReferences/TicketReferences.d.ts.map +0 -1
  78. package/dist/components/ticketReferences/TicketReferences.js +0 -453
  79. package/dist/components/ticketReferences/TicketReferences.js.map +0 -1
  80. package/dist/components/ticketReferences/index.d.ts +0 -3
  81. package/dist/components/ticketReferences/index.d.ts.map +0 -1
  82. package/dist/components/ticketReferences/index.js +0 -6
  83. package/dist/components/ticketReferences/index.js.map +0 -1
  84. package/dist/components/ticketThread/TicketThread.d.ts +0 -52
  85. package/dist/components/ticketThread/TicketThread.d.ts.map +0 -1
  86. package/dist/components/ticketThread/TicketThread.js +0 -248
  87. package/dist/components/ticketThread/TicketThread.js.map +0 -1
  88. package/dist/components/ticketThread/index.d.ts +0 -3
  89. package/dist/components/ticketThread/index.d.ts.map +0 -1
  90. package/dist/components/ticketThread/index.js +0 -7
  91. package/dist/components/ticketThread/index.js.map +0 -1
  92. package/dist/helpers/scrollbar.d.ts +0 -2
  93. package/dist/helpers/scrollbar.d.ts.map +0 -1
  94. package/dist/helpers/scrollbar.js +0 -25
  95. package/dist/helpers/scrollbar.js.map +0 -1
  96. package/src/components/composer/Composer.stories.tsx +0 -238
  97. package/src/components/composer/Composer.tsx +0 -545
  98. package/src/components/composer/helpers.ts +0 -74
  99. package/src/components/composer/index.ts +0 -2
  100. package/src/components/imageLightbox/ImageLightbox.stories.tsx +0 -156
  101. package/src/components/imageLightbox/ImageLightbox.tsx +0 -169
  102. package/src/components/imageLightbox/index.ts +0 -1
  103. package/src/components/supportTicket/AttachmentChips.stories.tsx +0 -122
  104. package/src/components/supportTicket/AttachmentChips.tsx +0 -142
  105. package/src/components/supportTicket/InterfaceReferenceTags.stories.tsx +0 -134
  106. package/src/components/supportTicket/InterfaceReferenceTags.tsx +0 -85
  107. package/src/components/supportTicket/ReferencePicker.stories.tsx +0 -296
  108. package/src/components/supportTicket/ReferencePicker.tsx +0 -237
  109. package/src/components/supportTicket/TicketConversation.stories.tsx +0 -122
  110. package/src/components/supportTicket/TicketHeader.stories.tsx +0 -183
  111. package/src/components/supportTicket/TicketHeader.tsx +0 -247
  112. package/src/components/supportTicket/TicketMetaTags.stories.tsx +0 -103
  113. package/src/components/supportTicket/TicketMetaTags.tsx +0 -85
  114. package/src/components/supportTicket/TicketReplyBox.stories.tsx +0 -355
  115. package/src/components/supportTicket/TicketReplyBox.tsx +0 -146
  116. package/src/components/supportTicket/fileToAttachment.ts +0 -24
  117. package/src/components/supportTicket/index.ts +0 -8
  118. package/src/components/supportTicket/meta.ts +0 -145
  119. package/src/components/ticketReferences/TicketReferences.stories.tsx +0 -301
  120. package/src/components/ticketReferences/TicketReferences.tsx +0 -899
  121. package/src/components/ticketReferences/index.ts +0 -2
  122. package/src/components/ticketThread/TicketThread.stories.tsx +0 -751
  123. package/src/components/ticketThread/TicketThread.tsx +0 -650
  124. package/src/components/ticketThread/index.ts +0 -6
  125. package/src/helpers/scrollbar.ts +0 -32
@@ -1,650 +0,0 @@
1
- import {
2
- ReqoreBubble,
3
- ReqoreBubbleGroup,
4
- ReqoreButton,
5
- ReqoreControlGroup,
6
- ReqoreEmptyState,
7
- ReqoreIcon,
8
- ReqoreP,
9
- ReqoreSkeleton,
10
- ReqoreTimeAgo,
11
- useReqoreTheme,
12
- } from '@qoretechnologies/reqore';
13
- import { getReadableColor } from '@qoretechnologies/reqore/dist/helpers/colors';
14
- import { IReqoreIconName } from '@qoretechnologies/reqore/dist/types/icons';
15
- import { rgba } from 'polished';
16
- import { ComponentProps, useEffect, useMemo, useRef, useState } from 'react';
17
- import ReactMarkdown from 'react-markdown';
18
- import styled from 'styled-components';
19
- import { formatBytes, isImage } from '../../helpers/common';
20
- import { ImageLightbox } from '../imageLightbox';
21
- import {
22
- IInterfaceReference,
23
- InterfaceReferenceTags,
24
- TTicketMessageAuthor,
25
- TTicketViewerRole,
26
- } from '../supportTicket';
27
-
28
- /*
29
- * Shared support-ticket conversation thread, used by every Qorus surface that
30
- * shows a ticket: the qorus-ide customer view, the admin-portal staff queue, and
31
- * the Qonsole `support-ticket` renderer. Presentational — data in, callbacks out
32
- * — so each consumer keeps its own fetch/websocket wiring.
33
- *
34
- * Rendered as a comment feed: an avatar beside a bordered, accent-tinted card per
35
- * message, each hugging its own side. Built on Reqore's `ReqoreBubble` (which
36
- * supplies the avatar, the bold author label, the alignment and the tint), so the
37
- * accent follows whatever the host app themes `custom1` to rather than a colour
38
- * baked in here. Interface references render via the shared
39
- * `InterfaceReferenceTags`; the status/priority/category vocabularies live in
40
- * `../supportTicket/meta`.
41
- *
42
- * Runs of consecutive messages are wrapped in a `ReqoreBubbleGroup`, which prints
43
- * one time under the last card of each same-side run instead of one per card — a
44
- * burst of replies reads as a single moment.
45
- *
46
- * The `viewerRole` decides which side "you" sit on and how staff-only internal
47
- * notes render: the customer view never receives internal notes (the server
48
- * filters them) and sees staff under a masked "Qorus Support" label; the staff
49
- * view puts staff on the right and paints internal notes amber so they can never
50
- * be mistaken for a customer-visible reply. System messages render as a centered
51
- * muted line, not a card.
52
- */
53
-
54
- export interface ITicketThreadAttachment {
55
- attachment_id: string;
56
- filename: string;
57
- content_type: string;
58
- size_bytes: number;
59
- }
60
-
61
- export interface ITicketThreadMessage {
62
- message_id: string;
63
- author_type: TTicketMessageAuthor;
64
- author_id: string;
65
- body: string;
66
- internal?: boolean;
67
- created: string;
68
- attachments?: ITicketThreadAttachment[];
69
- /** Qorus interfaces this message references, as `{kind, name}` snapshots. */
70
- referenced_interfaces?: IInterfaceReference[];
71
- }
72
-
73
- export interface ITicketThreadProps {
74
- messages: ITicketThreadMessage[];
75
- /** which side "you" sit on + how internal notes render. */
76
- viewerRole?: TTicketViewerRole;
77
- loading?: boolean;
78
- /** download an attachment (the consumer wires this to its API). */
79
- onDownloadAttachment?: (attachmentId: string, filename: string) => void;
80
- /**
81
- * Fetch an image attachment's bytes as an object URL, for the inline thumbnail +
82
- * click-to-enlarge preview. Omitted ⇒ image attachments fall back to the same
83
- * download chip as every other file, so the thread degrades rather than breaks
84
- * where a consumer hasn't wired it. Non-image attachments never use it.
85
- */
86
- fetchAttachmentUrl?: (attachmentId: string) => Promise<string>;
87
- /** resolve a per-kind icon for a referenced interface. Consumers with their own
88
- * icon vocabulary (e.g. the qorus-ide IDE) pass one; when omitted, a built-in
89
- * per-kind default is used so every surface shows consistent chips. */
90
- resolveInterfaceIcon?: (kind: string) => IReqoreIconName;
91
- /** open a referenced interface; reference chips are static when omitted (e.g. the staff
92
- * view, which can't reach the customer's instance, leaves this out). */
93
- onInterfaceClick?: (reference: IInterfaceReference) => void;
94
- }
95
-
96
- interface IAuthorMeta {
97
- icon: IReqoreIconName;
98
- }
99
-
100
- const AUTHOR_META: Record<TTicketMessageAuthor, IAuthorMeta> = {
101
- customer: { icon: 'User3Line' },
102
- staff: { icon: 'CustomerService2Line' },
103
- system: { icon: 'InformationLine' },
104
- };
105
-
106
- // Both sides share one accent: the side, the avatar and the author label already
107
- // carry who is speaking, which frees colour to mean "internal note" and nothing
108
- // else. `custom1` is a theme slot, so each host app supplies its own hue.
109
- const ACCENT: ComponentProps<typeof ReqoreBubble>['customTheme'] = { main: 'custom1' };
110
-
111
- /** Avatar glyph; an internal note carries the "not visible to the customer" eye. */
112
- const authorIcon = (message: ITicketThreadMessage): IReqoreIconName =>
113
- message.internal ? 'EyeOffLine' : AUTHOR_META[message.author_type].icon;
114
-
115
-
116
- /** The label above a message. The customer view masks staff identity as "Qorus
117
- * Support"; the staff view shows the real author with a role prefix. Internal
118
- * notes always label as "Internal note" regardless of viewer. */
119
- const authorLabel = (message: ITicketThreadMessage, viewerRole: TTicketViewerRole): string => {
120
- if (message.internal) {
121
- return 'Internal note';
122
- }
123
- if (viewerRole === 'customer') {
124
- return message.author_type === 'customer' ? 'You' : 'Qorus Support';
125
- }
126
- return `${message.author_type === 'staff' ? 'Support' : 'Customer'} · ${message.author_id}`;
127
- };
128
-
129
- /**
130
- * DOM id of a message in the rendered thread.
131
- *
132
- * Exported rather than inlined so that anything wanting to reveal a message — a
133
- * "show in chat" action on a reference, a deep link — derives the id from the same
134
- * function the thread renders with. Two copies of the same template string is exactly
135
- * how that contract silently breaks when one side is renamed.
136
- */
137
- export const ticketMessageDomId = (messageId: string): string => `ticket-message-${messageId}`;
138
-
139
- const StyledThread = styled.div`
140
- display: flex;
141
- flex-direction: column;
142
- gap: 12px;
143
- width: 100%;
144
-
145
- /*
146
- * A thread too short to fill its scroller sits at the BOTTOM, against the
147
- * composer, the way every chat surface behaves — otherwise the first reply
148
- * floats at the top of a tall drawer with dead space beneath it, and each new
149
- * message appears further from the box you just typed in.
150
- *
151
- * The auto top margin does the pushing rather than 'justify-content: flex-end':
152
- * with flex-end, once the thread outgrows the scroller the overflow spills past
153
- * the top edge and those first messages cannot be scrolled back into view. An
154
- * auto margin only consumes FREE space, so it collapses to zero the moment the
155
- * content overflows and normal scrolling is preserved.
156
- *
157
- * min-height needs a definite height on the scroll parent to resolve; where a
158
- * consumer doesn't provide one it simply computes to auto and the thread keeps
159
- * its natural top-aligned flow.
160
- */
161
- min-height: 100%;
162
-
163
- > *:first-child {
164
- margin-top: auto;
165
- }
166
- `;
167
-
168
- // The loading placeholder: pulsing skeleton "bubbles" alternating sides, so the
169
- // wait previews the thread it's about to become rather than a bare spinner. Built
170
- // from reqore's `ReqoreSkeleton` — the shape (avatar circle + a short label line +
171
- // N body lines) mirrors a real message. Sizes vary so it doesn't read as a grid.
172
- const SKELETON_BUBBLES: { self: boolean; lines: number; width: number }[] = [
173
- { self: false, lines: 2, width: 58 },
174
- { self: true, lines: 1, width: 42 },
175
- { self: true, lines: 3, width: 64 },
176
- { self: false, lines: 2, width: 50 },
177
- { self: false, lines: 1, width: 46 },
178
- { self: true, lines: 2, width: 60 },
179
- { self: false, lines: 3, width: 54 },
180
- ];
181
-
182
- /*
183
- * The skeleton fills the height from the TOP, unlike a real thread, which sits at the
184
- * bottom against the composer. The bottom-pin is right for real messages — a short
185
- * conversation belongs next to the box you type in — but a placeholder inheriting it
186
- * clusters a few bubbles at the bottom under a large empty gap, which reads as a
187
- * broken render rather than "loading". A loading skeleton grows top-down, the
188
- * universal convention, so it occupies the space it's given no matter how tall.
189
- */
190
- const StyledSkeletonThread = styled.div`
191
- display: flex;
192
- flex-direction: column;
193
- gap: 12px;
194
- width: 100%;
195
- min-height: 100%;
196
- `;
197
-
198
- const StyledSkeletonRow = styled.div<{ $self: boolean }>`
199
- display: flex;
200
- gap: 10px;
201
- align-items: flex-start;
202
- justify-content: ${({ $self }) => ($self ? 'flex-end' : 'flex-start')};
203
- `;
204
-
205
- // Content stays left-aligned even on a right-side row — like a real bubble, where
206
- // the label sits top-left however the bubble is aligned; the row positions the
207
- // whole block, this just lays the lines out within it.
208
- const StyledSkeletonLines = styled.div`
209
- display: flex;
210
- flex-direction: column;
211
- gap: 6px;
212
- align-items: flex-start;
213
- `;
214
-
215
- const ConversationSkeleton = () => (
216
- <StyledSkeletonThread aria-busy='true' aria-label='Loading conversation'>
217
- {SKELETON_BUBBLES.map((bubble, index) => {
218
- const avatar = <ReqoreSkeleton circle width='30px' height='30px' />;
219
- return (
220
- <StyledSkeletonRow key={index} $self={bubble.self}>
221
- {!bubble.self && avatar}
222
- <StyledSkeletonLines style={{ width: `${bubble.width}%` }}>
223
- <ReqoreSkeleton width='38%' height='10px' />
224
- {Array.from({ length: bubble.lines }).map((_, line) => (
225
- <ReqoreSkeleton
226
- key={line}
227
- width={line === bubble.lines - 1 ? '72%' : '100%'}
228
- height='8px'
229
- />
230
- ))}
231
- </StyledSkeletonLines>
232
- {bubble.self && avatar}
233
- </StyledSkeletonRow>
234
- );
235
- })}
236
- </StyledSkeletonThread>
237
- );
238
-
239
- // Debosses the empty state: washes the icon + title back with opacity (kept
240
- // theme-agnostic) and adds a faint light edge below, so "No messages yet" reads
241
- // as pressed into the surface rather than announced.
242
- const StyledEmpty = styled.div`
243
- /*
244
- * Centre the placeholder in the space it's given rather than letting it sit at the
245
- * top. Like the thread, this fills its scroll parent (min-height: 100%, which needs a
246
- * definite height to resolve — the drawer body provides one; where a consumer doesn't,
247
- * it collapses to auto and the state keeps its natural top-aligned flow).
248
- */
249
- min-height: 100%;
250
- display: flex;
251
- flex-direction: column;
252
- align-items: center;
253
- justify-content: center;
254
-
255
- .reqore-icon {
256
- opacity: 0.28;
257
- }
258
- h1,
259
- h2,
260
- h3,
261
- h4,
262
- h5,
263
- h6 {
264
- opacity: 0.4;
265
- text-shadow: 0 1px 0 rgba(255, 255, 255, 0.07);
266
- }
267
- `;
268
-
269
- // System messages read as a centered muted note between cards; the nested rule
270
- // flattens react-markdown's own <p> margins so it sits on one line.
271
- const StyledSystemRow = styled.div`
272
- display: flex;
273
- align-items: center;
274
- justify-content: center;
275
- gap: 6px;
276
- font-size: 11px;
277
- opacity: 0.55;
278
- text-align: center;
279
- p {
280
- margin: 0;
281
- }
282
- `;
283
-
284
- interface IStyledMarkdownProps {
285
- $color: string;
286
- $emphasis: string;
287
- $code: string;
288
- $link: string;
289
- }
290
-
291
- // The message body, washed a step below the bright author name in the card's
292
- // header so the two read as different things; in-body **bold** lifts back toward
293
- // full strength as emphasis. Every colour derives from the active Reqore theme
294
- // rather than a hardcoded hex, so the thread reads correctly on any host app.
295
- const StyledMarkdown = styled.div<IStyledMarkdownProps>`
296
- color: ${({ $color }) => $color};
297
- word-break: break-word;
298
-
299
- > *:first-child {
300
- margin-top: 0;
301
- }
302
- > *:last-child {
303
- margin-bottom: 0;
304
- }
305
-
306
- p {
307
- margin: 0 0 6px;
308
- }
309
- strong {
310
- color: ${({ $emphasis }) => $emphasis};
311
- font-weight: 600;
312
- }
313
- ul,
314
- ol {
315
- margin: 4px 0;
316
- padding-left: 18px;
317
- }
318
- li {
319
- margin: 2px 0;
320
- }
321
- code {
322
- font-family: monospace;
323
- background: ${({ $code }) => $code};
324
- padding: 1px 5px;
325
- border-radius: 4px;
326
- }
327
- pre {
328
- margin: 6px 0;
329
- padding: 8px 10px;
330
- background: rgba(0, 0, 0, 0.35);
331
- border-radius: 4px;
332
- overflow-x: auto;
333
- }
334
- pre code {
335
- background: none;
336
- padding: 0;
337
- white-space: pre;
338
- }
339
- a {
340
- color: ${({ $link }) => $link};
341
- text-decoration: none;
342
- }
343
- a:hover {
344
- text-decoration: underline;
345
- }
346
- `;
347
-
348
- /** A message body rendered as markdown, tinted from the active theme. */
349
- const MessageBody = ({ children }: { children: string }) => {
350
- const theme = useReqoreTheme();
351
- const readable = getReadableColor(theme);
352
- const link = theme.intents?.info ?? readable;
353
- return (
354
- <StyledMarkdown
355
- $color={rgba(readable, 0.72)}
356
- $emphasis={rgba(readable, 0.95)}
357
- $code={rgba(readable, 0.1)}
358
- $link={link}
359
- >
360
- <ReactMarkdown>{children}</ReactMarkdown>
361
- </StyledMarkdown>
362
- );
363
- };
364
-
365
- /** A file attachment as a download chip — the fallback for every non-image, and for
366
- * images when no `fetchAttachmentUrl` is wired. */
367
- const AttachmentChip = ({
368
- attachment,
369
- onDownloadAttachment,
370
- }: {
371
- attachment: ITicketThreadAttachment;
372
- onDownloadAttachment?: (attachmentId: string, filename: string) => void;
373
- }) => (
374
- <ReqoreButton
375
- icon='Download2Line'
376
- size='small'
377
- flat
378
- badge={formatBytes(attachment.size_bytes)}
379
- tooltip={`${attachment.content_type} · download`}
380
- onClick={() => onDownloadAttachment?.(attachment.attachment_id, attachment.filename)}
381
- >
382
- {attachment.filename}
383
- </ReqoreButton>
384
- );
385
-
386
- const StyledThumb = styled.button`
387
- appearance: none;
388
- padding: 0;
389
- border: 1px solid ${rgba('#ffffff', 0.12)};
390
- border-radius: 8px;
391
- overflow: hidden;
392
- background: ${rgba('#000000', 0.25)};
393
- cursor: zoom-in;
394
- line-height: 0;
395
- display: block;
396
-
397
- img {
398
- display: block;
399
- max-width: 240px;
400
- max-height: 200px;
401
- object-fit: cover;
402
- }
403
- `;
404
-
405
- /**
406
- * An image attachment as a thumbnail; clicking it opens the shared `ImageLightbox`
407
- * (owned by `AttachmentList`, which knows the whole image set for paging). The bytes
408
- * come from `fetchAttachmentUrl`, so until they arrive a skeleton holds the space, and
409
- * if the fetch fails the attachment degrades to the same download chip as any other
410
- * file rather than showing a broken image.
411
- */
412
- const ImageThumb = ({
413
- attachment,
414
- fetchAttachmentUrl,
415
- onOpen,
416
- onDownloadAttachment,
417
- }: {
418
- attachment: ITicketThreadAttachment;
419
- fetchAttachmentUrl: (attachmentId: string) => Promise<string>;
420
- onOpen: () => void;
421
- onDownloadAttachment?: (attachmentId: string, filename: string) => void;
422
- }) => {
423
- const [url, setUrl] = useState<string | null>(null);
424
- const [failed, setFailed] = useState<boolean>(false);
425
-
426
- useEffect(() => {
427
- let alive = true;
428
- fetchAttachmentUrl(attachment.attachment_id)
429
- .then((resolved) => alive && setUrl(resolved))
430
- .catch(() => alive && setFailed(true));
431
- return () => {
432
- alive = false;
433
- };
434
- }, [attachment.attachment_id]);
435
-
436
- if (failed) {
437
- return <AttachmentChip attachment={attachment} onDownloadAttachment={onDownloadAttachment} />;
438
- }
439
- if (!url) {
440
- return <ReqoreSkeleton width='180px' height='120px' />;
441
- }
442
- return (
443
- <StyledThumb type='button' title={`${attachment.filename} — click to enlarge`} onClick={onOpen}>
444
- <img src={url} alt={attachment.filename} />
445
- </StyledThumb>
446
- );
447
- };
448
-
449
- /**
450
- * A message's attachments, split into two rows: previewable images as a row of
451
- * thumbnails, and everything else as a row of download chips beneath.
452
- *
453
- * They can't share one wrapping row — a thumbnail is ~120px tall and a chip ~26px, so
454
- * mixed together the chips wrap raggedly around the image and the group reads as
455
- * broken. Grouping by kind keeps each row uniform. Images only preview when a
456
- * `fetchAttachmentUrl` is wired; without it they're files like any other and fall into
457
- * the chip row.
458
- */
459
- const AttachmentList = ({
460
- attachments,
461
- fetchAttachmentUrl,
462
- onDownloadAttachment,
463
- }: {
464
- attachments: ITicketThreadAttachment[];
465
- fetchAttachmentUrl?: (attachmentId: string) => Promise<string>;
466
- onDownloadAttachment?: (attachmentId: string, filename: string) => void;
467
- }) => {
468
- const previewable = Boolean(fetchAttachmentUrl);
469
- const images = previewable ? attachments.filter((a) => isImage(a.content_type)) : [];
470
- const imageIds = new Set(images.map((a) => a.attachment_id));
471
- const files = attachments.filter((a) => !imageIds.has(a.attachment_id));
472
- // which image the shared lightbox is showing; null = closed
473
- const [openIndex, setOpenIndex] = useState<number | null>(null);
474
-
475
- return (
476
- <ReqoreControlGroup vertical gapSize='small' style={{ marginTop: 8 }}>
477
- {images.length ? (
478
- <ReqoreControlGroup wrap gapSize='small' verticalAlign='flex-start'>
479
- {images.map((attachment, index) => (
480
- <ImageThumb
481
- key={attachment.attachment_id}
482
- attachment={attachment}
483
- fetchAttachmentUrl={fetchAttachmentUrl!}
484
- onOpen={() => setOpenIndex(index)}
485
- onDownloadAttachment={onDownloadAttachment}
486
- />
487
- ))}
488
- </ReqoreControlGroup>
489
- ) : null}
490
- {files.length ? (
491
- <ReqoreControlGroup wrap gapSize='small'>
492
- {files.map((attachment) => (
493
- <AttachmentChip
494
- key={attachment.attachment_id}
495
- attachment={attachment}
496
- onDownloadAttachment={onDownloadAttachment}
497
- />
498
- ))}
499
- </ReqoreControlGroup>
500
- ) : null}
501
- {openIndex !== null && fetchAttachmentUrl ? (
502
- <ImageLightbox
503
- images={images}
504
- index={openIndex}
505
- onIndex={setOpenIndex}
506
- onClose={() => setOpenIndex(null)}
507
- fetchAttachmentUrl={fetchAttachmentUrl}
508
- onDownload={onDownloadAttachment}
509
- />
510
- ) : null}
511
- </ReqoreControlGroup>
512
- );
513
- };
514
-
515
- type TThreadSegment =
516
- | { kind: 'system'; message: ITicketThreadMessage }
517
- | { kind: 'bubbles'; messages: ITicketThreadMessage[] };
518
-
519
- /** Split the thread into centred system lines and runs of consecutive non-system
520
- * messages — each run becomes one `ReqoreBubbleGroup`, which is what collapses a
521
- * same-side burst onto a single timestamp. */
522
- const toSegments = (messages: ITicketThreadMessage[]): TThreadSegment[] => {
523
- const segments: TThreadSegment[] = [];
524
-
525
- for (const message of messages) {
526
- if (message.author_type === 'system') {
527
- segments.push({ kind: 'system', message });
528
- continue;
529
- }
530
- const last = segments[segments.length - 1];
531
- if (last?.kind === 'bubbles') {
532
- last.messages.push(message);
533
- } else {
534
- segments.push({ kind: 'bubbles', messages: [message] });
535
- }
536
- }
537
-
538
- return segments;
539
- };
540
-
541
- export const TicketThread = ({
542
- messages,
543
- viewerRole = 'customer',
544
- loading,
545
- onDownloadAttachment,
546
- fetchAttachmentUrl,
547
- resolveInterfaceIcon,
548
- onInterfaceClick,
549
- }: ITicketThreadProps) => {
550
- // Open scrolled to the newest message, and follow new arrivals down — a thread is read
551
- // from the bottom, like any chat. Keyed on the message COUNT so it fires on open and when
552
- // a reply lands, not on every re-render (which would fight a user who has scrolled up to
553
- // read history). Scrolls the nearest scrollable ancestor (the drawer body) straight to its
554
- // end rather than scrollIntoView on a sentinel — scrollIntoView also drags any outer scroll
555
- // container around and stops one bottom-padding short of the real end.
556
- const threadRef = useRef<HTMLDivElement>(null);
557
- useEffect(() => {
558
- // Find the thread's OWN scroll container — the nearest ancestor that actually scrolls
559
- // (overflow-y auto/scroll), not merely the first one that currently overflows. A short
560
- // thread's container fits its content, so a "does it overflow?" test would walk straight
561
- // past it and scroll the whole page/panel to the bottom instead.
562
- let scroller = threadRef.current?.parentElement ?? null;
563
- while (scroller) {
564
- const overflowY = getComputedStyle(scroller).overflowY;
565
- if (overflowY === 'auto' || overflowY === 'scroll') {
566
- break;
567
- }
568
- scroller = scroller.parentElement;
569
- }
570
- if (scroller) {
571
- scroller.scrollTop = scroller.scrollHeight;
572
- }
573
- }, [messages.length]);
574
-
575
- // Segment the flat message list into system rows + author-grouped bubble runs once per
576
- // message change — not on every re-render (scroll, hover and resize all re-render this).
577
- const segments = useMemo(() => toSegments(messages), [messages]);
578
-
579
- if (loading) {
580
- return <ConversationSkeleton />;
581
- }
582
-
583
- if (!messages.length) {
584
- return (
585
- <StyledEmpty>
586
- <ReqoreEmptyState icon='Chat3Line' title='No messages yet' flat transparent />
587
- </StyledEmpty>
588
- );
589
- }
590
-
591
- return (
592
- <StyledThread ref={threadRef}>
593
- {segments.map((segment, index) =>
594
- segment.kind === 'system' ? (
595
- <StyledSystemRow
596
- key={segment.message.message_id}
597
- id={ticketMessageDomId(segment.message.message_id)}
598
- >
599
- <ReqoreIcon icon='InformationLine' size='tiny' />
600
- <ReactMarkdown>{segment.message.body}</ReactMarkdown>
601
- </StyledSystemRow>
602
- ) : (
603
- <ReqoreBubbleGroup key={`group-${index}`}>
604
- {segment.messages.map((message) => (
605
- <ReqoreBubble
606
- key={message.message_id}
607
- // anchor for "show in chat"; ReqoreBubble forwards unknown props to
608
- // its DOM node, so this lands on the rendered element
609
- id={ticketMessageDomId(message.message_id)}
610
- size='small'
611
- maxWidth='76%'
612
- align={message.author_type === viewerRole ? 'right' : 'left'}
613
- avatar={{ icon: authorIcon(message) }}
614
- label={authorLabel(message, viewerRole)}
615
- timestamp={message.created ? <ReqoreTimeAgo time={message.created} /> : undefined}
616
- intent={message.internal ? 'warning' : undefined}
617
- customTheme={message.internal ? undefined : ACCENT}
618
- flat={false}
619
- minimal
620
- >
621
- <MessageBody>{message.body}</MessageBody>
622
- {message.attachments?.length ? (
623
- <AttachmentList
624
- attachments={message.attachments}
625
- fetchAttachmentUrl={fetchAttachmentUrl}
626
- onDownloadAttachment={onDownloadAttachment}
627
- />
628
- ) : null}
629
- {message.referenced_interfaces?.length ? (
630
- <div style={{ marginTop: 8 }}>
631
- <InterfaceReferenceTags
632
- size='tiny'
633
- customTheme={ACCENT}
634
- references={message.referenced_interfaces}
635
- resolveInterfaceIcon={resolveInterfaceIcon}
636
- onInterfaceClick={onInterfaceClick}
637
- />
638
- </div>
639
- ) : null}
640
- </ReqoreBubble>
641
- ))}
642
- </ReqoreBubbleGroup>
643
- )
644
- )}
645
- <ReqoreP size='tiny' effect={{ opacity: 0.5, textAlign: 'center' }}>
646
- {messages.length} message{messages.length === 1 ? '' : 's'}
647
- </ReqoreP>
648
- </StyledThread>
649
- );
650
- };
@@ -1,6 +0,0 @@
1
- export { TicketThread, ticketMessageDomId } from './TicketThread';
2
- export type {
3
- ITicketThreadAttachment,
4
- ITicketThreadMessage,
5
- ITicketThreadProps,
6
- } from './TicketThread';
@@ -1,32 +0,0 @@
1
- import { css } from 'styled-components';
2
-
3
- /*
4
- * The thin, unobtrusive scrollbar the Qorus surfaces use — a transparent track and a
5
- * translucent rounded thumb — in place of the platform default, which reads as heavy
6
- * chrome inside a dark panel. Drop it into any `styled` scroll container:
7
- *
8
- * const Scroll = styled.div`
9
- * overflow-y: auto;
10
- * ${thinScrollbar}
11
- * `;
12
- *
13
- * webkit-only on purpose: setting `scrollbar-width` as well lets Chromium override this
14
- * custom 6px with its own wider "thin", so the two disagree. Firefox keeps its native
15
- * bar, which is already slim.
16
- */
17
- export const thinScrollbar = css`
18
- &::-webkit-scrollbar {
19
- width: 6px;
20
- height: 6px;
21
- }
22
- &::-webkit-scrollbar-track {
23
- background: transparent;
24
- }
25
- &::-webkit-scrollbar-thumb {
26
- background: rgba(255, 255, 255, 0.15);
27
- border-radius: 3px;
28
- }
29
- &::-webkit-scrollbar-thumb:hover {
30
- background: rgba(255, 255, 255, 0.28);
31
- }
32
- `;