@openpeepshq/react 0.7.1 → 0.8.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 (86) hide show
  1. package/dist/components/markdown/compileMarkdown.js +1 -0
  2. package/dist/components/navigation/FooterMobile.js +4 -3
  3. package/dist/components/navigation/HeaderMobile.js +5 -2
  4. package/dist/components/navigation/MobileMenuItem.d.ts +3 -1
  5. package/dist/components/navigation/MobileMenuItem.js +7 -2
  6. package/dist/components/navigation/NavWithTooltip.d.ts +9 -0
  7. package/dist/components/navigation/NavWithTooltip.js +4 -0
  8. package/dist/components/navigation/index.d.ts +2 -0
  9. package/dist/components/navigation/index.js +1 -0
  10. package/dist/components/navigation/sideBarNavLinkClass.d.ts +6 -4
  11. package/dist/components/navigation/sideBarNavLinkClass.js +6 -2
  12. package/dist/components/post/CompactReplyParent.js +5 -6
  13. package/dist/components/post/TruncatedMarkdown.d.ts +27 -0
  14. package/dist/components/post/TruncatedMarkdown.js +37 -0
  15. package/dist/components/post/helpers.d.ts +2 -2
  16. package/dist/components/post/helpers.js +3 -16
  17. package/dist/components/post/index.d.ts +2 -0
  18. package/dist/components/post/index.js +1 -0
  19. package/dist/components/post/pieces/EventLocation.js +14 -0
  20. package/dist/components/post/pieces/EventRsvpButton.js +3 -1
  21. package/dist/components/post/pieces/PollContent.js +8 -2
  22. package/dist/components/post/post-form/ArticleForm.js +1 -1
  23. package/dist/components/post/post-form/EventForm.js +23 -3
  24. package/dist/components/post/post-form/ResourceForm.d.ts +3 -1
  25. package/dist/components/post/post-form/ResourceForm.js +48 -7
  26. package/dist/components/post/post-form/VisibilitySelector.js +9 -3
  27. package/dist/components/post/types/Article.js +2 -3
  28. package/dist/components/post/types/Event.js +10 -1
  29. package/dist/components/post/types/resource/FullResource.js +3 -3
  30. package/dist/components/preview-link/local/WelcomePreview.js +4 -2
  31. package/dist/components/resources/ResourceCard.d.ts +5 -1
  32. package/dist/components/resources/ResourceCard.js +29 -5
  33. package/dist/components/resources/ResourceCard.test.d.ts +1 -0
  34. package/dist/components/resources/ResourceCard.test.js +75 -0
  35. package/dist/components/resources/ResourceLibrary.js +1 -1
  36. package/dist/hooks/events/useEventRsvp.d.ts +1 -0
  37. package/dist/hooks/events/useEventRsvp.js +15 -7
  38. package/dist/hooks/posts/useResourceComposer.d.ts +2 -0
  39. package/dist/hooks/posts/useResourceComposer.js +131 -25
  40. package/dist/hooks/resources/useResourceLibrary.d.ts +1 -1
  41. package/dist/hooks/resources/useResourceLibrary.js +6 -2
  42. package/dist/hooks/useWelcomePreview.d.ts +3 -0
  43. package/dist/hooks/useWelcomePreview.js +1 -0
  44. package/dist/navigation/menuItems.js +15 -0
  45. package/dist/navigation/targets.d.ts +2 -0
  46. package/dist/pages/admin/community/CommunityMarkdownPage.js +2 -1
  47. package/dist/pages/auth/Register.js +3 -1
  48. package/dist/pages/resources/Edit.js +3 -3
  49. package/dist/pages/resources/New.js +2 -2
  50. package/dist/pages/settings/Account.js +30 -2
  51. package/package.json +2 -2
  52. package/src/components/markdown/compileMarkdown.ts +1 -0
  53. package/src/components/navigation/FooterMobile.tsx +41 -33
  54. package/src/components/navigation/HeaderMobile.tsx +55 -41
  55. package/src/components/navigation/MobileMenuItem.tsx +15 -2
  56. package/src/components/navigation/NavWithTooltip.tsx +26 -0
  57. package/src/components/navigation/index.ts +2 -0
  58. package/src/components/navigation/sideBarNavLinkClass.ts +9 -6
  59. package/src/components/post/CompactReplyParent.tsx +17 -10
  60. package/src/components/post/TruncatedMarkdown.tsx +91 -0
  61. package/src/components/post/helpers.ts +4 -18
  62. package/src/components/post/index.ts +2 -0
  63. package/src/components/post/pieces/EventLocation.tsx +27 -0
  64. package/src/components/post/pieces/EventRsvpButton.tsx +3 -0
  65. package/src/components/post/pieces/PollContent.tsx +8 -2
  66. package/src/components/post/post-form/ArticleForm.tsx +1 -1
  67. package/src/components/post/post-form/EventForm.tsx +43 -15
  68. package/src/components/post/post-form/ResourceForm.tsx +132 -4
  69. package/src/components/post/post-form/VisibilitySelector.tsx +11 -3
  70. package/src/components/post/types/Article.tsx +5 -5
  71. package/src/components/post/types/Event.tsx +68 -7
  72. package/src/components/post/types/resource/FullResource.tsx +9 -1
  73. package/src/components/preview-link/local/WelcomePreview.tsx +11 -2
  74. package/src/components/resources/ResourceCard.tsx +68 -10
  75. package/src/components/resources/ResourceLibrary.tsx +2 -2
  76. package/src/hooks/events/useEventRsvp.ts +19 -7
  77. package/src/hooks/posts/useResourceComposer.ts +157 -33
  78. package/src/hooks/resources/useResourceLibrary.ts +6 -2
  79. package/src/hooks/useWelcomePreview.ts +4 -0
  80. package/src/navigation/menuItems.ts +16 -0
  81. package/src/navigation/targets.ts +2 -0
  82. package/src/pages/admin/community/CommunityMarkdownPage.tsx +5 -1
  83. package/src/pages/auth/Register.tsx +12 -0
  84. package/src/pages/resources/Edit.tsx +3 -2
  85. package/src/pages/resources/New.tsx +6 -1
  86. package/src/pages/settings/Account.tsx +51 -1
@@ -35,6 +35,7 @@ export const compileMarkdownToHtml = (source, options = {}) => {
35
35
  }
36
36
  if (isExternalLink(cleaned, origin) || opensNewTab) {
37
37
  out += ' target="_blank" rel="noopener noreferrer"';
38
+ out += ' class="external-link"';
38
39
  }
39
40
  out += `>${text}</a>`;
40
41
  return out;
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Bell, Home, Newspaper, PlusSquare, Users } from 'lucide-react';
3
+ import { TooltipProvider } from '@openpeepshq/react-ui';
3
4
  import { MobileMenuItem } from './MobileMenuItem.js';
4
5
  import { useHrefOf } from '../../contexts/router/index.js';
5
6
  import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
