@openpeepshq/react 0.2.6 → 0.3.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 (530) hide show
  1. package/dist/components/configuration/ConfigurationCategory.d.ts +1 -1
  2. package/dist/components/configuration/ConfigurationCategory.js +1 -1
  3. package/dist/components/configuration/ConfigurationList.d.ts +1 -1
  4. package/dist/components/configuration/ConfigurationList.js +1 -1
  5. package/dist/components/configuration/ConfigurationTree.d.ts +1 -1
  6. package/dist/components/configuration/ConfigurationTree.js +1 -1
  7. package/dist/components/configuration/ConfigurationValueEditor.d.ts +1 -1
  8. package/dist/components/configuration/ConfigurationValueEditor.js +1 -1
  9. package/dist/components/post/pieces/EventRsvpButton.js +12 -1
  10. package/dist/components/server-data/context.d.ts +1 -0
  11. package/dist/contexts/openpeeps/hooks/admin.d.ts +130 -130
  12. package/dist/contexts/openpeeps/hooks/other.d.ts +1 -0
  13. package/dist/contexts/openpeeps/hooks/posts.d.ts +1018 -1018
  14. package/dist/hooks/events/useEventComposer.d.ts +145 -145
  15. package/dist/hooks/events/useEventForm.d.ts +1 -1
  16. package/dist/hooks/events/useEventRsvp.d.ts +1 -0
  17. package/dist/hooks/events/useEventRsvp.js +11 -2
  18. package/dist/hooks/events/useEventsCalendar.d.ts +252 -252
  19. package/dist/hooks/jams/useCreateNewJamForm.d.ts +7 -7
  20. package/dist/hooks/jams/useJamDetails.d.ts +18 -18
  21. package/dist/hooks/jams/useJamRoom.d.ts +36 -36
  22. package/dist/hooks/posts/useArticleComposer.d.ts +144 -144
  23. package/dist/hooks/posts/useFeedPostPresentation.d.ts +252 -252
  24. package/dist/hooks/posts/usePostDetailTitle.d.ts +18 -18
  25. package/dist/hooks/settings/useAccessTokens.d.ts +4 -4
  26. package/dist/index.d.ts +2 -1
  27. package/dist/index.js +2 -1
  28. package/dist/lib/configuration/helpers.d.ts +1 -1
  29. package/dist/lib/configuration/helpers.js +1 -1
  30. package/dist/lib/configuration/resolveSchema.d.ts +1 -1
  31. package/dist/pages/admin/Members.js +2 -2
  32. package/dist/pages/admin/community/CommunityTheme.js +1 -1
  33. package/dist/pages/admin/community/useCommunityConfig.d.ts +2 -0
  34. package/dist/pages/admin/configurationSsoShared.d.ts +3 -3
  35. package/dist/pages/settings/PublicProfile.js +1 -1
  36. package/dist/push/index.d.ts +1 -15
  37. package/dist/push/index.js +1 -144
  38. package/dist/push/usePushSubscription.d.ts +1 -1
  39. package/dist/push/usePushSubscription.js +1 -1
  40. package/dist/push/webPush.d.ts +15 -0
  41. package/dist/push/webPush.js +144 -0
  42. package/dist/stores/newPosts.d.ts +12 -12
  43. package/package.json +20 -14
  44. package/src/auth/credentials/index.ts +70 -0
  45. package/src/auth/credentials/types.ts +7 -0
  46. package/src/components/CapabilityMatrix.tsx +216 -0
  47. package/src/components/RelationCapabilitiesEditor.tsx +234 -0
  48. package/src/components/RoleCapabilityMatrix.tsx +219 -0
  49. package/src/components/accounts/SignUpLoginModal.tsx +52 -0
  50. package/src/components/accounts/SignUpLoginModalContext.tsx +43 -0
  51. package/src/components/accounts/index.ts +6 -0
  52. package/src/components/configuration/ConfigMenuButton.tsx +50 -0
  53. package/src/components/configuration/ConfigurationCategory.tsx +161 -0
  54. package/src/components/configuration/ConfigurationList.tsx +105 -0
  55. package/src/components/configuration/ConfigurationTree.tsx +63 -0
  56. package/src/components/configuration/ConfigurationValueEditor.tsx +145 -0
  57. package/src/components/configuration/index.ts +6 -0
  58. package/src/components/conversations/ConversationMessageBubble.tsx +35 -0
  59. package/src/components/conversations/ConversationParticipantsModal.tsx +46 -0
  60. package/src/components/conversations/CreateNewConversation.tsx +137 -0
  61. package/src/components/conversations/CreateNewConversationContext.tsx +63 -0
  62. package/src/components/conversations/DirectMessagesHeaderActions.tsx +20 -0
  63. package/src/components/conversations/MessageInThread.tsx +120 -0
  64. package/src/components/conversations/index.ts +13 -0
  65. package/src/components/form/HeaderAvatarInput.tsx +49 -0
  66. package/src/components/form/ImageEditModal.tsx +232 -0
  67. package/src/components/form/ImageInput.tsx +208 -0
  68. package/src/components/form/LocationInput.tsx +141 -0
  69. package/src/components/form/TimeZoneSelect.tsx +33 -0
  70. package/src/components/form/index.ts +10 -0
  71. package/src/components/groups/AddGroupMemberModal.tsx +59 -0
  72. package/src/components/groups/AddGroupMembersButton.tsx +45 -0
  73. package/src/components/groups/ChangeGroupRolesModal.tsx +124 -0
  74. package/src/components/groups/ConfirmGroupExitModal.tsx +78 -0
  75. package/src/components/groups/ConfirmMemberRemovalModal.tsx +78 -0
  76. package/src/components/groups/DeleteGroupModal.tsx +74 -0
  77. package/src/components/groups/GroupAvatar.tsx +77 -0
  78. package/src/components/groups/GroupCapabilityMatrix.tsx +37 -0
  79. package/src/components/groups/GroupCard.tsx +92 -0
  80. package/src/components/groups/GroupFeed.tsx +23 -0
  81. package/src/components/groups/GroupForm.tsx +172 -0
  82. package/src/components/groups/GroupHeader.tsx +64 -0
  83. package/src/components/groups/GroupMembersList.tsx +179 -0
  84. package/src/components/groups/GroupOptionsMenu.tsx +184 -0
  85. package/src/components/groups/GroupShareMenu.tsx +75 -0
  86. package/src/components/groups/JoinGroupButton.tsx +28 -0
  87. package/src/components/groups/index.ts +36 -0
  88. package/src/components/index.ts +23 -0
  89. package/src/components/jams/CreateNewJam.tsx +161 -0
  90. package/src/components/jams/CreateNewJamContext.tsx +36 -0
  91. package/src/components/jams/JamAnimatedEmoji.tsx +26 -0
  92. package/src/components/jams/JamCallParticipant.tsx +314 -0
  93. package/src/components/jams/JamCapacityGate.tsx +94 -0
  94. package/src/components/jams/JamChatDrawer.tsx +156 -0
  95. package/src/components/jams/JamChatMessage.tsx +96 -0
  96. package/src/components/jams/JamConference.tsx +76 -0
  97. package/src/components/jams/JamContext.tsx +72 -0
  98. package/src/components/jams/JamDetailsDrawer.tsx +177 -0
  99. package/src/components/jams/JamDeviceSelectors.tsx +213 -0
  100. package/src/components/jams/JamEventsContext.tsx +226 -0
  101. package/src/components/jams/JamFooter.tsx +486 -0
  102. package/src/components/jams/JamGuestForm.tsx +130 -0
  103. package/src/components/jams/JamLobby.tsx +254 -0
  104. package/src/components/jams/JamObserverShell.tsx +41 -0
  105. package/src/components/jams/JamParticipantConference.tsx +171 -0
  106. package/src/components/jams/JamPeopleDrawer.tsx +196 -0
  107. package/src/components/jams/JamReactionMenu.tsx +208 -0
  108. package/src/components/jams/JamRequestJoin.tsx +42 -0
  109. package/src/components/jams/JamRoom.tsx +232 -0
  110. package/src/components/jams/JamRoomIndicators.tsx +68 -0
  111. package/src/components/jams/JamToolbarButton.tsx +101 -0
  112. package/src/components/jams/JamVideoCall.tsx +57 -0
  113. package/src/components/jams/JamVideoLayout.tsx +467 -0
  114. package/src/components/jams/LeaveCloseButton.tsx +79 -0
  115. package/src/components/jams/LiveJamsSection.tsx +56 -0
  116. package/src/components/jams/animateEmoji.ts +79 -0
  117. package/src/components/jams/blurProcessor.ts +34 -0
  118. package/src/components/jams/constants.ts +53 -0
  119. package/src/components/jams/disconnectReason.ts +22 -0
  120. package/src/components/jams/emojiPickerElement.d.ts +16 -0
  121. package/src/components/jams/index.ts +24 -0
  122. package/src/components/jams/jamEventActions.ts +138 -0
  123. package/src/components/jams/jamLocalSettings.ts +75 -0
  124. package/src/components/jams/jamReactionPreferences.ts +86 -0
  125. package/src/components/jams/jamRecordingState.ts +72 -0
  126. package/src/components/jams/livekit-light-theme.css +48 -0
  127. package/src/components/jams/reactionEmojis.ts +24 -0
  128. package/src/components/jams/speakerLayout.ts +50 -0
  129. package/src/components/jams/useJamHands.ts +45 -0
  130. package/src/components/jams/useJamSpotlight.ts +106 -0
  131. package/src/components/jams/useParticipantConnection.ts +13 -0
  132. package/src/components/layout/AccessDenied.tsx +60 -0
  133. package/src/components/layout/AccessDeniedLoader.tsx +41 -0
  134. package/src/components/layout/Auth.tsx +174 -0
  135. package/src/components/layout/IdentityContext.ts +73 -0
  136. package/src/components/layout/Infos.tsx +78 -0
  137. package/src/components/layout/OpenpeepsContextProvider.tsx +117 -0
  138. package/src/components/layout/OpenpeepsThemeProvider.tsx +104 -0
  139. package/src/components/layout/ProfileGuard.tsx +53 -0
  140. package/src/components/layout/ProfileProvider.tsx +62 -0
  141. package/src/components/layout/Root.tsx +97 -0
  142. package/src/components/layout/ToastProvider.tsx +95 -0
  143. package/src/components/layout/index.ts +28 -0
  144. package/src/components/layout/useProfileIdentity.ts +51 -0
  145. package/src/components/markdown/CompiledMarkdown.tsx +32 -0
  146. package/src/components/markdown/OpenpeepsMarkdown.tsx +107 -0
  147. package/src/components/markdown/classes.ts +9 -0
  148. package/src/components/markdown/compileMarkdown.ts +53 -0
  149. package/src/components/markdown/index.ts +20 -0
  150. package/src/components/markdown/linkTargets.ts +31 -0
  151. package/src/components/markdown/staticRender.ts +30 -0
  152. package/src/components/navigation/ContentHeader.tsx +50 -0
  153. package/src/components/navigation/FooterMobile.tsx +53 -0
  154. package/src/components/navigation/HeaderMobile.tsx +106 -0
  155. package/src/components/navigation/MobileMenuItem.tsx +56 -0
  156. package/src/components/navigation/PageHeaderAction.tsx +23 -0
  157. package/src/components/navigation/PlusButton.tsx +24 -0
  158. package/src/components/navigation/SideBar.tsx +112 -0
  159. package/src/components/navigation/SidebarNavContext.tsx +8 -0
  160. package/src/components/navigation/breadcrumbs/Breadcrumbs.tsx +31 -0
  161. package/src/components/navigation/breadcrumbs/Crumb.tsx +19 -0
  162. package/src/components/navigation/index.ts +20 -0
  163. package/src/components/navigation/sideBarNavLinkClass.ts +8 -0
  164. package/src/components/notifications/NotificationErrorBoundary.tsx +37 -0
  165. package/src/components/notifications/NotificationHeaderActions.tsx +60 -0
  166. package/src/components/notifications/NotificationItem.tsx +15 -0
  167. package/src/components/notifications/NotificationWrapper.tsx +42 -0
  168. package/src/components/notifications/NotificationsList.tsx +147 -0
  169. package/src/components/notifications/TypedNotification.tsx +685 -0
  170. package/src/components/notifications/index.ts +7 -0
  171. package/src/components/post/CompactReplyParent.tsx +268 -0
  172. package/src/components/post/EventViewSwitch.tsx +40 -0
  173. package/src/components/post/Feed.tsx +151 -0
  174. package/src/components/post/FeedFormatSwitch.tsx +40 -0
  175. package/src/components/post/FeedPost.tsx +93 -0
  176. package/src/components/post/FeedPostContent.tsx +44 -0
  177. package/src/components/post/FullPostLayout.tsx +79 -0
  178. package/src/components/post/Markdown.tsx +2 -0
  179. package/src/components/post/NewEventButton.tsx +86 -0
  180. package/src/components/post/NewNoteButton.tsx +84 -0
  181. package/src/components/post/PinnedPost.tsx +34 -0
  182. package/src/components/post/PostDetail.tsx +48 -0
  183. package/src/components/post/ReplyBox.tsx +53 -0
  184. package/src/components/post/VideoPlayOverlay.tsx +18 -0
  185. package/src/components/post/attachmentPreview.ts +24 -0
  186. package/src/components/post/feed/events/EventsCalendar.tsx +227 -0
  187. package/src/components/post/feed/events/EventsFeed.tsx +92 -0
  188. package/src/components/post/feed/events/EventsView.tsx +27 -0
  189. package/src/components/post/feed/events/eventCalendar.ts +203 -0
  190. package/src/components/post/feed/threaded/ThreadPost.tsx +77 -0
  191. package/src/components/post/feed/threaded/ThreadedFeed.tsx +40 -0
  192. package/src/components/post/helpers.ts +32 -0
  193. package/src/components/post/index.ts +102 -0
  194. package/src/components/post/pieces/Attachments.tsx +140 -0
  195. package/src/components/post/pieces/AudioAttachment.tsx +188 -0
  196. package/src/components/post/pieces/EventLocation.tsx +139 -0
  197. package/src/components/post/pieces/EventMenu.tsx +110 -0
  198. package/src/components/post/pieces/EventOccurrenceList.tsx +146 -0
  199. package/src/components/post/pieces/EventRsvpButton.tsx +159 -0
  200. package/src/components/post/pieces/EventRsvpList.tsx +375 -0
  201. package/src/components/post/pieces/EventRsvpScopeDialog.tsx +237 -0
  202. package/src/components/post/pieces/FeedPostStats.tsx +83 -0
  203. package/src/components/post/pieces/FeedThreadPreview.tsx +123 -0
  204. package/src/components/post/pieces/GalleryModal.tsx +153 -0
  205. package/src/components/post/pieces/ParticipantsCard.tsx +35 -0
  206. package/src/components/post/pieces/PollContent.tsx +274 -0
  207. package/src/components/post/pieces/PostActions.tsx +85 -0
  208. package/src/components/post/pieces/PostInfoHeader.tsx +43 -0
  209. package/src/components/post/pieces/PostMenu.tsx +334 -0
  210. package/src/components/post/pieces/PostReactionHeader.tsx +109 -0
  211. package/src/components/post/pieces/ShareMenu.tsx +104 -0
  212. package/src/components/post/pieces/UnreadPostIndicator.tsx +37 -0
  213. package/src/components/post/pieces/VideoPlayer.tsx +188 -0
  214. package/src/components/post/pieces/modals/DeletePostModal.tsx +68 -0
  215. package/src/components/post/pieces/modals/ReactionsModal.tsx +51 -0
  216. package/src/components/post/pieces/modals/RepostModal.tsx +65 -0
  217. package/src/components/post/post-form/ArticleForm.tsx +119 -0
  218. package/src/components/post/post-form/AttachmentCard.tsx +312 -0
  219. package/src/components/post/post-form/ComposeAttachments.tsx +327 -0
  220. package/src/components/post/post-form/ComposePreviewLinks.tsx +19 -0
  221. package/src/components/post/post-form/DescriptionEditModal.tsx +75 -0
  222. package/src/components/post/post-form/EditPostModal.tsx +195 -0
  223. package/src/components/post/post-form/EditPostModalContext.tsx +44 -0
  224. package/src/components/post/post-form/EventForm.tsx +441 -0
  225. package/src/components/post/post-form/EventTypeSwitcher.tsx +188 -0
  226. package/src/components/post/post-form/NewPostModal.tsx +519 -0
  227. package/src/components/post/post-form/NewPostModalContext.tsx +64 -0
  228. package/src/components/post/post-form/OpenpeepsMarkdownInput.tsx +184 -0
  229. package/src/components/post/post-form/PollComposerFields.tsx +113 -0
  230. package/src/components/post/post-form/PostAudienceSelector.tsx +236 -0
  231. package/src/components/post/post-form/PostTypeSwitcher.tsx +112 -0
  232. package/src/components/post/post-form/ReplyModal.tsx +347 -0
  233. package/src/components/post/post-form/ReplyModalContext.tsx +29 -0
  234. package/src/components/post/post-form/VisibilitySelector.tsx +109 -0
  235. package/src/components/post/post-form/audienceChoices.ts +47 -0
  236. package/src/components/post/types/Article.tsx +64 -0
  237. package/src/components/post/types/Event.tsx +84 -0
  238. package/src/components/post/types/Note.tsx +33 -0
  239. package/src/components/post/types/Poll.tsx +58 -0
  240. package/src/components/post/types/article/FullArticle.tsx +46 -0
  241. package/src/components/post/types/event/CardEvent.tsx +131 -0
  242. package/src/components/post/types/event/FullEvent.tsx +636 -0
  243. package/src/components/post/types/event/ProfileEventRelationship.tsx +67 -0
  244. package/src/components/post/types/note/FullNote.tsx +15 -0
  245. package/src/components/post/types/poll/FullPoll.tsx +24 -0
  246. package/src/components/post/visibility.ts +12 -0
  247. package/src/components/preview-link/LocalPreviewLink.tsx +27 -0
  248. package/src/components/preview-link/PreviewLink.tsx +25 -0
  249. package/src/components/preview-link/RemotePreviewLink.tsx +66 -0
  250. package/src/components/preview-link/helpers.ts +42 -0
  251. package/src/components/preview-link/index.ts +3 -0
  252. package/src/components/preview-link/local/GroupPreview.tsx +25 -0
  253. package/src/components/preview-link/local/JamPreview.tsx +30 -0
  254. package/src/components/preview-link/local/PostPreview.tsx +31 -0
  255. package/src/components/profile/Avatar.tsx +102 -0
  256. package/src/components/profile/AvatarWithName.tsx +15 -0
  257. package/src/components/profile/FollowUnfollowButton.tsx +60 -0
  258. package/src/components/profile/ProfileActivitySummary.tsx +187 -0
  259. package/src/components/profile/ProfileBadge.tsx +43 -0
  260. package/src/components/profile/ProfileCard.tsx +82 -0
  261. package/src/components/profile/ProfileFromId.tsx +46 -0
  262. package/src/components/profile/ProfileHeader.tsx +130 -0
  263. package/src/components/profile/ProfileLink.tsx +25 -0
  264. package/src/components/profile/ProfilePageAction.tsx +195 -0
  265. package/src/components/profile/ProfilePostsAndReplies.tsx +100 -0
  266. package/src/components/profile/ProfileSelector.tsx +206 -0
  267. package/src/components/profile/ProfileStats.tsx +33 -0
  268. package/src/components/profile/ProfileWithActionCard.tsx +32 -0
  269. package/src/components/profile/ProfilesInput.tsx +100 -0
  270. package/src/components/profile/ReportProfileOrPostModal.tsx +173 -0
  271. package/src/components/profile/index.ts +35 -0
  272. package/src/components/profile/profileFieldDisplay.ts +42 -0
  273. package/src/components/registry/ErrorComponent.tsx +27 -0
  274. package/src/components/registry/PluginLoader.tsx +71 -0
  275. package/src/components/registry/PluginRegistryProvider.tsx +145 -0
  276. package/src/components/registry/PluginSlot.tsx +65 -0
  277. package/src/components/registry/index.tsx +48 -0
  278. package/src/components/server-data/ServerDataProvider.tsx +52 -0
  279. package/src/components/server-data/context.ts +16 -0
  280. package/src/components/server-data/index.ts +9 -0
  281. package/src/components/server-data/types.ts +6 -0
  282. package/src/contexts/credentialsStore/index.tsx +26 -0
  283. package/src/contexts/credentialsStore/types.ts +5 -0
  284. package/src/contexts/index.ts +3 -0
  285. package/src/contexts/openpeeps/helpers.ts +601 -0
  286. package/src/contexts/openpeeps/hooks/accounts.ts +81 -0
  287. package/src/contexts/openpeeps/hooks/admin.ts +244 -0
  288. package/src/contexts/openpeeps/hooks/auth.ts +60 -0
  289. package/src/contexts/openpeeps/hooks/conversations.ts +42 -0
  290. package/src/contexts/openpeeps/hooks/groups.ts +38 -0
  291. package/src/contexts/openpeeps/hooks/index.ts +56 -0
  292. package/src/contexts/openpeeps/hooks/jams.ts +67 -0
  293. package/src/contexts/openpeeps/hooks/other.ts +141 -0
  294. package/src/contexts/openpeeps/hooks/payments.ts +15 -0
  295. package/src/contexts/openpeeps/hooks/posts.ts +269 -0
  296. package/src/contexts/openpeeps/hooks/profiles.ts +194 -0
  297. package/src/contexts/openpeeps/hooks/search.ts +60 -0
  298. package/src/contexts/openpeeps/hooks/streaming.ts +25 -0
  299. package/src/contexts/openpeeps/hooks/useHasAuthToken.ts +47 -0
  300. package/src/contexts/openpeeps/index.tsx +293 -0
  301. package/src/contexts/openpeeps/types.ts +12 -0
  302. package/src/contexts/router/index.tsx +107 -0
  303. package/src/email/index.ts +17 -0
  304. package/src/hooks/auth/useAuthForms.ts +117 -0
  305. package/src/hooks/community/useCommunityInfoPages.ts +22 -0
  306. package/src/hooks/conversations/useCreateConversation.ts +74 -0
  307. package/src/hooks/events/useEventComposer.ts +194 -0
  308. package/src/hooks/events/useEventForm.ts +191 -0
  309. package/src/hooks/events/useEventMenu.ts +68 -0
  310. package/src/hooks/events/useEventRsvp.ts +171 -0
  311. package/src/hooks/events/useEventTypeSwitcher.ts +197 -0
  312. package/src/hooks/events/useEventsCalendar.ts +153 -0
  313. package/src/hooks/groups/useEditGroup.ts +109 -0
  314. package/src/hooks/groups/useGroupTemplateSelection.ts +92 -0
  315. package/src/hooks/groups/useJoinGroup.ts +33 -0
  316. package/src/hooks/groups/useNewGroup.ts +99 -0
  317. package/src/hooks/index.ts +106 -0
  318. package/src/hooks/jams/useCreateNewJamForm.ts +181 -0
  319. package/src/hooks/jams/useJamChat.ts +82 -0
  320. package/src/hooks/jams/useJamDetails.ts +92 -0
  321. package/src/hooks/jams/useJamFooterControls.ts +127 -0
  322. package/src/hooks/jams/useJamLobby.ts +79 -0
  323. package/src/hooks/jams/useJamParticipant.ts +72 -0
  324. package/src/hooks/jams/useJamPeople.ts +84 -0
  325. package/src/hooks/jams/useJamRoom.ts +279 -0
  326. package/src/hooks/jams/useJamStage.ts +69 -0
  327. package/src/hooks/jams/useLeaveCloseJam.ts +78 -0
  328. package/src/hooks/posts/replyOpener.tsx +27 -0
  329. package/src/hooks/posts/useArticleComposer.ts +127 -0
  330. package/src/hooks/posts/useFeedPostActions.ts +84 -0
  331. package/src/hooks/posts/useFeedPostPresentation.ts +60 -0
  332. package/src/hooks/posts/usePostDetailTitle.ts +37 -0
  333. package/src/hooks/posts/usePostThreads.ts +28 -0
  334. package/src/hooks/posts/useShareMenu.ts +29 -0
  335. package/src/hooks/profile/useFollowProfile.ts +32 -0
  336. package/src/hooks/settings/useAccessTokens.ts +175 -0
  337. package/src/hooks/settings/useFeedFormatPreference.ts +38 -0
  338. package/src/hooks/settings/useLanguagePreference.ts +60 -0
  339. package/src/hooks/settings/useNotificationPreferences.ts +102 -0
  340. package/src/hooks/settings/usePushEnabledDevices.ts +83 -0
  341. package/src/hooks/settings/useThemePreference.ts +31 -0
  342. package/src/hooks/settings/useTimezonePreference.ts +63 -0
  343. package/src/hooks/useResolvedFeedFormat.ts +35 -0
  344. package/src/i18n/I18nProvider.tsx +63 -0
  345. package/src/i18n/context.ts +19 -0
  346. package/src/i18n/index.ts +71 -0
  347. package/src/index.ts +19 -0
  348. package/src/lib/Markdown.tsx +29 -0
  349. package/src/lib/analyticsClicks.ts +70 -0
  350. package/src/lib/apiErrorMessage.ts +21 -0
  351. package/src/lib/audienceChoices.ts +81 -0
  352. package/src/lib/audienceSetting.ts +29 -0
  353. package/src/lib/auth.ts +74 -0
  354. package/src/lib/canvasUtils.ts +228 -0
  355. package/src/lib/capabilityMatrix.ts +490 -0
  356. package/src/lib/configuration/helpers.ts +149 -0
  357. package/src/lib/configuration/resolveSchema.ts +18 -0
  358. package/src/lib/groupCapabilityMatrix.ts +73 -0
  359. package/src/lib/groupFormErrors.ts +93 -0
  360. package/src/lib/initialsAvatar.ts +27 -0
  361. package/src/lib/notificationBadge.ts +70 -0
  362. package/src/lib/passwordStrength.ts +21 -0
  363. package/src/lib/postUnread.ts +17 -0
  364. package/src/lib/postViewCounter.tsx +246 -0
  365. package/src/lib/reactionEmojis.ts +81 -0
  366. package/src/lib/routeHandles.ts +3 -0
  367. package/src/lib/svgCover.ts +21 -0
  368. package/src/lib/threadHelpers.ts +30 -0
  369. package/src/lib/unseenCountsOptimistic.ts +77 -0
  370. package/src/log/index.ts +15 -0
  371. package/src/navigation/index.ts +13 -0
  372. package/src/navigation/menuItems.ts +100 -0
  373. package/src/navigation/targets.ts +70 -0
  374. package/src/pages/About.tsx +52 -0
  375. package/src/pages/CodeOfConduct.tsx +48 -0
  376. package/src/pages/Explore.tsx +361 -0
  377. package/src/pages/Home.tsx +43 -0
  378. package/src/pages/Members.tsx +79 -0
  379. package/src/pages/NotFound.tsx +20 -0
  380. package/src/pages/Notifications.tsx +16 -0
  381. package/src/pages/PostDetail.tsx +35 -0
  382. package/src/pages/Profile.tsx +78 -0
  383. package/src/pages/Tags.tsx +91 -0
  384. package/src/pages/Welcome.tsx +218 -0
  385. package/src/pages/admin/Analytics.tsx +12 -0
  386. package/src/pages/admin/ApiKeys.tsx +401 -0
  387. package/src/pages/admin/Backups.tsx +127 -0
  388. package/src/pages/admin/ConfigEditor.tsx +193 -0
  389. package/src/pages/admin/Configuration.tsx +69 -0
  390. package/src/pages/admin/ConfigurationCommunity.tsx +63 -0
  391. package/src/pages/admin/ConfigurationCommunityFeed.tsx +134 -0
  392. package/src/pages/admin/ConfigurationCommunityLanguage.tsx +132 -0
  393. package/src/pages/admin/ConfigurationCommunityTimezone.tsx +119 -0
  394. package/src/pages/admin/ConfigurationEmail.tsx +357 -0
  395. package/src/pages/admin/ConfigurationI18n.tsx +194 -0
  396. package/src/pages/admin/ConfigurationPluginPage.tsx +34 -0
  397. package/src/pages/admin/ConfigurationSso.tsx +290 -0
  398. package/src/pages/admin/ConfigurationSsoNew.tsx +103 -0
  399. package/src/pages/admin/Dashboard.tsx +316 -0
  400. package/src/pages/admin/Db.tsx +607 -0
  401. package/src/pages/admin/Diagnostics.tsx +25 -0
  402. package/src/pages/admin/DiagnosticsEmail.tsx +202 -0
  403. package/src/pages/admin/DiagnosticsJob.tsx +173 -0
  404. package/src/pages/admin/DiagnosticsLogs.tsx +206 -0
  405. package/src/pages/admin/DiagnosticsPerformance.tsx +120 -0
  406. package/src/pages/admin/GroupMembers.tsx +244 -0
  407. package/src/pages/admin/Groups.tsx +159 -0
  408. package/src/pages/admin/Invites.tsx +268 -0
  409. package/src/pages/admin/MemberDetail.tsx +189 -0
  410. package/src/pages/admin/Members.tsx +186 -0
  411. package/src/pages/admin/Moderation.tsx +191 -0
  412. package/src/pages/admin/Plugins.tsx +510 -0
  413. package/src/pages/admin/Reports.tsx +470 -0
  414. package/src/pages/admin/analytics/AnalyticsLayout.tsx +259 -0
  415. package/src/pages/admin/analytics/AnalyticsRangeContext.tsx +21 -0
  416. package/src/pages/admin/analytics/Content.tsx +302 -0
  417. package/src/pages/admin/analytics/Engagement.tsx +407 -0
  418. package/src/pages/admin/analytics/Groups.tsx +289 -0
  419. package/src/pages/admin/analytics/Members.tsx +264 -0
  420. package/src/pages/admin/analytics/Overview.tsx +397 -0
  421. package/src/pages/admin/analytics/PluginPage.tsx +40 -0
  422. package/src/pages/admin/analytics/ReportSettings.tsx +118 -0
  423. package/src/pages/admin/analytics/analyticsInfo.tsx +10 -0
  424. package/src/pages/admin/analytics/analyticsPluginTabs.ts +31 -0
  425. package/src/pages/admin/analytics/downloadCsv.ts +27 -0
  426. package/src/pages/admin/community/CommunityFavicons.tsx +99 -0
  427. package/src/pages/admin/community/CommunityInfo.tsx +138 -0
  428. package/src/pages/admin/community/CommunityLinks.tsx +126 -0
  429. package/src/pages/admin/community/CommunityMarkdownPage.tsx +80 -0
  430. package/src/pages/admin/community/CommunityProfileFields.tsx +124 -0
  431. package/src/pages/admin/community/CommunityRoles.tsx +355 -0
  432. package/src/pages/admin/community/CommunityTheme.tsx +307 -0
  433. package/src/pages/admin/community/useCommunityConfig.ts +39 -0
  434. package/src/pages/admin/components/AdminCharts.tsx +122 -0
  435. package/src/pages/admin/components/AdminGroupCard.tsx +127 -0
  436. package/src/pages/admin/components/AdminInviteActions.tsx +60 -0
  437. package/src/pages/admin/components/InviteWithEmailModal.tsx +216 -0
  438. package/src/pages/admin/components/InviteWithLinkModal.tsx +320 -0
  439. package/src/pages/admin/components/ProfileRowActions.tsx +365 -0
  440. package/src/pages/admin/components/RestoreBackupModal.tsx +79 -0
  441. package/src/pages/admin/components/RestoreTestBackupModal.tsx +76 -0
  442. package/src/pages/admin/components/ServerStatusSection.tsx +134 -0
  443. package/src/pages/admin/components/inviteQr.ts +94 -0
  444. package/src/pages/admin/components/serverStatusFormat.ts +31 -0
  445. package/src/pages/admin/configurationPluginPages.ts +34 -0
  446. package/src/pages/admin/configurationSsoShared.tsx +476 -0
  447. package/src/pages/articles/Edit.tsx +74 -0
  448. package/src/pages/articles/Index.tsx +30 -0
  449. package/src/pages/articles/New.tsx +53 -0
  450. package/src/pages/auth/Closed.tsx +40 -0
  451. package/src/pages/auth/Login.tsx +316 -0
  452. package/src/pages/auth/OidcCallback.tsx +51 -0
  453. package/src/pages/auth/OidcPending.tsx +62 -0
  454. package/src/pages/auth/Register.tsx +409 -0
  455. package/src/pages/auth/RegisterInvitation.tsx +5 -0
  456. package/src/pages/auth/RequestResetPassword.tsx +113 -0
  457. package/src/pages/auth/ResetPassword.tsx +91 -0
  458. package/src/pages/auth/SsoCallback.tsx +55 -0
  459. package/src/pages/auth/ValidateEmail.tsx +91 -0
  460. package/src/pages/conversations/Index.tsx +230 -0
  461. package/src/pages/conversations/Info.tsx +159 -0
  462. package/src/pages/conversations/New.tsx +14 -0
  463. package/src/pages/conversations/Show.tsx +238 -0
  464. package/src/pages/events/Edit.tsx +82 -0
  465. package/src/pages/events/Index.tsx +98 -0
  466. package/src/pages/events/My.tsx +71 -0
  467. package/src/pages/events/New.tsx +54 -0
  468. package/src/pages/feeds/Bookmarks.tsx +17 -0
  469. package/src/pages/feeds/Local.tsx +34 -0
  470. package/src/pages/feeds/My.tsx +21 -0
  471. package/src/pages/groups/Edit.tsx +67 -0
  472. package/src/pages/groups/EditInfo.tsx +69 -0
  473. package/src/pages/groups/EditRoles.tsx +81 -0
  474. package/src/pages/groups/Index.tsx +150 -0
  475. package/src/pages/groups/Info.tsx +70 -0
  476. package/src/pages/groups/Members.tsx +47 -0
  477. package/src/pages/groups/New.tsx +72 -0
  478. package/src/pages/groups/Show.tsx +242 -0
  479. package/src/pages/index.ts +108 -0
  480. package/src/pages/jams/Event.tsx +95 -0
  481. package/src/pages/jams/Index.tsx +126 -0
  482. package/src/pages/payment/Success.tsx +49 -0
  483. package/src/pages/plugins/Index.tsx +135 -0
  484. package/src/pages/profile/Followers.tsx +60 -0
  485. package/src/pages/settings/AccessTokens.tsx +266 -0
  486. package/src/pages/settings/Account.tsx +223 -0
  487. package/src/pages/settings/Billing.tsx +178 -0
  488. package/src/pages/settings/Blocked.tsx +83 -0
  489. package/src/pages/settings/Feed.tsx +78 -0
  490. package/src/pages/settings/Index.tsx +77 -0
  491. package/src/pages/settings/Language.tsx +70 -0
  492. package/src/pages/settings/NotificationPreferences.tsx +300 -0
  493. package/src/pages/settings/Notifications.tsx +32 -0
  494. package/src/pages/settings/PublicProfile.tsx +265 -0
  495. package/src/pages/settings/PushEnabledDevices.tsx +139 -0
  496. package/src/pages/settings/Theme.tsx +61 -0
  497. package/src/pages/settings/Timezone.tsx +60 -0
  498. package/src/pages/test/Error.tsx +20 -0
  499. package/src/pages/test/Markdown.tsx +37 -0
  500. package/src/push/index.ts +12 -0
  501. package/src/push/usePushSubscription.tsx +131 -0
  502. package/src/push/vapid.ts +25 -0
  503. package/src/push/webPush.ts +190 -0
  504. package/src/pwa/InstallPrompt.tsx +43 -0
  505. package/src/pwa/NotificationPermissionPrompt.tsx +100 -0
  506. package/src/pwa/PwaProvider.tsx +91 -0
  507. package/src/pwa/UpdatePrompt.tsx +46 -0
  508. package/src/pwa/index.ts +33 -0
  509. package/src/pwa/pageReload.ts +43 -0
  510. package/src/pwa/pushInvalidate.ts +47 -0
  511. package/src/pwa/registration.ts +116 -0
  512. package/src/pwa/staleAppReload.ts +171 -0
  513. package/src/pwa/useInstallPrompt.ts +65 -0
  514. package/src/pwa/useNotificationBadgeSync.ts +36 -0
  515. package/src/pwa/useServiceWorker.ts +93 -0
  516. package/src/pwa/vite.ts +107 -0
  517. package/src/react-native.ts +143 -0
  518. package/src/session/useSessionEvents.ts +81 -0
  519. package/src/setupTests.ts +5 -0
  520. package/src/stores/breadcrumbs.ts +8 -0
  521. package/src/stores/createStore.ts +76 -0
  522. package/src/stores/eventView.ts +21 -0
  523. package/src/stores/feedFormat.ts +19 -0
  524. package/src/stores/index.ts +46 -0
  525. package/src/stores/newPosts.ts +241 -0
  526. package/src/stores/pageHeader.ts +30 -0
  527. package/src/stores/plusButton.ts +17 -0
  528. package/src/stores/types.ts +43 -0
  529. package/src/streaming.ts +10 -0
  530. package/src/types/index.ts +0 -0
