@openpeepshq/react 0.5.1 → 0.6.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.
Files changed (112) hide show
  1. package/dist/components/index.d.ts +1 -0
  2. package/dist/components/index.js +1 -0
  3. package/dist/components/markdown/CompiledMarkdown.d.ts +3 -1
  4. package/dist/components/markdown/CompiledMarkdown.js +17 -1
  5. package/dist/components/markdown/OpenpeepsMarkdown.d.ts +3 -7
  6. package/dist/components/markdown/OpenpeepsMarkdown.js +11 -7
  7. package/dist/components/markdown/classes.d.ts +3 -3
  8. package/dist/components/markdown/classes.js +3 -3
  9. package/dist/components/markdown/compileMarkdown.d.ts +3 -1
  10. package/dist/components/markdown/compileMarkdown.js +29 -4
  11. package/dist/components/markdown/index.d.ts +3 -1
  12. package/dist/components/markdown/linkTargets.d.ts +2 -3
  13. package/dist/components/markdown/linkTargets.js +2 -27
  14. package/dist/components/post/CompactReplyParent.js +8 -0
  15. package/dist/components/post/FeedPostContent.js +3 -0
  16. package/dist/components/post/NewResourceButton.d.ts +8 -0
  17. package/dist/components/post/NewResourceButton.js +36 -0
  18. package/dist/components/post/PostDetail.js +3 -0
  19. package/dist/components/post/index.d.ts +5 -0
  20. package/dist/components/post/index.js +3 -0
  21. package/dist/components/post/pieces/PostMenu.js +4 -0
  22. package/dist/components/post/post-form/PostTypeSwitcher.js +12 -2
  23. package/dist/components/post/post-form/ResourceForm.d.ts +7 -0
  24. package/dist/components/post/post-form/ResourceForm.js +68 -0
  25. package/dist/components/post/types/resource/FullResource.d.ts +5 -0
  26. package/dist/components/post/types/resource/FullResource.js +99 -0
  27. package/dist/components/resources/CategoryPathPicker.d.ts +7 -0
  28. package/dist/components/resources/CategoryPathPicker.js +26 -0
  29. package/dist/components/resources/ResourceCard.d.ts +8 -0
  30. package/dist/components/resources/ResourceCard.js +121 -0
  31. package/dist/components/resources/ResourceLibrary.d.ts +4 -0
  32. package/dist/components/resources/ResourceLibrary.js +106 -0
  33. package/dist/components/resources/index.d.ts +6 -0
  34. package/dist/components/resources/index.js +3 -0
  35. package/dist/contexts/openpeeps/hooks/admin.d.ts +1064 -38
  36. package/dist/contexts/openpeeps/hooks/jams.d.ts +1064 -38
  37. package/dist/contexts/openpeeps/hooks/posts.d.ts +4508 -39936
  38. package/dist/hooks/events/useEventComposer.d.ts +1184 -44
  39. package/dist/hooks/events/useEventsCalendar.d.ts +2113 -61
  40. package/dist/hooks/index.d.ts +2 -0
  41. package/dist/hooks/index.js +2 -0
  42. package/dist/hooks/jams/useCreateNewJamForm.d.ts +39 -1
  43. package/dist/hooks/jams/useJamDetails.d.ts +1064 -38
  44. package/dist/hooks/jams/useJamRoom.d.ts +2113 -61
  45. package/dist/hooks/posts/useArticleComposer.d.ts +1184 -44
  46. package/dist/hooks/posts/useFeedPostPresentation.d.ts +2113 -61
  47. package/dist/hooks/posts/usePostDetailTitle.d.ts +1064 -38
  48. package/dist/hooks/posts/useResourceComposer.d.ts +12019 -0
  49. package/dist/hooks/posts/useResourceComposer.js +139 -0
  50. package/dist/hooks/resources/useResourceLibrary.d.ts +21880 -0
  51. package/dist/hooks/resources/useResourceLibrary.js +130 -0
  52. package/dist/hooks/settings/useNotificationPreferences.d.ts +1 -1
  53. package/dist/lib/analyticsClicks.js +1 -1
  54. package/dist/navigation/menuItems.js +5 -0
  55. package/dist/navigation/targets.d.ts +4 -0
  56. package/dist/pages/admin/analytics/Content.js +2 -1
  57. package/dist/pages/admin/analytics/Overview.js +15 -3
  58. package/dist/pages/groups/Show.js +7 -3
  59. package/dist/pages/index.d.ts +3 -0
  60. package/dist/pages/index.js +3 -0
  61. package/dist/pages/resources/Edit.d.ts +1 -0
  62. package/dist/pages/resources/Edit.js +26 -0
  63. package/dist/pages/resources/Index.d.ts +1 -0
  64. package/dist/pages/resources/Index.js +29 -0
  65. package/dist/pages/resources/New.d.ts +1 -0
  66. package/dist/pages/resources/New.js +15 -0
  67. package/dist/react-native.d.ts +3 -1
  68. package/dist/react-native.js +2 -1
  69. package/dist/stores/index.d.ts +1 -1
  70. package/dist/stores/index.js +1 -1
  71. package/dist/stores/newPosts.d.ts +79 -2
  72. package/dist/stores/newPosts.js +26 -2
  73. package/dist/stores/types.d.ts +2 -0
  74. package/package.json +7 -6
  75. package/src/components/index.ts +1 -0
  76. package/src/components/markdown/CompiledMarkdown.tsx +36 -7
  77. package/src/components/markdown/OpenpeepsMarkdown.tsx +16 -16
  78. package/src/components/markdown/classes.ts +3 -3
  79. package/src/components/markdown/compileMarkdown.ts +45 -5
  80. package/src/components/markdown/index.ts +6 -1
  81. package/src/components/markdown/linkTargets.ts +2 -31
  82. package/src/components/post/CompactReplyParent.tsx +8 -0
  83. package/src/components/post/FeedPostContent.tsx +3 -0
  84. package/src/components/post/NewResourceButton.tsx +75 -0
  85. package/src/components/post/PostDetail.tsx +3 -0
  86. package/src/components/post/index.ts +5 -0
  87. package/src/components/post/pieces/PostMenu.tsx +4 -0
  88. package/src/components/post/post-form/PostTypeSwitcher.tsx +19 -1
  89. package/src/components/post/post-form/ResourceForm.tsx +237 -0
  90. package/src/components/post/types/resource/FullResource.tsx +173 -0
  91. package/src/components/resources/CategoryPathPicker.tsx +95 -0
  92. package/src/components/resources/ResourceCard.tsx +335 -0
  93. package/src/components/resources/ResourceLibrary.tsx +374 -0
  94. package/src/components/resources/index.ts +6 -0
  95. package/src/contexts/openpeeps/hooks/posts.ts +11 -2
  96. package/src/hooks/index.ts +2 -0
  97. package/src/hooks/posts/useResourceComposer.ts +165 -0
  98. package/src/hooks/resources/useResourceLibrary.ts +156 -0
  99. package/src/lib/analyticsClicks.ts +1 -1
  100. package/src/navigation/menuItems.ts +6 -0
  101. package/src/navigation/targets.ts +1 -0
  102. package/src/pages/admin/analytics/Content.tsx +2 -1
  103. package/src/pages/admin/analytics/Overview.tsx +15 -3
  104. package/src/pages/groups/Show.tsx +30 -1
  105. package/src/pages/index.ts +3 -0
  106. package/src/pages/resources/Edit.tsx +73 -0
  107. package/src/pages/resources/Index.tsx +45 -0
  108. package/src/pages/resources/New.tsx +53 -0
  109. package/src/react-native.ts +12 -0
  110. package/src/stores/index.ts +1 -0
  111. package/src/stores/newPosts.ts +33 -2
  112. package/src/stores/types.ts +2 -0
