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

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-D8yiJ8Uw.cjs +2 -0
  2. package/dist/Card-D8yiJ8Uw.cjs.map +1 -0
  3. package/dist/Card-DSG-wR8t.js +96 -0
  4. package/dist/Card-DSG-wR8t.js.map +1 -0
  5. package/dist/Card-DVfSiq9b.cjs +2 -0
  6. package/dist/Card-DVfSiq9b.cjs.map +1 -0
  7. package/dist/Card-DX9nBx1S.js +221 -0
  8. package/dist/Card-DX9nBx1S.js.map +1 -0
  9. package/dist/Card-iKTcn1wg.cjs +2 -0
  10. package/dist/Card-iKTcn1wg.cjs.map +1 -0
  11. package/dist/Card-qDLtjK6u.js +108 -0
  12. package/dist/Card-qDLtjK6u.js.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-CZTUyiPe.js} +1154 -1113
  23. package/dist/index-CZTUyiPe.js.map +1 -0
  24. package/dist/index-DwUOvMxg.cjs +2 -0
  25. package/dist/index-DwUOvMxg.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-BG-pfsgP.js +323 -0
  31. package/dist/usePreviewToggle-BG-pfsgP.js.map +1 -0
  32. package/dist/usePreviewToggle-DXQT07ws.cjs +2 -0
  33. package/dist/usePreviewToggle-DXQT07ws.cjs.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
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-DRurVQ0-.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.resolveConversationParticipant=e.resolveConversationParticipant;exports.resolveLinkAttachment=e.resolveLinkAttachment;exports.resolveMediaFromMessage=e.resolveMediaFromMessage;exports.resolveParticipantDisplayName=e.resolveParticipantDisplayName;exports.useComposerLocked=e.useComposerLocked;exports.useCustomMessage=e.useCustomMessage;exports.useMessageVote=e.useMessageVote;exports.useMessaging=e.useMessaging;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-DwUOvMxg.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.resolveConversationParticipant=e.resolveConversationParticipant;exports.resolveLinkAttachment=e.resolveLinkAttachment;exports.resolveMediaFromMessage=e.resolveMediaFromMessage;exports.resolveParticipantDisplayName=e.resolveParticipantDisplayName;exports.useComposerLocked=e.useComposerLocked;exports.useCustomMessage=e.useCustomMessage;exports.useMessageVote=e.useMessageVote;exports.useMessaging=e.useMessaging;
2
2
  //# sourceMappingURL=index.cjs.map
package/dist/index.d.ts CHANGED
@@ -405,13 +405,18 @@ export declare interface ChannelViewProps {
405
405
  }
406
406
 