@@ -0,0 +1,312 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import { Pencil, X } from 'lucide-react';
3
+ import type { MediaAttachment, MediaAttachmentData } from '@openpeepshq/common';
4
+ import { useOpenpeeps } from '../../../contexts/openpeeps';
5
+ import { useT } from '../../../i18n';
6
+ import { DescriptionEditModal } from './DescriptionEditModal';
7
+ import { VideoPlayOverlay } from '../VideoPlayOverlay';
8
+ import { isBlobUrl, resolveAttachmentPreviewUrl } from '../attachmentPreview';
9
+ import { AudioAttachment } from '../pieces/AudioAttachment';
10
+
11
+ export interface ComposeItem {
12
+ key: string;
13
+ /** Local file pending upload; cleared once the server returns an attachment. */
14
+ file?: File;
15
+ usage: string;
16
+ description?: string;
17
+ /** Local blob preview shown during upload (images/videos). */
18
+ previewUrl?: string;
19
+ /** Server attachment once uploaded (carries `id`/`status` for processing). */
20
+ attachment?: MediaAttachmentData;
21
+ failed?: boolean;
22
+ error?: string;
23
+ }
24
+
25
+ export interface AttachmentCardProps {
26
+ item: ComposeItem;
27
+ onUploaded: (key: string, attachment: MediaAttachment) => void;
28
+ onProcessed: (key: string, attachment: MediaAttachmentData) => void;
29
+ onFailed: (key: string, error?: string) => void;
30
+ onRemove: (key: string) => void;
31
+ onUpdate: (key: string, attachment: MediaAttachmentData) => void;
32
+ }
33
+
34
+ const PIE = { cx: 18, cy: 18, r: 16 } as const;
35
+
36
+ const piePath = (percent: number): string => {
37
+ const p = Math.max(0, Math.min(100, percent));
38
+ if (p <= 0) return '';
39
+ const { cx, cy, r } = PIE;
40
+ if (p >= 100) {
41
+ return `M ${cx - r},${cy} A ${r},${r} 0 1,0 ${cx + r},${cy} A ${r},${r} 0 1,0 ${cx - r},${cy} Z`;
42
+ }
43
+ const angle = (p / 100) * 2 * Math.PI;
44
+ const endX = cx + r * Math.sin(angle);
45
+ const endY = cy - r * Math.cos(angle);
46
+ const largeArc = p > 50 ? 1 : 0;
47
+ return `M ${cx},${cy} L ${cx},${cy - r} A ${r},${r} 0 ${largeArc},1 ${endX},${endY} Z`;
48
+ };
49
+
50
+ const formatRemaining = (ms: number): string => {
51
+ const totalSeconds = Math.max(1, Math.ceil(ms / 1000));
52
+ const hours = Math.floor(totalSeconds / 3600);
53
+ const minutes = Math.floor((totalSeconds % 3600) / 60);
54
+ const seconds = totalSeconds % 60;
55
+ if (hours > 0) return `${hours}h ${minutes}m`;
56
+ if (minutes > 0) return `${minutes}m ${seconds}s`;
57
+ return `${seconds}s`;
58
+ };
59
+
60
+ const attachmentId = (a?: MediaAttachmentData): string | undefined =>
61
+ (a as MediaAttachment | undefined)?.id;
62
+
63
+ /**
64
+ * A single post-composer attachment, mirroring the Svelte `AttachmentContainer`:
65
+ * shows a pie overlay for the byte-upload phase, then for the server-side
66
+ * processing phase (SSE), a failed state, and finally the preview with a
67
+ * remove affordance.
68
+ */
69
+ export function AttachmentCard({
70
+ item,
71
+ onUploaded,
72
+ onProcessed,
73
+ onFailed,
74
+ onRemove,
75
+ onUpdate,
76
+ }: AttachmentCardProps) {
77
+ const t = useT();
78
+ const { openpeepsApi } = useOpenpeeps();
79
+ const { state, upload, abort } = openpeepsApi.useMediaUpload();
80
+ const [editing, setEditing] = useState(false);
81
+
82
+ const att = item.attachment;
83
+ const uploading = !!item.file && !att && !item.failed;
84
+ const processing = !item.failed && att?.status === 'processing';
85
+ const failed = !!item.failed;
86
+ const showOverlay = uploading || processing;
87
+ const showEdit = !showOverlay && !failed && !!att;
88
+
89
+ // Abort an in-flight byte upload if the card unmounts (e.g. the composer is
90
+ // dismissed) so the request doesn't linger, mirroring the Svelte
91
+ // `abortUploadsForAttachments` onDestroy cleanup.
92
+ const abortRef = useRef(abort);
93
+ abortRef.current = abort;
94
+ useEffect(() => () => abortRef.current(), []);
95
+
96
+ // --- Upload phase: run the byte transfer once, report up. -----------------
97
+ const startedRef = useRef(false);
98
+ useEffect(() => {
99
+ if (startedRef.current || !item.file) return;
100
+ startedRef.current = true;
101
+ upload({
102
+ file: item.file,
103
+ usage: item.usage,
104
+ description: item.description ?? item.file.name,
105
+ })
106
+ .then((attachment) => onUploaded(item.key, attachment))
107
+ .catch((err) =>
108
+ onFailed(item.key, err instanceof Error ? err.message : undefined),
109
+ );
110
+ // eslint-disable-next-line react-hooks/exhaustive-deps
111
+ }, [item.file]);
112
+
113
+ // --- Processing phase: subscribe to the SSE feed while processing. --------
114
+ const processingId = processing ? attachmentId(att) : undefined;
115
+ const event = openpeepsApi.useMediaProgress(processingId);
116
+ const reportedRef = useRef<string | undefined>(undefined);
117
+ useEffect(() => {
118
+ const data = event?.mediaAttachment;
119
+ if (!data || !processingId) return;
120
+ if (data.status === 'processing') return;
121
+ if (reportedRef.current === processingId) return;
122
+ reportedRef.current = processingId;
123
+ if (data.status === 'failed') {
124
+ onFailed(item.key, data.error);
125
+ } else {
126
+ onProcessed(item.key, { ...att, ...data, type: att?.type ?? data.type });
127
+ }
128
+ // eslint-disable-next-line react-hooks/exhaustive-deps
129
+ }, [event?.mediaAttachment?.status, processingId]);
130
+
131
+ const piePercent = uploading
132
+ ? Math.max(0, Math.min(100, state.uploadPercent))
133
+ : Math.min(95, Math.max(0, event?.progressPercent ?? 0));
134
+ const etaMs = uploading
135
+ ? state.uploadEstimatedRemainingMs
136
+ : event?.estimatedRemainingMs;
137
+ const phaseLabel = uploading
138
+ ? t('form.upload.uploading', { defaultValue: 'Uploading' })
139
+ : t('form.upload.processing', { defaultValue: 'Processing' });
140
+
141
+ const remove = () => {
142
+ abort();
143
+ onRemove(item.key);
144
+ };
145
+
146
+ const previewUrl = resolveAttachmentPreviewUrl(item.previewUrl, att);
147
+ const isImage =
148
+ (att?.type ?? (item.file?.type.startsWith('image/') ? 'image' : '')) ===
149
+ 'image';
150
+ const isVideo =
151
+ (att?.type ?? (item.file?.type.startsWith('video/') ? 'video' : '')) ===
152
+ 'video';
153
+ const isAudio =
154
+ att?.type === 'audio' ||
155
+ !!att?.meta?.mimetype?.startsWith('audio/') ||
156
+ !!item.file?.type.startsWith('audio/') ||
157
+ item.usage === 'post-audio';
158
+ const editLabel = t('posts.attachments.editTitle', {
159
+ defaultValue: 'Edit description',
160
+ });
161
+ const deleteLabel = t('posts.attachments.deleteTitle', {
162
+ defaultValue: 'Delete attachment',
163
+ });
164
+
165
+ return (
166
+ <div
167
+ className={
168
+ isAudio
169
+ ? `relative col-span-2 w-full ${
170
+ showOverlay || failed ? 'min-h-24' : ''
171
+ }`
172
+ : 'relative aspect-square w-full overflow-hidden rounded-md border'
173
+ }
174
+ >
175
+ {!failed ? (
176
+ <div
177
+ className={
178
+ isAudio
179
+ ? 'absolute right-1.5 top-1.5 z-20 flex gap-1'
180
+ : 'absolute right-1 top-1 z-20 flex gap-1'
181
+ }
182
+ >
183
+ {showEdit ? (
184
+ <button
185
+ type="button"
186
+ title={editLabel}
187
+ aria-label={editLabel}
188
+ onClick={() => setEditing(true)}
189
+ className="bg-background/80 rounded-full p-1"
190
+ >
191
+ <Pencil className="size-4" aria-hidden="true" />
192
+ <span className="sr-only">{editLabel}</span>
193
+ </button>
194
+ ) : null}
195
+ <button
196
+ type="button"
197
+ title={deleteLabel}
198
+ aria-label={deleteLabel}
199
+ onClick={remove}
200
+ className="bg-background/80 rounded-full p-1"
201
+ >
202
+ <X className="size-4" aria-hidden="true" />
203
+ <span className="sr-only">{deleteLabel}</span>
204
+ </button>
205
+ </div>
206
+ ) : null}
207
+
208
+ {showEdit && att ? (
209
+ <DescriptionEditModal
210
+ attachment={att}
211
+ open={editing}
212
+ onClose={() => setEditing(false)}
213
+ onSave={(description) => onUpdate(item.key, { ...att, description })}
214
+ />
215
+ ) : null}
216
+
217
+ {showOverlay ? (
218
+ <div
219
+ data-testid="attachment-progress"
220
+ className="bg-foreground absolute inset-0 z-10 flex flex-col items-center justify-center gap-1 text-white"
221
+ >
222
+ <svg
223
+ viewBox="0 0 36 36"
224
+ className="h-16 w-16"
225
+ role="progressbar"
226
+ aria-valuemin={0}
227
+ aria-valuemax={100}
228
+ aria-valuenow={Math.round(piePercent)}
229
+ >
230
+ <circle
231
+ cx={PIE.cx}
232
+ cy={PIE.cy}
233
+ r={PIE.r}
234
+ fill="rgba(255,255,255,0.25)"
235
+ />
236
+ {piePath(piePercent) ? (
237
+ <path d={piePath(piePercent)} fill="white" />
238
+ ) : null}
239
+ <text
240
+ x={PIE.cx}
241
+ y={PIE.cy + 1}
242
+ textAnchor="middle"
243
+ dominantBaseline="middle"
244
+ fontSize="8"
245
+ fontWeight="600"
246
+ fill="rgb(30 41 59)"
247
+ >
248
+ {Math.round(piePercent)}%
249
+ </text>
250
+ </svg>
251
+ <span className="text-xs font-medium uppercase tracking-wide">
252
+ {phaseLabel}
253
+ </span>
254
+ {etaMs !== undefined && etaMs > 1000 ? (
255
+ <span className="text-xs opacity-80">
256
+ ~{formatRemaining(etaMs)}
257
+ </span>
258
+ ) : null}
259
+ </div>
260
+ ) : null}
261
+
262
+ {failed ? (
263
+ <div
264
+ data-testid="attachment-failed"
265
+ className="bg-error absolute inset-0 z-30 flex flex-col items-center justify-center gap-2 text-white"
266
+ >
267
+ <span className="text-sm font-semibold">
268
+ {t('posts.attachments.failed', { defaultValue: 'Upload failed' })}
269
+ </span>
270
+ <button
271
+ type="button"
272
+ onClick={remove}
273
+ title={t('posts.attachments.deleteTitle', {
274
+ defaultValue: 'Delete attachment',
275
+ })}
276
+ className="bg-background text-destructive hover:bg-surface rounded-full p-3"
277
+ >
278
+ <X className="size-8" />
279
+ </button>
280
+ </div>
281
+ ) : null}
282
+
283
+ {showOverlay || failed ? (
284
+ <div
285
+ className={isAudio ? 'h-24 w-full' : 'bg-surface-2 h-full w-full'}
286
+ />
287
+ ) : isImage || isVideo ? (
288
+ <div className="relative h-full w-full">
289
+ <img
290
+ src={previewUrl}
291
+ alt={att?.description ?? ''}
292
+ className="h-full w-full object-cover"
293
+ />
294
+ <VideoPlayOverlay video={isVideo} />
295
+ </div>
296
+ ) : isAudio ? (
297
+ <AudioAttachment
298
+ src={isBlobUrl(item.previewUrl) ? item.previewUrl : att?.url}
299
+ label={att?.filename ?? item.file?.name ?? att?.description}
300
+ size={att?.meta?.size ?? item.file?.size}
301
+ reserveEnd
302
+ />
303
+ ) : (
304
+ <div className="flex h-full w-full items-center justify-center p-2">
305
+ <p className="truncate text-xs">
306
+ {att?.filename ?? item.file?.name ?? 'File'}
307
+ </p>
308
+ </div>
309
+ )}
310
+ </div>
311
+ );
312
+ }
@@ -0,0 +1,327 @@
1
+ import { useEffect, useRef, useState, type ReactNode } from 'react';
2
+ import { AudioLines, Image, Paperclip } from 'lucide-react';
3
+ import type { MediaAttachment, MediaAttachmentData } from '@openpeepshq/common';
4
+ import { useT } from '../../../i18n';
5
+ import { ImageEditModal } from '../../form/ImageEditModal';
6
+ import { convertToWebpIfHeic } from '../../../lib/canvasUtils';
7
+ import { AttachmentCard, type ComposeItem } from './AttachmentCard';
8
+ import { isBlobUrl, revokeBlobUrl } from '../attachmentPreview';
9
+
10
+ export interface ComposeAttachmentsProps {
11
+ attachments: MediaAttachmentData[];
12
+ onChange: (attachments: MediaAttachmentData[]) => void;
13
+ }
14
+
15
+ const AUDIO_NAME = /\.(mp3|wav|ogg|oga|m4a|aac|flac|opus|weba)$/i;
16
+
17
+ const isAudioFile = (file: File): boolean =>
18
+ file.type.startsWith('audio/') || AUDIO_NAME.test(file.name);
19
+
20
+ function usageForFile(file: File): string {
21
+ if (file.type.startsWith('image/')) return 'post-image';
22
+ if (file.type.startsWith('video/') || file.name.endsWith('.mkv'))
23
+ return 'post-video';
24
+ if (isAudioFile(file)) return 'post-audio';
25
+ return 'post-document';
26
+ }
27
+
28
+ const newKey = (): string =>
29
+ typeof crypto !== 'undefined' && 'randomUUID' in crypto
30
+ ? crypto.randomUUID()
31
+ : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
32
+
33
+ const readyItem = (attachment: MediaAttachmentData): ComposeItem => ({
34
+ key: newKey(),
35
+ usage: attachment.meta?.usage ?? 'unknown',
36
+ attachment,
37
+ previewUrl: attachment.previewUrl ?? attachment.url ?? undefined,
38
+ });
39
+
40
+ export interface ComposeAttachmentsApi {
41
+ openImagePicker: () => void;
42
+ openAudioPicker: () => void;
43
+ openDocumentPicker: () => void;
44
+ /** True while any attachment is still uploading or processing. */
45
+ pending: boolean;
46
+ /** Attachment cards — render where the previews should appear. */
47
+ previews: ReactNode;
48
+ /** Hidden file inputs + image cropper — render once anywhere in the tree. */
49
+ inputs: ReactNode;
50
+ }
51
+
52
+ /**
53
+ * Owns the attachment list and its upload lifecycle. Each item is shown
54
+ * immediately as a card with byte-upload and server-processing progress
55
+ * (mirrors the Svelte `Attachments` + `AttachmentContainer`), and only ready
56
+ * attachments are reported back via `onChange`. Exposes the toolbar pickers and
57
+ * preview grid separately so callers can lay them out independently.
58
+ */
59
+ export function useComposeAttachments({
60
+ attachments,
61
+ onChange,
62
+ }: ComposeAttachmentsProps): ComposeAttachmentsApi {
63
+ const imageInputRef = useRef<HTMLInputElement>(null);
64
+ const audioInputRef = useRef<HTMLInputElement>(null);
65
+ const documentInputRef = useRef<HTMLInputElement>(null);
66
+ const [pendingImage, setPendingImage] = useState<{
67
+ file: File;
68
+ previewUrl: string;
69
+ } | null>(null);
70
+
71
+ // `attachments` seeds the list once; thereafter the items are the source of
72
+ // truth (so in-flight upload/processing state isn't clobbered by re-renders).
73
+ const [items, setItems] = useState<ComposeItem[]>(() =>
74
+ attachments.map(readyItem),
75
+ );
76
+
77
+ // Report only ready attachments upward; uploading/processing/failed ones stay
78
+ // local until they resolve (matching the Svelte submit-gating model).
79
+ const onChangeRef = useRef(onChange);
80
+ onChangeRef.current = onChange;
81
+ useEffect(() => {
82
+ const ready = items
83
+ .filter(
84
+ (i) =>
85
+ i.attachment && !i.failed && i.attachment.status !== 'processing',
86
+ )
87
+ .map((i) => i.attachment as MediaAttachmentData);
88
+ onChangeRef.current(ready);
89
+ }, [items]);
90
+
91
+ const enqueue = (
92
+ file: File,
93
+ usage: string,
94
+ description?: string,
95
+ previewUrl?: string,
96
+ ) => {
97
+ setItems((prev) => [
98
+ ...prev,
99
+ { key: newKey(), file, usage, description, previewUrl },
100
+ ]);
101
+ };
102
+
103
+ const enqueueFile = (file: File) => {
104
+ const usage = usageForFile(file);
105
+ const previewUrl =
106
+ file.type.startsWith('image/') ||
107
+ file.type.startsWith('video/') ||
108
+ isAudioFile(file)
109
+ ? URL.createObjectURL(file)
110
+ : undefined;
111
+ enqueue(
112
+ file,
113
+ usage,
114
+ usage === 'post-document' || usage === 'post-audio'
115
+ ? file.name
116
+ : undefined,
117
+ previewUrl,
118
+ );
119
+ };
120
+
121
+ const handleImageSelected = async (file: File) => {
122
+ const processed = await convertToWebpIfHeic(file);
123
+ if (processed.type.startsWith('image/')) {
124
+ setPendingImage({
125
+ file: processed,
126
+ previewUrl: URL.createObjectURL(processed),
127
+ });
128
+ return;
129
+ }
130
+ enqueueFile(processed);
131
+ };
132
+
133
+ const onUploaded = (key: string, attachment: MediaAttachment) =>
134
+ setItems((prev) =>
135
+ prev.map((i) => {
136
+ if (i.key !== key) return i;
137
+ const previewUrl = attachment.previewUrl ?? i.previewUrl;
138
+ if (attachment.previewUrl && isBlobUrl(i.previewUrl)) {
139
+ revokeBlobUrl(i.previewUrl);
140
+ }
141
+ return {
142
+ ...i,
143
+ file: undefined,
144
+ attachment,
145
+ previewUrl,
146
+ };
147
+ }),
148
+ );
149
+
150
+ const onProcessed = (key: string, attachment: MediaAttachmentData) =>
151
+ setItems((prev) =>
152
+ prev.map((i) => {
153
+ if (i.key !== key) return i;
154
+ if (attachment.previewUrl && isBlobUrl(i.previewUrl)) {
155
+ revokeBlobUrl(i.previewUrl);
156
+ }
157
+ return {
158
+ ...i,
159
+ attachment,
160
+ previewUrl: attachment.previewUrl ?? undefined,
161
+ };
162
+ }),
163
+ );
164
+
165
+ const onFailed = (key: string, error?: string) =>
166
+ setItems((prev) =>
167
+ prev.map((i) => (i.key === key ? { ...i, failed: true, error } : i)),
168
+ );
169
+
170
+ const onRemove = (key: string) =>
171
+ setItems((prev) => prev.filter((i) => i.key !== key));
172
+
173
+ const onUpdate = (key: string, attachment: MediaAttachmentData) =>
174
+ setItems((prev) =>
175
+ prev.map((i) => (i.key === key ? { ...i, attachment } : i)),
176
+ );
177
+
178
+ const pending = items.some(
179
+ (i) =>
180
+ (i.file && !i.attachment && !i.failed) ||
181
+ i.attachment?.status === 'processing',
182
+ );
183
+
184
+ const previews =
185
+ items.length > 0 ? (
186
+ <div className="grid grid-cols-2 gap-2">
187
+ {items.map((item) => (
188
+ <AttachmentCard
189
+ key={item.key}
190
+ item={item}
191
+ onUploaded={onUploaded}
192
+ onProcessed={onProcessed}
193
+ onFailed={onFailed}
194
+ onRemove={onRemove}
195
+ onUpdate={onUpdate}
196
+ />
197
+ ))}
198
+ </div>
199
+ ) : null;
200
+
201
+ const inputs = (
202
+ <>
203
+ <input
204
+ ref={imageInputRef}
205
+ type="file"
206
+ accept="image/*,video/*,.mkv"
207
+ className="hidden"
208
+ onChange={(e) => {
209
+ const file = e.target.files?.[0];
210
+ if (file) void handleImageSelected(file);
211
+ e.target.value = '';
212
+ }}
213
+ />
214
+ <input
215
+ ref={audioInputRef}
216
+ type="file"
217
+ accept="audio/*,.mp3,.wav,.ogg,.m4a,.aac,.flac,.opus,.weba"
218
+ multiple
219
+ className="hidden"
220
+ onChange={(e) => {
221
+ const files = e.target.files;
222
+ if (files) {
223
+ Array.from(files).forEach((file) => enqueueFile(file));
224
+ }
225
+ e.target.value = '';
226
+ }}
227
+ />
228
+ <input
229
+ ref={documentInputRef}
230
+ type="file"
231
+ accept=".pdf,.doc,.docx,.txt,.md,.csv"
232
+ className="hidden"
233
+ onChange={(e) => {
234
+ const file = e.target.files?.[0];
235
+ if (file) enqueueFile(file);
236
+ e.target.value = '';
237
+ }}
238
+ />
239
+ {pendingImage ? (
240
+ <ImageEditModal
241
+ file={pendingImage.file}
242
+ previewUrl={pendingImage.previewUrl}
243
+ open
244
+ onClose={() => {
245
+ URL.revokeObjectURL(pendingImage.previewUrl);
246
+ setPendingImage(null);
247
+ }}
248
+ onConfirm={(file, description) => {
249
+ URL.revokeObjectURL(pendingImage.previewUrl);
250
+ setPendingImage(null);
251
+ enqueue(file, 'post-image', description, URL.createObjectURL(file));
252
+ }}
253
+ />
254
+ ) : null}
255
+ </>
256
+ );
257
+
258
+ return {
259
+ openImagePicker: () => imageInputRef.current?.click(),
260
+ openAudioPicker: () => audioInputRef.current?.click(),
261
+ openDocumentPicker: () => documentInputRef.current?.click(),
262
+ pending,
263
+ previews,
264
+ inputs,
265
+ };
266
+ }
267
+
268
+ export function ComposeAttachments(props: ComposeAttachmentsProps) {
269
+ const t = useT();
270
+ const {
271
+ openImagePicker,
272
+ openAudioPicker,
273
+ openDocumentPicker,
274
+ previews,
275
+ inputs,
276
+ } = useComposeAttachments(props);
277
+
278
+ const addImageLabel = t('posts.form.addImage', {
279
+ defaultValue: 'Add image or video',
280
+ });
281
+ const addAudioLabel = t('posts.form.addAudio', {
282
+ defaultValue: 'Add audio',
283
+ });
284
+ const addDocumentLabel = t('posts.form.addDocument', {
285
+ defaultValue: 'Add document',
286
+ });
287
+
288
+ return (
289
+ <div className="space-y-2">
290
+ <div className="flex items-center gap-2">
291
+ <button
292
+ type="button"
293
+ title={addImageLabel}
294
+ aria-label={addImageLabel}
295
+ onClick={openImagePicker}
296
+ className="hover:bg-surface rounded-button p-2"
297
+ >
298
+ <Image className="size-5" aria-hidden="true" />
299
+ <span className="sr-only">{addImageLabel}</span>
300
+ </button>
301
+ <button
302
+ type="button"
303
+ title={addAudioLabel}
304
+ aria-label={addAudioLabel}
305
+ onClick={openAudioPicker}
306
+ className="hover:bg-surface rounded-button p-2"
307
+ >
308
+ <AudioLines className="size-5" aria-hidden="true" />
309
+ <span className="sr-only">{addAudioLabel}</span>
310
+ </button>
311
+ <button
312
+ type="button"
313
+ title={addDocumentLabel}
314
+ aria-label={addDocumentLabel}
315
+ onClick={openDocumentPicker}
316
+ className="hover:bg-surface rounded-button p-2"
317
+ >
318
+ <Paperclip className="size-5" aria-hidden="true" />
319
+ <span className="sr-only">{addDocumentLabel}</span>
320
+ </button>
321
+ </div>
322
+
323
+ {previews}
324
+ {inputs}
325
+ </div>
326
+ );
327
+ }
@@ -0,0 +1,19 @@
1
+ import { extractUrlsFromText } from '../../preview-link/helpers';
2
+ import { PreviewLink } from '../../preview-link/PreviewLink';
3
+
4
+ export interface ComposePreviewLinksProps {
5
+ content?: string;
6
+ }
7
+
8
+ export function ComposePreviewLinks({ content }: ComposePreviewLinksProps) {
9
+ const urls = extractUrlsFromText(content);
10
+ if (urls.length === 0) return null;
11
+
12
+ return (
13
+ <div className="my-2 min-w-0 space-y-2">
14
+ {urls.map((url) => (
15
+ <PreviewLink key={url} url={url.replace(/[),.]+$/, '')} />
16
+ ))}
17
+ </div>
18
+ );
19
+ }