@@ -0,0 +1,99 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Download, ExternalLink, Image as ImageIcon, Play } from 'lucide-react';
3
+ import { useState } from 'react';
4
+ import { attachmentMediaKind } from '@openpeepshq/common/lib';
5
+ import { useT } from '../../../../i18n/index.js';
6
+ import { FullPostLayout } from '../../FullPostLayout.js';
7
+ import { PostInfoHeader } from '../../pieces/PostInfoHeader.js';
8
+ import { PostMarkdown } from '../../Markdown.js';
9
+ import { ResourceCard } from '../../../resources/ResourceCard.js';
10
+ import { VideoPlayer } from '../../pieces/VideoPlayer.js';
11
+ import { AudioAttachment } from '../../pieces/AudioAttachment.js';
12
+ import { GalleryModal } from '../../pieces/GalleryModal.js';
13
+ export const FullResource = ({ post }) => {
14
+ const t = useT();
15
+ const resource = post.data?.type === 'resource' ? post.data : null;
16
+ const [galleryIndex, setGalleryIndex] = useState(null);
17
+ const [playerVisible, setPlayerVisible] = useState(false);
18
+ if (!resource)
19
+ return null;
20
+ const handlePreviewClick = () => {
21
+ switch (resource.resourceKind) {
22
+ case 'video':
23
+ case 'audio':
24
+ setPlayerVisible(true);
25
+ break;
26
+ case 'gallery':
27
+ setGalleryIndex(0);
28
+ break;
29
+ case 'file': {
30
+ const att = resource.attachments?.find((a) => attachmentMediaKind(a) === 'file');
31
+ if (att?.url)
32
+ window.open(att.url, '_blank');
33
+ break;
34
+ }
35
+ case 'link':
36
+ if (resource.url)
37
+ window.open(resource.url, '_blank');
38
+ break;
39
+ default:
40
+ break;
41
+ }
42
+ };
43
+ const previewIcon = () => {
44
+ switch (resource.resourceKind) {
45
+ case 'video':
46
+ case 'audio':
47
+ return _jsx(Play, { className: "size-12 text-white" });
48
+ case 'gallery':
49
+ return _jsx(ImageIcon, { className: "size-12 text-white" });
50
+ case 'file':
51
+ return _jsx(Download, { className: "size-12 text-white" });
52
+ case 'link':
53
+ return _jsx(ExternalLink, { className: "size-12 text-white" });
54
+ default:
55
+ return null;
56
+ }
57
+ };
58
+ const previewLabel = () => {
59
+ switch (resource.resourceKind) {
60
+ case 'video':
61
+ return t('resources.actions.watch', { defaultValue: 'Play video' });
62
+ case 'audio':
63
+ return t('resources.actions.listen', {
64
+ defaultValue: 'Play audio',
65
+ });
66
+ case 'gallery':
67
+ return t('resources.actions.view', {
68
+ defaultValue: 'View images',
69
+ });
70
+ case 'file':
71
+ return t('resources.actions.download', {
72
+ defaultValue: 'Download',
73
+ });
74
+ case 'link':
75
+ return t('resources.actions.openLink', {
76
+ defaultValue: 'Open link',
77
+ });
78
+ default:
79
+ return '';
80
+ }
81
+ };
82
+ const renderMedia = () => {
83
+ if (resource.resourceKind === 'video' && playerVisible) {
84
+ const videoAtt = resource.attachments?.find((a) => attachmentMediaKind(a) === 'video');
85
+ if (videoAtt) {
86
+ return (_jsx(ResourceCard, { post: post, preview: _jsx(VideoPlayer, { attachment: videoAtt, className: "max-h-[600px] w-full" }) }));
87
+ }
88
+ }
89
+ if (resource.resourceKind === 'audio' && playerVisible) {
90
+ const audioAtt = resource.attachments?.find((a) => attachmentMediaKind(a) === 'audio');
91
+ if (audioAtt?.url) {
92
+ return (_jsx(ResourceCard, { post: post, preview: _jsx(AudioAttachment, { src: audioAtt.url, label: audioAtt.filename ?? audioAtt.description, size: audioAtt.meta?.size }) }));
93
+ }
94
+ }
95
+ // All kinds: ResourceCard with click overlay
96
+ return (_jsxs("div", { className: "relative", children: [_jsx(ResourceCard, { post: post }), _jsx("div", { className: "pointer-events-none absolute left-0 right-0 top-0 flex h-48 items-center justify-center", children: _jsx("div", { className: "pointer-events-auto flex size-20 cursor-pointer items-center justify-center rounded-full bg-black/60 text-white", onClick: handlePreviewClick, role: "button", "aria-label": previewLabel(), children: previewIcon() }) })] }));
97
+ };
98
+ return (_jsx(FullPostLayout, { post: post, deleteCallback: () => window.history.back(), children: _jsxs("article", { className: "bg-background border-border relative min-w-0 border-b p-4", children: [_jsx(PostInfoHeader, { post: post, showMenu: true, deleteCallback: () => window.history.back() }), _jsxs("div", { className: "flex w-full min-w-0 flex-col gap-3", children: [renderMedia(), galleryIndex !== null ? (_jsx(GalleryModal, { attachments: resource.attachments ?? [], initialIndex: galleryIndex, onClose: () => setGalleryIndex(null) })) : null, resource?.content ? (_jsx(PostMarkdown, { source: resource.content })) : null] })] }) }));
99
+ };
@@ -0,0 +1,7 @@
1
+ import type { CategoryNode } from '@openpeepshq/common/lib';
2
+ export interface CategoryPathPickerProps {
3
+ path: string[];
4
+ tree: CategoryNode[];
5
+ onChange: (path: string[]) => void;
6
+ }
7
+ export declare const CategoryPathPicker: ({ path, tree, onChange, }: CategoryPathPickerProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { Button, Input } from '@openpeepshq/react-ui';
4
+ import { useT } from '../../i18n/index.js';
5
+ const NodeList = ({ nodes, selected, onSelect, }) => (_jsx("ul", { className: "border-border ml-3 border-l pl-3", children: nodes.map((node) => {
6
+ const active = selected.length === node.path.length &&
7
+ node.path.every((segment, index) => selected[index] === segment);
8
+ return (_jsxs("li", { className: "py-0.5", children: [_jsx("button", { type: "button", className: `text-sm ${active ? 'text-foreground font-semibold' : 'text-muted-foreground hover:text-foreground'}`, onClick: () => onSelect(node.path), children: node.name }), node.children.length ? (_jsx(NodeList, { nodes: node.children, selected: selected, onSelect: onSelect })) : null] }, node.path.join('/')));
9
+ }) }));
10
+ export const CategoryPathPicker = ({ path, tree, onChange, }) => {
11
+ const t = useT();
12
+ const [level, setLevel] = useState('');
13
+ return (_jsxs("div", { className: "space-y-2", children: [_jsx("p", { className: "text-muted-foreground text-sm", children: path.length
14
+ ? path.join(' / ')
15
+ : t('resources.form.uncategorized', {
16
+ defaultValue: 'Uncategorized',
17
+ }) }), tree.length ? (_jsx(NodeList, { nodes: tree, selected: path, onSelect: onChange })) : null, _jsxs("div", { className: "flex gap-2", children: [_jsx(Input, { value: level, onChange: (event) => setLevel(event.target.value), placeholder: t('resources.form.addLevel', {
18
+ defaultValue: 'Add a folder',
19
+ }) }), _jsx(Button, { variant: "outline", action: () => {
20
+ const name = level.trim();
21
+ if (!name)
22
+ return;
23
+ onChange([...path, name]);
24
+ setLevel('');
25
+ }, children: t('resources.form.addLevelAction', { defaultValue: 'Add' }) }), path.length ? (_jsx(Button, { variant: "ghost", action: () => onChange([]), children: t('resources.form.clearPath', { defaultValue: 'Clear' }) })) : null] })] }));
26
+ };
@@ -0,0 +1,8 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { PublicPost } from '@openpeepshq/common/types';
3
+ export interface ResourceCardProps {
4
+ post: PublicPost;
5
+ layout?: 'card' | 'list';
6
+ preview?: ReactNode;
7
+ }
8
+ export declare const ResourceCard: ({ post, layout, preview, }: ResourceCardProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,121 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useMemo, useState } from 'react';
3
+ import { BookmarkCheck, BookmarkPlus, Link as LinkIcon, ImageOff, } from 'lucide-react';
4
+ import { attachmentMediaKind, normalizeResourceTags, truncateMarkdown, formatSize, } from '@openpeepshq/common/lib';
5
+ import { useT } from '../../i18n/index.js';
6
+ import { useOpenpeeps } from '../../contexts/openpeeps/index.js';
7
+ import { useCurrentProfile } from '../layout/IdentityContext.js';
8
+ import { VideoPlayOverlay } from '../post/VideoPlayOverlay.js';
9
+ const visualAttachments = (attachments) => attachments.filter((att) => attachmentMediaKind(att) !== 'audio');
10
+ const previewSrc = (att) => att.previewUrl ?? att.url;
11
+ /** Thumbnail size shared between list and card previews. */
12
+ const THUMB_CLASS = 'h-12 w-12 object-cover';
13
+ const CARD_IMG_CLASS = 'h-48 w-full object-cover';
14
+ const primaryActionLabel = (kind, t) => {
15
+ switch (kind) {
16
+ case 'video':
17
+ return t('resources.actions.watch', { defaultValue: 'Watch' });
18
+ case 'file':
19
+ return t('resources.actions.download', { defaultValue: 'Download' });
20
+ case 'audio':
21
+ return t('resources.actions.listen', { defaultValue: 'Listen' });
22
+ case 'gallery':
23
+ return t('resources.actions.view', { defaultValue: 'View images' });
24
+ default:
25
+ return null;
26
+ }
27
+ };
28
+ const MediaPreview = ({ src, alt, className, isVideo, isLast, extra, }) => {
29
+ const [errored, setErrored] = useState(false);
30
+ if (!src) {
31
+ return (_jsx("div", { className: "bg-surface flex h-full w-full items-center justify-center overflow-hidden", children: _jsx(ImageOff, { className: "text-muted-foreground/50 size-6" }) }));
32
+ }
33
+ if (errored) {
34
+ return (_jsx("div", { className: "bg-surface flex h-full w-full items-center justify-center overflow-hidden", children: _jsx(ImageOff, { className: "text-muted-foreground/50 size-6" }) }));
35
+ }
36
+ return (_jsxs(_Fragment, { children: [_jsx("img", { src: src, alt: alt, className: className, onError: () => setErrored(true) }), isVideo ? _jsx(VideoPlayOverlay, { video: true }) : null, isLast && extra > 0 ? (_jsxs("div", { className: "absolute inset-0 flex items-center justify-center bg-black/60 text-lg font-semibold text-white", children: ["+", extra] })) : null] }));
37
+ };
38
+ export const ResourceCard = ({ post, layout = 'card', preview, }) => {
39
+ const t = useT();
40
+ const { openpeepsApi } = useOpenpeeps();
41
+ const me = useCurrentProfile();
42
+ if (post.data?.type !== 'resource')
43
+ return null;
44
+ const resource = post.data;
45
+ const attachments = resource.attachments ?? [];
46
+ const visuals = visualAttachments(attachments);
47
+ const excerpt = truncateMarkdown(resource.content, 2, 240);
48
+ const tags = normalizeResourceTags(resource.tags);
49
+ const isGallery = resource.resourceKind === 'gallery' && visuals.length > 1;
50
+ const tiles = isGallery ? visuals.slice(0, 4) : visuals.slice(0, 1);
51
+ const extra = isGallery ? Math.max(0, visuals.length - 4) : 0;
52
+ const actionLabel = primaryActionLabel(resource.resourceKind, t);
53
+ const thumbnail = visuals[0];
54
+ const thumbSrc = thumbnail ? previewSrc(thumbnail) : null;
55
+ const metaText = useMemo(() => {
56
+ if (resource.resourceKind === 'gallery' && visuals.length > 1) {
57
+ return t('resources.meta.imagesCount', {
58
+ defaultValue: '{{count}} images',
59
+ count: visuals.length,
60
+ });
61
+ }
62
+ const fileAtt = attachments.find((att) => attachmentMediaKind(att) === 'file' ||
63
+ attachmentMediaKind(att) === 'video' ||
64
+ attachmentMediaKind(att) === 'audio');
65
+ const size = fileAtt?.meta?.size;
66
+ if (size)
67
+ return formatSize(size);
68
+ return null;
69
+ }, [resource.resourceKind, visuals, attachments, t]);
70
+ const bookmarkedIdsQuery = openpeepsApi.useCurrentProfileBookmarkedIds();
71
+ const isBookmarked = bookmarkedIdsQuery.data?.includes(post.id) ?? false;
72
+ const bookmarkPost = openpeepsApi.bookmarkPostAction({ id: post.id });
73
+ const unbookmarkPost = openpeepsApi.unbookmarkPostAction({ id: post.id });
74
+ const toggleBookmark = () => {
75
+ if (!me)
76
+ return;
77
+ if (isBookmarked) {
78
+ unbookmarkPost(undefined);
79
+ }
80
+ else {
81
+ bookmarkPost(undefined);
82
+ }
83
+ };
84
+ const downloadUrl = resource.resourceKind === 'file'
85
+ ? attachments.find((att) => attachmentMediaKind(att) === 'file')?.url
86
+ : null;
87
+ const renderBookmarkButton = (className) => (_jsx("button", { type: "button", onClick: (e) => {
88
+ e.preventDefault();
89
+ e.stopPropagation();
90
+ toggleBookmark();
91
+ }, disabled: !me, className: className, title: isBookmarked
92
+ ? t('resources.actions.saved', { defaultValue: 'Saved' })
93
+ : t('resources.actions.save', { defaultValue: 'Save' }), children: isBookmarked ? (_jsx(BookmarkCheck, { className: "text-primary size-4" })) : (_jsx(BookmarkPlus, { className: "size-4" })) }));
94
+ const renderThumbnail = () => {
95
+ if (thumbSrc) {
96
+ return (_jsx("img", { src: thumbSrc, alt: thumbnail?.description ?? resource.title, className: THUMB_CLASS, onError: (e) => {
97
+ e.target.style.display = 'none';
98
+ } }));
99
+ }
100
+ if (resource.resourceKind === 'link' && resource.url) {
101
+ return (_jsx("div", { className: "bg-muted flex h-12 w-12 items-center justify-center rounded-md", children: _jsx(LinkIcon, { className: "text-muted-foreground size-5" }) }));
102
+ }
103
+ return null;
104
+ };
105
+ if (layout === 'list') {
106
+ return (_jsxs("div", { className: "flex w-full min-w-0 items-center gap-3 px-4 py-3", children: [renderThumbnail(), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("h3", { className: "text-lg font-semibold", children: resource.title }), resource.categoryPath?.length ? (_jsx("p", { className: "text-muted-foreground text-xs", children: resource.categoryPath.join(' / ') })) : null, excerpt ? (_jsx("p", { className: "text-muted-foreground text-sm", children: excerpt })) : null, metaText ? (_jsx("p", { className: "text-muted-foreground text-xs", children: metaText })) : null] }), _jsxs("div", { className: "flex items-center gap-2", children: [resource.resourceKind === 'link' &&
107
+ resource.url ? null : actionLabel ? (resource.resourceKind === 'file' && downloadUrl ? (_jsx("a", { href: downloadUrl, download: true, onClick: (e) => e.stopPropagation(), className: "text-primary text-xs font-medium", children: actionLabel })) : (_jsx("span", { className: "text-muted-foreground text-xs", children: actionLabel }))) : null, renderBookmarkButton('text-muted-foreground hover:text-foreground disabled:opacity-50')] })] }));
108
+ }
109
+ return (_jsxs("div", { className: "flex w-full min-w-0 flex-col gap-2", children: [_jsxs("div", { className: "relative", children: [preview ? (preview) : tiles.length ? (_jsx("div", { className: `overflow-hidden rounded-md ${tiles.length > 1
110
+ ? 'grid h-48 grid-cols-2 grid-rows-2 gap-1'
111
+ : 'h-48 w-full'}`, children: tiles.map((att, index) => {
112
+ const src = previewSrc(att);
113
+ const last = index === tiles.length - 1 && extra > 0;
114
+ const kind = attachmentMediaKind(att);
115
+ return (_jsx("div", { className: "bg-surface relative h-full w-full overflow-hidden", children: _jsx(MediaPreview, { src: src, alt: att.description ?? resource.title, className: tiles.length > 1
116
+ ? 'h-full w-full object-cover'
117
+ : CARD_IMG_CLASS, isVideo: kind === 'video', isLast: last, extra: extra }) }, `${att.url ?? index}-${index}`));
118
+ }) })) : resource.resourceKind === 'link' && resource.url ? (_jsx("div", { className: "bg-muted flex h-48 w-full items-center justify-center rounded-md", children: _jsx(LinkIcon, { className: "text-muted-foreground/50 size-8" }) })) : null, renderBookmarkButton('bg-background text-muted-foreground hover:text-foreground absolute right-2 top-2 rounded-full p-1 opacity-70 hover:opacity-100 disabled:opacity-50')] }), _jsx("h3", { className: "text-lg font-semibold", children: resource.title }), resource.categoryPath?.length ? (_jsx("p", { className: "text-muted-foreground text-xs", children: resource.categoryPath.join(' / ') })) : null, excerpt ? (_jsx("p", { className: "text-muted-foreground text-sm", children: excerpt })) : null, metaText ? (_jsx("p", { className: "text-muted-foreground text-xs", children: metaText })) : null, tags.length ? (_jsx("div", { className: "flex flex-wrap gap-1", children: tags.map((value) => (_jsxs("span", { className: "bg-muted text-muted-foreground rounded-full px-2 py-0.5 text-xs", children: ["#", value] }, value))) })) : null, _jsx("p", { className: "text-muted-foreground text-xs uppercase", children: t(`resources.kinds.${resource.resourceKind}`, {
119
+ defaultValue: resource.resourceKind,
120
+ }) })] }));
121
+ };
@@ -0,0 +1,4 @@
1
+ export interface ResourceLibraryProps {
2
+ groupId?: string;
3
+ }
4
+ export declare const ResourceLibrary: ({ groupId }: ResourceLibraryProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,106 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { LayoutList, LayoutGrid, BookmarkIcon, ChevronDown, ChevronRight, } from 'lucide-react';
3
+ import { RESOURCE_KINDS } from '@openpeepshq/common/lib';
4
+ import { Button, Input, LoadingSpinner } from '@openpeepshq/react-ui';
5
+ import { useMemo, useState } from 'react';
6
+ import { useT } from '../../i18n/index.js';
7
+ import { useHrefOf } from '../../contexts/router/index.js';
8
+ import { useResourceLibrary } from '../../hooks/index.js';
9
+ import { ResourceCard } from './ResourceCard.js';
10
+ const COLLECTION_LIMIT = 5;
11
+ const Tree = ({ nodes, selected, onSelect, counts, expanded, onToggle, }) => (_jsx("ul", { className: "space-y-1", children: nodes.map((node) => {
12
+ const nodeKey = node.path.join('/');
13
+ const nodeCount = counts.get(nodeKey) ?? 0;
14
+ const isExpanded = expanded.has(nodeKey);
15
+ const isSelected = selected.join('/') === nodeKey;
16
+ const hasChildren = node.children.length > 0;
17
+ return (_jsxs("li", { children: [_jsxs("div", { className: "flex items-center gap-1", children: [_jsx("button", { type: "button", className: `text-muted-foreground hover:text-foreground ${hasChildren ? '' : 'invisible'}`, onClick: hasChildren ? () => onToggle(nodeKey) : undefined, children: _jsx(ChevronRight, { className: `size-3 transition-transform ${isExpanded ? 'rotate-90' : ''}` }) }), _jsxs("button", { type: "button", className: `text-sm ${isSelected
18
+ ? 'font-semibold'
19
+ : 'text-muted-foreground hover:text-foreground'}`, onClick: () => onSelect(node.path), children: [node.name, nodeCount > 0 ? (_jsxs("span", { className: "text-xs opacity-60", children: ["(", nodeCount, ")"] })) : null] })] }), hasChildren && isExpanded ? (_jsx("div", { className: "ml-4", children: _jsx(Tree, { nodes: node.children, selected: selected, onSelect: onSelect, counts: counts, expanded: expanded, onToggle: onToggle }) })) : null] }, nodeKey));
20
+ }) }));
21
+ export const ResourceLibrary = ({ groupId }) => {
22
+ const t = useT();
23
+ const hrefOf = useHrefOf();
24
+ const library = useResourceLibrary(groupId);
25
+ const [expanded, setExpanded] = useState(new Set());
26
+ const toggleNode = (nodeKey) => {
27
+ setExpanded((prev) => {
28
+ const next = new Set(prev);
29
+ if (next.has(nodeKey))
30
+ next.delete(nodeKey);
31
+ else
32
+ next.add(nodeKey);
33
+ return next;
34
+ });
35
+ };
36
+ const collectionCounts = useMemo(() => {
37
+ const counts = new Map();
38
+ let rootCount = 0;
39
+ for (const post of library.posts) {
40
+ if (post.data?.type !== 'resource')
41
+ continue;
42
+ const path = post.data.categoryPath;
43
+ if (!path?.length)
44
+ continue;
45
+ rootCount++;
46
+ for (let i = 1; i <= path.length; i++) {
47
+ const key = path.slice(0, i).join('/');
48
+ counts.set(key, (counts.get(key) ?? 0) + 1);
49
+ }
50
+ }
51
+ counts.set('', rootCount);
52
+ return counts;
53
+ }, [library.posts]);
54
+ const treeNodes = useMemo(() => {
55
+ if (library.tree.length === 0)
56
+ return [];
57
+ return [
58
+ {
59
+ name: t('resources.library.allFolders', {
60
+ defaultValue: 'All folders',
61
+ }),
62
+ path: [],
63
+ children: library.tree,
64
+ },
65
+ ];
66
+ }, [library.tree, t]);
67
+ const sortedTags = useMemo(() => library.tags
68
+ .filter((entry) => library.selectedTags.includes(entry.name))
69
+ .concat(library.tags.filter((entry) => !library.selectedTags.includes(entry.name))), [library.tags, library.selectedTags]);
70
+ const visibleTags = library.tagsOpen
71
+ ? sortedTags
72
+ : sortedTags.slice(0, COLLECTION_LIMIT);
73
+ const hasMoreTags = sortedTags.length > COLLECTION_LIMIT;
74
+ return (_jsxs("div", { children: [_jsxs("div", { className: "flex flex-col gap-3 p-4", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx(Input, { className: "flex-1", value: library.search, onChange: (event) => library.setSearch(event.target.value), placeholder: t('resources.library.search', {
75
+ defaultValue: 'Search resources',
76
+ }), "data-testid": "resources-search" }), _jsxs("div", { className: "ml-auto flex gap-1", children: [_jsx(Button, { compact: true, size: "sm", variant: library.view === 'list' ? 'default' : 'outline', action: () => library.setView('list'), "data-testid": "resources-view-list", title: t('resources.library.viewList', {
77
+ defaultValue: 'List view',
78
+ }), children: _jsx(LayoutList, { className: "size-4" }) }), _jsx(Button, { compact: true, size: "sm", variant: library.view === 'cards' ? 'default' : 'outline', action: () => library.setView('cards'), "data-testid": "resources-view-cards", title: t('resources.library.viewCards', {
79
+ defaultValue: 'Cards view',
80
+ }), children: _jsx(LayoutGrid, { className: "size-4" }) }), _jsxs(Button, { compact: true, size: "sm", variant: library.saved ? 'default' : 'outline', action: () => library.setSaved(!library.saved), "data-testid": "resources-saved", title: t('resources.library.saved', { defaultValue: 'Saved' }), children: [_jsx(BookmarkIcon, { className: "size-4" }), t('resources.library.saved', { defaultValue: 'Saved' })] })] })] }), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { compact: true, variant: library.kind === 'all' ? 'default' : 'outline', action: () => library.setKind('all'), children: t('resources.library.allKinds', { defaultValue: 'All' }) }), RESOURCE_KINDS.map((kind) => (_jsx(Button, { compact: true, variant: library.kind === kind ? 'default' : 'outline', action: () => library.setKind(kind), children: t(`resources.kinds.${kind}`, { defaultValue: kind }) }, kind)))] }), _jsxs("div", { children: [_jsxs("div", { className: "flex items-center gap-2 text-sm", children: [_jsx("button", { type: "button", className: "text-muted-foreground hover:text-foreground", onClick: () => library.setPathPrefix([]), children: "All" }), library.pathPrefix.length > 0 ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "text-muted-foreground", children: "/" }), _jsx("span", { className: "text-muted-foreground", children: library.pathPrefix.join(' / ') })] })) : null, _jsx("button", { type: "button", className: "text-muted-foreground hover:text-foreground ml-auto", onClick: () => library.setHierarchy(!library.hierarchy), children: library.hierarchy ? (_jsx(ChevronDown, { className: "size-4" })) : (_jsx(ChevronRight, { className: "size-4" })) })] }), library.hierarchy ? (_jsx("div", { className: "border-border mt-2 rounded-md border p-3", children: treeNodes.length ? (_jsx(Tree, { nodes: treeNodes, selected: library.pathPrefix, onSelect: library.setPathPrefix, counts: collectionCounts, expanded: expanded, onToggle: toggleNode })) : null })) : null] }), library.tags.length ? (_jsxs("div", { className: "flex flex-col gap-1", children: [_jsx("div", { className: "flex flex-wrap gap-1", children: visibleTags.map((entry) => {
81
+ const isSelected = library.selectedTags.includes(entry.name);
82
+ return (_jsxs("button", { type: "button", className: `rounded-full px-2 py-0.5 text-xs ${isSelected
83
+ ? 'bg-primary text-primary-foreground'
84
+ : 'bg-muted text-muted-foreground'}`, onClick: () => library.toggleTag(entry.name), children: ["#", entry.name, " ", entry.count] }, entry.name));
85
+ }) }), hasMoreTags ? (_jsx("button", { type: "button", className: "bg-muted text-muted-foreground rounded-full px-2 py-0.5 text-xs", onClick: () => library.setTagsOpen(!library.tagsOpen), children: library.tagsOpen
86
+ ? t('resources.library.hideTags', {
87
+ defaultValue: 'Hide',
88
+ })
89
+ : t('resources.library.showHiddenTags', {
90
+ defaultValue: '+ {{count}}',
91
+ count: sortedTags.length - COLLECTION_LIMIT,
92
+ }) })) : null] })) : null, library.posts.length > 0 ? (_jsx("p", { className: "text-muted-foreground text-xs", children: t('resources.library.resourceCount', {
93
+ defaultValue: 'Showing {{count}} resources',
94
+ count: library.posts.length,
95
+ }) })) : null] }), library.query.isLoading ? (_jsx("div", { className: "flex h-32 items-center justify-center", children: _jsx(LoadingSpinner, {}) })) : library.posts.length === 0 ? (_jsx("p", { className: "text-muted-foreground p-8 text-center text-sm", children: library.activeFilterCount > 0
96
+ ? t('resources.library.noResults', {
97
+ defaultValue: 'No resources match your current filters.',
98
+ })
99
+ : library.pathPrefix.length
100
+ ? t('resources.library.emptyCollection', {
101
+ defaultValue: 'This collection has no resources yet.',
102
+ })
103
+ : t('resources.library.empty', {
104
+ defaultValue: 'No resources yet.',
105
+ }) })) : library.view === 'list' ? (_jsx("div", { className: "divide-border flex flex-col divide-y", children: library.posts.map((post) => (_jsx("a", { href: hrefOf({ type: 'post', id: post.id }), className: "block", children: _jsx(ResourceCard, { post: post, layout: "list" }) }, post.id))) })) : (_jsx("div", { className: "grid grid-cols-1 gap-4 p-4 sm:grid-cols-2 lg:grid-cols-3", children: library.posts.map((post) => (_jsx("a", { href: hrefOf({ type: 'post', id: post.id }), className: "block", children: _jsx(ResourceCard, { post: post, layout: "card" }) }, post.id))) }))] }));
106
+ };
@@ -0,0 +1,6 @@
1
+ export { ResourceLibrary } from './ResourceLibrary';
2
+ export type { ResourceLibraryProps } from './ResourceLibrary';
3
+ export { ResourceCard } from './ResourceCard';
4
+ export type { ResourceCardProps } from './ResourceCard';
5
+ export { CategoryPathPicker } from './CategoryPathPicker';
6
+ export type { CategoryPathPickerProps } from './CategoryPathPicker';
@@ -0,0 +1,3 @@
1
+ export { ResourceLibrary } from './ResourceLibrary.js';
2
+ export { ResourceCard } from './ResourceCard.js';
3
+ export { CategoryPathPicker } from './CategoryPathPicker.js';