@openpeepshq/react 0.7.1 → 0.8.1
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.
- package/dist/components/markdown/compileMarkdown.js +1 -0
- package/dist/components/navigation/FooterMobile.js +4 -3
- package/dist/components/navigation/HeaderMobile.js +5 -2
- package/dist/components/navigation/MobileMenuItem.d.ts +3 -1
- package/dist/components/navigation/MobileMenuItem.js +7 -2
- package/dist/components/navigation/NavWithTooltip.d.ts +9 -0
- package/dist/components/navigation/NavWithTooltip.js +4 -0
- package/dist/components/navigation/index.d.ts +2 -0
- package/dist/components/navigation/index.js +1 -0
- package/dist/components/navigation/sideBarNavLinkClass.d.ts +6 -4
- package/dist/components/navigation/sideBarNavLinkClass.js +6 -2
- package/dist/components/post/CompactReplyParent.js +5 -6
- package/dist/components/post/TruncatedMarkdown.d.ts +27 -0
- package/dist/components/post/TruncatedMarkdown.js +37 -0
- package/dist/components/post/helpers.d.ts +2 -2
- package/dist/components/post/helpers.js +3 -16
- package/dist/components/post/index.d.ts +2 -0
- package/dist/components/post/index.js +1 -0
- package/dist/components/post/pieces/EventLocation.js +14 -0
- package/dist/components/post/pieces/EventRsvpButton.js +3 -1
- package/dist/components/post/pieces/PollContent.js +8 -2
- package/dist/components/post/post-form/ArticleForm.js +1 -1
- package/dist/components/post/post-form/ComposeAttachments.d.ts +5 -1
- package/dist/components/post/post-form/ComposeAttachments.js +20 -6
- package/dist/components/post/post-form/ComposeAttachments.test.d.ts +1 -0
- package/dist/components/post/post-form/ComposeAttachments.test.js +131 -0
- package/dist/components/post/post-form/EventForm.js +23 -3
- package/dist/components/post/post-form/ResourceForm.d.ts +3 -1
- package/dist/components/post/post-form/ResourceForm.js +51 -7
- package/dist/components/post/post-form/VisibilitySelector.js +9 -3
- package/dist/components/post/types/Article.js +2 -3
- package/dist/components/post/types/Event.js +10 -1
- package/dist/components/post/types/resource/FullResource.js +3 -3
- package/dist/components/preview-link/local/WelcomePreview.js +4 -2
- package/dist/components/resources/ResourceCard.d.ts +5 -1
- package/dist/components/resources/ResourceCard.js +94 -37
- package/dist/components/resources/ResourceCard.test.d.ts +1 -0
- package/dist/components/resources/ResourceCard.test.js +75 -0
- package/dist/components/resources/ResourceLibrary.js +1 -1
- package/dist/hooks/events/useEventRsvp.d.ts +1 -0
- package/dist/hooks/events/useEventRsvp.js +15 -7
- package/dist/hooks/posts/useResourceComposer.d.ts +2 -0
- package/dist/hooks/posts/useResourceComposer.js +131 -25
- package/dist/hooks/resources/useResourceLibrary.d.ts +1 -1
- package/dist/hooks/resources/useResourceLibrary.js +6 -2
- package/dist/hooks/useWelcomePreview.d.ts +3 -0
- package/dist/hooks/useWelcomePreview.js +1 -0
- package/dist/navigation/menuItems.js +15 -0
- package/dist/navigation/targets.d.ts +2 -0
- package/dist/pages/admin/community/CommunityMarkdownPage.js +2 -1
- package/dist/pages/auth/Register.js +3 -1
- package/dist/pages/resources/Edit.js +3 -3
- package/dist/pages/resources/New.js +2 -2
- package/dist/pages/settings/Account.js +30 -2
- package/package.json +2 -2
- package/src/components/markdown/compileMarkdown.ts +1 -0
- package/src/components/navigation/FooterMobile.tsx +41 -33
- package/src/components/navigation/HeaderMobile.tsx +55 -41
- package/src/components/navigation/MobileMenuItem.tsx +15 -2
- package/src/components/navigation/NavWithTooltip.tsx +26 -0
- package/src/components/navigation/index.ts +2 -0
- package/src/components/navigation/sideBarNavLinkClass.ts +9 -6
- package/src/components/post/CompactReplyParent.tsx +17 -10
- package/src/components/post/TruncatedMarkdown.tsx +91 -0
- package/src/components/post/helpers.ts +4 -18
- package/src/components/post/index.ts +2 -0
- package/src/components/post/pieces/EventLocation.tsx +27 -0
- package/src/components/post/pieces/EventRsvpButton.tsx +3 -0
- package/src/components/post/pieces/PollContent.tsx +8 -2
- package/src/components/post/post-form/ArticleForm.tsx +1 -1
- package/src/components/post/post-form/ComposeAttachments.tsx +24 -3
- package/src/components/post/post-form/EventForm.tsx +43 -15
- package/src/components/post/post-form/ResourceForm.tsx +135 -4
- package/src/components/post/post-form/VisibilitySelector.tsx +11 -3
- package/src/components/post/types/Article.tsx +5 -5
- package/src/components/post/types/Event.tsx +68 -7
- package/src/components/post/types/resource/FullResource.tsx +9 -1
- package/src/components/preview-link/local/WelcomePreview.tsx +11 -2
- package/src/components/resources/ResourceCard.tsx +184 -62
- package/src/components/resources/ResourceLibrary.tsx +2 -2
- package/src/hooks/events/useEventRsvp.ts +19 -7
- package/src/hooks/posts/useResourceComposer.ts +157 -33
- package/src/hooks/resources/useResourceLibrary.ts +6 -2
- package/src/hooks/useWelcomePreview.ts +4 -0
- package/src/navigation/menuItems.ts +16 -0
- package/src/navigation/targets.ts +2 -0
- package/src/pages/admin/community/CommunityMarkdownPage.tsx +5 -1
- package/src/pages/auth/Register.tsx +12 -0
- package/src/pages/resources/Edit.tsx +3 -2
- package/src/pages/resources/New.tsx +6 -1
- 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
|
-
|
|
14
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
/**
|
|
3
|
-
|
|
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
|
|
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 (!
|
|
62
|
+
if (!post.data.content && !docName)
|
|
63
63
|
return null;
|
|
64
|
-
return (_jsxs(_Fragment, { children: [
|
|
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: [
|
|
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: [
|
|
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
|
-
:
|
|
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.
|
|
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)',
|
|
@@ -3,6 +3,10 @@ import type { MediaAttachmentData } from '@openpeepshq/common';
|
|
|
3
3
|
export interface ComposeAttachmentsProps {
|
|
4
4
|
attachments: MediaAttachmentData[];
|
|
5
5
|
onChange: (attachments: MediaAttachmentData[]) => void;
|
|
6
|
+
/** Image picker may select several files at once (resource galleries). */
|
|
7
|
+
multipleImages?: boolean;
|
|
8
|
+
/** Audio picker may select several files at once (default: yes). */
|
|
9
|
+
multipleAudio?: boolean;
|
|
6
10
|
}
|
|
7
11
|
export interface ComposeAttachmentsApi {
|
|
8
12
|
openImagePicker: () => void;
|
|
@@ -22,5 +26,5 @@ export interface ComposeAttachmentsApi {
|
|
|
22
26
|
* attachments are reported back via `onChange`. Exposes the toolbar pickers and
|
|
23
27
|
* preview grid separately so callers can lay them out independently.
|
|
24
28
|
*/
|
|
25
|
-
export declare function useComposeAttachments({ attachments, onChange, }: ComposeAttachmentsProps): ComposeAttachmentsApi;
|
|
29
|
+
export declare function useComposeAttachments({ attachments, onChange, multipleImages, multipleAudio, }: ComposeAttachmentsProps): ComposeAttachmentsApi;
|
|
26
30
|
export declare function ComposeAttachments(props: ComposeAttachmentsProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -33,7 +33,7 @@ const readyItem = (attachment) => ({
|
|
|
33
33
|
* attachments are reported back via `onChange`. Exposes the toolbar pickers and
|
|
34
34
|
* preview grid separately so callers can lay them out independently.
|
|
35
35
|
*/
|
|
36
|
-
export function useComposeAttachments({ attachments, onChange, }) {
|
|
36
|
+
export function useComposeAttachments({ attachments, onChange, multipleImages = false, multipleAudio = true, }) {
|
|
37
37
|
const imageInputRef = useRef(null);
|
|
38
38
|
const audioInputRef = useRef(null);
|
|
39
39
|
const documentInputRef = useRef(null);
|
|
@@ -79,6 +79,20 @@ export function useComposeAttachments({ attachments, onChange, }) {
|
|
|
79
79
|
}
|
|
80
80
|
enqueueFile(processed);
|
|
81
81
|
};
|
|
82
|
+
// A single pick keeps the crop/alt-text flow; a bulk pick is enqueued
|
|
83
|
+
// directly, since per-file cropping isn't practical for a gallery batch.
|
|
84
|
+
const handleImageFilesSelected = async (files) => {
|
|
85
|
+
const first = files[0];
|
|
86
|
+
if (!first)
|
|
87
|
+
return;
|
|
88
|
+
if (files.length === 1) {
|
|
89
|
+
await handleImageSelected(first);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
for (const file of files) {
|
|
93
|
+
enqueueFile(await convertToWebpIfHeic(file));
|
|
94
|
+
}
|
|
95
|
+
};
|
|
82
96
|
const onUploaded = (key, attachment) => setItems((prev) => prev.map((i) => {
|
|
83
97
|
if (i.key !== key)
|
|
84
98
|
return i;
|
|
@@ -111,12 +125,12 @@ export function useComposeAttachments({ attachments, onChange, }) {
|
|
|
111
125
|
const pending = items.some((i) => (i.file && !i.attachment && !i.failed) ||
|
|
112
126
|
i.attachment?.status === 'processing');
|
|
113
127
|
const previews = items.length > 0 ? (_jsx("div", { className: "grid grid-cols-2 gap-2", children: items.map((item) => (_jsx(AttachmentCard, { item: item, onUploaded: onUploaded, onProcessed: onProcessed, onFailed: onFailed, onRemove: onRemove, onUpdate: onUpdate }, item.key))) })) : null;
|
|
114
|
-
const inputs = (_jsxs(_Fragment, { children: [_jsx("input", { ref: imageInputRef, type: "file", accept: "image/*,video/*,.mkv", className: "hidden", onChange: (e) => {
|
|
115
|
-
const
|
|
116
|
-
if (
|
|
117
|
-
void
|
|
128
|
+
const inputs = (_jsxs(_Fragment, { children: [_jsx("input", { ref: imageInputRef, type: "file", accept: "image/*,video/*,.mkv", multiple: multipleImages, className: "hidden", onChange: (e) => {
|
|
129
|
+
const files = e.target.files;
|
|
130
|
+
if (files?.length)
|
|
131
|
+
void handleImageFilesSelected(Array.from(files));
|
|
118
132
|
e.target.value = '';
|
|
119
|
-
} }), _jsx("input", { ref: audioInputRef, type: "file", accept: "audio/*,.mp3,.wav,.ogg,.m4a,.aac,.flac,.opus,.weba", multiple:
|
|
133
|
+
} }), _jsx("input", { ref: audioInputRef, type: "file", accept: "audio/*,.mp3,.wav,.ogg,.m4a,.aac,.flac,.opus,.weba", multiple: multipleAudio, className: "hidden", onChange: (e) => {
|
|
120
134
|
const files = e.target.files;
|
|
121
135
|
if (files) {
|
|
122
136
|
Array.from(files).forEach((file) => enqueueFile(file));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/** @vitest-environment jsdom */
|
|
2
|
+
import { act, createElement } from 'react';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import { useComposeAttachments } from './ComposeAttachments.js';
|
|
6
|
+
const { useMediaUpload } = vi.hoisted(() => ({
|
|
7
|
+
useMediaUpload: vi.fn(),
|
|
8
|
+
}));
|
|
9
|
+
vi.mock('../../../contexts/openpeeps', () => ({
|
|
10
|
+
useOpenpeeps: () => ({
|
|
11
|
+
openpeepsApi: {
|
|
12
|
+
useMediaUpload,
|
|
13
|
+
useMediaProgress: () => undefined,
|
|
14
|
+
},
|
|
15
|
+
}),
|
|
16
|
+
}));
|
|
17
|
+
vi.mock('../../../i18n', () => ({
|
|
18
|
+
useT: () => (key, opts) => opts?.defaultValue ?? key,
|
|
19
|
+
}));
|
|
20
|
+
// The crop modal is exercised through its presence, not its internals.
|
|
21
|
+
vi.mock('../../form/ImageEditModal', () => ({
|
|
22
|
+
ImageEditModal: ({ open }) => open ? createElement('div', { 'data-testid': 'crop-modal' }) : null,
|
|
23
|
+
}));
|
|
24
|
+
vi.mock('./DescriptionEditModal', () => ({
|
|
25
|
+
DescriptionEditModal: () => null,
|
|
26
|
+
}));
|
|
27
|
+
const uploadMock = vi.fn();
|
|
28
|
+
let urlCounter = 0;
|
|
29
|
+
const imageFile = (name) => new File([new Uint8Array(16)], name, { type: 'image/png' });
|
|
30
|
+
const Harness = ({ multipleImages, multipleAudio, onChange, }) => {
|
|
31
|
+
const api = useComposeAttachments({
|
|
32
|
+
attachments: [],
|
|
33
|
+
onChange,
|
|
34
|
+
multipleImages,
|
|
35
|
+
multipleAudio,
|
|
36
|
+
});
|
|
37
|
+
return createElement('div', null, api.previews, api.inputs);
|
|
38
|
+
};
|
|
39
|
+
const pickFiles = (container, files) => act(async () => {
|
|
40
|
+
const input = container.querySelector('input[accept^="image"]');
|
|
41
|
+
if (!(input instanceof HTMLInputElement)) {
|
|
42
|
+
throw new Error('image input not found');
|
|
43
|
+
}
|
|
44
|
+
Object.defineProperty(input, 'files', { value: files, configurable: true });
|
|
45
|
+
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
46
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
47
|
+
});
|
|
48
|
+
describe('useComposeAttachments pickers', () => {
|
|
49
|
+
let container;
|
|
50
|
+
let root;
|
|
51
|
+
const render = (props) => {
|
|
52
|
+
const onChange = vi.fn();
|
|
53
|
+
const r = createRoot(container);
|
|
54
|
+
root = r;
|
|
55
|
+
act(() => {
|
|
56
|
+
r.render(createElement(Harness, { ...props, onChange }));
|
|
57
|
+
});
|
|
58
|
+
return { onChange };
|
|
59
|
+
};
|
|
60
|
+
const inputs = () => ({
|
|
61
|
+
image: container.querySelector('input[accept^="image"]'),
|
|
62
|
+
audio: container.querySelector('input[accept^="audio"]'),
|
|
63
|
+
});
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
useMediaUpload.mockReset();
|
|
66
|
+
useMediaUpload.mockReturnValue({
|
|
67
|
+
state: { uploading: false, uploadPercent: 0 },
|
|
68
|
+
upload: uploadMock,
|
|
69
|
+
abort: vi.fn(),
|
|
70
|
+
});
|
|
71
|
+
uploadMock.mockReset();
|
|
72
|
+
uploadMock.mockImplementation(async ({ description }) => {
|
|
73
|
+
urlCounter += 1;
|
|
74
|
+
return {
|
|
75
|
+
id: `attachment-${urlCounter}`,
|
|
76
|
+
type: 'image',
|
|
77
|
+
url: `https://cdn.example.com/images/${urlCounter}.webp`,
|
|
78
|
+
previewUrl: null,
|
|
79
|
+
textUrl: null,
|
|
80
|
+
filename: description ?? 'image',
|
|
81
|
+
meta: { usage: 'post-image', mimetype: 'image/webp', size: 16 },
|
|
82
|
+
status: 'ready',
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
urlCounter = 0;
|
|
86
|
+
container = document.createElement('div');
|
|
87
|
+
document.body.appendChild(container);
|
|
88
|
+
vi.stubGlobal('URL', class extends URL {
|
|
89
|
+
static createObjectURL() {
|
|
90
|
+
urlCounter += 1;
|
|
91
|
+
return `blob:mock-${urlCounter}`;
|
|
92
|
+
}
|
|
93
|
+
static revokeObjectURL() { }
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
afterEach(() => {
|
|
97
|
+
act(() => {
|
|
98
|
+
root?.unmount();
|
|
99
|
+
});
|
|
100
|
+
container.remove();
|
|
101
|
+
vi.unstubAllGlobals();
|
|
102
|
+
});
|
|
103
|
+
it('marks the image input multiple only when requested', () => {
|
|
104
|
+
render({ multipleImages: true, multipleAudio: false });
|
|
105
|
+
const { image, audio } = inputs();
|
|
106
|
+
expect(image.multiple).toBe(true);
|
|
107
|
+
expect(audio.multiple).toBe(false);
|
|
108
|
+
});
|
|
109
|
+
it('enqueues each file of a bulk pick without the crop modal', async () => {
|
|
110
|
+
const { onChange } = render({ multipleImages: true, multipleAudio: false });
|
|
111
|
+
await pickFiles(container, [imageFile('one.png'), imageFile('two.png')]);
|
|
112
|
+
expect(uploadMock).toHaveBeenCalledTimes(2);
|
|
113
|
+
const ready = onChange.mock.calls.at(-1)?.[0] ?? [];
|
|
114
|
+
expect(ready).toHaveLength(2);
|
|
115
|
+
const urls = ready.map((attachment) => attachment.url);
|
|
116
|
+
expect(new Set(urls).size).toBe(2);
|
|
117
|
+
expect(container.querySelector('[data-testid="crop-modal"]')).toBeNull();
|
|
118
|
+
});
|
|
119
|
+
it('keeps the crop modal for a single image pick', async () => {
|
|
120
|
+
render({ multipleImages: true, multipleAudio: false });
|
|
121
|
+
await pickFiles(container, [imageFile('one.png')]);
|
|
122
|
+
expect(container.querySelector('[data-testid="crop-modal"]')).not.toBeNull();
|
|
123
|
+
expect(uploadMock).not.toHaveBeenCalled();
|
|
124
|
+
});
|
|
125
|
+
it('stays single-file by default for post composers', () => {
|
|
126
|
+
render({});
|
|
127
|
+
const { image, audio } = inputs();
|
|
128
|
+
expect(image.multiple).toBe(false);
|
|
129
|
+
expect(audio.multiple).toBe(true);
|
|
130
|
+
});
|
|
131
|
+
});
|