407
407
  export declare interface ComposerCardProps extends LockedAttachmentBaseProps {
408
- /** Placeholder shown in the title slot before the composer types one. */
409
- placeholderTitle?: string;
408
+ /**
409
+ * The message's own text, shown as-is (not redacted yet — the message
410
+ * hasn't been sent). Only used when `contentType` is `"text"`.
411
+ */
412
+ text?: string;
410
413
  /** Placeholder shown in the amount slot before one is configured. */
411
414
  placeholderAmountText?: string;
412
415
  /**
413
- * When provided, renders a dismiss X in the thumbnail corner. Called when
414
- * the composer clicks it to remove the attachment.
416
+ * Renders a persistent dismiss X on the thumbnail (media) or next to the
417
+ * text (text mode); called to remove the draft attachment. Unrelated to
418
+ * `TextCardProps.onDismiss`, which only appears for `isMine` after a
419
+ * failed payment.
415
420
  */
416
421
  onDismiss?: () => void;
417
422
  /** Fired the first time the composer taps the thumbnail to preview. */
@@ -420,8 +425,9 @@ export declare interface ComposerCardProps extends LockedAttachmentBaseProps {
420
425
  * Lazily loads the underlying source so the composer can preview the
421
426
  * attachment they're about to send. Called the first time the thumbnail is
422
427
  * tapped; the returned source is cached and reused on subsequent toggles.
428
+ * Ignored when `contentType` is `"text"`.
423
429
  */
424
- onFetchSource?: () => Promise<LockedAttachmentSource | void>;
430
+ onFetchSource?: FetchSourceHandler;
425
431
  /**
426
432
  * When provided, renders a pencil button in the body bottom-right that the
427
433
  * composer can use to edit the attachment metadata (e.g. open the price /
@@ -436,12 +442,6 @@ declare interface ComposerExtras {
436
442
  onDismiss?: () => void;
437
443
  }
438
444
 
439
- /**
440
- * @deprecated Renamed to `SentCardProps`. Drafting usages (with `onDismiss`)
441
- * should migrate to `ComposerCardProps`.
442
- */
443
- export declare type CreatorCardProps = SentCardProps;
444
-
445
445
  export declare const CustomMessageProvider: Provider<Partial<CustomMessageRegistry>>;
446
446
 
447
447
  export declare interface CustomMessageRegistry {
@@ -479,6 +479,13 @@ export declare interface FaqListProps {
479
479
  avatarName?: string;
480
480
  }
481
481
 
482
+ /**
483
+ * Lazily fetches the underlying source (URL/thumbnail) for a locked
484
+ * attachment. Returns `void` to signal "no source available" — the card
485
+ * stays locked. Shared by `ComposerCardProps`/`MediaCardProps.onFetchSource`.
486
+ */
487
+ declare type FetchSourceHandler = () => Promise<LockedAttachmentSource | void>;
488
+
482
489
  declare interface FileAttachmentSharedProps extends MessageAttachmentBaseProps {
483
490
  /** Source URL of the file (used as the download target). */
484
491
  src?: string;
@@ -730,33 +737,45 @@ export declare interface LinkAttachmentSentCardProps extends LinkAttachmentBaseP
730
737
 
731
738
  export declare const LockedAttachment: {
732
739
  Composer: (props: ComposerCardProps) => JSX_2.Element;
733
- Sent: (props: SentCardProps) => JSX_2.Element;
734
- Received: (props: ReceivedCardProps) => JSX_2.Element;
735
- Creator: (props: SentCardProps) => JSX_2.Element;
736
- Visitor: (props: ReceivedCardProps) => JSX_2.Element;
740
+ Text: (props: LockedAttachmentTextCardProps) => JSX_2.Element;
741
+ Media: (props: LockedAttachmentMediaCardProps) => JSX_2.Element;
737
742
  };
738
743
 
739
744
  declare interface LockedAttachmentBaseProps {
740
745
  title?: string;
746
+ /** Dimmed fallback shown in the title slot when `title` is unset (no attachment metadata yet — still drafting). */
747
+ placeholderTitle?: string;
741
748
  mimeType?: string;
742
749
  thumbnailUrl?: string;
743
750
  detail?: string;
744
751
  amountText?: string;
745
- paymentStatus?: PaymentStatus;
746
752
  /**
747
753
  * When provided with 2+ items, the card renders as a mixed-media carousel
748
754
  * (e.g. a couple of photos + a video) instead of a single thumbnail. Each
749
755
  * item brings its own thumbnail and optional source so that
750
- * `LockedAttachment.Composer` / `.Sent` / `.Received` can all share the
751
- * same carousel chrome.
756
+ * `LockedAttachment.Composer` / `.Media` can share the same carousel
757
+ * chrome.
752
758
  */
753
759
  gallery?: LockedAttachmentGalleryItem[];
760
+ /**
761
+ * "text" renders the card as a locked/plain chat bubble showing the
762
+ * message's own text (skeleton-blurred until purchased) instead of a media
763
+ * thumbnail card — for a paid text-only message. Media-only props
764
+ * (`mimeType`, `thumbnailUrl`, `title`, `detail`, `gallery`) are ignored in
765
+ * this mode. Defaults to `"media"`.
766
+ */
767
+ contentType?: 'text' | 'media';
754
768
  }
755
769
 
756
770
  export declare interface LockedAttachmentContextValue {
757
771
  isUnlocking: (id: string) => boolean;
758
772
  onUnlockClick?: (message: LocalMessage, channel: Channel) => void;
759
773
  onDownloadClick?: (message: LocalMessage, channel: Channel) => void;
774
+ /**
775
+ * Reveal the locked media's underlying source (URL/thumbnail). Not used
776
+ * for a paid text message — the backend writes the real text directly onto
777
+ * the message on purchase and `message.text` alone drives that reveal.
778
+ */
760
779
  onFetchSource?: (message: LocalMessage, channel: Channel) => Promise<LockedAttachmentSource | void>;
761
780
  }
762
781
 
@@ -769,6 +788,31 @@ export declare interface LockedAttachmentGalleryItem {
769
788
  sourceUrl?: string;
770
789
  }
771
790
 
791
+ export declare type LockedAttachmentMediaCardProps = (MediaCardSharedProps & {
792
+ isMine: true;
793
+ /** Dimmed fallback shown in the title slot when `title` is unset. */
794
+ placeholderTitle?: string;
795
+ /** Fired the first time the sender taps the thumbnail to preview their own attachment. */
796
+ onPreviewClick?: () => void;
797
+ }) | (MediaCardSharedProps & {
798
+ isMine: false;
799
+ /**
800
+ * When true, shows a loading spinner on the Unlock button. Driven by
801
+ * the LockedAttachmentContext (e.g. checkout in progress).
802
+ */
803
+ isUnlocking?: boolean;
804
+ /**
805
+ * Called when the recipient clicks Unlock on an unpaid attachment.
806
+ * Use this to open a checkout flow. Omit to hide the Unlock button.
807
+ */
808
+ onUnlockClick?: () => void;
809
+ /**
810
+ * Called when the recipient clicks Download on an unlocked card.
811
+ * Omit to hide the Download button.
812
+ */
813
+ onDownloadClick?: () => void;
814
+ });
815
+
772
816
  export declare interface LockedAttachmentSource {
773
817
  /** Proxied URL used by the media player for in-app playback. */
774
818
  sourceUrl: string;
@@ -778,6 +822,33 @@ export declare interface LockedAttachmentSource {
778
822
  thumbnailUrl?: string;
779
823
  }
780
824
 
825
+ export declare type LockedAttachmentTextCardProps = (TextCardSharedProps & {
826
+ isMine: true;
827
+ }) | (TextCardSharedProps & {
828
+ isMine: false;
829
+ /**
830
+ * Called when the recipient clicks Unlock on an unpaid attachment.
831
+ * Use this to open a checkout flow. Omit to hide the Unlock button.
832
+ */
833
+ onUnlockClick?: () => void;
834
+ /**
835
+ * When true, shows a loading spinner on the Unlock button. Driven by
836
+ * the LockedAttachmentContext (e.g. checkout in progress).
837
+ */
838
+ isUnlocking?: boolean;
839
+ });
840
+
841
+ declare interface MediaCardSharedProps {
842
+ title?: string;
843
+ mimeType?: string;
844
+ thumbnailUrl?: string;
845
+ detail?: string;
846
+ amountText?: string;
847
+ paymentStatus?: PaymentStatus;
848
+ gallery?: LockedAttachmentGalleryItem[];
849
+ onFetchSource?: FetchSourceHandler;
850
+ }
851
+
781
852
  export declare const MediaMessage: default_2.FC<MediaMessageProps> & {
782
853
  Creator: default_2.FC<{
783
854
  message: LocalMessage;
@@ -1184,6 +1255,7 @@ export declare interface MessageMetadata {
1184
1255
  amount_text?: string;
1185
1256
  payment_status?: PaymentStatus;
1186
1257
  attachment_title?: string;
1258
+ attachment_content_type?: 'text' | 'media';
1187
1259
  attachment_mime_type?: string;
1188
1260
  attachment_thumbnail?: string;
1189
1261
  attachment_detail?: string;
@@ -1396,31 +1468,6 @@ declare interface PdfAttachmentSharedProps extends MessageAttachmentBaseProps {
1396
1468
  onClick?: (index: number) => boolean | void;
1397
1469
  }
1398
1470
 
1399
- export declare interface ReceivedCardProps extends LockedAttachmentBaseProps {
1400
- /**
1401
- * Called when the recipient clicks Unlock on an unpaid attachment.
1402
- * Use this to open a checkout flow. Omit to hide the Unlock button.
1403
- */
1404
- onUnlockClick?: () => void;
1405
- /**
1406
- * Called to fetch the attachment source — fired automatically when
1407
- * `paymentStatus` transitions to `'paid'`, or immediately on click when
1408
- * `paymentStatus` is already `'paid'`. Return a `LockedAttachmentSource`
1409
- * to unlock the card.
1410
- */
1411
- onFetchSource?: () => Promise<LockedAttachmentSource | void>;
1412
- /**
1413
- * Called when the recipient clicks Download on an unlocked card.
1414
- * Omit to hide the Download button.
1415
- */
1416
- onDownloadClick?: () => void;
1417
- /**
1418
- * When true, shows a loading spinner on the Unlock button.
1419
- * Driven by the LockedAttachmentContext (e.g. checkout in progress).
1420
- */
1421
- isUnlocking?: boolean;
1422
- }
1423
-
1424
1471
  /**
1425
1472
  * Resolves the member to display as the conversation's "other party".
1426
1473
  *
@@ -1443,17 +1490,16 @@ export declare function resolveMediaFromMessage(message: LocalMessage): MediaMes
1443
1490
  */
1444
1491
  export declare function resolveParticipantDisplayName(user?: ParticipantDisplayUser | null): string;
1445
1492
 
1446
- export declare interface SentCardProps extends LockedAttachmentBaseProps {
1447
- /** Placeholder shown in the title slot when no title is set. */
1448
- placeholderTitle?: string;
1449
- /** Fired the first time the sender taps the thumbnail to preview their own attachment. */
1450
- onPreviewClick?: () => void;
1493
+ declare interface TextCardSharedProps {
1494
+ amountText?: string;
1495
+ paymentStatus?: PaymentStatus;
1451
1496
  /**
1452
- * Lazily loads the underlying source so the sender can preview the attachment.
1453
- * Called the first time the thumbnail is tapped; the returned source is cached
1454
- * and reused on subsequent toggles.
1497
+ * The message's real, revealed content shown instead of the skeleton
1498
+ * loader once `paymentStatus` is `'paid'`. Ignored otherwise. Lets the
1499
+ * caller supply its own text renderer (e.g. Stream's `MessageText`)
1500
+ * without `LockedAttachment` depending on it.
1455
1501
  */
1456
- onFetchSource?: () => Promise<LockedAttachmentSource | void>;
1502
+ children?: default_2.ReactNode;
1457
1503
  }
1458
1504
 
1459
1505
  /**
@@ -1524,9 +1570,6 @@ declare interface VideoAttachmentSharedProps extends MessageAttachmentBaseProps
1524
1570
  onClick?: (index: number) => boolean | void;
1525
1571
  }
1526
1572
 
1527
- /** @deprecated Renamed to `ReceivedCardProps`. */
1528
- export declare type VisitorCardProps = ReceivedCardProps;
1529
-
1530
1573
  export declare type VoteSelection = 'up' | 'down' | null;
1531
1574
 
1532
1575
  export { }
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as e, b as t, C as i, c as o, d as n, e as m, F as r, f as g, L as l, h as M, M as c, i as u, j as L, k as h, l as d, m as p, n as v, o as C, p as A, q as k, s as F, t as P, u as b, v as f, w as x, x as y, y as S, z as q, B as z, D as B, E as D, G as E } from "./index-BCgRoF_u.js";
1
+ import { a as e, b as t, C as i, c as o, d as n, e as m, F as r, f as g, L as l, h as M, M as c, i as u, j as L, k as h, l as d, m as p, n as v, o as C, p as A, q as k, s as F, t as P, u as b, v as f, w as x, x as y, y as S, z as q, B as z, D as B, E as D, G as E } from "./index-CZTUyiPe.js";
2
2
  export {
3
3
  e as ActionButton,
4
4
  t as Avatar,
package/dist/testing.d.ts CHANGED
@@ -47,6 +47,7 @@ export declare interface MessageMetadata {
47
47
  amount_text?: string;
48
48
  payment_status?: PaymentStatus;
49
49
  attachment_title?: string;
50
+ attachment_content_type?: 'text' | 'media';
50
51
  attachment_mime_type?: string;
51
52
  attachment_thumbnail?: string;
52
53
  attachment_detail?: string;
@@ -0,0 +1,323 @@
1
+ import { jsxs as b, jsx as a } from "react/jsx-runtime";
2
+ import f from "classnames";
3
+ import { r as w, g as y, A as k } from "./index-CZTUyiPe.js";
4
+ import I, { useState as g, useRef as T, useCallback as U } from "react";
5
+ import { PlayIcon as _, LockOpenIcon as j, LockSimpleIcon as D, CaretLeftIcon as M, CaretRightIcon as C, ImagesIcon as S } from "@phosphor-icons/react";
6
+ const J = ({
7
+ variant: t,
8
+ title: e,
9
+ placeholderTitle: r = "Attachment title",
10
+ mimeType: i,
11
+ detail: l,
12
+ statusBadge: o,
13
+ action: d,
14
+ icon: u,
15
+ trailingAction: c
16
+ }) => {
17
+ const s = t === "dark", n = s ? e ?? r : e ?? "", m = s && !e, h = u ?? w(i, {
18
+ className: f(
19
+ "size-5 shrink-0",
20
+ s ? "text-white/55" : "text-black/55"
21
+ ),
22
+ weight: "regular"
23
+ });
24
+ return /* @__PURE__ */ b("div", { className: "px-4 py-3", children: [
25
+ /* @__PURE__ */ b("div", { className: "flex items-end gap-3", children: [
26
+ /* @__PURE__ */ b("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
27
+ n.trim() !== "" && /* @__PURE__ */ a(
28
+ "p",
29
+ {
30
+ className: f("truncate text-base font-medium leading-6", {
31
+ "text-black/90": !s,
32
+ "text-white/30": s && m,
33
+ "text-white": s && !m
34
+ }),
35
+ children: n
36
+ }
37
+ ),
38
+ /* @__PURE__ */ b("div", { className: "flex flex-wrap items-center gap-1", children: [
39
+ h,
40
+ l != null && l !== "" && /* @__PURE__ */ a(
41
+ "span",
42
+ {
43
+ className: f(
44
+ "text-xs font-medium",
45
+ s ? "text-white/55" : "text-black/55"
46
+ ),
47
+ children: l
48
+ }
49
+ ),
50
+ o
51
+ ] })
52
+ ] }),
53
+ c && /* @__PURE__ */ a("div", { className: "shrink-0", children: c })
54
+ ] }),
55
+ d
56
+ ] });
57
+ }, P = ({
58
+ paymentStatus: t,
59
+ mimeType: e,
60
+ isPlayable: r
61
+ }) => {
62
+ const i = e ? y(e) : void 0;
63
+ return /* @__PURE__ */ a("div", { className: "pointer-events-none absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ a("div", { className: "flex size-12 items-center justify-center rounded-full bg-black/25 text-white", children: /* @__PURE__ */ a(r ?? (i === "video" || i === "audio") ? _ : t === "paid" ? j : D, { className: "size-6", weight: "fill" }) }) });
64
+ };
65
+ function V(t) {
66
+ const e = y(t.mimeType);
67
+ return e === "video" || e === "audio";
68
+ }
69
+ const A = ({
70
+ variant: t,
71
+ gallery: e,
72
+ title: r,
73
+ showLocked: i,
74
+ paymentStatus: l,
75
+ topRight: o
76
+ }) => {
77
+ const [d, u] = g(0), c = e.length, s = Math.min(d, c - 1), n = e[s], m = V(n), h = (p) => {
78
+ p.stopPropagation(), u((x) => Math.max(0, x - 1));
79
+ }, z = (p) => {
80
+ p.stopPropagation(), u((x) => Math.min(c - 1, x + 1));
81
+ }, v = s === 0, N = s === c - 1;
82
+ return /* @__PURE__ */ b("div", { className: "relative aspect-[337/386] overflow-hidden rounded-t-md", children: [
83
+ i ? /* @__PURE__ */ a(
84
+ "div",
85
+ {
86
+ className: f(
87
+ "absolute inset-0",
88
+ t === "dark" ? "bg-white/10" : "bg-black/5"
89
+ ),
90
+ children: n.thumbnailUrl && /* @__PURE__ */ a(
91
+ "img",
92
+ {
93
+ src: n.thumbnailUrl,
94
+ alt: "",
95
+ "aria-hidden": !0,
96
+ draggable: !1,
97
+ className: "absolute inset-0 h-full w-full scale-110 object-cover blur-[40px]"
98
+ }
99
+ )
100
+ }
101
+ ) : /* @__PURE__ */ a(
102
+ k,
103
+ {
104
+ mimeType: n.mimeType,
105
+ sourceUrl: n.sourceUrl,
106
+ thumbnailUrl: n.thumbnailUrl,
107
+ title: r,
108
+ variant: t
109
+ }
110
+ ),
111
+ (m || i) && /* @__PURE__ */ a(P, { paymentStatus: l, isPlayable: m }),
112
+ c > 1 && /* @__PURE__ */ b(I.Fragment, { children: [
113
+ /* @__PURE__ */ a(
114
+ "button",
115
+ {
116
+ type: "button",
117
+ onClick: h,
118
+ disabled: v,
119
+ "aria-label": "Previous item",
120
+ className: f(
121
+ "absolute left-3 top-1/2 -translate-y-1/2 flex size-7 items-center justify-center rounded-full bg-black/30 text-white transition-opacity",
122
+ v ? "opacity-40" : "hover:bg-black/40"
123
+ ),
124
+ children: /* @__PURE__ */ a(M, { className: "size-5", weight: "bold" })
125
+ }
126
+ ),
127
+ /* @__PURE__ */ a(
128
+ "button",
129
+ {
130
+ type: "button",
131
+ onClick: z,
132
+ disabled: N,
133
+ "aria-label": "Next item",
134
+ className: f(
135
+ "absolute right-3 top-1/2 -translate-y-1/2 flex size-7 items-center justify-center rounded-full bg-black/30 text-white transition-opacity",
136
+ N ? "opacity-40" : "hover:bg-black/40"
137
+ ),
138
+ children: /* @__PURE__ */ a(C, { className: "size-5", weight: "bold" })
139
+ }
140
+ ),
141
+ /* @__PURE__ */ a("div", { className: "pointer-events-none absolute bottom-5 left-1/2 -translate-x-1/2 rounded-lg bg-black/30 px-2 py-1", children: /* @__PURE__ */ b("span", { className: "text-xs font-medium leading-4 text-white", children: [
142
+ s + 1,
143
+ "/",
144
+ c
145
+ ] }) })
146
+ ] }),
147
+ o && /* @__PURE__ */ a("div", { className: "pointer-events-auto absolute right-3 top-3 z-10", children: o })
148
+ ] });
149
+ }, E = ({
150
+ variant: t,
151
+ mimeType: e,
152
+ thumbnailUrl: r,
153
+ title: i,
154
+ source: l,
155
+ showLocked: o,
156
+ paymentStatus: d,
157
+ topRight: u,
158
+ containedImage: c = !1
159
+ }) => {
160
+ const s = o || l == null ? void 0 : l.sourceUrl, n = o ? r : (l == null ? void 0 : l.thumbnailUrl) ?? r, m = t === "dark";
161
+ return /* @__PURE__ */ b("div", { className: "relative overflow-hidden rounded-t-md", children: [
162
+ o ? /* @__PURE__ */ b(
163
+ "div",
164
+ {
165
+ className: f(
166
+ "relative aspect-video overflow-hidden",
167
+ m ? "bg-white/10" : "bg-black/5"
168
+ ),
169
+ children: [
170
+ n ? /* @__PURE__ */ a(
171
+ "img",
172
+ {
173
+ src: n,
174
+ alt: "",
175
+ "aria-hidden": !0,
176
+ draggable: !1,
177
+ className: "absolute inset-0 h-full w-full scale-110 object-cover blur-[40px]"
178
+ }
179
+ ) : /* @__PURE__ */ a("div", { className: "absolute inset-0 flex items-center justify-center", children: w(e, {
180
+ className: m ? "size-12 text-white/20" : "size-12 text-black/20",
181
+ weight: "regular"
182
+ }) }),
183
+ /* @__PURE__ */ a(P, { paymentStatus: d, mimeType: e })
184
+ ]
185
+ }
186
+ ) : /* @__PURE__ */ a(
187
+ k,
188
+ {
189
+ mimeType: e,
190
+ sourceUrl: s,
191
+ thumbnailUrl: n,
192
+ title: i,
193
+ variant: t,
194
+ containedImage: c,
195
+ mediaPlayerProps: s ? { autoPlay: !0, loop: !0, controls: !0, muted: !1 } : void 0
196
+ }
197
+ ),
198
+ u && /* @__PURE__ */ a("div", { className: "pointer-events-auto absolute right-3 top-3 z-10", children: u })
199
+ ] });
200
+ }, L = (t) => t.length >= 2, Q = (t) => /* @__PURE__ */ a(
201
+ S,
202
+ {
203
+ className: t === "dark" ? "size-5 shrink-0 text-white/55" : "size-5 shrink-0 text-black/55"
204
+ }
205
+ ), W = ({
206
+ variant: t,
207
+ gallery: e,
208
+ title: r,
209
+ showLocked: i,
210
+ paymentStatus: l,
211
+ mimeType: o,
212
+ thumbnailUrl: d,
213
+ source: u,
214
+ containedImage: c,
215
+ topRight: s
216
+ }) => L(e) ? /* @__PURE__ */ a(
217
+ A,
218
+ {
219
+ variant: t,
220
+ gallery: e,
221
+ title: r,
222
+ showLocked: i,
223
+ paymentStatus: l,
224
+ topRight: s
225
+ }
226
+ ) : /* @__PURE__ */ a(
227
+ E,
228
+ {
229
+ variant: t,
230
+ mimeType: o,
231
+ thumbnailUrl: d,
232
+ title: r,
233
+ source: u,
234
+ showLocked: i,
235
+ paymentStatus: l,
236
+ topRight: s,
237
+ containedImage: c
238
+ }
239
+ ), X = ({
240
+ variant: t,
241
+ children: e,
242
+ rootRef: r,
243
+ "data-testid": i
244
+ }) => /* @__PURE__ */ a(
245
+ "div",
246
+ {
247
+ ref: r,
248
+ "data-testid": i,
249
+ className: f(
250
+ "relative w-[280px] select-none overflow-hidden rounded-md",
251
+ "shadow-[0_0_0_1px_rgba(0,0,0,0.04),0_1px_2px_rgba(0,0,0,0.04),0_8px_32px_rgba(0,0,0,0.1)]",
252
+ t === "dark" ? "bg-[#1e2330]" : "bg-white"
253
+ ),
254
+ children: e
255
+ }
256
+ ), Y = ({
257
+ onToggle: t,
258
+ isBusy: e,
259
+ isPreviewVisible: r,
260
+ children: i
261
+ }) => t ? /* @__PURE__ */ a(
262
+ "div",
263
+ {
264
+ role: "button",
265
+ tabIndex: e ? -1 : 0,
266
+ "aria-label": "Toggle preview",
267
+ "aria-busy": e,
268
+ "aria-pressed": r,
269
+ "aria-disabled": e || void 0,
270
+ onClick: e ? void 0 : t,
271
+ onKeyDown: (l) => {
272
+ e || l.target === l.currentTarget && (l.key === "Enter" || l.key === " ") && (l.preventDefault(), t());
273
+ },
274
+ className: e ? "block w-full text-left" : "block w-full cursor-pointer text-left",
275
+ children: i
276
+ }
277
+ ) : /* @__PURE__ */ a(I.Fragment, { children: i });
278
+ function Z({
279
+ isGallery: t,
280
+ onFetchSource: e,
281
+ onPreviewClick: r
282
+ }) {
283
+ const [i, l] = g(), [o, d] = g(!1), [u, c] = g(!1), s = T(!1), n = U(async () => {
284
+ if (r == null || r(), o) {
285
+ d(!1);
286
+ return;
287
+ }
288
+ if (t) {
289
+ d(!0);
290
+ return;
291
+ }
292
+ if (i) {
293
+ d(!0);
294
+ return;
295
+ }
296
+ if (e && !s.current) {
297
+ s.current = !0, c(!0);
298
+ try {
299
+ const h = await e();
300
+ h && (l(h), d(!0));
301
+ } finally {
302
+ s.current = !1, c(!1);
303
+ }
304
+ }
305
+ }, [o, t, i, r, e]), m = t || e != null || r != null ? n : void 0;
306
+ return {
307
+ source: i,
308
+ isPreviewVisible: o,
309
+ isLoadingPreview: u,
310
+ handleToggle: n,
311
+ togglePreview: m
312
+ };
313
+ }
314
+ export {
315
+ W as C,
316
+ X as M,
317
+ Y as P,
318
+ J as a,
319
+ Q as g,
320
+ L as i,
321
+ Z as u
322
+ };
323
+ //# sourceMappingURL=usePreviewToggle-BG-pfsgP.js.map