@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
@@ -6,6 +6,7 @@ export * from './registry';
6
6
  export * from './form';
7
7
  export * from './profile';
8
8
  export * from './post';
9
+ export * from './resources';
9
10
  export * from './markdown';
10
11
  export * from './notifications';
11
12
  export * from './groups';
@@ -6,6 +6,7 @@ export * from './registry/index.js';
6
6
  export * from './form/index.js';
7
7
  export * from './profile/index.js';
8
8
  export * from './post/index.js';
9
+ export * from './resources/index.js';
9
10
  export * from './markdown/index.js';
10
11
  export * from './notifications/index.js';
11
12
  export * from './groups/index.js';
@@ -1,5 +1,7 @@
1
1
  export interface CompiledMarkdownProps {
2
2
  html: string;
3
3
  className?: string;
4
+ /** When false, HTML is rendered as-is without sanitization (for trusted sources). */
5
+ sanitize?: boolean;
4
6
  }
5
- export declare const CompiledMarkdown: ({ html, className, }: CompiledMarkdownProps) => import("react/jsx-runtime").JSX.Element;
7
+ export declare const CompiledMarkdown: ({ html, className, sanitize, }: CompiledMarkdownProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
3
+ import DOMPurify from 'dompurify';
4
+ import { injectIframeSafetyAttrs, MARKDOWN_HTML_ALLOWED_TAGS, MARKDOWN_HTML_ALLOWED_ATTRS, MARKDOWN_HTML_FORBIDDEN_TAGS, MARKDOWN_HTML_FORBIDDEN_ATTRS, } from '@openpeepshq/common/lib';
2
5
  import { OPENPEEPS_MARKDOWN_PROSE_CLASS } from './classes.js';
3
6
  import { isExternalLink } from './linkTargets.js';
4
7
  import { recordOutboundClick } from '../../lib/analyticsClicks.js';
@@ -14,4 +17,17 @@ const onMarkdownClick = (event) => {
14
17
  recordOutboundClick(href, origin);
15
18
  }
16
19
  };
17
- export const CompiledMarkdown = ({ html, className, }) => (_jsx("div", { className: className ?? OPENPEEPS_MARKDOWN_PROSE_CLASS, dangerouslySetInnerHTML: { __html: html }, onClick: onMarkdownClick }));
20
+ const sanitizeHtml = (html) => {
21
+ let clean = DOMPurify.sanitize(html, {
22
+ ALLOWED_TAGS: [...MARKDOWN_HTML_ALLOWED_TAGS],
23
+ ALLOWED_ATTR: [...MARKDOWN_HTML_ALLOWED_ATTRS],
24
+ FORBID_TAGS: [...MARKDOWN_HTML_FORBIDDEN_TAGS],
25
+ FORBID_ATTR: [...MARKDOWN_HTML_FORBIDDEN_ATTRS],
26
+ });
27
+ clean = injectIframeSafetyAttrs(clean);
28
+ return clean;
29
+ };
30
+ export const CompiledMarkdown = ({ html, className, sanitize = true, }) => {
31
+ const safeHtml = useMemo(() => (sanitize ? sanitizeHtml(html) : html), [html, sanitize]);
32
+ return (_jsx("div", { className: className ?? OPENPEEPS_MARKDOWN_PROSE_CLASS, dangerouslySetInnerHTML: { __html: safeHtml }, onClick: onMarkdownClick }));
33
+ };
@@ -1,16 +1,12 @@
1
+ import type { MarkdownRenderProps } from '@openpeepshq/common/lib';
2
+ /** @deprecated Use {@link MentionProfileRef} from @openpeepshq/common. */
1
3
  export type MarkdownMention = {
2
- text?: string;
3
4
  profile: {
4
5
  handle: string;
5
6
  displayName?: string | null;
6
7
  };
7
8
  };
8
- export interface OpenpeepsMarkdownProps {
9
- source?: string;
10
- mentions?: MarkdownMention[];
9
+ export interface OpenpeepsMarkdownProps extends MarkdownRenderProps {
11
10
  className?: string;
12
- linkPreviewMode?: 'prepend' | 'append' | 'none';
13
- /** When true, all links open in a new tab. External links always do. */
14
- newTab?: boolean;
15
11
  }
16
12
  export declare function OpenpeepsMarkdown({ source, mentions, className, linkPreviewMode, newTab, }: OpenpeepsMarkdownProps): import("react/jsx-runtime").JSX.Element;
@@ -1,17 +1,17 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useMemo } from 'react';
3
- import { linkProfileMentions } from '@openpeepshq/common/lib';
3
+ import { preprocessMarkdownSource } from '@openpeepshq/common/lib';
4
4
  import { extractUrlsFromText, isEmail } from '../preview-link/helpers.js';
