@linktr.ee/messaging-react 2.2.3 → 2.3.0-rc-1779486690
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Card-DOws_Rs6.js → Card-4takoN_-.js} +2 -2
- package/dist/{Card-DOws_Rs6.js.map → Card-4takoN_-.js.map} +1 -1
- package/dist/{Card-Ccy5fPho.js → Card-BuROm0u7.js} +2 -2
- package/dist/{Card-Ccy5fPho.js.map → Card-BuROm0u7.js.map} +1 -1
- package/dist/{Card-DWH_vCQD.cjs → Card-CexShqpK.cjs} +2 -2
- package/dist/{Card-DWH_vCQD.cjs.map → Card-CexShqpK.cjs.map} +1 -1
- package/dist/{Card-CyszwESe.cjs → Card-CgpHBx-W.cjs} +2 -2
- package/dist/{Card-CyszwESe.cjs.map → Card-CgpHBx-W.cjs.map} +1 -1
- package/dist/{Card-BRub_HpW.js → Card-DdpdnSh_.js} +3 -3
- package/dist/{Card-BRub_HpW.js.map → Card-DdpdnSh_.js.map} +1 -1
- package/dist/{Card-imQIyJzJ.cjs → Card-ot16XqS2.cjs} +2 -2
- package/dist/{Card-imQIyJzJ.cjs.map → Card-ot16XqS2.cjs.map} +1 -1
- package/dist/{LockedThumbnail-D512VE6T.cjs → LockedThumbnail-CydtYOSA.cjs} +2 -2
- package/dist/{LockedThumbnail-D512VE6T.cjs.map → LockedThumbnail-CydtYOSA.cjs.map} +1 -1
- package/dist/{LockedThumbnail-C9eocsRT.js → LockedThumbnail-Drsh4B5o.js} +2 -2
- package/dist/{LockedThumbnail-C9eocsRT.js.map → LockedThumbnail-Drsh4B5o.js.map} +1 -1
- package/dist/assets/index.css +1 -1
- package/dist/{index-uxWUZe1M.js → index-BCbVXFHI.js} +1648 -1740
- package/dist/index-BCbVXFHI.js.map +1 -0
- package/dist/index-CQ913euH.cjs +2 -0
- package/dist/index-CQ913euH.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +22 -13
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/components/MessageAttachment/Image/ImageAttachment.stories.tsx +8 -5
- package/src/components/MessageAttachment/Image/index.tsx +7 -1
- package/src/components/MessageAttachment/MessageAttachment.test.tsx +200 -19
- package/src/components/MessageAttachment/Pdf/index.tsx +14 -15
- package/src/components/MessageAttachment/Video/VideoAttachment.stories.tsx +2 -2
- package/src/components/MessageAttachment/Video/index.tsx +11 -2
- package/src/components/MessageAttachment/_shared/CarouselNav.tsx +47 -0
- package/src/components/MessageAttachment/_shared/DownloadAction.tsx +27 -27
- package/src/components/MessageAttachment/_shared/ImageViewer.tsx +59 -261
- package/src/components/MessageAttachment/_shared/PdfViewer.tsx +56 -30
- package/src/components/MessageAttachment/_shared/VideoViewer.tsx +53 -109
- package/src/components/MessageAttachment/_shared/ViewerShell.tsx +127 -107
- package/src/components/MessageAttachment/_shared/useCarousel.ts +103 -0
- package/src/components/MessageAttachment/index.tsx +18 -9
- package/src/components/MessageAttachment/types.ts +1 -1
- package/src/styles.css +158 -1
- package/dist/index-IlgylJT2.cjs +0 -2
- package/dist/index-IlgylJT2.cjs.map +0 -1
- package/dist/index-uxWUZe1M.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-CQ913euH.cjs");exports.ActionButton=e.ActionButton;exports.Avatar=e.Avatar;exports.ChannelEmptyState=e.ChannelEmptyState;exports.ChannelList=e.ChannelList;exports.ChannelView=e.ChannelView;exports.CustomMessageProvider=e.CustomMessageProvider;exports.FaqList=e.FaqList;exports.FaqListItem=e.FaqListItem;exports.LinkAttachment=e.LinkAttachment;exports.LockedAttachment=e.LockedAttachment;exports.MediaMessage=e.MediaMessage;exports.MessageAttachment=e.MessageAttachment;exports.MessageVoteButtons=e.MessageVoteButtons;exports.MessagingProvider=e.MessagingProvider;exports.MessagingShell=e.MessagingShell;exports.buildCompactMetaLabel=e.buildCompactMetaLabel;exports.formatFileSize=e.formatFileSize;exports.formatRelativeTime=e.formatRelativeTime;exports.getFileExtensionLabel=e.getFileExtensionLabel;exports.getMessageDisplayText=e.getMessageDisplayText;exports.isLinkAttachment=e.isLinkAttachment;exports.isUuidLike=e.isUuidLike;exports.messageAttachmentGroupPositionFromStream=e.bubbleGroupPositionFromStream;exports.normalizeLanguageCode=e.normalizeLanguageCode;exports.resolveLinkAttachment=e.resolveLinkAttachment;exports.resolveMediaFromMessage=e.resolveMediaFromMessage;exports.resolveParticipantDisplayName=e.resolveParticipantDisplayName;exports.useCustomMessage=e.useCustomMessage;exports.useMessageVote=e.useMessageVote;exports.useMessaging=e.useMessaging;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.ts
CHANGED
|
@@ -428,7 +428,7 @@ declare interface ImageAttachmentSharedProps extends MessageAttachmentBaseProps
|
|
|
428
428
|
/** Single image — convenience for the most common case. */
|
|
429
429
|
src?: string;
|
|
430
430
|
alt?: string;
|
|
431
|
-
/** Filename
|
|
431
|
+
/** Filename used as the viewer dialog's accessible name. */
|
|
432
432
|
filename?: string;
|
|
433
433
|
/**
|
|
434
434
|
* Stacked images. Takes precedence over `src` when set. Renders a
|
|
@@ -703,13 +703,15 @@ declare type MediaPreloadMode = 'none' | 'metadata' | 'auto';
|
|
|
703
703
|
*
|
|
704
704
|
* - Image / Video render a 1 / 2 / 3 / 4-tile grid (5+ collapse
|
|
705
705
|
* into a `+N` overflow tile). Activating any tile opens the
|
|
706
|
-
* built-in `ImageViewer` / `VideoViewer` at that index
|
|
707
|
-
*
|
|
706
|
+
* built-in `ImageViewer` / `VideoViewer` at that index; when
|
|
707
|
+
* `items.length > 1` the lightbox becomes a carousel (prev / next
|
|
708
|
+
* chrome, ArrowLeft / ArrowRight, current / total counter) so the
|
|
709
|
+
* user can browse siblings without closing the modal.
|
|
708
710
|
* - Pdf / Audio / File render their compact rows / players in a
|
|
709
711
|
* vertical stack with an 8px gap between rows. Each row keeps
|
|
710
|
-
* its own activation target — Pdf opens the
|
|
711
|
-
* index, Audio gets its own native player,
|
|
712
|
-
* the asset for that row.
|
|
712
|
+
* its own activation target — Pdf opens the carousel-aware
|
|
713
|
+
* `PdfViewer` at that index, Audio gets its own native player,
|
|
714
|
+
* and File downloads the asset for that row.
|
|
713
715
|
*
|
|
714
716
|
* The Composer surface accepts only a single attachment at a time,
|
|
715
717
|
* so its props omit `items` / `text`.
|
|
@@ -720,10 +722,17 @@ declare type MediaPreloadMode = 'none' | 'metadata' | 'auto';
|
|
|
720
722
|
* message. Sent / Received wrap the media in the shared bubble chrome.
|
|
721
723
|
*
|
|
722
724
|
* Image / Video / Pdf are interactive in every state (Composer, Sent,
|
|
723
|
-
* Received) — clicks open the corresponding native
|
|
724
|
-
*
|
|
725
|
-
*
|
|
726
|
-
*
|
|
725
|
+
* Received) — clicks open the corresponding native lightbox `<dialog>`,
|
|
726
|
+
* which centers the media at reasonable max dimensions (Escape and
|
|
727
|
+
* backdrop click also dismiss). The Image viewer adds an explicit
|
|
728
|
+
* download button to the chrome; the Video viewer relies on the
|
|
729
|
+
* native `<video controls>` download menu, and the Pdf viewer
|
|
730
|
+
* inherits the browser's built-in PDF download. Sibling-row Download
|
|
731
|
+
* buttons on Pdf / File and the native `<audio>` controls expose
|
|
732
|
+
* downloads outside the viewer too. The lightbox chrome is styled
|
|
733
|
+
* with plain CSS (`.mes-media-viewer*`) so the package's shipped
|
|
734
|
+
* stylesheet is enough to render the viewer correctly without a
|
|
735
|
+
* Tailwind dependency in the consumer.
|
|
727
736
|
*
|
|
728
737
|
* # Lazy-loading defaults
|
|
729
738
|
*
|
|
@@ -976,7 +985,7 @@ export declare interface MessageAttachmentPdfComposerProps extends ComposerExtra
|
|
|
976
985
|
/** A single PDF inside a Pdf attachment (single or stacked). */
|
|
977
986
|
export declare interface MessageAttachmentPdfItem {
|
|
978
987
|
src: string;
|
|
979
|
-
/** Filename — drives the title + the meta line + the viewer
|
|
988
|
+
/** Filename — drives the row title + the meta line + the viewer dialog's accessible name. */
|
|
980
989
|
filename?: string;
|
|
981
990
|
/** File size in bytes — formatted into the `EXT · SIZE` meta line. */
|
|
982
991
|
fileSize?: number;
|
|
@@ -1190,7 +1199,7 @@ declare type PaymentStatus = 'pending' | 'paid' | 'failed' | 'refunded';
|
|
|
1190
1199
|
declare interface PdfAttachmentSharedProps extends MessageAttachmentBaseProps {
|
|
1191
1200
|
/** Single PDF — convenience for the most common case. */
|
|
1192
1201
|
src?: string;
|
|
1193
|
-
/** Filename — drives the title + the meta line + the viewer
|
|
1202
|
+
/** Filename — drives the row title + the meta line + the viewer dialog's accessible name. */
|
|
1194
1203
|
filename?: string;
|
|
1195
1204
|
/** File size in bytes — formatted into the `EXT · SIZE` meta line. */
|
|
1196
1205
|
fileSize?: number;
|
|
@@ -1295,7 +1304,7 @@ declare interface VideoAttachmentSharedProps extends MessageAttachmentBaseProps
|
|
|
1295
1304
|
poster?: string;
|
|
1296
1305
|
/** MIME type hint — typed onto the inline `<source>` element. */
|
|
1297
1306
|
mimeType?: string;
|
|
1298
|
-
/** Filename
|
|
1307
|
+
/** Filename used as the viewer dialog's accessible name. */
|
|
1299
1308
|
filename?: string;
|
|
1300
1309
|
/**
|
|
1301
1310
|
* Stacked videos. Takes precedence over `src` when set. Renders a
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as e, b as t, C as i, c as n, d as o, e as m, F as g, f as l, L as r, h as M, M as u, i as L, j as c, k as h, l as d, m as p, n as v, o as A, p as C, q as F, s as k, t as b, u as f, v as x, w as y, x as P, y as S, z as q, B as z, D as B } from "./index-
|
|
1
|
+
import { a as e, b as t, C as i, c as n, d as o, e as m, F as g, f as l, L as r, h as M, M as u, i as L, j as c, k as h, l as d, m as p, n as v, o as A, p as C, q as F, s as k, t as b, u as f, v as x, w as y, x as P, y as S, z as q, B as z, D as B } from "./index-BCbVXFHI.js";
|
|
2
2
|
export {
|
|
3
3
|
e as ActionButton,
|
|
4
4
|
t as Avatar,
|
package/package.json
CHANGED
|
@@ -35,14 +35,15 @@ const handleDismiss = () => {
|
|
|
35
35
|
/**
|
|
36
36
|
* Single image — renders inside a chat bubble with rounded corners.
|
|
37
37
|
* Composer / Sent / Received are all interactive: clicking opens the
|
|
38
|
-
* built-in `ImageViewer` lightbox
|
|
39
|
-
*
|
|
38
|
+
* built-in `ImageViewer` lightbox (full-viewport `<dialog>`, image
|
|
39
|
+
* centered at reasonable max dimensions, close + download buttons in
|
|
40
|
+
* the chrome — Escape or backdrop click also dismiss).
|
|
40
41
|
*/
|
|
41
42
|
export const Single: StoryFn = () => (
|
|
42
43
|
<StoryPage>
|
|
43
44
|
<StoryHeading
|
|
44
45
|
title="Single image"
|
|
45
|
-
description="Click any bubble to open the lightbox viewer
|
|
46
|
+
description="Click any bubble to open the lightbox viewer. The dialog centers the image at reasonable max dimensions; close with the × button, Escape, or a backdrop click. The chrome carries a download button for grabbing the image without leaving the lightbox."
|
|
46
47
|
/>
|
|
47
48
|
<StoryGrid>
|
|
48
49
|
<StoryRow
|
|
@@ -143,7 +144,9 @@ export const SingleWithText: StoryFn = () => (
|
|
|
143
144
|
* Stacked image attachments — multiple images in one bubble laid out
|
|
144
145
|
* in a 1 / 2 / 3 / 4-tile grid. Five or more collapse into a `+N`
|
|
145
146
|
* overflow tile on the bottom-right. Click any tile to open the
|
|
146
|
-
* lightbox
|
|
147
|
+
* lightbox on that specific image; the viewer becomes a carousel
|
|
148
|
+
* (prev/next chrome, ArrowLeft / ArrowRight, and a `current / total`
|
|
149
|
+
* counter) so the user can browse siblings without closing.
|
|
147
150
|
*
|
|
148
151
|
* Sent + Received only — the composer surface accepts a single image
|
|
149
152
|
* at a time, so the Composer column is intentionally blank.
|
|
@@ -152,7 +155,7 @@ export const Stacked: StoryFn = () => (
|
|
|
152
155
|
<StoryPage>
|
|
153
156
|
<StoryHeading
|
|
154
157
|
title="Stacked images"
|
|
155
|
-
description="Click any tile to open the lightbox at that index. Use
|
|
158
|
+
description="Click any tile to open the lightbox at that index. Use the prev / next chrome or ArrowLeft / ArrowRight to navigate between siblings inside the viewer. Composer column is intentionally blank — the composer accepts a single image at a time."
|
|
156
159
|
/>
|
|
157
160
|
<StoryGrid>
|
|
158
161
|
<StoryRow
|
|
@@ -21,7 +21,7 @@ export interface ImageAttachmentSharedProps extends MessageAttachmentBaseProps {
|
|
|
21
21
|
/** Single image — convenience for the most common case. */
|
|
22
22
|
src?: string
|
|
23
23
|
alt?: string
|
|
24
|
-
/** Filename
|
|
24
|
+
/** Filename used as the viewer dialog's accessible name. */
|
|
25
25
|
filename?: string
|
|
26
26
|
/**
|
|
27
27
|
* Stacked images. Takes precedence over `src` when set. Renders a
|
|
@@ -98,6 +98,12 @@ interface InternalImageRowProps extends ImageAttachmentSharedProps {
|
|
|
98
98
|
onDismiss?: () => void
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Project the bubble's `ImageItem`s onto the carousel-aware viewer's
|
|
103
|
+
* `ImageViewerItem` shape. When a shared outer `filename` is supplied
|
|
104
|
+
* for a stacked bubble, suffix `(N)` per sibling so each carousel page
|
|
105
|
+
* still gets a distinct accessible name + download default.
|
|
106
|
+
*/
|
|
101
107
|
const buildViewerItems = (
|
|
102
108
|
resolvedItems: ImageItem[],
|
|
103
109
|
filename?: string
|
|
@@ -17,6 +17,21 @@ beforeEach(() => {
|
|
|
17
17
|
mockTriggerDownload.mockClear()
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
+
// The viewer's `<dialog>` stays mounted across open/close so the
|
|
21
|
+
// platform open / close transitions (via `@starting-style` +
|
|
22
|
+
// `allow-discrete`) can play. That means we can't gate openness on
|
|
23
|
+
// "is the dialog in the DOM" — we have to look at the `[open]`
|
|
24
|
+
// attribute the platform sets on a `<dialog>` while it's visible.
|
|
25
|
+
const expectViewerClosed = (testId: string) => {
|
|
26
|
+
const dialog = screen.queryByTestId(testId)
|
|
27
|
+
if (dialog) expect(dialog).not.toHaveAttribute('open')
|
|
28
|
+
}
|
|
29
|
+
const expectViewerOpen = (testId: string) => {
|
|
30
|
+
const dialog = screen.getByTestId(testId)
|
|
31
|
+
expect(dialog).toHaveAttribute('open')
|
|
32
|
+
return dialog
|
|
33
|
+
}
|
|
34
|
+
|
|
20
35
|
describe('MessageAttachment.Image', () => {
|
|
21
36
|
it('renders an image bubble with caption', () => {
|
|
22
37
|
renderWithProviders(
|
|
@@ -43,11 +58,11 @@ describe('MessageAttachment.Image', () => {
|
|
|
43
58
|
/>
|
|
44
59
|
)
|
|
45
60
|
|
|
46
|
-
|
|
61
|
+
expectViewerClosed('image-viewer')
|
|
47
62
|
|
|
48
63
|
fireEvent.click(screen.getByLabelText('Open image 1 of 1'))
|
|
49
64
|
|
|
50
|
-
|
|
65
|
+
expectViewerOpen('image-viewer')
|
|
51
66
|
})
|
|
52
67
|
|
|
53
68
|
it('renders the dismiss button only on Composer state', () => {
|
|
@@ -81,6 +96,104 @@ describe('MessageAttachment.Image', () => {
|
|
|
81
96
|
expect(screen.getByLabelText('Open image 3 of 3')).toBeInTheDocument()
|
|
82
97
|
})
|
|
83
98
|
|
|
99
|
+
it('renders a download button inside the image viewer', () => {
|
|
100
|
+
renderWithProviders(
|
|
101
|
+
<MessageAttachment.Image.Received
|
|
102
|
+
src="https://cdn.example.com/photo.jpg"
|
|
103
|
+
alt="Photo"
|
|
104
|
+
filename="photo.jpg"
|
|
105
|
+
/>
|
|
106
|
+
)
|
|
107
|
+
fireEvent.click(screen.getByLabelText('Open image 1 of 1'))
|
|
108
|
+
const viewer = expectViewerOpen('image-viewer')
|
|
109
|
+
// The viewer chrome carries its own download action — separate
|
|
110
|
+
// from any sibling download button on the bubble surface — so the
|
|
111
|
+
// user can grab the image without leaving the lightbox.
|
|
112
|
+
expect(
|
|
113
|
+
viewer.querySelector('button[aria-label="Download photo.jpg"]')
|
|
114
|
+
).not.toBeNull()
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('does not render carousel nav controls for a single image', () => {
|
|
118
|
+
renderWithProviders(
|
|
119
|
+
<MessageAttachment.Image.Received
|
|
120
|
+
src="https://cdn.example.com/photo.jpg"
|
|
121
|
+
filename="photo.jpg"
|
|
122
|
+
/>
|
|
123
|
+
)
|
|
124
|
+
fireEvent.click(screen.getByLabelText('Open image 1 of 1'))
|
|
125
|
+
expectViewerOpen('image-viewer')
|
|
126
|
+
expect(screen.queryByLabelText('Next image')).toBeNull()
|
|
127
|
+
expect(screen.queryByLabelText('Previous image')).toBeNull()
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('renders the stacked images as a carousel inside the viewer', () => {
|
|
131
|
+
renderWithProviders(
|
|
132
|
+
<MessageAttachment.Image.Sent
|
|
133
|
+
filename="album"
|
|
134
|
+
items={[
|
|
135
|
+
{ src: 'https://cdn.example.com/a.jpg', alt: 'A' },
|
|
136
|
+
{ src: 'https://cdn.example.com/b.jpg', alt: 'B' },
|
|
137
|
+
{ src: 'https://cdn.example.com/c.jpg', alt: 'C' },
|
|
138
|
+
]}
|
|
139
|
+
/>
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
// Open the second tile — the viewer should land on image 2.
|
|
143
|
+
fireEvent.click(screen.getByLabelText('Open image 2 of 3'))
|
|
144
|
+
const viewer = expectViewerOpen('image-viewer')
|
|
145
|
+
expect(viewer.querySelector('img')?.getAttribute('src')).toBe(
|
|
146
|
+
'https://cdn.example.com/b.jpg'
|
|
147
|
+
)
|
|
148
|
+
// Counter + nav chrome only appear on multi-item viewers.
|
|
149
|
+
expect(viewer.textContent).toContain('2 / 3')
|
|
150
|
+
|
|
151
|
+
// Next button advances by one.
|
|
152
|
+
fireEvent.click(screen.getByLabelText('Next image'))
|
|
153
|
+
expect(viewer.querySelector('img')?.getAttribute('src')).toBe(
|
|
154
|
+
'https://cdn.example.com/c.jpg'
|
|
155
|
+
)
|
|
156
|
+
expect(viewer.textContent).toContain('3 / 3')
|
|
157
|
+
|
|
158
|
+
// Next wraps from the last item back to the first.
|
|
159
|
+
fireEvent.click(screen.getByLabelText('Next image'))
|
|
160
|
+
expect(viewer.querySelector('img')?.getAttribute('src')).toBe(
|
|
161
|
+
'https://cdn.example.com/a.jpg'
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
// Previous wraps from the first item to the last.
|
|
165
|
+
fireEvent.click(screen.getByLabelText('Previous image'))
|
|
166
|
+
expect(viewer.querySelector('img')?.getAttribute('src')).toBe(
|
|
167
|
+
'https://cdn.example.com/c.jpg'
|
|
168
|
+
)
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
it('uses ArrowRight / ArrowLeft to navigate stacked images', () => {
|
|
172
|
+
renderWithProviders(
|
|
173
|
+
<MessageAttachment.Image.Sent
|
|
174
|
+
items={[
|
|
175
|
+
{ src: 'https://cdn.example.com/a.jpg', alt: 'A' },
|
|
176
|
+
{ src: 'https://cdn.example.com/b.jpg', alt: 'B' },
|
|
177
|
+
]}
|
|
178
|
+
/>
|
|
179
|
+
)
|
|
180
|
+
fireEvent.click(screen.getByLabelText('Open image 1 of 2'))
|
|
181
|
+
const viewer = expectViewerOpen('image-viewer')
|
|
182
|
+
expect(viewer.querySelector('img')?.getAttribute('src')).toBe(
|
|
183
|
+
'https://cdn.example.com/a.jpg'
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
fireEvent.keyDown(window, { key: 'ArrowRight' })
|
|
187
|
+
expect(viewer.querySelector('img')?.getAttribute('src')).toBe(
|
|
188
|
+
'https://cdn.example.com/b.jpg'
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
fireEvent.keyDown(window, { key: 'ArrowLeft' })
|
|
192
|
+
expect(viewer.querySelector('img')?.getAttribute('src')).toBe(
|
|
193
|
+
'https://cdn.example.com/a.jpg'
|
|
194
|
+
)
|
|
195
|
+
})
|
|
196
|
+
|
|
84
197
|
it('shows a +N overflow tile for 5+ items', () => {
|
|
85
198
|
renderWithProviders(
|
|
86
199
|
<MessageAttachment.Image.Sent
|
|
@@ -113,9 +226,9 @@ describe('MessageAttachment.Pdf', () => {
|
|
|
113
226
|
filename="doc.pdf"
|
|
114
227
|
/>
|
|
115
228
|
)
|
|
116
|
-
|
|
229
|
+
expectViewerClosed('pdf-viewer')
|
|
117
230
|
fireEvent.click(screen.getByLabelText('Open doc.pdf'))
|
|
118
|
-
|
|
231
|
+
expectViewerOpen('pdf-viewer')
|
|
119
232
|
})
|
|
120
233
|
|
|
121
234
|
it('forwards the onClick handler before opening the viewer', () => {
|
|
@@ -167,11 +280,42 @@ describe('MessageAttachment.Pdf', () => {
|
|
|
167
280
|
]}
|
|
168
281
|
/>
|
|
169
282
|
)
|
|
170
|
-
|
|
283
|
+
expectViewerClosed('pdf-viewer')
|
|
171
284
|
fireEvent.click(screen.getByLabelText('Open b.pdf'))
|
|
172
|
-
const viewer =
|
|
173
|
-
|
|
174
|
-
|
|
285
|
+
const viewer = expectViewerOpen('pdf-viewer')
|
|
286
|
+
// The active filename surfaces as the dialog's accessible name —
|
|
287
|
+
// the lightbox chrome is intentionally just close + carousel chrome
|
|
288
|
+
// so the filename isn't rendered as visible text inside the modal.
|
|
289
|
+
expect(viewer.getAttribute('aria-label')).toBe('b.pdf')
|
|
290
|
+
// Carousel chrome is present because items.length > 1.
|
|
291
|
+
expect(screen.getByLabelText('Next document')).toBeInTheDocument()
|
|
292
|
+
expect(screen.getByLabelText('Previous document')).toBeInTheDocument()
|
|
293
|
+
expect(viewer.textContent).toContain('2 / 2')
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
it('navigates between stacked PDFs via the carousel controls', () => {
|
|
297
|
+
renderWithProviders(
|
|
298
|
+
<MessageAttachment.Pdf.Received
|
|
299
|
+
items={[
|
|
300
|
+
{ src: 'https://cdn.example.com/a.pdf', filename: 'a.pdf' },
|
|
301
|
+
{ src: 'https://cdn.example.com/b.pdf', filename: 'b.pdf' },
|
|
302
|
+
{ src: 'https://cdn.example.com/c.pdf', filename: 'c.pdf' },
|
|
303
|
+
]}
|
|
304
|
+
/>
|
|
305
|
+
)
|
|
306
|
+
fireEvent.click(screen.getByLabelText('Open a.pdf'))
|
|
307
|
+
const viewer = expectViewerOpen('pdf-viewer')
|
|
308
|
+
expect(viewer.getAttribute('aria-label')).toBe('a.pdf')
|
|
309
|
+
|
|
310
|
+
fireEvent.click(screen.getByLabelText('Next document'))
|
|
311
|
+
expect(viewer.getAttribute('aria-label')).toBe('b.pdf')
|
|
312
|
+
|
|
313
|
+
fireEvent.click(screen.getByLabelText('Next document'))
|
|
314
|
+
expect(viewer.getAttribute('aria-label')).toBe('c.pdf')
|
|
315
|
+
|
|
316
|
+
// Wraps back to the start.
|
|
317
|
+
fireEvent.click(screen.getByLabelText('Next document'))
|
|
318
|
+
expect(viewer.getAttribute('aria-label')).toBe('a.pdf')
|
|
175
319
|
})
|
|
176
320
|
|
|
177
321
|
it('renders a sibling Download button on Sent / Received rows', () => {
|
|
@@ -214,11 +358,11 @@ describe('MessageAttachment.Pdf', () => {
|
|
|
214
358
|
filename="notes.pdf"
|
|
215
359
|
/>
|
|
216
360
|
)
|
|
217
|
-
|
|
361
|
+
expectViewerClosed('pdf-viewer')
|
|
218
362
|
fireEvent.click(screen.getByLabelText('Download notes.pdf'))
|
|
219
363
|
// Download should fire on its own without bubbling up to the row
|
|
220
364
|
// activation that opens the viewer.
|
|
221
|
-
|
|
365
|
+
expectViewerClosed('pdf-viewer')
|
|
222
366
|
})
|
|
223
367
|
|
|
224
368
|
it('hides the Download button on the Composer state (dismiss takes its place)', () => {
|
|
@@ -249,7 +393,7 @@ describe('MessageAttachment.Pdf', () => {
|
|
|
249
393
|
/>
|
|
250
394
|
)
|
|
251
395
|
fireEvent.click(screen.getByLabelText('Open c.pdf'))
|
|
252
|
-
|
|
396
|
+
expectViewerOpen('pdf-viewer')
|
|
253
397
|
|
|
254
398
|
expect(() =>
|
|
255
399
|
rerender(
|
|
@@ -263,8 +407,12 @@ describe('MessageAttachment.Pdf', () => {
|
|
|
263
407
|
|
|
264
408
|
// Bubble still renders the surviving row instead of blowing up.
|
|
265
409
|
expect(screen.getByLabelText('Open a.pdf')).toBeInTheDocument()
|
|
266
|
-
// Viewer falls back to the last available item (the surviving one)
|
|
267
|
-
|
|
410
|
+
// Viewer falls back to the last available item (the surviving one)
|
|
411
|
+
// — surfaced as the dialog's aria-label since the chrome no longer
|
|
412
|
+
// renders the filename as visible text.
|
|
413
|
+
expect(screen.getByTestId('pdf-viewer').getAttribute('aria-label')).toBe(
|
|
414
|
+
'a.pdf'
|
|
415
|
+
)
|
|
268
416
|
})
|
|
269
417
|
|
|
270
418
|
it('does not open the viewer when onClick returns false', () => {
|
|
@@ -278,7 +426,7 @@ describe('MessageAttachment.Pdf', () => {
|
|
|
278
426
|
)
|
|
279
427
|
fireEvent.click(screen.getByLabelText('Open doc.pdf'))
|
|
280
428
|
expect(onClick).toHaveBeenCalledTimes(1)
|
|
281
|
-
|
|
429
|
+
expectViewerClosed('pdf-viewer')
|
|
282
430
|
})
|
|
283
431
|
})
|
|
284
432
|
|
|
@@ -450,9 +598,41 @@ describe('MessageAttachment.Video', () => {
|
|
|
450
598
|
filename="clip.mp4"
|
|
451
599
|
/>
|
|
452
600
|
)
|
|
453
|
-
|
|
601
|
+
expectViewerClosed('video-viewer')
|
|
454
602
|
fireEvent.click(screen.getByLabelText('Play video 1 of 1'))
|
|
455
|
-
|
|
603
|
+
expectViewerOpen('video-viewer')
|
|
604
|
+
// Single-item viewer has no carousel chrome.
|
|
605
|
+
expect(screen.queryByLabelText('Next video')).toBeNull()
|
|
606
|
+
})
|
|
607
|
+
|
|
608
|
+
it('navigates between stacked videos via the carousel controls', () => {
|
|
609
|
+
renderWithProviders(
|
|
610
|
+
<MessageAttachment.Video.Sent
|
|
611
|
+
filename="clip"
|
|
612
|
+
items={[
|
|
613
|
+
{
|
|
614
|
+
src: 'https://cdn.example.com/a.mp4',
|
|
615
|
+
poster: 'https://cdn.example.com/a.jpg',
|
|
616
|
+
mimeType: 'video/mp4',
|
|
617
|
+
},
|
|
618
|
+
{
|
|
619
|
+
src: 'https://cdn.example.com/b.mp4',
|
|
620
|
+
poster: 'https://cdn.example.com/b.jpg',
|
|
621
|
+
mimeType: 'video/mp4',
|
|
622
|
+
},
|
|
623
|
+
]}
|
|
624
|
+
/>
|
|
625
|
+
)
|
|
626
|
+
fireEvent.click(screen.getByLabelText('Play video 1 of 2'))
|
|
627
|
+
const viewer = expectViewerOpen('video-viewer')
|
|
628
|
+
expect(viewer.querySelector('video')?.getAttribute('src')).toBe(
|
|
629
|
+
'https://cdn.example.com/a.mp4'
|
|
630
|
+
)
|
|
631
|
+
|
|
632
|
+
fireEvent.click(screen.getByLabelText('Next video'))
|
|
633
|
+
expect(viewer.querySelector('video')?.getAttribute('src')).toBe(
|
|
634
|
+
'https://cdn.example.com/b.mp4'
|
|
635
|
+
)
|
|
456
636
|
})
|
|
457
637
|
})
|
|
458
638
|
|
|
@@ -485,13 +665,14 @@ describe('ViewerShell focus management', () => {
|
|
|
485
665
|
expect(document.activeElement).toBe(opener)
|
|
486
666
|
|
|
487
667
|
fireEvent.click(opener)
|
|
488
|
-
|
|
668
|
+
expectViewerOpen('pdf-viewer')
|
|
489
669
|
|
|
490
670
|
fireEvent.click(screen.getByLabelText('Close viewer'))
|
|
491
671
|
|
|
492
672
|
// After close, focus should hop back to whatever was focused
|
|
493
|
-
// before the viewer mounted (the row's Open button)
|
|
494
|
-
|
|
673
|
+
// before the viewer mounted (the row's Open button), and the
|
|
674
|
+
// dialog should no longer carry the `[open]` attribute.
|
|
675
|
+
expectViewerClosed('pdf-viewer')
|
|
495
676
|
expect(document.activeElement).toBe(opener)
|
|
496
677
|
})
|
|
497
678
|
})
|
|
@@ -5,7 +5,7 @@ import CompactDocumentRow from '../_shared/CompactDocumentRow'
|
|
|
5
5
|
import DismissButton from '../_shared/DismissButton'
|
|
6
6
|
import DownloadAction from '../_shared/DownloadAction'
|
|
7
7
|
import { filenameFromUrl } from '../_shared/fileMeta'
|
|
8
|
-
import PdfViewer from '../_shared/PdfViewer'
|
|
8
|
+
import PdfViewer, { type PdfViewerItem } from '../_shared/PdfViewer'
|
|
9
9
|
import { useViewer } from '../_shared/useViewer'
|
|
10
10
|
import {
|
|
11
11
|
bubbleVariantForState,
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
export interface PdfAttachmentSharedProps extends MessageAttachmentBaseProps {
|
|
20
20
|
/** Single PDF — convenience for the most common case. */
|
|
21
21
|
src?: string
|
|
22
|
-
/** Filename — drives the title + the meta line + the viewer
|
|
22
|
+
/** Filename — drives the row title + the meta line + the viewer dialog's accessible name. */
|
|
23
23
|
filename?: string
|
|
24
24
|
/** File size in bytes — formatted into the `EXT · SIZE` meta line. */
|
|
25
25
|
fileSize?: number
|
|
@@ -128,15 +128,13 @@ const PdfAttachmentRow: React.FC<InternalPdfRowProps> = ({
|
|
|
128
128
|
return null
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const activeFilename =
|
|
139
|
-
activeItem.filename ?? filenameFromUrl(activeItem.src)
|
|
131
|
+
// Project the bubble's `PdfItem`s onto the viewer's carousel-aware
|
|
132
|
+
// shape. The viewer clamps its own active index defensively, so we
|
|
133
|
+
// don't need to second-guess `viewerIndex` here.
|
|
134
|
+
const viewerItems: PdfViewerItem[] = resolvedItems.map((item) => ({
|
|
135
|
+
src: item.src,
|
|
136
|
+
filename: item.filename ?? filenameFromUrl(item.src),
|
|
137
|
+
}))
|
|
140
138
|
|
|
141
139
|
return (
|
|
142
140
|
<Bubble
|
|
@@ -154,8 +152,9 @@ const PdfAttachmentRow: React.FC<InternalPdfRowProps> = ({
|
|
|
154
152
|
// Composer only supports a single attachment so the dismiss
|
|
155
153
|
// control sits on the only row. Sent / Received rows expose
|
|
156
154
|
// a download icon button so the user can grab the PDF
|
|
157
|
-
// without opening the viewer first
|
|
158
|
-
//
|
|
155
|
+
// without opening the viewer first — the viewer dialog is
|
|
156
|
+
// intentionally just the document + a close button, so this
|
|
157
|
+
// sibling action is the only one-click download surface.
|
|
159
158
|
const trailingAction =
|
|
160
159
|
showDismiss && index === 0 ? (
|
|
161
160
|
<DismissButton onClick={onDismiss!} variant="inline" />
|
|
@@ -183,8 +182,8 @@ const PdfAttachmentRow: React.FC<InternalPdfRowProps> = ({
|
|
|
183
182
|
|
|
184
183
|
<PdfViewer
|
|
185
184
|
open={viewerOpen}
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
items={viewerItems}
|
|
186
|
+
initialIndex={viewerIndex}
|
|
188
187
|
onClose={closeViewer}
|
|
189
188
|
/>
|
|
190
189
|
</Bubble>
|
|
@@ -53,13 +53,13 @@ const handleDismiss = () => {
|
|
|
53
53
|
/**
|
|
54
54
|
* Single video — the bubble shows the poster with a play overlay.
|
|
55
55
|
* Clicking opens the full-viewport `VideoViewer` with native controls
|
|
56
|
-
* (play / pause / seek / fullscreen / volume
|
|
56
|
+
* (play / pause / seek / fullscreen / volume / download).
|
|
57
57
|
*/
|
|
58
58
|
export const Single: StoryFn = () => (
|
|
59
59
|
<StoryPage>
|
|
60
60
|
<StoryHeading
|
|
61
61
|
title="Single video"
|
|
62
|
-
description="Click any bubble to open the full-screen video viewer with native controls
|
|
62
|
+
description="Click any bubble to open the full-screen video viewer with the browser's native controls (play / pause / seek / fullscreen / volume / download)."
|
|
63
63
|
/>
|
|
64
64
|
<StoryGrid>
|
|
65
65
|
<StoryRow
|
|
@@ -23,7 +23,7 @@ export interface VideoAttachmentSharedProps extends MessageAttachmentBaseProps {
|
|
|
23
23
|
poster?: string
|
|
24
24
|
/** MIME type hint — typed onto the inline `<source>` element. */
|
|
25
25
|
mimeType?: string
|
|
26
|
-
/** Filename
|
|
26
|
+
/** Filename used as the viewer dialog's accessible name. */
|
|
27
27
|
filename?: string
|
|
28
28
|
/**
|
|
29
29
|
* Stacked videos. Takes precedence over `src` when set. Renders a
|
|
@@ -121,6 +121,12 @@ interface InternalVideoRowProps extends VideoAttachmentSharedProps {
|
|
|
121
121
|
state: MessageAttachmentState
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Project the bubble's `VideoItem`s onto the carousel-aware viewer's
|
|
126
|
+
* `VideoViewerItem` shape. When a shared outer `filename` is supplied
|
|
127
|
+
* for a stacked bubble, suffix `(N)` per sibling so each carousel page
|
|
128
|
+
* still gets a distinct accessible name.
|
|
129
|
+
*/
|
|
124
130
|
const buildViewerItems = (
|
|
125
131
|
resolvedItems: VideoItem[],
|
|
126
132
|
filename?: string
|
|
@@ -177,7 +183,10 @@ const VideoComposerInner: React.FC<{
|
|
|
177
183
|
|
|
178
184
|
<VideoViewer
|
|
179
185
|
open={viewerOpen}
|
|
180
|
-
items={buildViewerItems(
|
|
186
|
+
items={buildViewerItems(
|
|
187
|
+
[{ src, poster, mimeType, preload }],
|
|
188
|
+
filename
|
|
189
|
+
)}
|
|
181
190
|
initialIndex={viewerIndex}
|
|
182
191
|
onClose={closeViewer}
|
|
183
192
|
/>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CaretLeftIcon, CaretRightIcon } from '@phosphor-icons/react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
export interface CarouselNavProps {
|
|
5
|
+
onPrev: () => void
|
|
6
|
+
onNext: () => void
|
|
7
|
+
/** Accessible label for the previous-item button. */
|
|
8
|
+
prevLabel?: string
|
|
9
|
+
/** Accessible label for the next-item button. */
|
|
10
|
+
nextLabel?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Prev / next chrome shared by every carousel-aware viewer. Rendered
|
|
15
|
+
* inside the dialog body so the buttons sit absolutely positioned
|
|
16
|
+
* against the viewer (`.mes-media-viewer__nav--{prev,next}`).
|
|
17
|
+
*
|
|
18
|
+
* Styling lives as plain CSS in `styles.css` so the buttons render
|
|
19
|
+
* correctly regardless of whether the consumer has Tailwind wired up.
|
|
20
|
+
*/
|
|
21
|
+
const CarouselNav: React.FC<CarouselNavProps> = ({
|
|
22
|
+
onPrev,
|
|
23
|
+
onNext,
|
|
24
|
+
prevLabel = 'Previous',
|
|
25
|
+
nextLabel = 'Next',
|
|
26
|
+
}) => (
|
|
27
|
+
<>
|
|
28
|
+
<button
|
|
29
|
+
type="button"
|
|
30
|
+
onClick={onPrev}
|
|
31
|
+
aria-label={prevLabel}
|
|
32
|
+
className="mes-media-viewer__nav mes-media-viewer__nav--prev"
|
|
33
|
+
>
|
|
34
|
+
<CaretLeftIcon size={20} weight="bold" aria-hidden />
|
|
35
|
+
</button>
|
|
36
|
+
<button
|
|
37
|
+
type="button"
|
|
38
|
+
onClick={onNext}
|
|
39
|
+
aria-label={nextLabel}
|
|
40
|
+
className="mes-media-viewer__nav mes-media-viewer__nav--next"
|
|
41
|
+
>
|
|
42
|
+
<CaretRightIcon size={20} weight="bold" aria-hidden />
|
|
43
|
+
</button>
|
|
44
|
+
</>
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
export default CarouselNav
|