@tribe-nest/forge 1.13.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.
Files changed (255) hide show
  1. package/package.json +42 -0
  2. package/src/client/createForgeClient.ts +54 -0
  3. package/src/content/ForgeContentProvider.tsx +118 -0
  4. package/src/content/ForgeEditBridge.tsx +134 -0
  5. package/src/content/editFlag.ts +23 -0
  6. package/src/content/index.ts +28 -0
  7. package/src/content/resolve.ts +67 -0
  8. package/src/content/types.ts +97 -0
  9. package/src/content/useField.ts +64 -0
  10. package/src/contexts/AppAuthContext.tsx +185 -0
  11. package/src/contexts/AudioPlayerContext.tsx +389 -0
  12. package/src/contexts/CartContext.tsx +131 -0
  13. package/src/contexts/PublicAuthContext.tsx +333 -0
  14. package/src/contexts/useAppAdminGuard.ts +56 -0
  15. package/src/css.d.ts +5 -0
  16. package/src/data/collectionParams.ts +57 -0
  17. package/src/data/queries/useAccount.ts +71 -0
  18. package/src/data/queries/useAccountSettings.ts +82 -0
  19. package/src/data/queries/useAnalytics.ts +86 -0
  20. package/src/data/queries/useAuthActions.ts +28 -0
  21. package/src/data/queries/useBlog.ts +103 -0
  22. package/src/data/queries/useBlogComments.ts +96 -0
  23. package/src/data/queries/useBroadcasts.ts +31 -0
  24. package/src/data/queries/useCertificates.ts +58 -0
  25. package/src/data/queries/useChat.ts +267 -0
  26. package/src/data/queries/useCoachingAvailability.ts +69 -0
  27. package/src/data/queries/useCoachingProducts.ts +67 -0
  28. package/src/data/queries/useCohortPage.ts +17 -0
  29. package/src/data/queries/useCollections.ts +211 -0
  30. package/src/data/queries/useCommunity.ts +794 -0
  31. package/src/data/queries/useCoupons.ts +20 -0
  32. package/src/data/queries/useCourseAccess.ts +50 -0
  33. package/src/data/queries/useCourses.ts +91 -0
  34. package/src/data/queries/useCurrencies.ts +33 -0
  35. package/src/data/queries/useDocuments.ts +208 -0
  36. package/src/data/queries/useDonations.ts +29 -0
  37. package/src/data/queries/useEngagement.ts +115 -0
  38. package/src/data/queries/useEvents.ts +69 -0
  39. package/src/data/queries/useFinalize.ts +109 -0
  40. package/src/data/queries/useForms.ts +31 -0
  41. package/src/data/queries/useInvoice.ts +65 -0
  42. package/src/data/queries/useLeadMagnet.ts +96 -0
  43. package/src/data/queries/useMembership.ts +20 -0
  44. package/src/data/queries/useNotifications.ts +267 -0
  45. package/src/data/queries/useOffers.ts +56 -0
  46. package/src/data/queries/useOrders.ts +71 -0
  47. package/src/data/queries/usePWA.ts +101 -0
  48. package/src/data/queries/usePageActions.ts +36 -0
  49. package/src/data/queries/usePaymentFlow.ts +80 -0
  50. package/src/data/queries/usePaymentLink.ts +47 -0
  51. package/src/data/queries/usePodcast.ts +85 -0
  52. package/src/data/queries/usePostCollections.ts +48 -0
  53. package/src/data/queries/usePosts.ts +94 -0
  54. package/src/data/queries/useProducts.ts +108 -0
  55. package/src/data/queries/useReplay.ts +19 -0
  56. package/src/data/queries/useReviews.ts +122 -0
  57. package/src/data/queries/useShipping.ts +109 -0
  58. package/src/data/queries/useSubscriptions.ts +66 -0
  59. package/src/data/queries/useWebsite.ts +128 -0
  60. package/src/data/queries/useWebsiteAgent.ts +100 -0
  61. package/src/index.ts +98 -0
  62. package/src/provider/ForgeAppProvider.tsx +149 -0
  63. package/src/provider/ForgeProvider.tsx +91 -0
  64. package/src/provider/SiteConfigProvider.tsx +27 -0
  65. package/src/server/_tests/buildPwaHead.spec.ts +182 -0
  66. package/src/server/_tests/buildWebManifest.spec.ts +313 -0
  67. package/src/server/_tests/forgeServiceWorkerScript.spec.ts +251 -0
  68. package/src/server/index.ts +260 -0
  69. package/src/server/jobs.ts +104 -0
  70. package/src/server/pwa.ts +332 -0
  71. package/src/types/index.ts +74 -0
  72. package/src/types/models.ts +1313 -0
  73. package/src/ui/analytics/ForgeAnalytics.tsx +208 -0
  74. package/src/ui/analytics/PageMetaPixel.tsx +92 -0
  75. package/src/ui/content/Editable.tsx +90 -0
  76. package/src/ui/format/PriceDisplay.tsx +142 -0
  77. package/src/ui/format/useFormatCurrency.ts +92 -0
  78. package/src/ui/headless/agent/useAiAgent.ts +106 -0
  79. package/src/ui/headless/auth/useLoginFlow.ts +72 -0
  80. package/src/ui/headless/auth/useSignupForm.ts +85 -0
  81. package/src/ui/headless/broadcast/useBroadcastWatch.ts +59 -0
  82. package/src/ui/headless/chat/attachmentKind.ts +27 -0
  83. package/src/ui/headless/chat/useChatAttachmentUpload.ts +132 -0
  84. package/src/ui/headless/chat/useChatRoom.ts +223 -0
  85. package/src/ui/headless/chat/useMessageThread.ts +60 -0
  86. package/src/ui/headless/checkout/useCheckout.ts +438 -0
  87. package/src/ui/headless/coaching/useCoachingBooking.ts +223 -0
  88. package/src/ui/headless/community/index.ts +20 -0
  89. package/src/ui/headless/community/lexical.ts +131 -0
  90. package/src/ui/headless/community/replyTree.ts +51 -0
  91. package/src/ui/headless/community/richLexical.ts +314 -0
  92. package/src/ui/headless/community/useCommunityAttachmentUpload.ts +137 -0
  93. package/src/ui/headless/community/useCommunitySpaceFeed.ts +122 -0
  94. package/src/ui/headless/community/useCommunityThread.ts +95 -0
  95. package/src/ui/headless/community/useMentionComposer.ts +105 -0
  96. package/src/ui/headless/community/useRichMentionComposer.ts +193 -0
  97. package/src/ui/headless/consent/useCookieConsent.ts +81 -0
  98. package/src/ui/headless/course/useCourseCheckout.ts +99 -0
  99. package/src/ui/headless/dialog.tsx +14 -0
  100. package/src/ui/headless/document/index.ts +7 -0
  101. package/src/ui/headless/document/useContractSignature.ts +68 -0
  102. package/src/ui/headless/document/useDocumentSigningFlow.ts +92 -0
  103. package/src/ui/headless/document/useOtpCodeInput.ts +86 -0
  104. package/src/ui/headless/document/useSignaturePad.ts +180 -0
  105. package/src/ui/headless/donation/Donation.tsx +115 -0
  106. package/src/ui/headless/donation/DonationContext.tsx +223 -0
  107. package/src/ui/headless/donation/fees.ts +15 -0
  108. package/src/ui/headless/donation/index.ts +10 -0
  109. package/src/ui/headless/engagement/usePostEngagement.ts +119 -0
  110. package/src/ui/headless/event/useEventCheckout.ts +141 -0
  111. package/src/ui/headless/forms/useContactForm.ts +58 -0
  112. package/src/ui/headless/forms/useEmailListForm.ts +75 -0
  113. package/src/ui/headless/forms/useSectionedForm.ts +256 -0
  114. package/src/ui/headless/index.ts +60 -0
  115. package/src/ui/headless/invoice/useInvoicePayment.ts +48 -0
  116. package/src/ui/headless/memberHome/index.ts +7 -0
  117. package/src/ui/headless/memberHome/useMemberHomeNav.ts +82 -0
  118. package/src/ui/headless/membership/MembershipGate.tsx +39 -0
  119. package/src/ui/headless/membership/useMembershipCheckout.ts +121 -0
  120. package/src/ui/headless/offer/Offer.tsx +88 -0
  121. package/src/ui/headless/offer/OfferContext.tsx +162 -0
  122. package/src/ui/headless/offer/index.ts +8 -0
  123. package/src/ui/headless/paymentLink/usePaymentLinkPayment.ts +46 -0
  124. package/src/ui/headless/podcast/usePodcastPlayer.ts +96 -0
  125. package/src/ui/headless/posts/index.ts +13 -0
  126. package/src/ui/headless/posts/upsell.ts +41 -0
  127. package/src/ui/headless/posts/useMemberPostsFeed.ts +110 -0
  128. package/src/ui/headless/posts/usePostCollectionDetail.ts +56 -0
  129. package/src/ui/headless/posts/usePostCollectionsList.ts +90 -0
  130. package/src/ui/headless/posts/usePostItem.ts +81 -0
  131. package/src/ui/headless/reviews/index.ts +6 -0
  132. package/src/ui/headless/reviews/useHelpfulVote.ts +45 -0
  133. package/src/ui/headless/reviews/useReviewForm.ts +108 -0
  134. package/src/ui/headless/reviews/useReviewsList.ts +79 -0
  135. package/src/ui/headless/work/index.ts +25 -0
  136. package/src/ui/headless/work/useWorkPortal.ts +349 -0
  137. package/src/ui/index.ts +144 -0
  138. package/src/ui/payment/ForgePaymentProvider.tsx +45 -0
  139. package/src/ui/payment/ForgeStripePayment.tsx +171 -0
  140. package/src/ui/shell/TribeNestApp.tsx +121 -0
  141. package/src/ui/shell/shellGating.spec.ts +28 -0
  142. package/src/ui/shell/shellGating.ts +11 -0
  143. package/src/ui/styled/AccountDashboard.tsx +575 -0
  144. package/src/ui/styled/AiAgentWidget.tsx +152 -0
  145. package/src/ui/styled/AudioPlayer.tsx +123 -0
  146. package/src/ui/styled/BlogCategory.tsx +79 -0
  147. package/src/ui/styled/BlogComments.tsx +236 -0
  148. package/src/ui/styled/BlogList.tsx +101 -0
  149. package/src/ui/styled/BlogPost.tsx +160 -0
  150. package/src/ui/styled/BlogPostFooter.tsx +33 -0
  151. package/src/ui/styled/BotProtection.tsx +101 -0
  152. package/src/ui/styled/Button.tsx +88 -0
  153. package/src/ui/styled/Cart.tsx +276 -0
  154. package/src/ui/styled/ChatRoom.tsx +252 -0
  155. package/src/ui/styled/Checkout.tsx +988 -0
  156. package/src/ui/styled/CheckoutConfirmation.tsx +452 -0
  157. package/src/ui/styled/CoachingBooking.tsx +605 -0
  158. package/src/ui/styled/CoachingConfirmation.tsx +151 -0
  159. package/src/ui/styled/CoachingDetail.tsx +99 -0
  160. package/src/ui/styled/CohortPage.tsx +82 -0
  161. package/src/ui/styled/ConfirmSubscription.tsx +134 -0
  162. package/src/ui/styled/Confirmation.tsx +171 -0
  163. package/src/ui/styled/ContactForm.tsx +81 -0
  164. package/src/ui/styled/CookieConsent.tsx +239 -0
  165. package/src/ui/styled/CourseAccess.tsx +169 -0
  166. package/src/ui/styled/CourseCheckout.tsx +425 -0
  167. package/src/ui/styled/CourseConfirmation.tsx +191 -0
  168. package/src/ui/styled/CourseDetail.tsx +140 -0
  169. package/src/ui/styled/CoursesGrid.tsx +85 -0
  170. package/src/ui/styled/CurrencySwitcher.tsx +51 -0
  171. package/src/ui/styled/DonationButton.tsx +247 -0
  172. package/src/ui/styled/DonationPage.tsx +29 -0
  173. package/src/ui/styled/EmailListForm.tsx +88 -0
  174. package/src/ui/styled/EventConfirmation.tsx +228 -0
  175. package/src/ui/styled/EventCountdown.tsx +98 -0
  176. package/src/ui/styled/EventDetail.tsx +141 -0
  177. package/src/ui/styled/EventTickets.tsx +548 -0
  178. package/src/ui/styled/EventsList.tsx +83 -0
  179. package/src/ui/styled/ForgotPasswordForm.tsx +105 -0
  180. package/src/ui/styled/FormRenderer.tsx +249 -0
  181. package/src/ui/styled/InstallBanner.tsx +114 -0
  182. package/src/ui/styled/InvoiceConfirmation.tsx +50 -0
  183. package/src/ui/styled/InvoicePayment.tsx +141 -0
  184. package/src/ui/styled/LeadMagnet.tsx +93 -0
  185. package/src/ui/styled/Loading.tsx +56 -0
  186. package/src/ui/styled/LoginForm.tsx +134 -0
  187. package/src/ui/styled/Markdown.tsx +103 -0
  188. package/src/ui/styled/MembershipCheckout.tsx +197 -0
  189. package/src/ui/styled/MembershipTiers.tsx +115 -0
  190. package/src/ui/styled/OfferButton.tsx +181 -0
  191. package/src/ui/styled/PageActions.tsx +124 -0
  192. package/src/ui/styled/PaymentLinkConfirmation.tsx +50 -0
  193. package/src/ui/styled/PaymentLinkPayment.tsx +85 -0
  194. package/src/ui/styled/Paywall.tsx +54 -0
  195. package/src/ui/styled/PlayButton.tsx +48 -0
  196. package/src/ui/styled/PodcastEpisode.tsx +137 -0
  197. package/src/ui/styled/PodcastList.tsx +58 -0
  198. package/src/ui/styled/PodcastShow.tsx +164 -0
  199. package/src/ui/styled/PostsFeed.tsx +63 -0
  200. package/src/ui/styled/ProductDetail.tsx +616 -0
  201. package/src/ui/styled/ProductGrid.tsx +82 -0
  202. package/src/ui/styled/PushOptIn.tsx +65 -0
  203. package/src/ui/styled/PwaRegistration.tsx +58 -0
  204. package/src/ui/styled/ReactionBar.tsx +93 -0
  205. package/src/ui/styled/ReplayList.tsx +134 -0
  206. package/src/ui/styled/ResetPasswordForm.tsx +127 -0
  207. package/src/ui/styled/ReviewForm.tsx +292 -0
  208. package/src/ui/styled/ReviewsSection.tsx +260 -0
  209. package/src/ui/styled/SectionedFormRenderer.tsx +146 -0
  210. package/src/ui/styled/SignupForm.tsx +109 -0
  211. package/src/ui/styled/UserMenu.tsx +166 -0
  212. package/src/ui/styled/chat/ChatAttachments.tsx +172 -0
  213. package/src/ui/styled/chat/ChatComposer.tsx +153 -0
  214. package/src/ui/styled/chat/ChatThreadPanel.tsx +94 -0
  215. package/src/ui/styled/chat/MessageBubble.tsx +66 -0
  216. package/src/ui/styled/chat/NewDmDialog.tsx +78 -0
  217. package/src/ui/styled/community/CommunityComposer.tsx +358 -0
  218. package/src/ui/styled/community/CommunityFeed.tsx +483 -0
  219. package/src/ui/styled/community/CommunityLeaderboard.tsx +109 -0
  220. package/src/ui/styled/community/CommunityMediaGallery.tsx +116 -0
  221. package/src/ui/styled/community/CommunityMemberProfile.tsx +285 -0
  222. package/src/ui/styled/community/CommunityNotifications.tsx +222 -0
  223. package/src/ui/styled/community/CommunityPostCard.tsx +165 -0
  224. package/src/ui/styled/community/CommunityPostDetail.tsx +337 -0
  225. package/src/ui/styled/community/CommunityReactionBar.tsx +107 -0
  226. package/src/ui/styled/community/CommunityRichText.tsx +157 -0
  227. package/src/ui/styled/community/CommunitySpaces.tsx +174 -0
  228. package/src/ui/styled/community/MemberAvatar.tsx +74 -0
  229. package/src/ui/styled/community/index.ts +23 -0
  230. package/src/ui/styled/community/util.ts +15 -0
  231. package/src/ui/styled/members/MemberHomeLayout.tsx +98 -0
  232. package/src/ui/styled/members/MemberPostCard.tsx +392 -0
  233. package/src/ui/styled/members/MemberPostsFeed.tsx +219 -0
  234. package/src/ui/styled/members/PostCollectionDetail.tsx +227 -0
  235. package/src/ui/styled/members/PostCollectionsGrid.tsx +287 -0
  236. package/src/ui/styled/members/index.ts +7 -0
  237. package/src/ui/styled/rich-text.css +150 -0
  238. package/src/ui/styled/work/WorkInviteAccept.tsx +222 -0
  239. package/src/ui/styled/work/WorkPortalProjects.tsx +163 -0
  240. package/src/ui/styled/work/WorkProjectInvoices.tsx +113 -0
  241. package/src/ui/styled/work/WorkProjectReport.tsx +66 -0
  242. package/src/ui/styled/work/WorkReportBody.tsx +327 -0
  243. package/src/ui/styled/work/WorkTaskAttachments.tsx +67 -0
  244. package/src/ui/styled/work/WorkTaskComments.tsx +151 -0
  245. package/src/ui/styled/work/WorkTaskDetail.tsx +92 -0
  246. package/src/ui/styled/work/WorkTokenReport.tsx +49 -0
  247. package/src/ui/styled/work/index.ts +10 -0
  248. package/src/ui/theme/ForgeThemeProvider.tsx +121 -0
  249. package/src/ui/theme/contrast.ts +22 -0
  250. package/src/utils/analyticsBus.ts +31 -0
  251. package/src/utils/attribution.ts +68 -0
  252. package/src/utils/cookieConsent.ts +83 -0
  253. package/src/utils/landing.ts +153 -0
  254. package/src/utils/metaPixel.ts +122 -0
  255. package/src/utils/structuredData.ts +126 -0