5
5
  import { PreviewLink } from '../preview-link/PreviewLink.js';
6
6
  import { OPENPEEPS_MARKDOWN_PROSE_CLASS, OPENPEEPS_MARKDOWN_STATIC_CLASS, } from './classes.js';
7
7
  import { compileMarkdownToHtml } from './compileMarkdown.js';
8
8
  import { resolveStaticUrl, useStaticRender } from './staticRender.js';
9
- const hashtagPattern = /(^|[\s(>])#([a-z0-9_]+)(?=\s|$|[.,!?;:])/gi;
10
- function preprocessSource(source, mentions = []) {
11
- let text = linkProfileMentions(source, mentions);
9
+ const hashtagPattern = /(^|[\s(>])#([a-z0-9_]+)(?=\s|$|[.,!?;:])$/gi;
10
+ const preprocessWithHashtags = (source, mentions = []) => {
11
+ let text = preprocessMarkdownSource(source, mentions);
12
12
  text = text.replace(hashtagPattern, (_, prefix, tag) => `${prefix}[#${tag}](/tags/${encodeURIComponent(tag)})`);
13
13
  return text;
14
- }
14
+ };
15
15
  const markdownOrigin = (staticRender, baseUrl) => {
16
16
  if (staticRender && baseUrl) {
17
17
  try {
@@ -39,8 +39,12 @@ export function OpenpeepsMarkdown({ source, mentions = [], className, linkPrevie
39
39
  .filter((url) => !isEmail(url));
40
40
  }, [source]);
41
41
  const html = useMemo(() => {
42
- const processed = preprocessSource(source ?? '', mentions);
43
- let out = compileMarkdownToHtml(processed, { origin, newTab });
42
+ const processed = preprocessWithHashtags(source ?? '', mentions);
43
+ let out = compileMarkdownToHtml(processed, {
44
+ origin,
45
+ newTab,
46
+ sanitize: true,
47
+ });
44
48
  if (staticRender && baseUrl) {
45
49
  out = out.replace(/href="(\/[^"]*)"/g, (_, path) => {
46
50
  return `href="${resolveStaticUrl(path, baseUrl)}"`;
@@ -1,4 +1,4 @@
1
- export declare const OPENPEEPS_MARKDOWN_PROSE_CLASS = "allpeep-markdown prose prose-sm max-w-none break-words dark:prose-invert prose-a:text-primary prose-a:no-underline hover:prose-a:underline prose-code:before:content-[''] prose-code:after:content-[''] prose-pre:max-w-full prose-pre:overflow-x-auto prose-table:text-base";
2
- export declare const OPENPEEPS_MARKDOWN_STATIC_CLASS = "allpeep-markdown text-sm leading-relaxed break-words text-foreground";
1
+ export declare const OPENPEEPS_MARKDOWN_PROSE_CLASS = "allpeep-markdown prose prose-sm max-w-none break-words dark:prose-invert prose-a:text-primary prose-a:no-underline hover:prose-a:underline prose-code:before:content-[''] prose-code:after:content-[''] prose-pre:max-w-full prose-pre:overflow-x-auto prose-table:text-base prose-iframe:max-w-full prose-iframe:w-full prose-iframe:border-0";
2
+ export declare const OPENPEEPS_MARKDOWN_STATIC_CLASS = "allpeep-markdown text-sm leading-relaxed break-words text-foreground prose-iframe:max-w-full prose-iframe:w-full prose-iframe:border-0";
3
3
  /** Post-card caption text (feed Note/Poll/Article bodies) — Figma "PostCards" postCaption uses base (16px), not the prose-sm default used elsewhere (jam chat, editor preview, full event page). */
4
- export declare const OPENPEEPS_POST_CAPTION_CLASS = "allpeep-markdown prose max-w-none break-words dark:prose-invert prose-a:text-primary prose-a:no-underline hover:prose-a:underline prose-code:before:content-[''] prose-code:after:content-[''] prose-pre:max-w-full prose-pre:overflow-x-auto prose-table:text-base";
4
+ export declare const OPENPEEPS_POST_CAPTION_CLASS = "allpeep-markdown prose max-w-none break-words dark:prose-invert prose-a:text-primary prose-a:no-underline hover:prose-a:underline prose-code:before:content-[''] prose-code:after:content-[''] prose-pre:max-w-full prose-pre:overflow-x-auto prose-table:text-base prose-iframe:max-w-full prose-iframe:w-full prose-iframe:border-0";
@@ -1,4 +1,4 @@
1
- export const OPENPEEPS_MARKDOWN_PROSE_CLASS = "allpeep-markdown prose prose-sm max-w-none break-words dark:prose-invert prose-a:text-primary prose-a:no-underline hover:prose-a:underline prose-code:before:content-[''] prose-code:after:content-[''] prose-pre:max-w-full prose-pre:overflow-x-auto prose-table:text-base";
2
- export const OPENPEEPS_MARKDOWN_STATIC_CLASS = 'allpeep-markdown text-sm leading-relaxed break-words text-foreground';
1
+ export const OPENPEEPS_MARKDOWN_PROSE_CLASS = "allpeep-markdown prose prose-sm max-w-none break-words dark:prose-invert prose-a:text-primary prose-a:no-underline hover:prose-a:underline prose-code:before:content-[''] prose-code:after:content-[''] prose-pre:max-w-full prose-pre:overflow-x-auto prose-table:text-base prose-iframe:max-w-full prose-iframe:w-full prose-iframe:border-0";
2
+ export const OPENPEEPS_MARKDOWN_STATIC_CLASS = 'allpeep-markdown text-sm leading-relaxed break-words text-foreground prose-iframe:max-w-full prose-iframe:w-full prose-iframe:border-0';
3
3
  /** Post-card caption text (feed Note/Poll/Article bodies) — Figma "PostCards" postCaption uses base (16px), not the prose-sm default used elsewhere (jam chat, editor preview, full event page). */
4
- export const OPENPEEPS_POST_CAPTION_CLASS = "allpeep-markdown prose max-w-none break-words dark:prose-invert prose-a:text-primary prose-a:no-underline hover:prose-a:underline prose-code:before:content-[''] prose-code:after:content-[''] prose-pre:max-w-full prose-pre:overflow-x-auto prose-table:text-base";
4
+ export const OPENPEEPS_POST_CAPTION_CLASS = "allpeep-markdown prose max-w-none break-words dark:prose-invert prose-a:text-primary prose-a:no-underline hover:prose-a:underline prose-code:before:content-[''] prose-code:after:content-[''] prose-pre:max-w-full prose-pre:overflow-x-auto prose-table:text-base prose-iframe:max-w-full prose-iframe:w-full prose-iframe:border-0";
@@ -1,5 +1,7 @@
1
1
  export type CompileMarkdownOptions = {
2
2
  origin?: string;
3
- newTab?: boolean;
3
+ /** When true (default), the compiled HTML is sanitized before output. */
4
+ newTab?: boolean | ((link: string) => boolean);
5
+ sanitize?: boolean;
4
6
  };
5
7
  export declare const compileMarkdownToHtml: (source: string, options?: CompileMarkdownOptions) => string;
@@ -1,5 +1,6 @@
1
1
  import { marked, Renderer } from 'marked';
2
- import { linkOpensInNewTab } from './linkTargets.js';
2
+ import DOMPurify from 'dompurify';
3
+ import { isExternalLink, injectIframeSafetyAttrs, MARKDOWN_HTML_ALLOWED_TAGS, MARKDOWN_HTML_ALLOWED_ATTRS, MARKDOWN_HTML_FORBIDDEN_TAGS, MARKDOWN_HTML_FORBIDDEN_ATTRS, } from '@openpeepshq/common/lib';
3
4
  const escapeHtml = (text) => text
4
5
  .replace(/&/g, '&')
5
6
  .replace(/</g, '&lt;')
@@ -13,8 +14,13 @@ const cleanHref = (href) => {
13
14
  return null;
14
15
  }
15
16
  };
17
+ const resolveNewTabFlag = (newTab, href) => {
18
+ if (typeof newTab === 'function')
19
+ return newTab(href);
20
+ return newTab ?? false;
21
+ };
16
22
  export const compileMarkdownToHtml = (source, options = {}) => {
17
- const { origin, newTab = false } = options;
23
+ const { origin, newTab = false, sanitize: shouldSanitize = true } = options;
18
24
  const renderer = new Renderer();
19
25
  renderer.link = function ({ href, title, tokens }) {
20
26
  const text = this.parser.parseInline(tokens);
@@ -22,15 +28,34 @@ export const compileMarkdownToHtml = (source, options = {}) => {
22
28
  if (!cleaned) {
23
29
  return text;
24
30
  }
31
+ const opensNewTab = resolveNewTabFlag(newTab, cleaned);
25
32
  let out = `<a href="${cleaned}"`;
26
33
  if (title) {
27
34
  out += ` title="${escapeHtml(title)}"`;
28
35
  }
29
- if (linkOpensInNewTab(cleaned, origin, newTab)) {
36
+ if (isExternalLink(cleaned, origin) || opensNewTab) {
30
37
  out += ' target="_blank" rel="noopener noreferrer"';
31
38
  }
32
39
  out += `>${text}</a>`;
33
40
  return out;
34
41
  };
35
- return marked.parse(source, { renderer, async: false });
42
+ let html = marked.parse(source, { renderer, async: false });
43
+ if (shouldSanitize) {
44
+ // DOMPurify requires a DOM and is effectively browser-only: in Node
45
+ // (build-time docs manifest, server-side emails) DOMPurify.sanitize is
46
+ // not a function, so skip it. That HTML is re-sanitized at render time
47
+ // via CompiledMarkdown in the browser.
48
+ if (typeof DOMPurify.sanitize === 'function') {
49
+ html = DOMPurify.sanitize(html, {
50
+ ALLOWED_TAGS: [...MARKDOWN_HTML_ALLOWED_TAGS],
51
+ ALLOWED_ATTR: [...MARKDOWN_HTML_ALLOWED_ATTRS],
52
+ FORBID_TAGS: [...MARKDOWN_HTML_FORBIDDEN_TAGS],
53
+ FORBID_ATTR: [...MARKDOWN_HTML_FORBIDDEN_ATTRS],
54
+ });
55
+ }
56
+ // Inject sandbox/loading/containment attrs on iframes after sanitization
57
+ // so attackers can't smuggle attributes through DOMPurify's allowlist.
58
+ html = injectIframeSafetyAttrs(html);
59
+ }
60
+ return html;
36
61
  };
@@ -1,7 +1,9 @@
1
1
  export { OpenpeepsMarkdown } from './OpenpeepsMarkdown';
2
- export type { OpenpeepsMarkdownProps } from './OpenpeepsMarkdown';
2
+ export type { OpenpeepsMarkdownProps, MarkdownMention, } from './OpenpeepsMarkdown';
3
+ export type { MarkdownRenderProps } from '@openpeepshq/common/lib';
3
4
  export { OPENPEEPS_MARKDOWN_PROSE_CLASS, OPENPEEPS_MARKDOWN_STATIC_CLASS, OPENPEEPS_POST_CAPTION_CLASS, } from './classes';
4
5
  export { compileMarkdownToHtml } from './compileMarkdown';
6
+ export type { CompileMarkdownOptions } from './compileMarkdown';
5
7
  export { CompiledMarkdown } from './CompiledMarkdown';
6
8
  export type { CompiledMarkdownProps } from './CompiledMarkdown';
7
9
  export { StaticRenderContext, useStaticRender, resolveStaticUrl, } from './staticRender';
@@ -1,3 +1,2 @@
1
- /** Mirrors Svelte `OpenpeepsMarkdown` / `a.svelte` external-link detection. */
2
- export declare const isExternalLink: (href: string, origin?: string) => boolean;
3
- export declare const linkOpensInNewTab: (href: string | null | undefined, origin: string | undefined, newTab: boolean) => boolean;
1
+ /** Re-exports shared link utilities from @openpeepshq/common. */
2
+ export { isExternalLink } from '@openpeepshq/common/lib';
@@ -1,27 +1,2 @@
1
- /** Mirrors Svelte `OpenpeepsMarkdown` / `a.svelte` external-link detection. */
2
- export const isExternalLink = (href, origin) => {
3
- if (!href || /^(mailto:|tel:|#)/.test(href)) {
4
- return false;
5
- }
6
- if (href.startsWith('/') && !href.startsWith('//')) {
7
- return false;
8
- }
9
- if (!origin) {
10
- return !href.startsWith('/');
11
- }
12
- try {
13
- return new URL(href, origin).origin !== origin;
14
- }
15
- catch {
16
- return !href.startsWith('/');
17
- }
18
- };
19
- export const linkOpensInNewTab = (href, origin, newTab) => {
20
- if (!href) {
21
- return false;
22
- }
23
- if (newTab) {
24
- return true;
25
- }
26
- return isExternalLink(href, origin);
27
- };
1
+ /** Re-exports shared link utilities from @openpeepshq/common. */
2
+ export { isExternalLink } from '@openpeepshq/common/lib';
@@ -39,6 +39,8 @@ const compactThumb = (post, t) => {
39
39
  return null;
40
40
  return _jsx(CompactThumb, { src: article.image, alt: article.title ?? alt });
41
41
  }
42
+ case 'resource':
43
+ return attachmentThumb(attachmentsOf(post), alt);
42
44
  default:
43
45
  return null;
44
46
  }
@@ -102,6 +104,12 @@ const CompactTypeBody = ({ post, t }) => {
102
104
  return _jsx(CompactEventBody, { post: post });
103
105
  case 'article':
104
106
  return _jsx(CompactArticleBody, { post: post });
107
+ case 'resource': {
108
+ const title = post.data?.type === 'resource' ? post.data.title.trim() : '';
109
+ if (!title)
110
+ return null;
111
+ return _jsx("p", { className: "line-clamp-2 text-sm font-medium", children: title });
112
+ }
105
113
  default:
106
114
  return null;
107
115
  }
@@ -5,6 +5,7 @@ import { FeedArticle } from './types/Article.js';
5
5
  import { FeedEvent } from './types/Event.js';
6
6
  import { FeedNote } from './types/Note.js';
7
7
  import { FeedPoll } from './types/Poll.js';
8
+ import { ResourceCard } from '../resources/ResourceCard.js';
8
9
  export function FeedPostContent({ post }) {
9
10
  const t = useT();
10
11
  const staticRender = useStaticRender();
@@ -23,6 +24,8 @@ export function FeedPostContent({ post }) {
23
24
  return _jsx(FeedEvent, { post: post });
24
25
  case 'article':
25
26
  return _jsx(FeedArticle, { post: post });
27
+ case 'resource':
28
+ return _jsx(ResourceCard, { post: post });
26
29
  default:
27
30
  return null;
28
31
  }
@@ -0,0 +1,8 @@
1
+ import { type GroupWithMeta, type ProfileWithMeta, type VisibilityType } from '@openpeepshq/common';
2
+ export interface NewResourceButtonProps {
3
+ visibility: VisibilityType;
4
+ currentProfile?: ProfileWithMeta;
5
+ group?: GroupWithMeta;
6
+ showButton?: boolean;
7
+ }
8
+ export declare const NewResourceButton: ({ visibility, currentProfile, group, showButton, }: NewResourceButtonProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,36 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useMemo } from 'react';
3
+ import { FilePlus } from 'lucide-react';
4
+ import { canCreatePost, } from '@openpeepshq/common';
5
+ import { Button } from '@openpeepshq/react-ui';
6
+ import { useT } from '../../i18n/index.js';
7
+ import { getNewPostStores, useSetPlusButtonActions } from '../../stores/index.js';
8
+ import { useAuthData } from '../layout/IdentityContext.js';
9
+ import { useNavigate } from '../../contexts/router/index.js';
10
+ export const NewResourceButton = ({ visibility, currentProfile, group, showButton = true, }) => {
11
+ const t = useT();
12
+ const authData = useAuthData();
13
+ const navigate = useNavigate();
14
+ const stores = getNewPostStores();
15
+ const profile = currentProfile ?? authData.profile;
16
+ const canPost = !!profile && canCreatePost(authData, 'resource', visibility, group);
17
+ const openNew = useCallback(() => {
18
+ stores.resource = {
19
+ ...stores.resource,
20
+ visibility,
21
+ groupId: group?.id,
22
+ };
23
+ navigate({ type: 'resources', view: 'new' });
24
+ }, [group?.id, navigate, stores, visibility]);
25
+ const plusActions = useMemo(() => canPost
26
+ ? {
27
+ title: t('resources.new', { defaultValue: 'New resource' }),
28
+ icon: FilePlus,
29
+ action: openNew,
30
+ }
31
+ : undefined, [canPost, openNew, t]);
32
+ useSetPlusButtonActions(plusActions);
33
+ if (!canPost || !showButton)
34
+ return null;
35
+ return (_jsx("div", { className: "mb-4 p-4 pb-0", children: _jsxs(Button, { title: t('resources.new', { defaultValue: 'New resource' }), variant: "default", action: openNew, "data-testid": "resources-new-resource-button", children: [_jsx(FilePlus, { className: "mr-1 size-4" }), t('resources.new', { defaultValue: 'New resource' })] }) }));
36
+ };
@@ -5,6 +5,7 @@ import { FullNote } from './types/note/FullNote.js';
5
5
  import { FullArticle } from './types/article/FullArticle.js';
6
6
  import { FullPoll } from './types/poll/FullPoll.js';
7
7
  import { FullEvent } from './types/event/FullEvent.js';
8
+ import { FullResource } from './types/resource/FullResource.js';
8
9
  import { LoadingSpinner } from '@openpeepshq/react-ui';
9
10
  export function PostDetail({ postId, occurrence }) {
10
11
  const t = useT();
@@ -20,6 +21,8 @@ export function PostDetail({ postId, occurrence }) {
20
21
  switch (post.type) {
21
22
  case 'article':
22
23
  return _jsx(FullArticle, { post: post });
24
+ case 'resource':
25
+ return _jsx(FullResource, { post: post });
23
26
  case 'event':
24
27
  return _jsx(FullEvent, { post: post, occurrence: occurrence });
25
28
  case 'question':
@@ -24,6 +24,8 @@ export { OpenpeepsMarkdownInput } from './post-form/OpenpeepsMarkdownInput';
24
24
  export type { OpenpeepsMarkdownInputProps } from './post-form/OpenpeepsMarkdownInput';
25
25
  export { ArticleForm } from './post-form/ArticleForm';
26
26
  export type { ArticleFormProps } from './post-form/ArticleForm';
27
+ export { ResourceForm } from './post-form/ResourceForm';
28
+ export type { ResourceFormProps } from './post-form/ResourceForm';
27
29
  export { EventForm } from './post-form/EventForm';
28
30
  export type { EventFormProps } from './post-form/EventForm';
29
31
  export { PreviewLink } from '../preview-link/PreviewLink';
@@ -31,6 +33,8 @@ export { NewNoteButton, useNewNotePlusButton } from './NewNoteButton';
31
33
  export type { NewNoteButtonProps } from './NewNoteButton';
32
34
  export { NewEventButton } from './NewEventButton';
33
35
  export type { NewEventButtonProps } from './NewEventButton';
36
+ export { NewResourceButton } from './NewResourceButton';
37
+ export type { NewResourceButtonProps } from './NewResourceButton';
34
38
  export { PinnedPost } from './PinnedPost';
35
39
  export type { PinnedPostProps } from './PinnedPost';
36
40
  export { FullPostLayout } from './FullPostLayout';
@@ -56,6 +60,7 @@ export { ParticipantsCard } from './pieces/ParticipantsCard';
56
60
  export type { ParticipantsCardProps } from './pieces/ParticipantsCard';
57
61
  export { FullNote } from './types/note/FullNote';
58
62
  export { FullArticle } from './types/article/FullArticle';
63
+ export { FullResource } from './types/resource/FullResource';
59
64
  export { FullPoll } from './types/poll/FullPoll';
60
65
  export { FullEvent } from './types/event/FullEvent';
61
66
  export { PollContent } from './pieces/PollContent';
@@ -15,10 +15,12 @@ export { ComposeAttachments } from './post-form/ComposeAttachments.js';
15
15
  export { DescriptionEditModal } from './post-form/DescriptionEditModal.js';
16
16
  export { OpenpeepsMarkdownInput } from './post-form/OpenpeepsMarkdownInput.js';
17
17
  export { ArticleForm } from './post-form/ArticleForm.js';
18
+ export { ResourceForm } from './post-form/ResourceForm.js';
18
19
  export { EventForm } from './post-form/EventForm.js';
19
20
  export { PreviewLink } from '../preview-link/PreviewLink.js';
20
21
  export { NewNoteButton, useNewNotePlusButton } from './NewNoteButton.js';
21
22
  export { NewEventButton } from './NewEventButton.js';
23
+ export { NewResourceButton } from './NewResourceButton.js';
22
24
  export { PinnedPost } from './PinnedPost.js';
23
25
  export { FullPostLayout } from './FullPostLayout.js';
24
26
  export { ReplyBox } from './ReplyBox.js';
@@ -33,6 +35,7 @@ export { ProfileEventRelationship } from './types/event/ProfileEventRelationship
33
35
  export { ParticipantsCard } from './pieces/ParticipantsCard.js';
34
36
  export { FullNote } from './types/note/FullNote.js';
35
37
  export { FullArticle } from './types/article/FullArticle.js';
38
+ export { FullResource } from './types/resource/FullResource.js';
36
39
  export { FullPoll } from './types/poll/FullPoll.js';
37
40
  export { FullEvent } from './types/event/FullEvent.js';
38
41
  export { PollContent } from './pieces/PollContent.js';
@@ -63,6 +63,10 @@ export function PostMenu({ post, deleteCallback }) {
63
63
  window.location.assign(`/articles/${post.id}/edit`);
64
64
  return;
65
65
  }
66
+ if (post.data?.type === 'resource') {
67
+ window.location.assign(`/resources/${post.id}/edit`);
68
+ return;
69
+ }
66
70
  openEditPost(post);
67
71
  };
68
72
  return (_jsxs(_Fragment, { children: [_jsxs(PopupMenu, { className: "h-max rounded-lg p-2 hover:opacity-80", title: t('posts.menu.title', { defaultValue: 'Post menu' }), children: [postProfile.id !== me.id ? (isFollowing ? (_jsx(PopupMenuButton, { title: t('profile.actions.unfollow', {
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { CalendarDays, ChartColumnBig, Notebook, ScrollText, } from 'lucide-react';
2
+ import { CalendarDays, ChartColumnBig, Library, Notebook, ScrollText, } from 'lucide-react';
3
3
  import { Button } from '@openpeepshq/react-ui';
4
4
  import { useT } from '../../../i18n/index.js';
5
5
  import { useNavigate } from '../../../contexts/router/index.js';
@@ -25,6 +25,14 @@ export function PostTypeSwitcher({ type, onSelect, onClose, showEventType = true
25
25
  groupId,
26
26
  };
27
27
  }
28
+ else if (path === '/resources/new') {
29
+ stores.resource = {
30
+ ...stores.resource,
31
+ type: 'resource',
32
+ visibility: visibility ?? stores.resource.visibility,
33
+ groupId,
34
+ };
35
+ }
28
36
  else {
29
37
  stores.event = {
30
38
  ...stores.event,
@@ -36,5 +44,7 @@ export function PostTypeSwitcher({ type, onSelect, onClose, showEventType = true
36
44
  onClose();
37
45
  navigate(path);
38
46
  };
39
- return (_jsxs("div", { className: "flex items-center gap-1", children: [type !== 'note' ? (_jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.note', { defaultValue: 'Write Note' }), action: () => onSelect('note'), children: _jsx(Notebook, { className: "size-5" }) })) : null, type !== 'question' ? (_jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.poll', { defaultValue: 'Add Poll' }), action: () => onSelect('question'), "data-testid": "posts-composer-poll-type", children: _jsx(ChartColumnBig, { className: "size-5" }) })) : null, showEventType && isOwner ? (_jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.event', { defaultValue: 'Create an Event' }), action: () => goto('/events/new'), children: _jsx(CalendarDays, { className: "size-5" }) })) : null, showArticleType ? (_jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.article', { defaultValue: 'Write Article' }), action: () => goto('/articles/new'), children: _jsx(ScrollText, { className: "size-5" }) })) : null] }));
47
+ return (_jsxs("div", { className: "flex items-center gap-1", children: [type !== 'note' ? (_jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.note', { defaultValue: 'Write Note' }), action: () => onSelect('note'), children: _jsx(Notebook, { className: "size-5" }) })) : null, type !== 'question' ? (_jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.poll', { defaultValue: 'Add Poll' }), action: () => onSelect('question'), "data-testid": "posts-composer-poll-type", children: _jsx(ChartColumnBig, { className: "size-5" }) })) : null, showEventType && isOwner ? (_jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.event', { defaultValue: 'Create an Event' }), action: () => goto('/events/new'), children: _jsx(CalendarDays, { className: "size-5" }) })) : null, showArticleType ? (_jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.article', { defaultValue: 'Write Article' }), action: () => goto('/articles/new'), children: _jsx(ScrollText, { className: "size-5" }) })) : null, _jsx(Button, { compact: true, variant: "ghost", title: t('posts.switcher.resource', {
48
+ defaultValue: 'Add a resource',
49
+ }), action: () => goto('/resources/new'), children: _jsx(Library, { className: "size-5" }) })] }));
40
50
  }
@@ -0,0 +1,7 @@
1
+ import type { PostCreationData } from '@openpeepshq/common/types';
2
+ export interface ResourceFormProps {
3
+ postData: PostCreationData;
4
+ onChange: (data: PostCreationData) => void;
5
+ isEdit?: boolean;
6
+ }
7
+ export declare const ResourceForm: ({ postData, onChange, isEdit, }: ResourceFormProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,68 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo, useState } from 'react';
3
+ import { RESOURCE_KINDS, normalizeResourceTags } from '@openpeepshq/common/lib';
4
+ import { Button, Input, Label } from '@openpeepshq/react-ui';
5
+ import { useT } from '../../../i18n/index.js';
6
+ import { useCurrentProfile } from '../../layout/IdentityContext.js';
7
+ import { applyAudienceSetting } from '../../../lib/audienceSetting.js';
8
+ import { CategoryPathPicker } from '../../resources/CategoryPathPicker.js';
9
+ import { useResourceLibrary } from '../../../hooks/index.js';
10
+ import { OpenpeepsMarkdownInput } from './OpenpeepsMarkdownInput.js';
11
+ import { PostAudienceSelector } from './PostAudienceSelector.js';
12
+ import { VisibilitySelector } from './VisibilitySelector.js';
13
+ import { useComposeAttachments } from './ComposeAttachments.js';
14
+ export const ResourceForm = ({ postData, onChange, isEdit = false, }) => {
15
+ const t = useT();
16
+ const me = useCurrentProfile();
17
+ const resource = postData.data;
18
+ const [audienceOpen, setAudienceOpen] = useState(false);
19
+ const [tagDraft, setTagDraft] = useState('');
20
+ const library = useResourceLibrary(postData.groupId ?? undefined);
21
+ const attachments = useComposeAttachments({
22
+ attachments: resource.attachments ?? [],
23
+ onChange: (next) => patchResource({ attachments: next }),
24
+ });
25
+ const patchResource = (patch) => {
26
+ onChange({
27
+ ...postData,
28
+ data: { ...resource, ...patch },
29
+ });
30
+ };
31
+ const setAudience = (settings) => onChange(applyAudienceSetting(postData, settings, me));
32
+ const addTag = () => {
33
+ const next = normalizeResourceTags([
34
+ ...(resource.tags ?? []),
35
+ ...tagDraft.split(/[,\s]+/),
36
+ ]);
37
+ patchResource({ tags: next });
38
+ setTagDraft('');
39
+ };
40
+ const onTagKey = (event) => {
41
+ if (event.key === 'Enter' || event.key === ',') {
42
+ event.preventDefault();
43
+ addTag();
44
+ }
45
+ };
46
+ const kindActions = useMemo(() => ({
47
+ gallery: attachments.openImagePicker,
48
+ video: attachments.openImagePicker,
49
+ audio: attachments.openAudioPicker,
50
+ file: attachments.openDocumentPicker,
51
+ link: undefined,
52
+ }), [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', {
54
+ 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', {
56
+ defaultValue: 'Describe this resource',
57
+ }) }), _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
+ defaultValue: 'Add tags, then press Enter',
59
+ }) }) }), resource.tags?.length ? (_jsx("div", { className: "flex flex-wrap gap-1", children: normalizeResourceTags(resource.tags).map((tag) => (_jsxs("button", { type: "button", className: "bg-muted rounded-full px-2 py-0.5 text-xs", onClick: () => patchResource({
60
+ tags: (resource.tags ?? []).filter((value) => value.toLowerCase() !== tag),
61
+ }), children: ["#", tag] }, tag))) })) : null, _jsxs("div", { children: [_jsx("p", { className: "mb-2 text-sm font-medium", children: t('resources.form.hierarchy', {
62
+ 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', {
64
+ defaultValue: 'Who can see this (Required)',
65
+ }), description: t('resources.form.visibilityNotChangeable', {
66
+ 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] }));
68
+ };
@@ -0,0 +1,5 @@
1
+ import type { PublicPost } from '@openpeepshq/common/types';
2
+ export interface FullResourceProps {
3
+ post: PublicPost;
4
+ }
5
+ export declare const FullResource: ({ post }: FullResourceProps) => import("react/jsx-runtime").JSX.Element | null;