@linktr.ee/messaging-react 3.8.1 → 3.9.0-rc-1783406511

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 (87) hide show
  1. package/dist/Card-BG-Mg_ss.js +221 -0
  2. package/dist/Card-BG-Mg_ss.js.map +1 -0
  3. package/dist/Card-CmRzkuPw.cjs +2 -0
  4. package/dist/Card-CmRzkuPw.cjs.map +1 -0
  5. package/dist/Card-DSG-wR8t.js +96 -0
  6. package/dist/Card-DSG-wR8t.js.map +1 -0
  7. package/dist/Card-DVEuTlf_.cjs +2 -0
  8. package/dist/Card-DVEuTlf_.cjs.map +1 -0
  9. package/dist/Card-K9ky-G-t.js +108 -0
  10. package/dist/Card-K9ky-G-t.js.map +1 -0
  11. package/dist/Card-iKTcn1wg.cjs +2 -0
  12. package/dist/Card-iKTcn1wg.cjs.map +1 -0
  13. package/dist/PurchaseStatusBadge-CJH4S-8Z.js +36 -0
  14. package/dist/PurchaseStatusBadge-CJH4S-8Z.js.map +1 -0
  15. package/dist/PurchaseStatusBadge-UjDzZhLj.cjs +2 -0
  16. package/dist/PurchaseStatusBadge-UjDzZhLj.cjs.map +1 -0
  17. package/dist/TextShell-BiqF2UB0.js +32 -0
  18. package/dist/TextShell-BiqF2UB0.js.map +1 -0
  19. package/dist/TextShell-Bnzh0T75.cjs +2 -0
  20. package/dist/TextShell-Bnzh0T75.cjs.map +1 -0
  21. package/dist/assets/index.css +1 -1
  22. package/dist/{index-BCgRoF_u.js → index-DO_dYsIf.js} +1154 -1113
  23. package/dist/index-DO_dYsIf.js.map +1 -0
  24. package/dist/index-DpzmKL5U.cjs +2 -0
  25. package/dist/index-DpzmKL5U.cjs.map +1 -0
  26. package/dist/index.cjs +1 -1
  27. package/dist/index.d.ts +98 -55
  28. package/dist/index.js +1 -1
  29. package/dist/testing.d.ts +1 -0
  30. package/dist/usePreviewToggle-B5kmPELX.cjs +2 -0
  31. package/dist/usePreviewToggle-B5kmPELX.cjs.map +1 -0
  32. package/dist/usePreviewToggle-D27Xw9Xx.js +323 -0
  33. package/dist/usePreviewToggle-D27Xw9Xx.js.map +1 -0
  34. package/package.json +2 -2
  35. package/src/components/CustomMessage/CustomMessage.stories.tsx +54 -1
  36. package/src/components/CustomMessage/MessageTag.tsx +8 -0
  37. package/src/components/CustomMessage/index.tsx +61 -22
  38. package/src/components/LockedAttachment/LockedAttachment.stories.tsx +410 -333
  39. package/src/components/LockedAttachment/LockedAttachment.test.tsx +104 -0
  40. package/src/components/LockedAttachment/components/Composer/Card.tsx +97 -120
  41. package/src/components/LockedAttachment/components/Media/Card.tsx +237 -0
  42. package/src/components/LockedAttachment/components/Text/Card.tsx +177 -0
  43. package/src/components/LockedAttachment/components/_shared/CardBody.tsx +3 -3
  44. package/src/components/LockedAttachment/components/_shared/CardThumbnail.tsx +92 -0
  45. package/src/components/LockedAttachment/components/_shared/GalleryThumbnail.tsx +11 -33
  46. package/src/components/LockedAttachment/components/_shared/LoadingDots.tsx +36 -0
  47. package/src/components/LockedAttachment/components/_shared/LockBadge.tsx +21 -11
  48. package/src/components/LockedAttachment/components/_shared/{LockedCardShell.tsx → MediaShell.tsx} +5 -5
  49. package/src/components/LockedAttachment/components/_shared/PreviewToggle.tsx +58 -0
  50. package/src/components/LockedAttachment/components/_shared/PriceLockRow.tsx +21 -0
  51. package/src/components/LockedAttachment/components/_shared/PurchaseStatusBadge.tsx +87 -0
  52. package/src/components/LockedAttachment/components/_shared/{LockedThumbnail.tsx → SingleThumbnail.tsx} +5 -5
  53. package/src/components/LockedAttachment/components/_shared/SkeletonTextLines.tsx +39 -0
  54. package/src/components/LockedAttachment/components/_shared/TextShell.tsx +19 -0
  55. package/src/components/LockedAttachment/components/_shared/usePreviewToggle.test.ts +67 -0
  56. package/src/components/LockedAttachment/components/_shared/usePreviewToggle.ts +89 -0
  57. package/src/components/LockedAttachment/components/_shared/useReceivedSource.ts +83 -0
  58. package/src/components/LockedAttachment/index.tsx +17 -28
  59. package/src/components/LockedAttachment/types.ts +28 -4
  60. package/src/index.ts +2 -5
  61. package/src/stream-custom-data.ts +1 -0
  62. package/src/styles.css +5 -0
  63. package/dist/Card-BRvcFjsq.js +0 -132
  64. package/dist/Card-BRvcFjsq.js.map +0 -1
  65. package/dist/Card-BuXkok0A.cjs +0 -2
  66. package/dist/Card-BuXkok0A.cjs.map +0 -1
  67. package/dist/Card-CvNHv3me.js +0 -107
  68. package/dist/Card-CvNHv3me.js.map +0 -1
  69. package/dist/Card-DOSuQdnk.cjs +0 -2
  70. package/dist/Card-DOSuQdnk.cjs.map +0 -1
  71. package/dist/Card-NnQw99XE.cjs +0 -2
  72. package/dist/Card-NnQw99XE.cjs.map +0 -1
  73. package/dist/Card-jGOcSN1O.js +0 -163
  74. package/dist/Card-jGOcSN1O.js.map +0 -1
  75. package/dist/LockedThumbnail-EsjaAqLR.js +0 -220
  76. package/dist/LockedThumbnail-EsjaAqLR.js.map +0 -1
  77. package/dist/LockedThumbnail-uAauUd5c.cjs +0 -2
  78. package/dist/LockedThumbnail-uAauUd5c.cjs.map +0 -1
  79. package/dist/index-BCgRoF_u.js.map +0 -1
  80. package/dist/index-DRurVQ0-.cjs +0 -2
  81. package/dist/index-DRurVQ0-.cjs.map +0 -1
  82. package/src/components/LockedAttachment/components/Composer/index.ts +0 -2
  83. package/src/components/LockedAttachment/components/Received/Card.tsx +0 -191
  84. package/src/components/LockedAttachment/components/Received/index.ts +0 -2
  85. package/src/components/LockedAttachment/components/Sent/Card.tsx +0 -177
  86. package/src/components/LockedAttachment/components/Sent/index.ts +0 -2
  87. /package/src/components/LockedAttachment/components/{Received → Media}/CardActions.tsx +0 -0