@@ -0,0 +1,66 @@
1
+ import type { ChatMessage } from "../../../data/queries/useChat";
2
+ import { useForgeTheme } from "../../theme/ForgeThemeProvider";
3
+ import { readableTextOn } from "../../theme/contrast";
4
+ import { ChatAttachments } from "./ChatAttachments";
5
+
6
+ export interface MessageBubbleProps {
7
+ message: ChatMessage;
8
+ mine: boolean;
9
+ /** Thread affordances hidden inside an already-open thread. */
10
+ onOpenThread?: (message: ChatMessage) => void;
11
+ showThreadControls?: boolean;
12
+ }
13
+
14
+ export function MessageBubble({ message, mine, onOpenThread, showThreadControls = true }: MessageBubbleProps) {
15
+ const theme = useForgeTheme();
16
+ const replyCount = message.replyCount ?? 0;
17
+
18
+ return (
19
+ <div style={{ alignSelf: mine ? "flex-end" : "flex-start", maxWidth: "70%" }}>
20
+ {!mine && (
21
+ <div style={{ fontSize: 12, opacity: 0.6, marginBottom: 2 }}>
22
+ {message.senderFirstName} {message.senderLastName}
23
+ </div>
24
+ )}
25
+ <div
26
+ style={{
27
+ background: mine ? theme.colors.primary : `${theme.colors.text}10`,
28
+ color: mine ? readableTextOn(theme.colors.primary) : theme.colors.text,
29
+ padding: "8px 12px",
30
+ borderRadius: theme.cornerRadius,
31
+ }}
32
+ >
33
+ {message.content}
34
+ <ChatAttachments attachments={message.attachments} />
35
+ </div>
36
+
37
+ {showThreadControls && (
38
+ <div style={{ display: "flex", gap: 10, marginTop: 3 }}>
39
+ {replyCount > 0 ? (
40
+ <button
41
+ onClick={() => onOpenThread?.(message)}
42
+ style={{
43
+ background: "none",
44
+ border: "none",
45
+ padding: 0,
46
+ cursor: "pointer",
47
+ color: theme.colors.primary,
48
+ fontSize: 12,
49
+ fontWeight: 600,
50
+ }}
51
+ >
52
+ {replyCount} {replyCount === 1 ? "reply" : "replies"}
53
+ </button>
54
+ ) : (
55
+ <button
56
+ onClick={() => onOpenThread?.(message)}
57
+ style={{ background: "none", border: "none", padding: 0, cursor: "pointer", color: theme.colors.text, opacity: 0.55, fontSize: 12 }}
58
+ >
59
+ Reply
60
+ </button>
61
+ )}
62
+ </div>
63
+ )}
64
+ </div>
65
+ );
66
+ }
@@ -0,0 +1,78 @@
1
+ import { useMemo, useState } from "react";
2
+ import type { ChatDirectoryMember } from "../../../data/queries/useChat";
3
+ import { useForgeTheme } from "../../theme/ForgeThemeProvider";
4
+ import { readableTextOn } from "../../theme/contrast";
5
+
6
+ export interface NewDmDialogProps {
7
+ members: ChatDirectoryMember[];
8
+ isStarting?: boolean;
9
+ onSelect: (accountId: string) => void;
10
+ onClose: () => void;
11
+ }
12
+
13
+ const memberName = (m: ChatDirectoryMember) => `${m.firstName ?? ""} ${m.lastName ?? ""}`.trim() || m.email;
14
+
15
+ /** People-picker of same-tier members to start a DM with. */
16
+ export function NewDmDialog({ members, isStarting, onSelect, onClose }: NewDmDialogProps) {
17
+ const theme = useForgeTheme();
18
+ const [query, setQuery] = useState("");
19
+ const border = `1px solid ${theme.colors.text}1a`;
20
+
21
+ const filtered = useMemo(() => {
22
+ const q = query.trim().toLowerCase();
23
+ if (!q) return members;
24
+ return members.filter((m) => memberName(m).toLowerCase().includes(q) || m.email.toLowerCase().includes(q));
25
+ }, [members, query]);
26
+
27
+ return (
28
+ <div
29
+ onClick={onClose}
30
+ style={{ position: "fixed", inset: 0, background: "rgba(0,0,0,0.5)", display: "flex", alignItems: "center", justifyContent: "center", zIndex: 1000, padding: 16 }}
31
+ >
32
+ <div
33
+ onClick={(e) => e.stopPropagation()}
34
+ style={{ background: theme.colors.background, color: theme.colors.text, borderRadius: theme.cornerRadius, width: "100%", maxWidth: 420, maxHeight: "80vh", display: "flex", flexDirection: "column", overflow: "hidden", border }}
35
+ >
36
+ <header style={{ padding: "14px 16px", borderBottom: border, display: "flex", alignItems: "center", gap: 12 }}>
37
+ <strong style={{ flex: 1 }}>New message</strong>
38
+ <button onClick={onClose} style={{ background: "none", border: "none", cursor: "pointer", color: theme.colors.text, fontSize: 18 }} aria-label="Close">
39
+ ×
40
+ </button>
41
+ </header>
42
+ <div style={{ padding: 12, borderBottom: border }}>
43
+ <input
44
+ autoFocus
45
+ value={query}
46
+ onChange={(e) => setQuery(e.target.value)}
47
+ placeholder="Search members…"
48
+ style={{ width: "100%", padding: "8px 10px", borderRadius: theme.cornerRadius, border, background: theme.colors.background, color: theme.colors.text }}
49
+ />
50
+ </div>
51
+ <div style={{ overflowY: "auto", flex: 1 }}>
52
+ {filtered.length === 0 && (
53
+ <div style={{ padding: 20, textAlign: "center", opacity: 0.5, fontSize: 13 }}>No members to message.</div>
54
+ )}
55
+ {filtered.map((m) => {
56
+ const name = memberName(m);
57
+ const initial = name.charAt(0).toUpperCase();
58
+ return (
59
+ <button
60
+ key={m.accountId}
61
+ disabled={isStarting}
62
+ onClick={() => onSelect(m.accountId)}
63
+ style={{ display: "flex", alignItems: "center", gap: 10, width: "100%", textAlign: "left", padding: "10px 16px", background: "none", border: "none", borderBottom: border, cursor: isStarting ? "wait" : "pointer", color: theme.colors.text }}
64
+ >
65
+ <span
66
+ style={{ width: 32, height: 32, borderRadius: 999, background: theme.colors.primary, color: readableTextOn(theme.colors.primary), display: "flex", alignItems: "center", justifyContent: "center", fontSize: 14, flexShrink: 0 }}
67
+ >
68
+ {initial}
69
+ </span>
70
+ <span style={{ minWidth: 0, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }}>{name}</span>
71
+ </button>
72
+ );
73
+ })}
74
+ </div>
75
+ </div>
76
+ </div>
77
+ );
78
+ }
@@ -0,0 +1,358 @@
1
+ import { useRef, useState } from "react";
2
+ import { Bold, Italic, Underline, List, ListOrdered, Link as LinkIcon } from "lucide-react";
3
+ import { useThemeTokens } from "../../theme/ForgeThemeProvider";
4
+ import { formatBytes } from "../../headless/chat/attachmentKind";
5
+ import { useCommunityAttachmentUpload } from "../../headless/community/useCommunityAttachmentUpload";
6
+ import { useRichMentionComposer, type RichCommand } from "../../headless/community/useRichMentionComposer";
7
+ import { MemberAvatar } from "./MemberAvatar";
8
+ import type { CommunityAttachmentInput } from "../../../data/queries/useCommunity";
9
+
10
+ export interface CommunityComposerSubmit {
11
+ title?: string;
12
+ body: unknown;
13
+ attachments: CommunityAttachmentInput[];
14
+ mentionedAccountIds: string[];
15
+ }
16
+
17
+ export interface CommunityComposerProps {
18
+ /** Show the title input (forum spaces). */
19
+ withTitle?: boolean;
20
+ placeholder?: string;
21
+ submitLabel?: string;
22
+ autoFocus?: boolean;
23
+ compact?: boolean;
24
+ onSubmit: (input: CommunityComposerSubmit) => Promise<unknown>;
25
+ onCancel?: () => void;
26
+ }
27
+
28
+ /**
29
+ * Post/reply composer: a lean contentEditable rich-text editor (bold/italic/
30
+ * underline, bullet + numbered lists, links) with `@mention` autocomplete
31
+ * (member directory) and attachments. The DOM is the source of truth; on submit
32
+ * it serializes to the Lexical state CommunityRichText renders — no Lexical
33
+ * runtime is pulled into forge. Same onSubmit contract the plain-text composer
34
+ * used ({ title?, body, attachments, mentionedAccountIds }).
35
+ */
36
+ export function CommunityComposer({
37
+ withTitle = false,
38
+ placeholder = "Write something…",
39
+ submitLabel = "Post",
40
+ autoFocus = false,
41
+ compact = false,
42
+ onSubmit,
43
+ onCancel,
44
+ }: CommunityComposerProps) {
45
+ const t = useThemeTokens();
46
+ const composer = useRichMentionComposer();
47
+ const upload = useCommunityAttachmentUpload();
48
+ const [title, setTitle] = useState("");
49
+ const [sending, setSending] = useState(false);
50
+ const [error, setError] = useState<string | null>(null);
51
+ const fileInputRef = useRef<HTMLInputElement | null>(null);
52
+
53
+ const border = `1px solid ${t.border}`;
54
+ const canSubmit =
55
+ (!composer.isEmpty || upload.hasPending) && !sending && (!withTitle || title.trim().length > 0);
56
+
57
+ const submit = async () => {
58
+ if (!canSubmit) return;
59
+ setSending(true);
60
+ setError(null);
61
+ try {
62
+ const attachments = upload.hasPending ? await upload.uploadAll() : [];
63
+ await onSubmit({
64
+ title: withTitle ? title.trim() : undefined,
65
+ body: composer.getBody(),
66
+ attachments,
67
+ mentionedAccountIds: composer.getMentionedAccountIds(),
68
+ });
69
+ composer.reset();
70
+ setTitle("");
71
+ upload.clear();
72
+ } catch (err: any) {
73
+ setError(err?.response?.data?.message || "Couldn't publish. Please try again.");
74
+ } finally {
75
+ setSending(false);
76
+ }
77
+ };
78
+
79
+ const toolbarButton = (label: string, icon: React.ReactNode, onClick: () => void) => (
80
+ <button
81
+ key={label}
82
+ type="button"
83
+ title={label}
84
+ aria-label={label}
85
+ // mousedown so the editor keeps its selection.
86
+ onMouseDown={(e) => {
87
+ e.preventDefault();
88
+ onClick();
89
+ }}
90
+ style={{
91
+ display: "inline-flex",
92
+ alignItems: "center",
93
+ justifyContent: "center",
94
+ width: 28,
95
+ height: 28,
96
+ background: "none",
97
+ border,
98
+ borderRadius: t.cornerRadius,
99
+ cursor: "pointer",
100
+ color: t.text,
101
+ padding: 0,
102
+ }}
103
+ >
104
+ {icon}
105
+ </button>
106
+ );
107
+
108
+ const fmt = (command: RichCommand) => () => composer.format(command);
109
+
110
+ return (
111
+ <div
112
+ style={{
113
+ border,
114
+ borderRadius: t.cornerRadius,
115
+ background: t.surface,
116
+ padding: compact ? 8 : 12,
117
+ display: "flex",
118
+ flexDirection: "column",
119
+ gap: 8,
120
+ }}
121
+ >
122
+ {withTitle && (
123
+ <input
124
+ value={title}
125
+ onChange={(e) => setTitle(e.target.value)}
126
+ placeholder="Title"
127
+ maxLength={200}
128
+ style={{
129
+ padding: "8px 10px",
130
+ borderRadius: t.cornerRadius,
131
+ border,
132
+ background: t.background,
133
+ color: t.text,
134
+ fontWeight: 600,
135
+ }}
136
+ />
137
+ )}
138
+
139
+ {/* Formatting toolbar */}
140
+ <div style={{ display: "flex", alignItems: "center", gap: 4, flexWrap: "wrap" }}>
141
+ {toolbarButton("Bold", <Bold size={15} />, fmt("bold"))}
142
+ {toolbarButton("Italic", <Italic size={15} />, fmt("italic"))}
143
+ {toolbarButton("Underline", <Underline size={15} />, fmt("underline"))}
144
+ <span style={{ width: 1, height: 18, background: t.border, margin: "0 2px" }} aria-hidden />
145
+ {toolbarButton("Bullet list", <List size={15} />, fmt("insertUnorderedList"))}
146
+ {toolbarButton("Numbered list", <ListOrdered size={15} />, fmt("insertOrderedList"))}
147
+ <span style={{ width: 1, height: 18, background: t.border, margin: "0 2px" }} aria-hidden />
148
+ {toolbarButton("Link", <LinkIcon size={15} />, () => composer.insertLink())}
149
+ </div>
150
+
151
+ <div style={{ position: "relative" }}>
152
+ <div
153
+ ref={composer.editorRef}
154
+ contentEditable
155
+ suppressContentEditableWarning
156
+ role="textbox"
157
+ aria-multiline="true"
158
+ data-placeholder={placeholder}
159
+ autoFocus={autoFocus}
160
+ onInput={composer.onEditorChange}
161
+ onKeyUp={composer.onEditorChange}
162
+ onClick={composer.onEditorChange}
163
+ onBlur={() => {
164
+ // Delay so a suggestion mousedown fires first.
165
+ setTimeout(() => composer.dismissSuggestions(), 120);
166
+ }}
167
+ className="forge-community-composer-editable"
168
+ style={{
169
+ width: "100%",
170
+ minHeight: compact ? 72 : 100,
171
+ maxHeight: 260,
172
+ overflowY: "auto",
173
+ padding: "8px 10px",
174
+ borderRadius: t.cornerRadius,
175
+ border,
176
+ background: t.background,
177
+ color: t.text,
178
+ fontFamily: "inherit",
179
+ fontSize: 14,
180
+ lineHeight: 1.5,
181
+ boxSizing: "border-box",
182
+ outline: "none",
183
+ whiteSpace: "pre-wrap",
184
+ wordBreak: "break-word",
185
+ }}
186
+ />
187
+ {/* Placeholder + mention-chip styling (scoped by class). */}
188
+ <style>{`
189
+ .forge-community-composer-editable:empty:before {
190
+ content: attr(data-placeholder);
191
+ color: ${t.muted};
192
+ pointer-events: none;
193
+ }
194
+ .forge-community-composer-editable [data-account-id] {
195
+ color: ${t.primary};
196
+ font-weight: 600;
197
+ background: ${t.primary}1a;
198
+ border-radius: 4px;
199
+ padding: 0 3px;
200
+ }
201
+ .forge-community-composer-editable a { color: ${t.primary}; text-decoration: underline; }
202
+ `}</style>
203
+
204
+ {composer.isSuggesting && (
205
+ <div
206
+ style={{
207
+ position: "absolute",
208
+ top: "100%",
209
+ left: 0,
210
+ right: 0,
211
+ maxWidth: 320,
212
+ background: t.surface,
213
+ border,
214
+ borderRadius: t.cornerRadius,
215
+ boxShadow: "0 6px 20px rgba(0,0,0,0.14)",
216
+ zIndex: 30,
217
+ overflow: "hidden",
218
+ }}
219
+ >
220
+ {composer.suggestions.map((s) => (
221
+ <button
222
+ key={s.accountId}
223
+ type="button"
224
+ onMouseDown={(e) => {
225
+ // mousedown so the editor keeps focus.
226
+ e.preventDefault();
227
+ composer.insertMention(s);
228
+ }}
229
+ style={{
230
+ display: "flex",
231
+ alignItems: "center",
232
+ gap: 8,
233
+ width: "100%",
234
+ padding: "6px 10px",
235
+ background: "transparent",
236
+ border: "none",
237
+ cursor: "pointer",
238
+ color: t.text,
239
+ textAlign: "left",
240
+ fontSize: 14,
241
+ }}
242
+ >
243
+ <MemberAvatar member={{ displayName: s.name, avatarUrl: s.avatarUrl }} size={24} />
244
+ <span style={{ fontWeight: 500 }}>{s.name}</span>
245
+ </button>
246
+ ))}
247
+ </div>
248
+ )}
249
+ </div>
250
+
251
+ {upload.error && <div style={{ fontSize: 12, color: "#dc2626" }}>{upload.error}</div>}
252
+ {error && <div style={{ fontSize: 12, color: "#dc2626" }}>{error}</div>}
253
+
254
+ {upload.pending.length > 0 && (
255
+ <div style={{ display: "flex", flexWrap: "wrap", gap: 8 }}>
256
+ {upload.pending.map((p) => (
257
+ <div
258
+ key={p.id}
259
+ style={{
260
+ display: "flex",
261
+ alignItems: "center",
262
+ gap: 6,
263
+ padding: "4px 8px",
264
+ border,
265
+ borderRadius: t.cornerRadius,
266
+ maxWidth: 200,
267
+ }}
268
+ >
269
+ {p.kind === "image" && p.previewUrl ? (
270
+ <img src={p.previewUrl} alt="" style={{ width: 28, height: 28, objectFit: "cover", borderRadius: 4 }} />
271
+ ) : (
272
+ <span aria-hidden>📎</span>
273
+ )}
274
+ <div style={{ minWidth: 0, flex: 1 }}>
275
+ <div style={{ fontSize: 12, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }}>
276
+ {p.file.name}
277
+ </div>
278
+ <div style={{ fontSize: 10, color: t.muted }}>
279
+ {p.status === "uploading" ? `${p.progress}%` : formatBytes(p.file.size)}
280
+ </div>
281
+ </div>
282
+ <button
283
+ onClick={() => upload.removeFile(p.id)}
284
+ aria-label="Remove attachment"
285
+ style={{ background: "none", border: "none", cursor: "pointer", color: t.text }}
286
+ >
287
+ ×
288
+ </button>
289
+ </div>
290
+ ))}
291
+ </div>
292
+ )}
293
+
294
+ <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
295
+ <input
296
+ ref={fileInputRef}
297
+ type="file"
298
+ multiple
299
+ hidden
300
+ onChange={(e) => {
301
+ if (e.target.files) upload.addFiles(e.target.files);
302
+ e.target.value = "";
303
+ }}
304
+ />
305
+ <button
306
+ onClick={() => fileInputRef.current?.click()}
307
+ disabled={!upload.canAddMore}
308
+ title="Attach files"
309
+ style={{
310
+ background: "none",
311
+ border,
312
+ borderRadius: t.cornerRadius,
313
+ padding: "4px 10px",
314
+ cursor: upload.canAddMore ? "pointer" : "not-allowed",
315
+ color: t.text,
316
+ fontSize: 16,
317
+ }}
318
+ >
319
+ 📎
320
+ </button>
321
+ <span style={{ flex: 1, fontSize: 11, color: t.muted }}>Use @ to mention members</span>
322
+ {onCancel && (
323
+ <button
324
+ onClick={onCancel}
325
+ style={{
326
+ background: "none",
327
+ border,
328
+ borderRadius: t.cornerRadius,
329
+ padding: "6px 12px",
330
+ cursor: "pointer",
331
+ color: t.text,
332
+ fontSize: 13,
333
+ }}
334
+ >
335
+ Cancel
336
+ </button>
337
+ )}
338
+ <button
339
+ onClick={submit}
340
+ disabled={!canSubmit}
341
+ style={{
342
+ background: t.primary,
343
+ color: t.textPrimary,
344
+ border: "none",
345
+ borderRadius: t.cornerRadius,
346
+ padding: "6px 16px",
347
+ fontWeight: 600,
348
+ cursor: canSubmit ? "pointer" : "not-allowed",
349
+ opacity: canSubmit ? 1 : 0.6,
350
+ fontSize: 14,
351
+ }}
352
+ >
353
+ {sending ? "…" : submitLabel}
354
+ </button>
355
+ </div>
356
+ </div>
357
+ );
358
+ }