@linktr.ee/messaging-react 3.31.0-rc-1785485102 → 3.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Card-2l_y20FM.js → Card-CmlaSw7i.js} +2 -2
- package/dist/{Card-2l_y20FM.js.map → Card-CmlaSw7i.js.map} +1 -1
- package/dist/{Card-Gr4HDVbn.cjs → Card-EWN07XIl.cjs} +2 -2
- package/dist/{Card-Gr4HDVbn.cjs.map → Card-EWN07XIl.cjs.map} +1 -1
- package/dist/assets/index.css +1 -1
- package/dist/{index-B96WLmx6.js → index-CN3errpB.js} +3055 -3109
- package/dist/index-CN3errpB.js.map +1 -0
- package/dist/index-CcitzVoW.cjs +5 -0
- package/dist/index-CcitzVoW.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +56 -60
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/src/components/ChannelView.broadcast-name.integration.test.tsx +116 -0
- package/src/components/ChannelView.tsx +17 -3
- package/src/components/CustomLinkPreviewList/CustomLinkPreviewList.test.tsx +15 -0
- package/src/components/CustomLinkPreviewList/index.tsx +24 -26
- package/src/components/CustomMessage/BroadcastNameContext.test.ts +43 -0
- package/src/components/CustomMessage/BroadcastNameContext.ts +95 -0
- package/src/components/CustomMessage/CustomMessage.stories.tsx +54 -22
- package/src/components/CustomMessage/CustomMessage.test.tsx +48 -0
- package/src/components/CustomMessage/SentMessageDeliveryStatus.test.tsx +62 -0
- package/src/components/CustomMessage/SentMessageDeliveryStatus.tsx +8 -2
- package/src/components/CustomMessage/StreamAttachmentMessage.test.tsx +0 -33
- package/src/components/CustomMessage/StreamAttachmentMessage.tsx +0 -8
- package/src/components/CustomMessage/index.tsx +23 -3
- package/src/components/CustomMessageInput/CustomMessageInput.stories.tsx +50 -2
- package/src/components/CustomMessageInput/CustomMessageInput.test.tsx +180 -2
- package/src/components/CustomMessageInput/index.tsx +143 -16
- package/src/components/MessageAttachment/Audio/AudioAttachment.stories.tsx +57 -166
- package/src/components/MessageAttachment/Audio/index.tsx +77 -71
- package/src/components/MessageAttachment/MessageAttachment.test.tsx +75 -175
- package/src/components/MessageAttachment/index.tsx +9 -25
- package/src/components/MessageAttachment/types.ts +9 -19
- package/src/components/MessagingShell/index.tsx +2 -0
- package/src/index.ts +1 -0
- package/src/styles.css +5 -120
- package/src/types.ts +11 -0
- package/src/utils/formatRelativeTime.test.ts +63 -57
- package/src/utils/formatRelativeTime.ts +21 -20
- package/dist/index-B96WLmx6.js.map +0 -1
- package/dist/index-CCtHMrmO.cjs +0 -5
- package/dist/index-CCtHMrmO.cjs.map +0 -1
- package/src/components/MessageAttachment/Audio/WaveformAudioRow.tsx +0 -335
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DownloadSimpleIcon,
|
|
3
|
-
PauseIcon,
|
|
4
|
-
PlayIcon,
|
|
5
|
-
XIcon,
|
|
6
|
-
} from '@phosphor-icons/react'
|
|
7
|
-
import classNames from 'classnames'
|
|
8
|
-
import React from 'react'
|
|
9
|
-
import {
|
|
10
|
-
displayDuration,
|
|
11
|
-
resampleWaveformData,
|
|
12
|
-
useAudioPlayer,
|
|
13
|
-
useStateStore,
|
|
14
|
-
type AudioPlayerState,
|
|
15
|
-
} from 'stream-chat-react'
|
|
16
|
-
|
|
17
|
-
import { triggerDownload } from '../_shared/triggerDownload'
|
|
18
|
-
import type { AudioItem, BubbleVariant } from '../types'
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Bar count in the design's waveform (Figma `2754:17710`, nodes
|
|
22
|
-
* `…;2754:8066` – `…;2754:8100`). The 138px track is exactly
|
|
23
|
-
* `35 × 2px bars + 34 × 2px gaps`, so the count is derived from the
|
|
24
|
-
* drawn geometry rather than picked.
|
|
25
|
-
*/
|
|
26
|
-
export const WAVEFORM_BAR_COUNT = 35
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Total fallback for every case where no amplitudes exist: a decode
|
|
30
|
-
* failure, an unsupported codec, a re-staged zero-byte placeholder, a
|
|
31
|
-
* file over the composer's decode ceiling, or any attachment sent
|
|
32
|
-
* before `waveform_data` was persisted (legacy web, the mobile app, a
|
|
33
|
-
* visitor).
|
|
34
|
-
*
|
|
35
|
-
* `.mes-audio-wave__bar` floors every bar at the design's 4px minimum,
|
|
36
|
-
* so all 35 bars render as the shortest bar the design already draws:
|
|
37
|
-
* the card's silhouette, height and geometry are identical to a real
|
|
38
|
-
* waveform, and the progress fill still sweeps left to right during
|
|
39
|
-
* playback. A shape-changing degraded state (e.g. a plain progress
|
|
40
|
-
* bar) would read as a different feature.
|
|
41
|
-
*/
|
|
42
|
-
const FLAT_WAVEFORM: readonly number[] = Object.freeze(
|
|
43
|
-
new Array<number>(WAVEFORM_BAR_COUNT).fill(0)
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
/** Shown in the fixed duration slot until a duration is known. */
|
|
47
|
-
const UNKNOWN_DURATION = '--:--'
|
|
48
|
-
|
|
49
|
-
const AUDIO_PLAYER_STATE_SELECTOR = (state: AudioPlayerState) => ({
|
|
50
|
-
canPlayRecord: state.canPlayRecord,
|
|
51
|
-
isPlaying: state.isPlaying,
|
|
52
|
-
progressPercent: state.progressPercent,
|
|
53
|
-
secondsElapsed: state.secondsElapsed,
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
// Both of Figma's `content-control-buttons` instances (`…;2754:8063`
|
|
57
|
-
// play, `…;2754:8102` trailing) are the same 32×32 pill with a 6px inset
|
|
58
|
-
// around a 12px glyph and a 20px background blur; only the fill differs.
|
|
59
|
-
const CONTROL_CLASS =
|
|
60
|
-
'flex size-8 shrink-0 items-center justify-center rounded-full backdrop-blur-[20px]'
|
|
61
|
-
|
|
62
|
-
// Figma draws only the dark sender card (`fill:#1E2330`), with every
|
|
63
|
-
// control in white. The light (`Received`) variant — the one visitors see
|
|
64
|
-
// on linktr.ee-profiles — is undrawn, so it inverts the same treatment
|
|
65
|
-
// against the `#f2f1ef` bubble. Ratios below were measured off the
|
|
66
|
-
// composited render, not estimated:
|
|
67
|
-
//
|
|
68
|
-
// played unplayed played:unplayed play button
|
|
69
|
-
// dark on #1E2330 15.69 3.71 4.24 15.69
|
|
70
|
-
// light on #F2F1EF 18.17 3.78 4.81 15.16
|
|
71
|
-
//
|
|
72
|
-
// Both unplayed fills clear WCAG 1.4.11's 3:1 floor for non-text contrast,
|
|
73
|
-
// and the played/unplayed step is well past it so progress is legible on
|
|
74
|
-
// its own. The light variant needs `#040403` at 0.5 where dark needs white
|
|
75
|
-
// at 0.4, because it composites towards a lighter backdrop.
|
|
76
|
-
const PLAY_BUTTON_BY_VARIANT: Record<BubbleVariant, string> = {
|
|
77
|
-
dark: 'bg-white text-black/90 disabled:bg-white/40',
|
|
78
|
-
light: 'bg-[#040403]/90 text-white disabled:bg-[#040403]/30',
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const TRAILING_BUTTON_BY_VARIANT: Record<BubbleVariant, string> = {
|
|
82
|
-
dark: 'bg-[#040403]/80 text-white hover:bg-[#040403]',
|
|
83
|
-
light: 'bg-black/10 text-black/90 hover:bg-black/20',
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* What the design's trailing 32px control does. The ticket asks to
|
|
88
|
-
* "keep the same options as current production", and production has no
|
|
89
|
-
* product-owned menu on an audio attachment — the only menu was the
|
|
90
|
-
* native `<audio controls>` kebab, which disappears with the native
|
|
91
|
-
* player. So each surface carries forward the single action it already
|
|
92
|
-
* had: the composer removes the draft, and a sent / received card
|
|
93
|
-
* downloads the file (the capability the browser kebab provided).
|
|
94
|
-
*/
|
|
95
|
-
export type AudioRowTrailingAction =
|
|
96
|
-
| { kind: 'dismiss'; onDismiss: () => void }
|
|
97
|
-
| { kind: 'download' }
|
|
98
|
-
|
|
99
|
-
export interface WaveformAudioRowProps {
|
|
100
|
-
item: AudioItem
|
|
101
|
-
variant: BubbleVariant
|
|
102
|
-
trailingAction: AudioRowTrailingAction
|
|
103
|
-
/**
|
|
104
|
-
* Namespaces the pooled `AudioPlayer` so the same asset rendered in
|
|
105
|
-
* two different messages keeps two independent playback positions.
|
|
106
|
-
* Derived from the Stream message id where one is available.
|
|
107
|
-
*/
|
|
108
|
-
requester?: string
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Resolves the track length. `durationSeconds` (persisted on the Stream
|
|
113
|
-
* attachment at send time) is authoritative and correct on first paint.
|
|
114
|
-
* Without it — legacy sends, mobile-app sends, visitor sends — a single
|
|
115
|
-
* detached `preload="metadata"` element resolves it from the response
|
|
116
|
-
* headers, which is exactly what the native player it replaces did.
|
|
117
|
-
*/
|
|
118
|
-
const useResolvedDuration = (
|
|
119
|
-
src: string,
|
|
120
|
-
durationSeconds?: number
|
|
121
|
-
): number | undefined => {
|
|
122
|
-
const [probed, setProbed] = React.useState<number>()
|
|
123
|
-
|
|
124
|
-
React.useEffect(() => {
|
|
125
|
-
if (durationSeconds != null || !src) return
|
|
126
|
-
|
|
127
|
-
const probe = document.createElement('audio')
|
|
128
|
-
probe.preload = 'metadata'
|
|
129
|
-
const handleLoadedMetadata = () => {
|
|
130
|
-
if (Number.isFinite(probe.duration) && probe.duration > 0) {
|
|
131
|
-
setProbed(probe.duration)
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
probe.addEventListener('loadedmetadata', handleLoadedMetadata)
|
|
135
|
-
probe.src = src
|
|
136
|
-
|
|
137
|
-
return () => {
|
|
138
|
-
probe.removeEventListener('loadedmetadata', handleLoadedMetadata)
|
|
139
|
-
probe.removeAttribute('src')
|
|
140
|
-
setProbed(undefined)
|
|
141
|
-
}
|
|
142
|
-
}, [src, durationSeconds])
|
|
143
|
-
|
|
144
|
-
return durationSeconds ?? probed
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* One waveform player row: 32px play toggle, 35-bar waveform with a
|
|
149
|
-
* progress fill and a native seek control, the duration, and the 32px
|
|
150
|
-
* trailing action. A single-item bubble is the design's 299×72 card;
|
|
151
|
-
* a stacked bubble repeats the row.
|
|
152
|
-
*
|
|
153
|
-
* Playback is `stream-chat-react`'s pooled `AudioPlayer`, which gives
|
|
154
|
-
* single-player-at-a-time across the thread, pause-on-unmount and
|
|
155
|
-
* saved-position restore. That pool lives on `<Channel>`, so outside
|
|
156
|
-
* one the card still renders in full with its controls disabled rather
|
|
157
|
-
* than vanishing.
|
|
158
|
-
*/
|
|
159
|
-
const WaveformAudioRow: React.FC<WaveformAudioRowProps> = ({
|
|
160
|
-
item,
|
|
161
|
-
variant,
|
|
162
|
-
trailingAction,
|
|
163
|
-
requester,
|
|
164
|
-
}) => {
|
|
165
|
-
const trackRef = React.useRef<HTMLDivElement>(null)
|
|
166
|
-
const [isStarting, setIsStarting] = React.useState(false)
|
|
167
|
-
|
|
168
|
-
// An empty array must never reach `resampleWaveformData` — its
|
|
169
|
-
// `upSample` branch `console.warn`s and returns `[]`, which renders no
|
|
170
|
-
// bars at all (and trips consumers whose tests fail on console output).
|
|
171
|
-
const amplitudes = React.useMemo<readonly number[]>(() => {
|
|
172
|
-
const data = item.waveformData
|
|
173
|
-
if (!data || data.length === 0) return FLAT_WAVEFORM
|
|
174
|
-
if (data.length === WAVEFORM_BAR_COUNT) return data
|
|
175
|
-
return resampleWaveformData(data, WAVEFORM_BAR_COUNT)
|
|
176
|
-
}, [item.waveformData])
|
|
177
|
-
const durationSeconds = useResolvedDuration(item.src, item.durationSeconds)
|
|
178
|
-
|
|
179
|
-
const audioPlayer = useAudioPlayer({
|
|
180
|
-
durationSeconds,
|
|
181
|
-
mimeType: item.mimeType,
|
|
182
|
-
requester,
|
|
183
|
-
src: item.src,
|
|
184
|
-
title: item.filename,
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
const {
|
|
188
|
-
canPlayRecord = false,
|
|
189
|
-
isPlaying = false,
|
|
190
|
-
progressPercent = 0,
|
|
191
|
-
secondsElapsed = 0,
|
|
192
|
-
} = useStateStore(audioPlayer?.state, AUDIO_PLAYER_STATE_SELECTOR) ?? {}
|
|
193
|
-
|
|
194
|
-
const progress = Math.min(Math.max(progressPercent, 0), 100)
|
|
195
|
-
const playable = !!audioPlayer && canPlayRecord
|
|
196
|
-
const showPause = isPlaying || isStarting
|
|
197
|
-
|
|
198
|
-
const totalLabel =
|
|
199
|
-
durationSeconds == null ? UNKNOWN_DURATION : displayDuration(durationSeconds)
|
|
200
|
-
// Mirrors the native player: the slot counts up while playing and
|
|
201
|
-
// holds the elapsed position when paused, falling back to the total.
|
|
202
|
-
const displayedLabel =
|
|
203
|
-
secondsElapsed > 0 ? displayDuration(secondsElapsed) : totalLabel
|
|
204
|
-
|
|
205
|
-
const handleTogglePlay = () => {
|
|
206
|
-
if (!audioPlayer || isStarting) return
|
|
207
|
-
setIsStarting(true)
|
|
208
|
-
void audioPlayer.togglePlay().finally(() => setIsStarting(false))
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// One seek code path for pointer, keyboard and drag: the native range
|
|
212
|
-
// input owns the interaction, and its value is translated into the
|
|
213
|
-
// `SeekFn` contract from the bar track's own rect. Going through
|
|
214
|
-
// `AudioPlayer.seek` inherits its lazy element acquisition (so
|
|
215
|
-
// seeking before the first play works), its seekable-range check and
|
|
216
|
-
// its 16ms throttle — `setSecondsElapsed` alone would not, because
|
|
217
|
-
// no `<audio>` element exists until the pool hands one over.
|
|
218
|
-
const handleSeek = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
219
|
-
const track = trackRef.current
|
|
220
|
-
if (!audioPlayer || !track) return
|
|
221
|
-
const ratio = Math.min(Math.max(Number(event.target.value) / 100, 0), 1)
|
|
222
|
-
const rect = track.getBoundingClientRect()
|
|
223
|
-
void audioPlayer.seek({
|
|
224
|
-
clientX: rect.x + ratio * rect.width,
|
|
225
|
-
currentTarget: track,
|
|
226
|
-
})
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Suffixed onto each control's accessible name so a thread of stacked
|
|
230
|
-
// clips reads as "Play audio — take-2.mp3", not three identical labels.
|
|
231
|
-
const label = item.filename ? ` \u2014 ${item.filename}` : ''
|
|
232
|
-
|
|
233
|
-
return (
|
|
234
|
-
<div
|
|
235
|
-
role="group"
|
|
236
|
-
aria-label={item.filename ?? 'Audio attachment'}
|
|
237
|
-
className="flex items-center"
|
|
238
|
-
data-testid="audio-attachment-row"
|
|
239
|
-
>
|
|
240
|
-
<button
|
|
241
|
-
type="button"
|
|
242
|
-
onClick={handleTogglePlay}
|
|
243
|
-
disabled={!playable}
|
|
244
|
-
aria-busy={isStarting || undefined}
|
|
245
|
-
aria-label={`${showPause ? 'Pause audio' : 'Play audio'}${label}`}
|
|
246
|
-
className={classNames(CONTROL_CLASS, PLAY_BUTTON_BY_VARIANT[variant])}
|
|
247
|
-
>
|
|
248
|
-
{showPause ? (
|
|
249
|
-
<PauseIcon className="size-3" weight="fill" aria-hidden />
|
|
250
|
-
) : (
|
|
251
|
-
<PlayIcon className="size-3" weight="fill" aria-hidden />
|
|
252
|
-
)}
|
|
253
|
-
</button>
|
|
254
|
-
|
|
255
|
-
{/* Figma `soundwave-container` (…;2754:8064): 203×30, 10px gap,
|
|
256
|
-
12px horizontal inset, waveform flexing against a fixed
|
|
257
|
-
duration slot. */}
|
|
258
|
-
<div className="flex min-w-0 flex-1 items-center gap-2.5 px-3">
|
|
259
|
-
<div
|
|
260
|
-
className={classNames(
|
|
261
|
-
'mes-audio-wave',
|
|
262
|
-
variant === 'light' && 'mes-audio-wave--light'
|
|
263
|
-
)}
|
|
264
|
-
>
|
|
265
|
-
{/* The bars carry no information a screen reader can use —
|
|
266
|
-
elapsed / total is announced by the range input below —
|
|
267
|
-
so they stay out of the accessibility tree entirely. */}
|
|
268
|
-
<div ref={trackRef} className="mes-audio-wave__track" aria-hidden>
|
|
269
|
-
{amplitudes.map((amplitude, index) => (
|
|
270
|
-
<span
|
|
271
|
-
// Bars are positional, and the array is a fixed-length
|
|
272
|
-
// resample of the same track — index is the identity.
|
|
273
|
-
key={index}
|
|
274
|
-
data-testid="amplitude-bar"
|
|
275
|
-
className={classNames(
|
|
276
|
-
'mes-audio-wave__bar',
|
|
277
|
-
progress > (index / amplitudes.length) * 100 &&
|
|
278
|
-
'mes-audio-wave__bar--played'
|
|
279
|
-
)}
|
|
280
|
-
style={
|
|
281
|
-
{
|
|
282
|
-
'--mes-audio-wave-bar': `${
|
|
283
|
-
Math.min(Math.max(amplitude, 0), 1) * 100
|
|
284
|
-
}%`,
|
|
285
|
-
} as React.CSSProperties
|
|
286
|
-
}
|
|
287
|
-
/>
|
|
288
|
-
))}
|
|
289
|
-
</div>
|
|
290
|
-
<input
|
|
291
|
-
type="range"
|
|
292
|
-
className="mes-audio-wave__seek"
|
|
293
|
-
min={0}
|
|
294
|
-
max={100}
|
|
295
|
-
step={0.1}
|
|
296
|
-
value={progress}
|
|
297
|
-
onChange={handleSeek}
|
|
298
|
-
disabled={!playable}
|
|
299
|
-
aria-label={`Seek audio${label}`}
|
|
300
|
-
aria-valuetext={`${displayDuration(secondsElapsed)} of ${totalLabel}`}
|
|
301
|
-
/>
|
|
302
|
-
</div>
|
|
303
|
-
|
|
304
|
-
<span className="shrink-0 text-xs leading-4 tracking-[0.24px] tabular-nums">
|
|
305
|
-
{displayedLabel}
|
|
306
|
-
</span>
|
|
307
|
-
</div>
|
|
308
|
-
|
|
309
|
-
<button
|
|
310
|
-
type="button"
|
|
311
|
-
onClick={
|
|
312
|
-
trailingAction.kind === 'dismiss'
|
|
313
|
-
? trailingAction.onDismiss
|
|
314
|
-
: () => {
|
|
315
|
-
void triggerDownload(item.src, item.filename)
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
aria-label={
|
|
319
|
-
trailingAction.kind === 'dismiss'
|
|
320
|
-
? 'Remove attachment'
|
|
321
|
-
: `Download audio${label}`
|
|
322
|
-
}
|
|
323
|
-
className={classNames(CONTROL_CLASS, TRAILING_BUTTON_BY_VARIANT[variant])}
|
|
324
|
-
>
|
|
325
|
-
{trailingAction.kind === 'dismiss' ? (
|
|
326
|
-
<XIcon className="size-3" weight="bold" aria-hidden />
|
|
327
|
-
) : (
|
|
328
|
-
<DownloadSimpleIcon className="size-3" weight="bold" aria-hidden />
|
|
329
|
-
)}
|
|
330
|
-
</button>
|
|
331
|
-
</div>
|
|
332
|
-
)
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
export default WaveformAudioRow
|