@@ -9,7 +10,7 @@ export function FooterMobile({ onNewPost } = {}) {
9
10
  const hrefOf = useHrefOf();
10
11
  const { openpeepsApi } = useOpenpeeps();
11
12
  const notificationStats = openpeepsApi.useCurrentProfileNotificationStats();
12
- return (_jsxs("nav", { "aria-label": t('navigation.primaryMobile', {
13
- defaultValue: 'Primary',
14
- }), className: "bg-surface flex h-20 w-full items-center justify-evenly md:hidden", children: [_jsx(MobileMenuItem, { title: t('navigation.home'), icon: Home, action: hrefOf({ type: 'feed', feed: 'local' }) }), _jsx(MobileMenuItem, { title: t('navigation.myFeed'), icon: Newspaper, action: hrefOf({ type: 'feed', feed: 'my' }) }), _jsx(MobileMenuItem, { title: t('navigation.newPost'), icon: PlusSquare, action: onNewPost ?? hrefOf({ type: 'postNew' }) }), _jsx(MobileMenuItem, { title: t('navigation.groups'), icon: Users, action: hrefOf({ type: 'groups' }) }), _jsx(MobileMenuItem, { title: t('navigation.openNotifications'), icon: Bell, action: hrefOf({ type: 'notifications' }), badge: notificationStats.data?.unseen })] }));
13
+ return (_jsx(TooltipProvider, { delayDuration: 300, children: _jsxs("nav", { "aria-label": t('navigation.primaryMobile', {
14
+ defaultValue: 'Primary',
15
+ }), className: "bg-surface flex h-20 w-full items-center justify-evenly md:hidden", children: [_jsx(MobileMenuItem, { title: t('navigation.home'), tooltip: t('navigation.tooltips.community'), icon: Home, action: hrefOf({ type: 'feed', feed: 'local' }) }), _jsx(MobileMenuItem, { title: t('navigation.myFeed'), tooltip: t('navigation.tooltips.myFeed'), icon: Newspaper, action: hrefOf({ type: 'feed', feed: 'my' }) }), _jsx(MobileMenuItem, { title: t('navigation.newPost'), tooltip: t('navigation.tooltips.newPost'), icon: PlusSquare, action: onNewPost ?? hrefOf({ type: 'postNew' }) }), _jsx(MobileMenuItem, { title: t('navigation.groups'), tooltip: t('navigation.tooltips.groups'), icon: Users, action: hrefOf({ type: 'groups' }) }), _jsx(MobileMenuItem, { title: t('navigation.openNotifications'), tooltip: t('navigation.tooltips.notifications'), icon: Bell, action: hrefOf({ type: 'notifications' }), badge: notificationStats.data?.unseen })] }) }));
15
16
  }
@@ -1,7 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from 'react';
3
3
  import { MessageSquareText, Menu } from 'lucide-react';
4
- import { Dialog, DialogContent, DialogPortal, DialogOverlay, DialogTrigger, } from '@openpeepshq/react-ui';
4
+ import { Dialog, DialogContent, DialogPortal, DialogOverlay, DialogTrigger, TooltipProvider, } from '@openpeepshq/react-ui';
5
+ import { NavWithTooltip } from './NavWithTooltip.js';
5
6
  import { getTheme } from '@openpeepshq/common';
6
7
  import { useServerInfo } from '../server-data/index.js';
7
8
  import { useCurrentProfile, useCurrentProfileSettings, } from '../layout/IdentityContext.js';
@@ -18,13 +19,15 @@ export function HeaderMobile({ avatar, sideBar } = {}) {
18
19
  const t = useT();
19
20
  const [open, setOpen] = useState(false);
20
21
  const menuLabel = t('navigation.openMenu', { defaultValue: 'Open menu' });
22
+ const menuTooltip = t('navigation.tooltips.openMenu');
21
23
  const messagesLabel = t('navigation.openMessages', {
22
24
  defaultValue: 'Open messages',
23
25
  });
26
+ const messagesTooltip = t('navigation.tooltips.openMessages');
24
27
  const logoSmall = getTheme(serverInfo.communityConfig, profileSettings).logoSmall;
25
28
  // Mirror Svelte HeaderMobile: the avatar is the drawer trigger for signed-in
26
29
  // users; guests fall back to a generic menu icon.
27
30
  const trigger = avatar ??
28
31
  (profile ? (_jsx(Avatar, { profile: profile, size: 2.5, borderless: true })) : (_jsx(Menu, { "aria-hidden": "true" })));
29
- return (_jsx("header", { className: "bg-background sticky top-0 z-10 flex px-4 py-2 md:hidden", children: _jsxs("div", { className: "flex w-full items-center justify-between", children: [_jsxs(Dialog, { open: open, onOpenChange: setOpen, children: [_jsx(DialogTrigger, { asChild: true, children: _jsxs("button", { type: "button", title: menuLabel, "aria-label": menuLabel, children: [trigger, _jsx("span", { className: "sr-only", children: menuLabel })] }) }), _jsxs(DialogPortal, { children: [_jsx(DialogOverlay, {}), _jsx(DialogContent, { showCloseButton: false, className: "left-0 top-0 h-screen w-[380px] translate-x-0 translate-y-0 rounded-none border-r p-0", children: _jsx(SidebarNavCloseContext.Provider, { value: () => setOpen(false), children: _jsx(SideBar, { onClose: () => setOpen(false), mainMenu: sideBar?.mainMenu?.(), profileMenu: sideBar?.profileMenu?.() }) }) })] })] }), _jsx("div", { children: logoSmall && (_jsx("a", { href: "/", children: _jsx("img", { src: logoSmall, alt: "logo", className: "h-6 px-4" }) })) }), _jsxs("button", { type: "button", title: messagesLabel, "aria-label": messagesLabel, onClick: () => router.navigate({ type: 'conversation' }), children: [_jsx(MessageSquareText, { "aria-hidden": "true" }), _jsx("span", { className: "sr-only", children: messagesLabel })] })] }) }));
32
+ return (_jsx("header", { className: "bg-background sticky top-0 z-10 flex px-4 py-2 md:hidden", children: _jsx(TooltipProvider, { delayDuration: 300, children: _jsxs("div", { className: "flex w-full items-center justify-between", children: [_jsxs(Dialog, { open: open, onOpenChange: setOpen, children: [_jsx(NavWithTooltip, { label: menuTooltip, side: "bottom", children: _jsx(DialogTrigger, { asChild: true, children: _jsxs("button", { type: "button", title: menuTooltip, "aria-label": menuLabel, children: [trigger, _jsx("span", { className: "sr-only", children: menuLabel })] }) }) }), _jsxs(DialogPortal, { children: [_jsx(DialogOverlay, {}), _jsx(DialogContent, { showCloseButton: false, className: "left-0 top-0 h-screen w-[380px] translate-x-0 translate-y-0 rounded-none border-r p-0", children: _jsx(SidebarNavCloseContext.Provider, { value: () => setOpen(false), children: _jsx(SideBar, { onClose: () => setOpen(false), mainMenu: sideBar?.mainMenu?.(), profileMenu: sideBar?.profileMenu?.() }) }) })] })] }), _jsx("div", { children: logoSmall && (_jsx("a", { href: "/", children: _jsx("img", { src: logoSmall, alt: "logo", className: "h-6 px-4" }) })) }), _jsx(NavWithTooltip, { label: messagesTooltip, side: "bottom", children: _jsxs("button", { type: "button", title: messagesTooltip, "aria-label": messagesLabel, onClick: () => router.navigate({ type: 'conversation' }), children: [_jsx(MessageSquareText, { "aria-hidden": "true" }), _jsx("span", { className: "sr-only", children: messagesLabel })] }) })] }) }) }));
30
33
  }
@@ -3,7 +3,9 @@ export interface MobileMenuItemProps {
3
3
  action: string | (() => unknown);
4
4
  icon: IconType;
5
5
  title?: string;
6
+ /** Describes the action on hover (icon-only mobile footer). */
7
+ tooltip?: string;
6
8
  /** Unread/unseen count shown as a badge on the icon. */
7
9
  badge?: number;
8
10
  }