@@ -1,2 +0,0 @@
1
- export { default as ComposerCard } from './Card'
2
- export type { ComposerCardProps } from './Card'
@@ -1,191 +0,0 @@
1
- import { CheckCircleIcon, ImagesIcon } from '@phosphor-icons/react'
2
- import React, { useCallback, useEffect, useRef, useState } from 'react'
3
-
4
- import { getSourceType } from '../../../AttachmentCard'
5
- import type {
6
- LockedAttachmentBaseProps,
7
- LockedAttachmentSource,
8
- } from '../../types'
9
- import CardBody from '../_shared/CardBody'
10
- import GalleryThumbnail from '../_shared/GalleryThumbnail'
11
- import LockedCardShell from '../_shared/LockedCardShell'
12
- import LockedThumbnail from '../_shared/LockedThumbnail'
13
-
14
- import ReceivedCardActions from './CardActions'
15
-
16
- export interface ReceivedCardProps extends LockedAttachmentBaseProps {
17
- /**
18
- * Called when the recipient clicks Unlock on an unpaid attachment.
19
- * Use this to open a checkout flow. Omit to hide the Unlock button.
20
- */
21
- onUnlockClick?: () => void
22
- /**
23
- * Called to fetch the attachment source — fired automatically when
24
- * `paymentStatus` transitions to `'paid'`, or immediately on click when
25
- * `paymentStatus` is already `'paid'`. Return a `LockedAttachmentSource`
26
- * to unlock the card.
27
- */
28
- onFetchSource?: () => Promise<LockedAttachmentSource | void>
29
- /**
30
- * Called when the recipient clicks Download on an unlocked card.
31
- * Omit to hide the Download button.
32
- */
33
- onDownloadClick?: () => void
34
- /**
35
- * When true, shows a loading spinner on the Unlock button.
36
- * Driven by the LockedAttachmentContext (e.g. checkout in progress).
37
- */
38
- isUnlocking?: boolean
39
- }
40
-
41
- /**
42
- * The card the recipient sees in chat for a paid attachment.
43
- * Matches the Received column of the messaging design system in Figma:
44
- * locked → blurred thumbnail + Unlock CTA, unlocked → clear image + Download CTA.
45
- */
46
- const ReceivedCard: React.FC<ReceivedCardProps> = ({
47
- title,
48
- amountText,
49
- thumbnailUrl,
50
- mimeType = 'application/octet-stream',
51
- detail,
52
- gallery,
53
- onUnlockClick,
54
- onFetchSource,
55
- onDownloadClick,
56
- paymentStatus,
57
- isUnlocking = false,
58
- }) => {
59
- const isGallery = (gallery?.length ?? 0) >= 2
60
- const [source, setSource] = useState<LockedAttachmentSource | undefined>()
61
-
62
- const cardRef = useRef<HTMLDivElement>(null)
63
- const fetchingRef = useRef(false)
64
-
65
- const onFetchSourceRef = useRef(onFetchSource)
66
- onFetchSourceRef.current = onFetchSource
67
-
68
- const effectiveSourceUrl = source?.sourceUrl
69
- const effectiveRedeemUrl = source?.redeemUrl
70
-
71
- const fetchSource = useCallback(async (): Promise<void> => {
72
- if (fetchingRef.current) return
73
- fetchingRef.current = true
74
- try {
75
- const result = await onFetchSourceRef.current?.()
76
- if (result) setSource(result)
77
- } finally {
78
- fetchingRef.current = false
79
- }
80
- }, [])
81
-
82
- const handleUnlockClick = useCallback(() => {
83
- if (paymentStatus === 'paid') {
84
- void fetchSource()
85
- } else {
86
- onUnlockClick?.()
87
- }
88
- }, [paymentStatus, fetchSource, onUnlockClick])
89
-
90
- // Auto-fetch the source once the paid card scrolls into view.
91
- useEffect(() => {
92
- if (!cardRef.current) return
93
- if (paymentStatus !== 'paid' || source !== undefined) return
94
-
95
- const observer = new IntersectionObserver(
96
- ([entry]) => {
97
- if (entry.isIntersecting) {
98
- void fetchSource()
99
- observer.disconnect()
100
- }
101
- },
102
- { threshold: 1.0 }
103
- )
104
-
105
- observer.observe(cardRef.current)
106
- return () => observer.disconnect()
107
- }, [paymentStatus, source, fetchSource])
108
-
109
- // For gallery, the per-item sources are carried by `gallery` itself, so
110
- // the lock state is driven by paymentStatus rather than the single
111
- // `effectiveSourceUrl`. Everything else still respects the source fetch.
112
- const isLocked = isGallery
113
- ? paymentStatus !== 'paid'
114
- : effectiveSourceUrl === undefined
115
- const sourceType = getSourceType(mimeType)
116
-
117
- const statusBadge =
118
- paymentStatus === 'paid' ? (
119
- <React.Fragment>
120
- <span className="text-xs font-medium text-black/55">&bull;</span>
121
- <span className="text-xs font-medium text-[#008236]">Purchased</span>
122
- <CheckCircleIcon className="size-4 text-[#008236]" weight="bold" />
123
- </React.Fragment>
124
- ) : amountText != null ? (
125
- <React.Fragment>
126
- <span className="text-xs font-medium text-black/55">&bull;</span>
127
- <span className="text-xs font-medium text-black/55">{amountText}</span>
128
- </React.Fragment>
129
- ) : null
130
-
131
- // For gallery, ReceivedCardActions falls back to a plain <button>
132
- // (no anchor) because the gallery has no single sourceUrl to link to —
133
- // the per-item sources live on `gallery` itself.
134
- const actionSourceUrl = isGallery ? undefined : effectiveSourceUrl
135
-
136
- return (
137
- <LockedCardShell
138
- variant="light"
139
- rootRef={cardRef}
140
- data-testid="locked-attachment"
141
- >
142
- {isGallery ? (
143
- <GalleryThumbnail
144
- variant="light"
145
- gallery={gallery!}
146
- title={title}
147
- showLocked={isLocked}
148
- paymentStatus={paymentStatus}
149
- />
150
- ) : (
151
- <LockedThumbnail
152
- variant="light"
153
- mimeType={mimeType}
154
- thumbnailUrl={thumbnailUrl}
155
- title={title}
156
- source={source}
157
- showLocked={isLocked}
158
- paymentStatus={paymentStatus}
159
- containedImage={
160
- !isLocked && (sourceType === 'image' || sourceType === 'document')
161
- }
162
- />
163
- )}
164
-
165
- <CardBody
166
- variant="light"
167
- title={title}
168
- mimeType={mimeType}
169
- detail={detail}
170
- statusBadge={statusBadge}
171
- icon={
172
- isGallery ? (
173
- <ImagesIcon className="size-5 shrink-0 text-black/55" />
174
- ) : undefined
175
- }
176
- action={
177
- <ReceivedCardActions
178
- isLocked={isLocked}
179
- isUnlocking={isUnlocking}
180
- sourceUrl={actionSourceUrl}
181
- redeemUrl={effectiveRedeemUrl}
182
- onUnlockClicked={handleUnlockClick}
183
- onDownloadClicked={onDownloadClick}
184
- />
185
- }
186
- />
187
- </LockedCardShell>
188
- )
189
- }
190
-
191
- export default ReceivedCard
@@ -1,2 +0,0 @@
1
- export { default as ReceivedCard } from './Card'
2
- export type { ReceivedCardProps } from './Card'
@@ -1,177 +0,0 @@
1
- import { CheckCircleIcon, ImagesIcon } from '@phosphor-icons/react'
2
- import React, { useCallback, useRef, useState } from 'react'
3
-
4
- import type {
5
- LockedAttachmentBaseProps,
6
- LockedAttachmentSource,
7
- } from '../../types'
8
- import CardBody from '../_shared/CardBody'
9
- import GalleryThumbnail from '../_shared/GalleryThumbnail'
10
- import LockedCardShell from '../_shared/LockedCardShell'
11
- import LockedThumbnail from '../_shared/LockedThumbnail'
12
-
13
- export interface SentCardProps extends LockedAttachmentBaseProps {
14
- /** Placeholder shown in the title slot when no title is set. */
15
- placeholderTitle?: string
16
- /** Fired the first time the sender taps the thumbnail to preview their own attachment. */
17
- onPreviewClick?: () => void
18
- /**
19
- * Lazily loads the underlying source so the sender can preview the attachment.
20
- * Called the first time the thumbnail is tapped; the returned source is cached
21
- * and reused on subsequent toggles.
22
- */
23
- onFetchSource?: () => Promise<LockedAttachmentSource | void>
24
- }
25
-
26
- /**
27
- * The card the sender sees in chat after a paid attachment has been posted.
28
- * Matches the Sent column of the messaging design system in Figma.
29
- */
30
- const SentCard: React.FC<SentCardProps> = ({
31
- title,
32
- mimeType = 'application/octet-stream',
33
- thumbnailUrl,
34
- detail,
35
- amountText,
36
- placeholderTitle = 'Attachment title',
37
- paymentStatus,
38
- gallery,
39
- onPreviewClick,
40
- onFetchSource,
41
- }) => {
42
- const [source, setSource] = useState<LockedAttachmentSource | undefined>()
43
- const [isPreviewVisible, setIsPreviewVisible] = useState(false)
44
- const [isLoadingPreview, setIsLoadingPreview] = useState(false)
45
- const fetchingRef = useRef(false)
46
-
47
- const isGallery = (gallery?.length ?? 0) >= 2
48
-
49
- const handleToggle = useCallback(async () => {
50
- onPreviewClick?.()
51
- if (isPreviewVisible) {
52
- setIsPreviewVisible(false)
53
- return
54
- }
55
- // Gallery items carry their own per-item sources on the `gallery` prop, so
56
- // we just flip visibility — no async source fetch is needed.
57
- if (isGallery) {
58
- setIsPreviewVisible(true)
59
- return
60
- }
61
- if (source) {
62
- setIsPreviewVisible(true)
63
- return
64
- }
65
- if (!onFetchSource) return
66
- if (fetchingRef.current) return
67
- fetchingRef.current = true
68
- setIsLoadingPreview(true)
69
- try {
70
- const result = await onFetchSource()
71
- if (result) {
72
- setSource(result)
73
- setIsPreviewVisible(true)
74
- }
75
- } finally {
76
- fetchingRef.current = false
77
- setIsLoadingPreview(false)
78
- }
79
- }, [isPreviewVisible, isGallery, source, onPreviewClick, onFetchSource])
80
-
81
- // Gallery is always previewable for the sender because each item's source
82
- // is already provided up-front via `gallery[*].sourceUrl`.
83
- const togglePreview =
84
- isGallery || onFetchSource || onPreviewClick ? handleToggle : undefined
85
- const showLocked = !isPreviewVisible
86
- const isBusy = isLoadingPreview
87
-
88
- const statusBadge =
89
- paymentStatus === 'paid' ? (
90
- <React.Fragment>
91
- <span className="text-xs font-medium text-white/55">&bull;</span>
92
- <span className="text-xs font-medium text-[#34c759]">Sold</span>
93
- <CheckCircleIcon className="size-4 text-[#34c759]" weight="bold" />
94
- </React.Fragment>
95
- ) : amountText ? (
96
- <React.Fragment>
97
- <span className="text-xs font-medium text-white/55">&bull;</span>
98
- <span className="text-xs font-medium text-white/55">{amountText}</span>
99
- </React.Fragment>
100
- ) : null
101
-
102
- const thumbnail = isGallery ? (
103
- <GalleryThumbnail
104
- variant="dark"
105
- gallery={gallery!}
106
- title={title}
107
- showLocked={showLocked}
108
- paymentStatus={paymentStatus}
109
- />
110
- ) : (
111
- <LockedThumbnail
112
- variant="dark"
113
- mimeType={mimeType}
114
- thumbnailUrl={thumbnailUrl}
115
- title={title}
116
- source={source}
117
- showLocked={showLocked}
118
- paymentStatus={paymentStatus}
119
- />
120
- )
121
-
122
- return (
123
- <LockedCardShell variant="dark">
124
- {togglePreview ? (
125
- // Uses a `<div role="button">` rather than a native `<button>` so the
126
- // gallery's carousel arrow `<button>`s rendered inside `thumbnail`
127
- // don't produce invalid nested interactive elements.
128
- <div
129
- role="button"
130
- tabIndex={isBusy ? -1 : 0}
131
- aria-label="Toggle preview"
132
- aria-busy={isBusy}
133
- aria-pressed={!showLocked}
134
- aria-disabled={isBusy || undefined}
135
- onClick={isBusy ? undefined : togglePreview}
136
- onKeyDown={(e) => {
137
- if (isBusy) return
138
- // Only handle keys that originate on the wrapper itself, not on
139
- // inner interactive elements (gallery carousel arrows). Without
140
- // this guard, pressing Enter/Space on a focused child would bubble
141
- // up and toggle the preview in addition to activating the child.
142
- if (e.target !== e.currentTarget) return
143
- if (e.key === 'Enter' || e.key === ' ') {
144
- e.preventDefault()
145
- void togglePreview()
146
- }
147
- }}
148
- className={
149
- !isBusy
150
- ? 'block w-full cursor-pointer text-left'
151
- : 'block w-full text-left'
152
- }
153
- >
154
- {thumbnail}
155
- </div>
156
- ) : (
157
- thumbnail
158
- )}
159
-
160
- <CardBody
161
- variant="dark"
162
- title={title}
163
- placeholderTitle={placeholderTitle}
164
- mimeType={mimeType}
165
- detail={detail}
166
- statusBadge={statusBadge}
167
- icon={
168
- isGallery ? (
169
- <ImagesIcon className="size-5 shrink-0 text-white/55" />
170
- ) : undefined
171
- }
172
- />
173
- </LockedCardShell>
174
- )
175
- }
176
-
177
- export default SentCard
@@ -1,2 +0,0 @@
1
- export { default as SentCard } from './Card'
2
- export type { SentCardProps } from './Card'