9
- export declare function MobileMenuItem({ action, icon: Icon, title, badge, }: MobileMenuItemProps): import("react/jsx-runtime").JSX.Element;
11
+ export declare function MobileMenuItem({ action, icon: Icon, title, tooltip, badge, }: MobileMenuItemProps): import("react/jsx-runtime").JSX.Element;
@@ -2,14 +2,19 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { formatBadgeCount } from '@openpeepshq/common';
3
3
  import { cn } from '@openpeepshq/react-ui';
4
4
  import { useRouter } from '../../contexts/router/index.js';
5
- export function MobileMenuItem({ action, icon: Icon, title, badge, }) {
5
+ import { NavWithTooltip } from './NavWithTooltip.js';
6
+ export function MobileMenuItem({ action, icon: Icon, title, tooltip, badge, }) {
6
7
  const router = useRouter();
7
8
  const active = typeof action === 'string' && router.pathname === action;
8
9
  const showBadge = (badge ?? 0) > 0;
9
- return (_jsx("button", { type: "button", title: title, "aria-label": title, className: "relative", onClick: () => {
10
+ const hint = tooltip ?? title;
11
+ const button = (_jsx("button", { type: "button", title: hint, "aria-label": title, className: "relative", onClick: () => {
10
12
  if (typeof action === 'function')
11
13
  action();
12
14
  else
13
15
  router.navigate(action);
14
16
  }, children: _jsxs("span", { className: cn('relative flex items-center gap-x-2', active ? 'text-primary font-bold' : 'text-foreground/70'), children: [_jsx("span", { "aria-hidden": "true", children: _jsx(Icon, { className: "h-5 w-5" }) }), title ? _jsx("span", { className: "sr-only", children: title }) : null, showBadge ? (_jsx("span", { className: "bg-destructive text-destructive-foreground absolute -right-2.5 -top-2 flex size-5 min-w-5 items-center justify-center rounded-full px-1 text-xs font-semibold leading-none", "aria-label": `${badge} unread`, children: formatBadgeCount(badge ?? 0) })) : null] }) }));
17
+ if (!hint)
18
+ return button;
19
+ return (_jsx(NavWithTooltip, { label: hint, side: "top", children: button }));
15
20
  }
@@ -0,0 +1,9 @@
1
+ import type { ReactElement } from 'react';
2
+ export type NavTooltipSide = 'top' | 'bottom' | 'left' | 'right';
3
+ export type NavWithTooltipProps = {
4
+ label: string;
5
+ side?: NavTooltipSide;
6
+ children: ReactElement;
7
+ };
8
+ /** Hover tooltip for a single nav control; wrap the list in `TooltipProvider`. */
9
+ export declare const NavWithTooltip: ({ label, side, children, }: NavWithTooltipProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { TooltipContent, TooltipRoot, TooltipTrigger, } from '@openpeepshq/react-ui';
3
+ /** Hover tooltip for a single nav control; wrap the list in `TooltipProvider`. */
4
+ export const NavWithTooltip = ({ label, side = 'right', children, }) => (_jsxs(TooltipRoot, { children: [_jsx(TooltipTrigger, { asChild: true, children: children }), _jsx(TooltipContent, { side: side, children: label })] }));
@@ -8,6 +8,8 @@ export { FooterMobile } from './FooterMobile';
8
8
  export type { FooterMobileProps } from './FooterMobile';
9
9
  export { MobileMenuItem } from './MobileMenuItem';
10
10
  export type { MobileMenuItemProps } from './MobileMenuItem';
11
+ export { NavWithTooltip } from './NavWithTooltip';
12
+ export type { NavWithTooltipProps, NavTooltipSide } from './NavWithTooltip';
11
13
  export { ContentHeader } from './ContentHeader';
12
14
  export { PageHeaderAction } from './PageHeaderAction';
13
15
  export type { PageHeaderActionProps } from './PageHeaderAction';
@@ -4,6 +4,7 @@ export { SidebarNavCloseContext, useSidebarNavClose, } from './SidebarNavContext
4
4
  export { HeaderMobile } from './HeaderMobile.js';
5
5
  export { FooterMobile } from './FooterMobile.js';
6
6
  export { MobileMenuItem } from './MobileMenuItem.js';
7
+ export { NavWithTooltip } from './NavWithTooltip.js';
7
8
  export { ContentHeader } from './ContentHeader.js';
8
9
  export { PageHeaderAction } from './PageHeaderAction.js';
9
10
  export { PlusButton } from './PlusButton.js';
@@ -1,4 +1,6 @@
1
- /** Active/inactive classes for sidebar nav links (parity with Svelte `MenuItem.svelte`). */
2
- export declare const sideBarNavLinkClass: ({ isActive }: {
3
- isActive: boolean;
4
- }) => string;
1
+ /**
2
+ * Sidebar nav link classes. A string so Radix Tooltip's Slot can merge
3
+ * `className` — a NavLink callback gets stringified and the flex row is lost.
4
+ * Active state uses `aria-current="page"`, which NavLink sets itself.
5
+ */
6
+ export declare const sideBarNavLinkClass: string;
@@ -1,3 +1,7 @@
1
1
  import { cn } from '@openpeepshq/react-ui';
2
- /** Active/inactive classes for sidebar nav links (parity with Svelte `MenuItem.svelte`). */
3
- export const sideBarNavLinkClass = ({ isActive }) => cn('flex items-center gap-2 rounded-md px-3 py-2 hover:bg-surface', isActive ? 'text-primary font-bold' : 'text-foreground/70');
2
+ /**
3
+ * Sidebar nav link classes. A string so Radix Tooltip's Slot can merge
4
+ * `className` — a NavLink callback gets stringified and the flex row is lost.
5
+ * Active state uses `aria-current="page"`, which NavLink sets itself.
6
+ */
7
+ export const sideBarNavLinkClass = cn('flex items-center gap-2 rounded-md px-3 py-2 text-foreground/70 hover:bg-surface', 'aria-[current=page]:font-bold aria-[current=page]:text-primary');
@@ -1,10 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { formatEventWhen, isHiddenPost, markdownPlainText, } from '@openpeepshq/common/lib';
2
+ import { formatEventWhen, isHiddenPost } from '@openpeepshq/common/lib';
3
3
  import { AudioLines, Calendar, CirclePlay, Paperclip } from 'lucide-react';
4
4
  import { cn } from '@openpeepshq/react-ui';
5
5
  import { useT } from '../../i18n/index.js';
6
6
  import { Avatar } from '../profile/index.js';
7
7
  import { isAudioAttachment } from './pieces/AudioAttachment.js';
8
+ import { TruncatedMarkdown } from './TruncatedMarkdown.js';
8
9
  const attachmentsOf = (post) => {
9
10
  const data = post.data;
10
11
  return data?.attachments ?? [];
@@ -49,7 +50,6 @@ const CompactNoteBody = ({ post, t }) => {
49
50
  if (post.data?.type !== 'note')
50
51
  return null;
51
52
  const attachments = attachmentsOf(post);
52
- const text = markdownPlainText(post.data.content);
53
53
  const hasVisual = !!visualAttachment(attachments);
54
54
  const file = !hasVisual ? attachments[0] : undefined;
55
55
  const audio = !!file && isAudioAttachment(file);
@@ -59,17 +59,16 @@ const CompactNoteBody = ({ post, t }) => {
59
59
  ? t('posts.compact.audio', { defaultValue: 'Audio' })
60
60
  : t('posts.compact.document', { defaultValue: 'Document' }))
61
61
  : undefined;
62
- if (!text && !docName)
62
+ if (!post.data.content && !docName)
63
63
  return null;
64
- return (_jsxs(_Fragment, { children: [text ? _jsx("p", { className: "line-clamp-2 break-words text-sm", children: text }) : null, docName ? (_jsxs("p", { className: "text-muted-foreground flex items-center gap-1 text-xs", children: [audio ? (_jsx(AudioLines, { className: "size-3.5 shrink-0", "aria-hidden": true })) : (_jsx(Paperclip, { className: "size-3.5 shrink-0", "aria-hidden": true })), _jsx("span", { className: "truncate", children: docName })] })) : null] }));
64
+ return (_jsxs(_Fragment, { children: [_jsx(TruncatedMarkdown, { source: post.data.content ?? '', maxBlocks: 1, maxChars: 80, maxLines: 1, className: "break-words text-sm text-muted-foreground" }), docName ? (_jsxs("p", { className: "text-muted-foreground flex items-center gap-1 text-xs", children: [audio ? (_jsx(AudioLines, { className: "size-3.5 shrink-0", "aria-hidden": true })) : (_jsx(Paperclip, { className: "size-3.5 shrink-0", "aria-hidden": true })), _jsx("span", { className: "truncate", children: docName })] })) : null] }));
65
65
  };
66
66
  const CompactQuestionBody = ({ post, t, }) => {
67
67
  if (post.data?.type !== 'question')
68
68
  return null;
69
69
  const data = post.data;
70
- const text = markdownPlainText(data.content);
71
70
  const optionCount = data.options?.length ?? 0;
72
- return (_jsxs(_Fragment, { children: [text ? _jsx("p", { className: "line-clamp-2 break-words text-sm", children: text }) : null, optionCount > 0 ? (_jsx("p", { className: "text-muted-foreground truncate text-xs", children: t('posts.compact.pollOptions', {
71
+ return (_jsxs(_Fragment, { children: [_jsx(TruncatedMarkdown, { source: data.content ?? '', maxBlocks: 1, maxChars: 80, maxLines: 1, className: "break-words text-sm text-muted-foreground" }), optionCount > 0 ? (_jsx("p", { className: "text-muted-foreground truncate text-xs", children: t('posts.compact.pollOptions', {
73
72
  defaultValue: '{{count}} options',
74
73
  count: optionCount,
75
74
  }) })) : null] }));
@@ -0,0 +1,27 @@
1
+ import { type ReactNode } from 'react';
2
+ export interface TruncatedMarkdownProps {
3
+ /** Full markdown content; rendered in the popover when `interactive`. */
4
+ source: string;
5
+ /** Pre-truncated excerpt. When omitted, computed via `truncateMarkdown`. */
6
+ snippet?: string;
7
+ maxBlocks?: number;
8
+ maxChars?: number;
9
+ /** Lines the excerpt is clamped to (only when `interactive`). */
10
+ maxLines?: number;
11
+ /**
12
+ * When true, the excerpt is clamped and a "Show more" control reveals the
13
+ * full content in a popover (click/tap; hover on desktop via the popover).
14
+ * When false, the excerpt renders as-is — callers that own their own
15
+ * navigation keep it plain.
16
+ */
17
+ interactive?: boolean;
18
+ className?: string;
19
+ }
20
+ /**
21
+ * Single rendering surface for abbreviated markdown. The excerpt is always
22
+ * produced by the markdown-aware `truncateMarkdown` (links, images and
23
+ * emphasis are never severed), so every abbreviated preview renders as real
24
+ * markdown instead of raw text. Call sites with their own read-more navigation
25
+ * (e.g. Article) keep `interactive` off and render the link themselves.
26
+ */
27
+ export declare const TruncatedMarkdown: ({ source, snippet: snippetProp, maxBlocks, maxChars, maxLines, interactive, className, }: TruncatedMarkdownProps) => ReactNode;
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import {} from 'react';
3
+ import { truncateMarkdown } from '@openpeepshq/common/lib';
4
+ import { Popover, PopoverContent, PopoverTrigger } from '@openpeepshq/react-ui';
5
+ import { useT } from '../../i18n/index.js';
6
+ import { PostMarkdown } from './Markdown.js';
7
+ import { OPENPEEPS_POST_CAPTION_CLASS } from '../markdown/classes.js';
8
+ const clampClass = (n) => `line-clamp-${n}`;
9
+ /**
10
+ * Single rendering surface for abbreviated markdown. The excerpt is always
11
+ * produced by the markdown-aware `truncateMarkdown` (links, images and
12
+ * emphasis are never severed), so every abbreviated preview renders as real
13
+ * markdown instead of raw text. Call sites with their own read-more navigation
14
+ * (e.g. Article) keep `interactive` off and render the link themselves.
15
+ */
16
+ export const TruncatedMarkdown = ({ source, snippet: snippetProp, maxBlocks = 2, maxChars = 240, maxLines = 2, interactive = true, className, }) => {
17
+ const t = useT();
18
+ const excerpt = snippetProp ?? truncateMarkdown(source, maxBlocks, maxChars);
19
+ if (!excerpt)
20
+ return null;
21
+ const excerptClass = [
22
+ OPENPEEPS_POST_CAPTION_CLASS,
23
+ interactive && maxLines > 0 ? clampClass(maxLines) : '',
24
+ className ?? '',
25
+ ]
26
+ .join(' ')
27
+ .trim();
28
+ const body = _jsx(PostMarkdown, { source: excerpt, className: excerptClass });
29
+ if (!interactive)
30
+ return body;
31
+ return (_jsxs("div", { className: "inline-block max-w-full align-baseline", children: [body, _jsxs(Popover, { children: [_jsx(PopoverTrigger, { asChild: true, children: _jsx("button", { type: "button", onClick: (e) => {
32
+ e.stopPropagation();
33
+ e.preventDefault();
34
+ }, "aria-label": t('posts.truncatedMarkdown.showHint', {
35
+ defaultValue: 'Show more',
36
+ }), className: "text-primary inline-flex items-center gap-1 text-xs font-medium underline decoration-transparent underline-offset-2 hover:decoration-inherit", children: t('posts.truncatedMarkdown.show', { defaultValue: 'Show more' }) }) }), _jsx(PopoverContent, { side: "top", align: "start", sideOffset: 8, className: "bg-popover text-popover-foreground z-50 max-w-xs rounded-md border p-3 shadow-md", children: _jsx(PostMarkdown, { source: source }) })] })] }));
37
+ };
@@ -1,6 +1,6 @@
1
1
  import type { PublicPost } from '@openpeepshq/common/types';
2
+ /** @deprecated Use `firstNWords` from `@openpeepshq/common/lib` directly. */
3
+ export declare const firstNWords: (markdown: string | undefined, n: number) => string;
2
4
  /** Splits a string into user-visible grapheme clusters (so emojis don't get chopped). */
3
5
  export declare const stringToSegments: (text: string) => string[];
4
6
  export declare const postReactionStats: (post: PublicPost) => string;
5
- /** Truncates markdown to roughly the first N words, preserving links. */
6
- export declare const firstNWords: (markdown: string | undefined, n: number) => string;
@@ -1,3 +1,6 @@
1
+ import { firstNWords as _firstNWords } from '@openpeepshq/common/lib';
2
+ /** @deprecated Use `firstNWords` from `@openpeepshq/common/lib` directly. */
3
+ export const firstNWords = _firstNWords;
1
4
  /** Splits a string into user-visible grapheme clusters (so emojis don't get chopped). */
2
5
  export const stringToSegments = (text) => typeof Intl.Segmenter === 'function'
3
6
  ? [...new Intl.Segmenter().segment(text)].map((x) => x.segment)
@@ -8,19 +11,3 @@ export const postReactionStats = (post) => {
8
11
  ].join('');
9
12
  return `${uniqueEmojis} ${post.reactions?.length ?? 0}`;
10
13
  };
11
- /** Truncates markdown to roughly the first N words, preserving links. */
12
- export const firstNWords = (markdown, n) => {
13
- if (!markdown)
14
- return '';
15
- const regex = /\[.*?\]\(.*?\)|(\w+)/g;
16
- let wordCount = 0;
17
- const out = [];
18
- let match;
19
- while ((match = regex.exec(markdown)) !== null) {
20
- if (wordCount >= n)
21
- break;
22
- out.push(match[0]);
23
- wordCount++;
24
- }
25
- return out.join(' ');
26
- };
@@ -6,6 +6,8 @@ export { FeedPostContent } from './FeedPostContent';
6
6
  export { PostDetail } from './PostDetail';
7
7
  export type { PostDetailProps } from './PostDetail';
8
8
  export { PostMarkdown, OpenpeepsMarkdown } from './Markdown';
9
+ export { TruncatedMarkdown } from './TruncatedMarkdown';
10
+ export type { TruncatedMarkdownProps } from './TruncatedMarkdown';
9
11
  export { PostMenu } from './pieces/PostMenu';
10
12
  export type { PostMenuProps } from './pieces/PostMenu';
11
13
  export { ShareMenu } from './pieces/ShareMenu';
@@ -3,6 +3,7 @@ export { FeedPost } from './FeedPost.js';
3
3
  export { FeedPostContent } from './FeedPostContent.js';
4
4
  export { PostDetail } from './PostDetail.js';
5
5
  export { PostMarkdown, OpenpeepsMarkdown } from './Markdown.js';
6
+ export { TruncatedMarkdown } from './TruncatedMarkdown.js';
6
7
  export { PostMenu } from './pieces/PostMenu.js';
7
8
  export { ShareMenu } from './pieces/ShareMenu.js';
8
9
  export { EventMenu } from './pieces/EventMenu.js';
@@ -19,6 +19,20 @@ export function EventLocation({ post, preview = true, truncate = false, occurren
19
19
  ? window.location.origin
20
20
  : undefined;
21
21
  const jamLink = getJamUrl(post.id, origin, occurrence);
22
+ if (preview && staticRender) {
23
+ if (physicalLocation) {
24
+ return (_jsx("span", { className: "text-sm", children: truncate
25
+ ? truncateText(physicalLocation.text)
26
+ : physicalLocation.text }));
27
+ }
28
+ if (event.jam) {
29
+ return (_jsx("a", { href: jamLink, className: "text-primary text-sm underline", children: t('events.location.jam', { defaultValue: 'Jam Event' }) }));
30
+ }
31
+ if (event.url) {
32
+ return (_jsx("a", { href: event.url, className: "text-primary text-sm underline", children: t('events.location.online', { defaultValue: 'Online' }) }));
33
+ }
34
+ return null;
35
+ }
22
36
  if (preview) {
23
37
  return (_jsx("div", { className: "flex items-center gap-1 text-sm", children: physicalLocation ? (_jsxs(_Fragment, { children: [_jsx(MapPin, { className: "h-4 w-4 shrink-0" }), _jsx("span", { children: truncate
24
38
  ? truncateText(physicalLocation.text)
@@ -6,7 +6,7 @@ import { EventRsvpScopeDialog } from './EventRsvpScopeDialog.js';
6
6
  import { EventWaitlistJoinDialog } from './EventWaitlistJoinDialog.js';
7
7
  export const EventRsvpButton = ({ post, recurrenceId, lockToOccurrence = false, }) => {
8
8
  const t = useT();
9
- const { profile, myEvent, myRsvp, canRsvp, rsvpClosed, recurring, defaultId, occurrences, capacityEvent, full, onWaitlist, offerExpiresAt, error, pending, setPending, confirmingWaitlist, setConfirmingWaitlist, submitting, requestRespond, requestJoinWaitlist, confirmJoinWaitlist, claimSpot, confirmScope, } = useEventRsvp({ post, recurrenceId, lockToOccurrence });
9
+ const { profile, myEvent, myRsvp, canRsvp, rsvpClosed, hideRsvpButton, recurring, defaultId, occurrences, capacityEvent, full, onWaitlist, offerExpiresAt, error, pending, setPending, confirmingWaitlist, setConfirmingWaitlist, submitting, requestRespond, requestJoinWaitlist, confirmJoinWaitlist, claimSpot, confirmScope, } = useEventRsvp({ post, recurrenceId, lockToOccurrence });
10
10
  if (myEvent || !profile)
11
11
  return null;
12
12
  if (!canRsvp && !(myRsvp && myRsvp.response !== 'no'))
@@ -31,6 +31,8 @@ export const EventRsvpButton = ({ post, recurrenceId, lockToOccurrence = false,
31
31
  defaultValue: 'This event has ended.',
32
32
  }) })] }));
33
33
  }
34
+ if (hideRsvpButton)
35
+ return null;
34
36
  const scopeDialog = pending && recurring && !lockToOccurrence ? (_jsx(EventRsvpScopeDialog, { open: true, post: post, response: pending, defaultRecurrenceId: defaultId, occurrences: occurrences, error: error, submitting: submitting, onClose: () => {
35
37
  if (!submitting)
36
38
  setPending(null);
@@ -124,9 +124,15 @@ export function PollContent({ post }) {
124
124
  // fill is a circle at the start of the track.
125
125
  width: votePercent === 0 ? 8 : `${votePercent}%`,
126
126
  } }) })] })] }, `${option.content}-${index}`));
127
- }) }), canVote ? (_jsx(Button, { variant: "default", className: "mt-4", title: t('posts.poll.vote', { defaultValue: 'Vote' }), action: handleVote, children: t('posts.form.poll.submit', { defaultValue: 'Vote' }) })) : null, _jsxs("div", { className: "text-muted-foreground mt-4 flex flex-wrap items-center gap-3 text-sm", children: [_jsxs("span", { children: [votes.length || 0, " ", t('posts.vote.count', { defaultValue: 'votes' })] }), pollData.expiresAt ? (_jsx("span", { children: hasPollEnded
127
+ }) }), canVote ? (_jsx(Button, { variant: "default", className: "mt-4", title: t('posts.poll.vote', { defaultValue: 'Vote' }), action: handleVote, children: t('posts.form.poll.submit', { defaultValue: 'Vote' }) })) : null, _jsxs("div", { className: "text-muted-foreground mt-4 flex flex-wrap items-center gap-3 text-sm", children: [_jsx("span", { children: t('posts.vote.count', {
128
+ count: votes.length || 0,
129
+ defaultValue: 'votes',
130
+ }) }), pollData.expiresAt ? (_jsx("span", { children: hasPollEnded
128
131
  ? t('posts.poll.ended', { defaultValue: 'Poll ended' })
129
- : `${formatDistanceToNow(pollData.expiresAt)} ${t('posts.poll.timeLeft', { defaultValue: 'left' })}` })) : null, hasVoted && !hasPollEnded ? (_jsx(Button, { variant: "ghost", className: "h-auto min-h-0 px-0 font-semibold", title: t('posts.poll.undoVoteTitle', {
132
+ : t('posts.poll.timeLeft', {
133
+ time: formatDistanceToNow(pollData.expiresAt),
134
+ defaultValue: '{{time}} left',
135
+ }) })) : null, hasVoted && !hasPollEnded ? (_jsx(Button, { variant: "ghost", className: "h-auto min-h-0 px-0 font-semibold", title: t('posts.poll.undoVoteTitle', {
130
136
  defaultValue: 'Undo your vote',
131
137
  }), action: handleClearVote, children: t('posts.poll.undoVote', { defaultValue: 'Undo vote' }) })) : null] })] }));
132
138
  }
@@ -23,7 +23,7 @@ export function ArticleForm({ postData, onChange, isEdit = false, }) {
23
23
  const setAudience = (settings) => onChange(applyAudienceSetting(postData, settings, me));
24
24
  return (_jsxs("div", { children: [_jsx(ImageInput, { usage: "article-header-image", url: article.image, onChange: (image) => patchArticle({ image }), className: "h-96", showSelectAspectRatio: true, showFullImage: true, text: t('articles.form.uploadCover', {
25
25
  defaultValue: 'Upload your cover image',
26
- }), showAltInput: false }), _jsxs("div", { className: "mt-4 flex flex-col gap-4 px-3", children: [_jsx("h2", { className: "text-lg", children: t('articles.form.title', { defaultValue: 'New Article' }) }), _jsx(Label, { title: t('articles.form.title', { defaultValue: 'New Article' }), htmlFor: "article-title", children: _jsx(Input, { id: "article-title", value: article.title ?? '', onChange: (e) => patchArticle({ title: e.target.value }) }) }), _jsx(OpenpeepsMarkdownInput, { rows: 16, maxLength: 10000, value: article.content ?? '', onChange: (content) => patchArticle({ content }), placeholder: t('articles.form.contentPlaceholder', {
26
+ }), showAltInput: false }), _jsxs("div", { className: "mt-4 flex flex-col gap-4 px-3", children: [_jsx("h2", { className: "text-lg", children: t('articles.form.title', { defaultValue: 'New Article' }) }), _jsx(Label, { title: t('articles.form.titleInput', { defaultValue: 'Title' }), htmlFor: "article-title", children: _jsx(Input, { id: "article-title", value: article.title ?? '', onChange: (e) => patchArticle({ title: e.target.value }) }) }), _jsx(OpenpeepsMarkdownInput, { rows: 16, maxLength: 10000, value: article.content ?? '', onChange: (content) => patchArticle({ content }), placeholder: t('articles.form.contentPlaceholder', {
27
27
  defaultValue: 'Write your content here. User markdown for formatting',
28
28
  }) }), _jsx(ComposePreviewLinks, { content: article.content }), _jsx(Label, { title: t('articles.form.visibility', {
29
29
  defaultValue: 'Who can see this (Required)',
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useState } from 'react';
3
3
  import { X } from 'lucide-react';
4
4
  import { EVENT_HEADER_ASPECT_RATIO, parseEventMaxAttendeesInput, parseEventWaitlistOfferMinutesInput, utcIsoToZonedDateTime, zonedDateTimeToUtcIso, } from '@openpeepshq/common/lib';
@@ -19,6 +19,7 @@ const TIMEZONES = typeof Intl !== 'undefined' && 'supportedValuesOf' in Intl
19
19
  export const EventForm = ({ postData, onChange, isEdit = false, occurrenceEdit = false, }) => {
20
20
  const t = useT();
21
21
  const [audienceOpen, setAudienceOpen] = useState(false);
22
+ const [endBeforeStart, setEndBeforeStart] = useState(false);
22
23
  const { event, eventTimeZone, showEndDate, repeatFreq, repeatEnd, preview, patchEvent, setEvent, setAudience, applyFreq, toggleWeekday, applyRepeatEnd, setRepeatUntil, setRepeatCount, toggleEndDate, setTimeZone, } = useEventForm(postData, onChange);
23
24
  return (_jsxs("div", { "data-testid": "events-form-basic-details", children: [_jsx(ImageInput, { usage: "event-header-image", url: event.image, onChange: (image) => patchEvent({ image }), aspectRatio: EVENT_HEADER_ASPECT_RATIO, className: "aspect-video !h-auto", text: t('events.form.imageDescription', {
24
25
  defaultValue: 'Upload an image for your event',
@@ -32,11 +33,30 @@ export const EventForm = ({ postData, onChange, isEdit = false, occurrenceEdit =
32
33
  defaultValue: 'Date and Time',
33
34
  }) }), _jsx(Label, { title: t('events.form.startDate', { defaultValue: 'Start Date' }), htmlFor: "event-start", children: _jsx(Input, { id: "event-start", type: "datetime-local", step: 60, value: dateToInputValue(event.start, eventTimeZone), onChange: (e) => {
34
35
  const start = toIso(e.target.value, eventTimeZone);
35
- if (start)
36
+ if (start) {
37
+ if (event.end && new Date(event.end) <= new Date(start)) {
38
+ setEndBeforeStart(true);
39
+ }
40
+ else {
41
+ setEndBeforeStart(false);
42
+ }
36
43
  patchEvent({ start });
44
+ }
37
45
  }, "data-testid": "events-start-input" }) }), _jsx(Label, { description: t('events.form.addEndDate', {
38
46
  defaultValue: 'Add end date and time',
39
- }), forCheckbox: true, children: _jsx("input", { type: "checkbox", checked: showEndDate, onChange: (e) => toggleEndDate(e.target.checked) }) }), showEndDate ? (_jsx(Label, { title: t('events.form.endDate', { defaultValue: 'End Date' }), htmlFor: "event-end", children: _jsx(Input, { id: "event-end", type: "datetime-local", step: 60, value: dateToInputValue(event.end, eventTimeZone), onChange: (e) => patchEvent({ end: toIso(e.target.value, eventTimeZone) }) }) })) : null, _jsx(Label, { title: t('events.form.timezone', { defaultValue: 'Timezone' }), htmlFor: "event-timezone", children: _jsx("select", { id: "event-timezone", className: "bg-background w-full rounded-md border px-3 py-2 text-sm", value: eventTimeZone, onChange: (e) => setTimeZone(e.target.value), children: TIMEZONES.map((tz) => (_jsx("option", { value: tz, children: tz }, tz))) }) }), !occurrenceEdit ? (_jsxs(_Fragment, { children: [_jsx(Label, { title: t('events.form.repeat.title', { defaultValue: 'Repeat' }), htmlFor: "event-repeat", children: _jsxs("select", { id: "event-repeat", className: "bg-background w-full rounded-md border px-3 py-2 text-sm", value: repeatFreq, onChange: (e) => applyFreq(e.target.value), "data-testid": "events-repeat-input", children: [_jsx("option", { value: "none", children: t('events.form.repeat.none', {
47
+ }), forCheckbox: true, children: _jsx("input", { type: "checkbox", checked: showEndDate, onChange: (e) => toggleEndDate(e.target.checked) }) }), showEndDate ? (_jsxs(_Fragment, { children: [_jsx(Label, { title: t('events.form.endDate', { defaultValue: 'End Date' }), htmlFor: "event-end", children: _jsx(Input, { id: "event-end", type: "datetime-local", step: 60, value: dateToInputValue(event.end, eventTimeZone), onChange: (e) => {
48
+ const newEnd = toIso(e.target.value, eventTimeZone);
49
+ if (newEnd &&
50
+ event.start &&
51
+ new Date(newEnd) <= new Date(event.start)) {
52
+ setEndBeforeStart(true);
53
+ return;
54
+ }
55
+ setEndBeforeStart(false);
56
+ patchEvent({ end: newEnd });
57
+ } }) }), endBeforeStart ? (_jsx("p", { className: "text-destructive text-sm", children: t('events.form.endBeforeStart', {
58
+ defaultValue: 'The end date and time must be after the start date and time.',
59
+ }) })) : null] })) : null, _jsx(Label, { title: t('events.form.timezone', { defaultValue: 'Timezone' }), htmlFor: "event-timezone", children: _jsx("select", { id: "event-timezone", className: "bg-background w-full rounded-md border px-3 py-2 text-sm", value: eventTimeZone, onChange: (e) => setTimeZone(e.target.value), children: TIMEZONES.map((tz) => (_jsx("option", { value: tz, children: tz }, tz))) }) }), !occurrenceEdit ? (_jsxs(_Fragment, { children: [_jsx(Label, { title: t('events.form.repeat.title', { defaultValue: 'Repeat' }), htmlFor: "event-repeat", children: _jsxs("select", { id: "event-repeat", className: "bg-background w-full rounded-md border px-3 py-2 text-sm", value: repeatFreq, onChange: (e) => applyFreq(e.target.value), "data-testid": "events-repeat-input", children: [_jsx("option", { value: "none", children: t('events.form.repeat.none', {
40
60
  defaultValue: 'Does not repeat',
41
61
  }) }), _jsx("option", { value: "DAILY", children: t('events.form.repeat.daily', { defaultValue: 'Daily' }) }), _jsx("option", { value: "WEEKLY", children: t('events.form.repeat.weekly', { defaultValue: 'Weekly' }) }), _jsx("option", { value: "MONTHLY", children: t('events.form.repeat.monthly', { defaultValue: 'Monthly' }) })] }) }), event.recurrence?.freq === 'WEEKLY' ? (_jsxs("div", { children: [_jsx("p", { className: "mb-2 text-sm", children: t('events.form.repeat.weekdays', {
42
62
  defaultValue: 'Repeat on',
@@ -3,5 +3,7 @@ export interface ResourceFormProps {
3
3
  postData: PostCreationData;
4
4
  onChange: (data: PostCreationData) => void;
5
5
  isEdit?: boolean;
6
+ /** Member can post this resource only to a group. */
7
+ groupOnly?: boolean;
6
8
  }
7
- export declare const ResourceForm: ({ postData, onChange, isEdit, }: ResourceFormProps) => import("react/jsx-runtime").JSX.Element;
9
+ export declare const ResourceForm: ({ postData, onChange, isEdit, groupOnly, }: ResourceFormProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useMemo, useState } from 'react';
3
- import { RESOURCE_KINDS, normalizeResourceTags } from '@openpeepshq/common/lib';
3
+ import { RESOURCE_KINDS, RESOURCE_TITLE_MAX_LENGTH, normalizeResourceTags, resourceFormIssues, } from '@openpeepshq/common/lib';
4
4
  import { Button, Input, Label } from '@openpeepshq/react-ui';
5
5
  import { useT } from '../../../i18n/index.js';
6
6
  import { useCurrentProfile } from '../../layout/IdentityContext.js';
@@ -11,13 +11,13 @@ import { OpenpeepsMarkdownInput } from './OpenpeepsMarkdownInput.js';
11
11
  import { PostAudienceSelector } from './PostAudienceSelector.js';
12
12
  import { VisibilitySelector } from './VisibilitySelector.js';
13
13
  import { useComposeAttachments } from './ComposeAttachments.js';
14
- export const ResourceForm = ({ postData, onChange, isEdit = false, }) => {
14
+ export const ResourceForm = ({ postData, onChange, isEdit = false, groupOnly = false, }) => {
15
15
  const t = useT();
16
16
  const me = useCurrentProfile();
17
17
  const resource = postData.data;
18
18
  const [audienceOpen, setAudienceOpen] = useState(false);
19
19
  const [tagDraft, setTagDraft] = useState('');
20
- const library = useResourceLibrary(postData.groupId ?? undefined);
20
+ const library = useResourceLibrary(postData.groupId ?? undefined, !postData.groupId);
21
21
  const attachments = useComposeAttachments({
22
22
  attachments: resource.attachments ?? [],
23
23
  onChange: (next) => patchResource({ attachments: next }),
@@ -43,6 +43,25 @@ export const ResourceForm = ({ postData, onChange, isEdit = false, }) => {
43
43
  addTag();
44
44
  }
45
45
  };
46
+ const issues = resourceFormIssues({
47
+ title: resource.title,
48
+ resourceKind: resource.resourceKind,
49
+ url: resource.url,
50
+ attachments: resource.attachments,
51
+ visibility: postData.visibility,
52
+ audience: postData.audience,
53
+ groupId: postData.groupId,
54
+ });
55
+ const titleMissing = issues.includes('title');
56
+ const titleTooLong = issues.includes('titleLength');
57
+ const urlIssue = issues.includes('url');
58
+ const urlInvalid = urlIssue && Boolean(resource.url?.trim());
59
+ const mediaMissing = issues.includes('media');
60
+ const audienceMissing = issues.includes('audience');
61
+ const groupMissing = issues.includes('group');
62
+ const urlMessage = t('resources.validation.url', {
63
+ defaultValue: 'Enter a real link, like https://example.com',
64
+ });
46
65
  const kindActions = useMemo(() => ({
47
66
  gallery: attachments.openImagePicker,
48
67
  video: attachments.openImagePicker,
@@ -50,9 +69,25 @@ export const ResourceForm = ({ postData, onChange, isEdit = false, }) => {
50
69
  file: attachments.openDocumentPicker,
51
70
  link: undefined,
52
71
  }), [attachments]);
53
- return (_jsxs("div", { children: [_jsxs("div", { className: "mt-4 flex flex-col gap-4 px-3", children: [_jsx("h2", { className: "text-lg", children: t('resources.form.title', { defaultValue: 'New resource' }) }), _jsx(Label, { title: t('resources.form.name', { defaultValue: 'Title' }), htmlFor: "resource-title", children: _jsx(Input, { id: "resource-title", "data-testid": "resources-title", value: resource.title, onChange: (event) => patchResource({ title: event.target.value }) }) }), _jsxs("div", { children: [_jsx("p", { className: "mb-2 text-sm font-medium", children: t('resources.form.kind', { defaultValue: 'Type' }) }), _jsx("div", { className: "flex flex-wrap gap-2", children: RESOURCE_KINDS.map((kind) => (_jsx(Button, { variant: resource.resourceKind === kind ? 'default' : 'outline', compact: true, "data-testid": `resources-kind-${kind}`, action: () => patchResource({ resourceKind: kind }), children: t(`resources.kinds.${kind}`, { defaultValue: kind }) }, kind))) })] }), resource.resourceKind === 'link' ? (_jsx(Label, { title: t('resources.form.url', { defaultValue: 'URL' }), htmlFor: "resource-url", children: _jsx(Input, { id: "resource-url", "data-testid": "resources-url", value: resource.url ?? '', onChange: (event) => patchResource({ url: event.target.value }) }) })) : (_jsxs("div", { className: "space-y-2", children: [_jsx(Button, { variant: "outline", action: kindActions[resource.resourceKind], children: t('resources.form.addMedia', {
72
+ return (_jsxs("div", { children: [_jsxs("div", { className: "mt-4 flex flex-col gap-4 px-3", children: [_jsx("h2", { className: "text-lg", children: t('resources.form.title', { defaultValue: 'New resource' }) }), _jsxs(Label, { title: t('resources.form.nameRequired', {
73
+ defaultValue: 'Title (Required)',
74
+ }), htmlFor: "resource-title", children: [_jsx(Input, { id: "resource-title", "data-testid": "resources-title", value: resource.title, maxLength: RESOURCE_TITLE_MAX_LENGTH, "aria-invalid": titleMissing || titleTooLong, "aria-describedby": titleMissing
75
+ ? 'resource-title-error resource-title-count'
76
+ : 'resource-title-count', onChange: (event) => patchResource({ title: event.target.value }) }), titleMissing ? (_jsx("span", { id: "resource-title-error", role: "status", className: "text-muted-foreground mt-1 text-sm", children: t('resources.validation.titleRequired', {
77
+ defaultValue: 'Title is required',
78
+ }) })) : null, titleTooLong ? (_jsx("span", { role: "alert", className: "text-destructive mt-1 text-sm", children: t('resources.validation.titleTooLong', {
79
+ defaultValue: 'Title must be 200 characters or fewer',
80
+ }) })) : null, _jsxs("span", { id: "resource-title-count", className: "block w-full px-2 text-right text-sm", children: [_jsx("span", { className: titleTooLong ? 'text-error' : undefined, children: resource.title.length }), ' ', "/ ", RESOURCE_TITLE_MAX_LENGTH] })] }), _jsxs("div", { children: [_jsx("p", { className: "mb-2 text-sm font-medium", children: t('resources.form.kind', { defaultValue: 'Type' }) }), _jsx("div", { className: "flex flex-wrap gap-2", children: RESOURCE_KINDS.map((kind) => (_jsx(Button, { variant: resource.resourceKind === kind ? 'default' : 'outline', compact: true, "data-testid": `resources-kind-${kind}`, action: () => patchResource({ resourceKind: kind }), children: t(`resources.kinds.${kind}`, { defaultValue: kind }) }, kind))) })] }), resource.resourceKind === 'link' ? (_jsxs(Label, { title: t('resources.form.urlRequired', {
81
+ defaultValue: 'URL (Required)',
82
+ }), htmlFor: "resource-url", children: [_jsx(Input, { id: "resource-url", "data-testid": "resources-url", value: resource.url ?? '', placeholder: t('resources.form.urlPlaceholder', {
83
+ defaultValue: 'https://example.com',
84
+ }), inputMode: "url", spellCheck: false, error: urlInvalid, "aria-invalid": urlIssue, "aria-describedby": urlIssue ? 'resource-url-error' : undefined, onChange: (event) => patchResource({ url: event.target.value }) }), urlIssue ? (_jsx("span", { id: "resource-url-error", role: urlInvalid ? 'alert' : 'status', "data-testid": "resources-url-error", className: urlInvalid
85
+ ? 'text-destructive mt-1 text-sm'
86
+ : 'text-muted-foreground mt-1 text-sm', children: urlMessage })) : null] })) : (_jsxs("div", { className: "space-y-2", children: [_jsx(Button, { variant: "outline", action: kindActions[resource.resourceKind], children: t('resources.form.addMedia', {
54
87
  defaultValue: 'Add files',
55
- }) }), attachments.previews, attachments.inputs] })), _jsx(OpenpeepsMarkdownInput, { rows: 8, maxLength: 4000, value: resource.content ?? '', onChange: (content) => patchResource({ content }), placeholder: t('resources.form.descriptionPlaceholder', {
88
+ }) }), attachments.previews, attachments.inputs, mediaMissing ? (_jsx("p", { role: "status", className: "text-muted-foreground text-sm", children: t('resources.validation.mediaRequired', {
89
+ defaultValue: 'Add the media or link this resource needs',
90
+ }) })) : null] })), _jsx(OpenpeepsMarkdownInput, { rows: 8, maxLength: 4000, value: resource.content ?? '', onChange: (content) => patchResource({ content }), placeholder: t('resources.form.descriptionPlaceholder', {
56
91
  defaultValue: 'Describe this resource',
57
92
  }) }), _jsx(Label, { title: t('resources.form.tags', { defaultValue: 'Tags' }), htmlFor: "resource-tags", children: _jsx(Input, { id: "resource-tags", value: tagDraft, onChange: (event) => setTagDraft(event.target.value), onKeyDown: onTagKey, onBlur: addTag, placeholder: t('resources.form.tagsPlaceholder', {
58
93
  defaultValue: 'Add tags, then press Enter',
@@ -60,9 +95,15 @@ export const ResourceForm = ({ postData, onChange, isEdit = false, }) => {
60
95
  tags: (resource.tags ?? []).filter((value) => value.toLowerCase() !== tag),
61
96
  }), children: ["#", tag] }, tag))) })) : null, _jsxs("div", { children: [_jsx("p", { className: "mb-2 text-sm font-medium", children: t('resources.form.hierarchy', {
62
97
  defaultValue: 'Place in the library',
63
- }) }), _jsx(CategoryPathPicker, { path: resource.categoryPath ?? [], tree: library.tree, onChange: (categoryPath) => patchResource({ categoryPath }) })] }), _jsx(Label, { title: t('resources.form.visibility', {
98
+ }) }), _jsx(CategoryPathPicker, { path: resource.categoryPath ?? [], tree: library.tree, onChange: (categoryPath) => patchResource({ categoryPath }) })] }), _jsxs(Label, { title: t('resources.form.visibility', {
64
99
  defaultValue: 'Who can see this (Required)',
65
100
  }), description: t('resources.form.visibilityNotChangeable', {
66
101
  defaultValue: "Once you post your resource, you can't change the visibility",
67
- }), children: _jsx(VisibilitySelector, { postData: postData, onClick: () => setAudienceOpen(true), disabled: isEdit, showDirect: true }) })] }), !isEdit ? (_jsx(PostAudienceSelector, { open: audienceOpen, onClose: () => setAudienceOpen(false), type: "resource", visibility: postData.visibility, groupId: postData.groupId ?? undefined, audience: postData.audience ?? [], showDirect: true, onConfirm: setAudience })) : null] }));
102
+ }), children: [_jsx(VisibilitySelector, { postData: postData, onClick: () => setAudienceOpen(true), disabled: isEdit, showDirect: true }), !isEdit && groupOnly ? (_jsx("span", { role: "status", className: "text-muted-foreground mt-1 text-sm", children: t('resources.form.groupOnly', {
103
+ defaultValue: 'You can only share resources with a group.',
104
+ }) })) : null, groupMissing ? (_jsx("span", { id: "resource-group-error", role: "status", className: "text-muted-foreground mt-1 text-sm", children: t('resources.validation.groupRequired', {
105
+ defaultValue: 'Choose a group before creating this resource.',
106
+ }) })) : null, audienceMissing ? (_jsx("span", { id: "resource-audience-error", role: "status", className: "text-muted-foreground mt-1 text-sm", children: t('resources.validation.directAudience', {
107
+ defaultValue: 'Choose at least one recipient for a direct resource.',
108
+ }) })) : null] })] }), !isEdit ? (_jsx(PostAudienceSelector, { open: audienceOpen, onClose: () => setAudienceOpen(false), type: "resource", visibility: postData.visibility, groupId: postData.groupId ?? undefined, audience: postData.audience ?? [], showDirect: true, onConfirm: setAudience })) : null] }));
68
109
  };