@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
@@ -45,6 +45,18 @@ export const defaultNewArticle = (publicContent = false) => ({
45
45
  visibility: defaultVisibility(publicContent),
46
46
  data: { type: 'article', content: '' },
47
47
  });
48
+ export const defaultNewResource = (publicContent = false) => ({
49
+ type: 'resource',
50
+ visibility: defaultVisibility(publicContent),
51
+ data: {
52
+ type: 'resource',
53
+ title: '',
54
+ content: '',
55
+ resourceKind: 'link',
56
+ tags: [],
57
+ categoryPath: [],
58
+ },
59
+ });
48
60
  export const eventSanitizer = (publicContent = false) => {
49
61
  const def = defaultNewEvent(publicContent);
50
62
  return (event) => {
@@ -84,6 +96,7 @@ const ensureInitialized = (publicContent = false) => {
84
96
  const jam = persistedStore('new-jam-state', defaultNewEvent(publicContent));
85
97
  const event = persistedStore('new-event-state', defaultNewEvent(publicContent));
86
98
  const article = persistedStore('new-article-state', defaultNewArticle(publicContent));
99
+ const resource = persistedStore('new-resource-state', defaultNewResource(publicContent));
87
100
  const note = persistedStore('new-note-state', defaultNewNote(publicContent));
88
101
  const question = persistedStore('new-question-state', defaultNewQuestion(publicContent));
89
102
  initialized = {
@@ -108,6 +121,13 @@ const ensureInitialized = (publicContent = false) => {
108
121
  article.set(v);
109
122
  },
110
123
  resetNewArticleState: () => article.reset(),
124
+ get resource() {
125
+ return resource.get();
126
+ },
127
+ set resource(v) {
128
+ resource.set(v);
129
+ },
130
+ resetNewResourceState: () => resource.reset(),
111
131
  get note() {
112
132
  return note.get();
113
133
  },
@@ -124,7 +144,7 @@ const ensureInitialized = (publicContent = false) => {
124
144
  resetNewQuestionState: () => question.reset(),
125
145
  };
126
146
  // wire subscribe so React `useNewPostStores` can re-render on writes
127
- internalStores = { jam, event, article, note, question };
147
+ internalStores = { jam, event, article, resource, note, question };
128
148
  return initialized;
129
149
  };
130
150
  let internalStores;
@@ -134,12 +154,13 @@ export const initializeNewPostStores = (publicContent = false) => {
134
154
  export const getNewPostStores = () => ensureInitialized();
135
155
  export const useNewPostStores = () => {
136
156
  ensureInitialized();
137
- // Subscribe to all five sub-stores so any write triggers a re-render.
157
+ // Subscribe to all composer sub-stores so any write triggers a re-render.
138
158
  useSyncExternalStore((l) => {
139
159
  const subs = [
140
160
  internalStores.jam.subscribe(l),
141
161
  internalStores.event.subscribe(l),
142
162
  internalStores.article.subscribe(l),
163
+ internalStores.resource.subscribe(l),
143
164
  internalStores.note.subscribe(l),
144
165
  internalStores.question.subscribe(l),
145
166
  ];
@@ -185,6 +206,9 @@ export const resetStore = (type) => {
185
206
  case 'article':
186
207
  stores.resetNewArticleState();
187
208
  return;
209
+ case 'resource':
210
+ stores.resetNewResourceState();
211
+ return;
188
212
  default:
189
213
  return;
190
214
  }
@@ -28,6 +28,8 @@ export interface NewPostsState {
28
28
  resetNewEventState: () => void;
29
29
  article: PostCreationData;
30
30
  resetNewArticleState: () => void;
31
+ resource: PostCreationData;
32
+ resetNewResourceState: () => void;
31
33
  note: PostCreationData;
32
34
  resetNewNoteState: () => void;
33
35
  question: PostCreationData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/react",
3
- "version": "0.5.1",
3
+ "version": "0.6.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -34,6 +34,7 @@
34
34
  "@livekit/components-styles": "^1.1.6",
35
35
  "@tanstack/react-query": "5.90.16",
36
36
  "@videojs/react": "^10.0.0-beta.24",
37
+ "dompurify": "^3.4.15",
37
38
  "emoji-picker-element": "^1.29.1",
38
39
  "heic2any": "^0.0.4",
39
40
  "i18next": "^24.2.3",
@@ -50,10 +51,10 @@
50
51
  "react-i18next": "^15.4.1",
51
52
  "simple-icons": "^16.31.0",
52
53
  "uuidv7": "^1.0.2",
53
- "@openpeepshq/client": "^0.2.0",
54
- "@openpeepshq/common": "^0.2.0",
55
- "@openpeepshq/react-ui": "^0.3.0",
56
- "@openpeepshq/greenscreen": "^0.2.0"
54
+ "@openpeepshq/react-ui": "^0.4.1",
55
+ "@openpeepshq/common": "^0.3.1",
56
+ "@openpeepshq/greenscreen": "^0.2.1",
57
+ "@openpeepshq/client": "^0.2.1"
57
58
  },
58
59
  "peerDependencies": {
59
60
  "react": "^18.3.0 || ^19.0.0",
@@ -72,7 +73,7 @@
72
73
  "tsc-alias": "^1.8.10",
73
74
  "typescript": "^5.7.3",
74
75
  "vitest": "^2.1.8",
75
- "@openpeepshq/fetch-client": "^0.2.0"
76
+ "@openpeepshq/fetch-client": "^0.2.1"
76
77
  },
77
78
  "scripts": {
78
79
  "lint": "prettier --check . && ESLINT_USE_FLAT_CONFIG=false eslint .",
@@ -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';
@@ -1,4 +1,13 @@
1
+ import { useMemo } from 'react';
1
2
  import type { MouseEvent } from 'react';
3
+ import DOMPurify from 'dompurify';
4
+ import {
5
+ injectIframeSafetyAttrs,
6
+ MARKDOWN_HTML_ALLOWED_TAGS,
7
+ MARKDOWN_HTML_ALLOWED_ATTRS,
8
+ MARKDOWN_HTML_FORBIDDEN_TAGS,
9
+ MARKDOWN_HTML_FORBIDDEN_ATTRS,
10
+ } from '@openpeepshq/common/lib';
2
11
  import { OPENPEEPS_MARKDOWN_PROSE_CLASS } from './classes';
3
12
  import { isExternalLink } from './linkTargets';
4
13
  import { recordOutboundClick } from '../../lib/analyticsClicks';
@@ -6,6 +15,8 @@ import { recordOutboundClick } from '../../lib/analyticsClicks';
6
15
  export interface CompiledMarkdownProps {
7
16
  html: string;
8
17
  className?: string;
18
+ /** When false, HTML is rendered as-is without sanitization (for trusted sources). */
19
+ sanitize?: boolean;
9
20
  }
10
21
 
11
22
  const onMarkdownClick = (event: MouseEvent<HTMLDivElement>) => {
@@ -20,13 +31,31 @@ const onMarkdownClick = (event: MouseEvent<HTMLDivElement>) => {
20
31
  }
21
32
  };
22
33
 
34
+ const sanitizeHtml = (html: string): string => {
35
+ let clean = DOMPurify.sanitize(html, {
36
+ ALLOWED_TAGS: [...MARKDOWN_HTML_ALLOWED_TAGS],
37
+ ALLOWED_ATTR: [...MARKDOWN_HTML_ALLOWED_ATTRS],
38
+ FORBID_TAGS: [...MARKDOWN_HTML_FORBIDDEN_TAGS],
39
+ FORBID_ATTR: [...MARKDOWN_HTML_FORBIDDEN_ATTRS],
40
+ });
41
+ clean = injectIframeSafetyAttrs(clean);
42
+ return clean;
43
+ };
44
+
23
45
  export const CompiledMarkdown = ({
24
46
  html,
25
47
  className,
26
- }: CompiledMarkdownProps) => (
27
- <div
28
- className={className ?? OPENPEEPS_MARKDOWN_PROSE_CLASS}
29
- dangerouslySetInnerHTML={{ __html: html }}
30
- onClick={onMarkdownClick}
31
- />
32
- );
48
+ sanitize = true,
49
+ }: CompiledMarkdownProps) => {
50
+ const safeHtml = useMemo(
51
+ () => (sanitize ? sanitizeHtml(html) : html),
52
+ [html, sanitize],
53
+ );
54
+ return (
55
+ <div
56
+ className={className ?? OPENPEEPS_MARKDOWN_PROSE_CLASS}
57
+ dangerouslySetInnerHTML={{ __html: safeHtml }}
58
+ onClick={onMarkdownClick}
59
+ />
60
+ );
61
+ };
@@ -1,5 +1,6 @@
1
1
  import { useMemo } from 'react';
2
- import { linkProfileMentions } from '@openpeepshq/common/lib';
2
+ import { preprocessMarkdownSource } from '@openpeepshq/common/lib';
3
+ import type { MarkdownRenderProps } from '@openpeepshq/common/lib';
3
4
  import { extractUrlsFromText, isEmail } from '../preview-link/helpers';
4
5
  import { PreviewLink } from '../preview-link/PreviewLink';
5
6
  import {
@@ -9,34 +10,29 @@ import {
9
10
  import { compileMarkdownToHtml } from './compileMarkdown';
10
11
  import { resolveStaticUrl, useStaticRender } from './staticRender';
11
12
 
13
+ /** @deprecated Use {@link MentionProfileRef} from @openpeepshq/common. */
12
14
  export type MarkdownMention = {
13
- text?: string;
14
15
  profile: { handle: string; displayName?: string | null };
15
16
  };
16
17
 
17
- export interface OpenpeepsMarkdownProps {
18
- source?: string;
19
- mentions?: MarkdownMention[];
18
+ export interface OpenpeepsMarkdownProps extends MarkdownRenderProps {
20
19
  className?: string;
21
- linkPreviewMode?: 'prepend' | 'append' | 'none';
22
- /** When true, all links open in a new tab. External links always do. */
23
- newTab?: boolean;
24
20
  }
25
21
 
26
- const hashtagPattern = /(^|[\s(>])#([a-z0-9_]+)(?=\s|$|[.,!?;:])/gi;
22
+ const hashtagPattern = /(^|[\s(>])#([a-z0-9_]+)(?=\s|$|[.,!?;:])$/gi;
27
23
 
28
- function preprocessSource(
24
+ const preprocessWithHashtags = (
29
25
  source: string,
30
- mentions: MarkdownMention[] = [],
31
- ): string {
32
- let text = linkProfileMentions(source, mentions);
26
+ mentions: MarkdownRenderProps['mentions'] = [],
27
+ ): string => {
28
+ let text = preprocessMarkdownSource(source, mentions);
33
29
  text = text.replace(
34
30
  hashtagPattern,
35
31
  (_, prefix: string, tag: string) =>
36
32
  `${prefix}[#${tag}](/tags/${encodeURIComponent(tag)})`,
37
33
  );
38
34
  return text;
39
- }
35
+ };
40
36
 
41
37
  const markdownOrigin = (
42
38
  staticRender: boolean,
@@ -75,8 +71,12 @@ export function OpenpeepsMarkdown({
75
71
  }, [source]);
76
72
 
77
73
  const html = useMemo(() => {
78
- const processed = preprocessSource(source ?? '', mentions);
79
- let out = compileMarkdownToHtml(processed, { origin, newTab });
74
+ const processed = preprocessWithHashtags(source ?? '', mentions);
75
+ let out = compileMarkdownToHtml(processed, {
76
+ origin,
77
+ newTab,
78
+ sanitize: true,
79
+ });
80
80
  if (staticRender && baseUrl) {
81
81
  out = out.replace(/href="(\/[^"]*)"/g, (_, path: string) => {
82
82
  return `href="${resolveStaticUrl(path, baseUrl)}"`;
@@ -1,9 +1,9 @@
1
1
  export const OPENPEEPS_MARKDOWN_PROSE_CLASS =
2
- "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
+ "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";
3
3
 
4
4
  export const OPENPEEPS_MARKDOWN_STATIC_CLASS =
5
- 'allpeep-markdown text-sm leading-relaxed break-words text-foreground';
5
+ 'allpeep-markdown text-sm leading-relaxed break-words text-foreground prose-iframe:max-w-full prose-iframe:w-full prose-iframe:border-0';
6
6
 
7
7
  /** 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). */
8
8
  export const OPENPEEPS_POST_CAPTION_CLASS =
9
- "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";
9
+ "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,9 +1,19 @@
1
1
  import { marked, Renderer, type Tokens } from 'marked';
2
- import { linkOpensInNewTab } from './linkTargets';
2
+ import DOMPurify from 'dompurify';
3
+ import {
4
+ isExternalLink,
5
+ injectIframeSafetyAttrs,
6
+ MARKDOWN_HTML_ALLOWED_TAGS,
7
+ MARKDOWN_HTML_ALLOWED_ATTRS,
8
+ MARKDOWN_HTML_FORBIDDEN_TAGS,
9
+ MARKDOWN_HTML_FORBIDDEN_ATTRS,
10
+ } from '@openpeepshq/common/lib';
3
11
 
4
12
  export type CompileMarkdownOptions = {
5
13
  origin?: string;
6
- newTab?: boolean;
14
+ /** When true (default), the compiled HTML is sanitized before output. */
15
+ newTab?: boolean | ((link: string) => boolean);
16
+ sanitize?: boolean;
7
17
  };
8
18
 
9
19
  const escapeHtml = (text: string): string =>
@@ -21,11 +31,19 @@ const cleanHref = (href: string): string | null => {
21
31
  }
22
32
  };
23
33
 
34
+ const resolveNewTabFlag = (
35
+ newTab: boolean | ((link: string) => boolean) | undefined,
36
+ href: string,
37
+ ): boolean => {
38
+ if (typeof newTab === 'function') return newTab(href);
39
+ return newTab ?? false;
40
+ };
41
+
24
42
  export const compileMarkdownToHtml = (
25
43
  source: string,
26
44
  options: CompileMarkdownOptions = {},
27
45
  ): string => {
28
- const { origin, newTab = false } = options;
46
+ const { origin, newTab = false, sanitize: shouldSanitize = true } = options;
29
47
  const renderer = new Renderer();
30
48
 
31
49
  renderer.link = function (
@@ -38,16 +56,38 @@ export const compileMarkdownToHtml = (
38
56
  return text;
39
57
  }
40
58
 
59
+ const opensNewTab = resolveNewTabFlag(newTab, cleaned);
60
+
41
61
  let out = `<a href="${cleaned}"`;
42
62
  if (title) {
43
63
  out += ` title="${escapeHtml(title)}"`;
44
64
  }
45
- if (linkOpensInNewTab(cleaned, origin, newTab)) {
65
+ if (isExternalLink(cleaned, origin) || opensNewTab) {
46
66
  out += ' target="_blank" rel="noopener noreferrer"';
47
67
  }
48
68
  out += `>${text}</a>`;
49
69
  return out;
50
70
  };
51
71
 
52
- return marked.parse(source, { renderer, async: false }) as string;
72
+ let html = marked.parse(source, { renderer, async: false }) as string;
73
+
74
+ if (shouldSanitize) {
75
+ // DOMPurify requires a DOM and is effectively browser-only: in Node
76
+ // (build-time docs manifest, server-side emails) DOMPurify.sanitize is
77
+ // not a function, so skip it. That HTML is re-sanitized at render time
78
+ // via CompiledMarkdown in the browser.
79
+ if (typeof DOMPurify.sanitize === 'function') {
80
+ html = DOMPurify.sanitize(html, {
81
+ ALLOWED_TAGS: [...MARKDOWN_HTML_ALLOWED_TAGS],
82
+ ALLOWED_ATTR: [...MARKDOWN_HTML_ALLOWED_ATTRS],
83
+ FORBID_TAGS: [...MARKDOWN_HTML_FORBIDDEN_TAGS],
84
+ FORBID_ATTR: [...MARKDOWN_HTML_FORBIDDEN_ATTRS],
85
+ });
86
+ }
87
+ // Inject sandbox/loading/containment attrs on iframes after sanitization
88
+ // so attackers can't smuggle attributes through DOMPurify's allowlist.
89
+ html = injectIframeSafetyAttrs(html);
90
+ }
91
+
92
+ return html;
53
93
  };
@@ -1,11 +1,16 @@
1
1
  export { OpenpeepsMarkdown } from './OpenpeepsMarkdown';
2
- export type { OpenpeepsMarkdownProps } from './OpenpeepsMarkdown';
2
+ export type {
3
+ OpenpeepsMarkdownProps,
4
+ MarkdownMention,
5
+ } from './OpenpeepsMarkdown';
6
+ export type { MarkdownRenderProps } from '@openpeepshq/common/lib';
3
7
  export {
4
8
  OPENPEEPS_MARKDOWN_PROSE_CLASS,
5
9
  OPENPEEPS_MARKDOWN_STATIC_CLASS,
6
10
  OPENPEEPS_POST_CAPTION_CLASS,
7
11
  } from './classes';
8
12
  export { compileMarkdownToHtml } from './compileMarkdown';
13
+ export type { CompileMarkdownOptions } from './compileMarkdown';
9
14
  export { CompiledMarkdown } from './CompiledMarkdown';
10
15
  export type { CompiledMarkdownProps } from './CompiledMarkdown';
11
16
  export {
@@ -1,31 +1,2 @@
1
- /** Mirrors Svelte `OpenpeepsMarkdown` / `a.svelte` external-link detection. */
2
- export const isExternalLink = (href: string, origin?: string): boolean => {
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
- } catch {
15
- return !href.startsWith('/');
16
- }
17
- };
18
-
19
- export const linkOpensInNewTab = (
20
- href: string | null | undefined,
21
- origin: string | undefined,
22
- newTab: boolean,
23
- ): boolean => {
24
- if (!href) {
25
- return false;
26
- }
27
- if (newTab) {
28
- return true;
29
- }
30
- return isExternalLink(href, origin);
31
- };
1
+ /** Re-exports shared link utilities from @openpeepshq/common. */
2
+ export { isExternalLink } from '@openpeepshq/common/lib';
@@ -109,6 +109,8 @@ const compactThumb = (post: CompactPost, t: TFunction): ReactNode => {
109
109
  if (!article.image) return null;
110
110
  return <CompactThumb src={article.image} alt={article.title ?? alt} />;
111
111
  }
112
+ case 'resource':
113
+ return attachmentThumb(attachmentsOf(post), alt);
112
114
  default:
113
115
  return null;
114
116
  }
@@ -209,6 +211,12 @@ const CompactTypeBody = ({ post, t }: { post: CompactPost; t: TFunction }) => {
209
211
  return <CompactEventBody post={post} />;
210
212
  case 'article':
211
213
  return <CompactArticleBody post={post} />;
214
+ case 'resource': {
215
+ const title =
216
+ post.data?.type === 'resource' ? post.data.title.trim() : '';
217
+ if (!title) return null;
218
+ return <p className="line-clamp-2 text-sm font-medium">{title}</p>;
219
+ }
212
220
  default:
213
221
  return null;
214
222
  }
@@ -6,6 +6,7 @@ import { FeedArticle } from './types/Article';
6
6
  import { FeedEvent } from './types/Event';
7
7
  import { FeedNote } from './types/Note';
8
8
  import { FeedPoll } from './types/Poll';
9
+ import { ResourceCard } from '../resources/ResourceCard';
9
10
 
10
11
  export interface FeedPostContentProps {
11
12
  post: PublicPost;
@@ -38,6 +39,8 @@ export function FeedPostContent({ post }: FeedPostContentProps) {
38
39
  return <FeedEvent post={post} />;
39
40
  case 'article':
40
41
  return <FeedArticle post={post} />;
42
+ case 'resource':
43
+ return <ResourceCard post={post} />;
41
44
  default:
42
45
  return null;
43
46
  }
@@ -0,0 +1,75 @@
1
+ import { useCallback, useMemo } from 'react';
2
+ import { FilePlus } from 'lucide-react';
3
+ import {
4
+ canCreatePost,
5
+ type GroupWithMeta,
6
+ type ProfileWithMeta,
7
+ type VisibilityType,
8
+ } from '@openpeepshq/common';
9
+ import { Button } from '@openpeepshq/react-ui';
10
+ import { useT } from '../../i18n';
11
+ import { getNewPostStores, useSetPlusButtonActions } from '../../stores';
12
+ import { useAuthData } from '../layout/IdentityContext';
13
+ import { useNavigate } from '../../contexts/router';
14
+
15
+ export interface NewResourceButtonProps {
16
+ visibility: VisibilityType;
17
+ currentProfile?: ProfileWithMeta;
18
+ group?: GroupWithMeta;
19
+ showButton?: boolean;
20
+ }
21
+
22
+ export const NewResourceButton = ({
23
+ visibility,
24
+ currentProfile,
25
+ group,
26
+ showButton = true,
27
+ }: NewResourceButtonProps) => {
28
+ const t = useT();
29
+ const authData = useAuthData();
30
+ const navigate = useNavigate();
31
+ const stores = getNewPostStores();
32
+
33
+ const profile = currentProfile ?? authData.profile;
34
+ const canPost =
35
+ !!profile && canCreatePost(authData, 'resource', visibility, group);
36
+
37
+ const openNew = useCallback(() => {
38
+ stores.resource = {
39
+ ...stores.resource,
40
+ visibility,
41
+ groupId: group?.id,
42
+ };
43
+ navigate({ type: 'resources', view: 'new' });
44
+ }, [group?.id, navigate, stores, visibility]);
45
+
46
+ const plusActions = useMemo(
47
+ () =>
48
+ canPost
49
+ ? {
50
+ title: t('resources.new', { defaultValue: 'New resource' }),
51
+ icon: FilePlus,
52
+ action: openNew,
53
+ }
54
+ : undefined,
55
+ [canPost, openNew, t],
56
+ );
57
+
58
+ useSetPlusButtonActions(plusActions);
59
+
60
+ if (!canPost || !showButton) return null;
61
+
62
+ return (
63
+ <div className="mb-4 p-4 pb-0">
64
+ <Button
65
+ title={t('resources.new', { defaultValue: 'New resource' })}
66
+ variant="default"
67
+ action={openNew}
68
+ data-testid="resources-new-resource-button"
69
+ >
70
+ <FilePlus className="mr-1 size-4" />
71
+ {t('resources.new', { defaultValue: 'New resource' })}
72
+ </Button>
73
+ </div>
74
+ );
75
+ };
@@ -4,6 +4,7 @@ import { FullNote } from './types/note/FullNote';
4
4
  import { FullArticle } from './types/article/FullArticle';
5
5
  import { FullPoll } from './types/poll/FullPoll';
6
6
  import { FullEvent } from './types/event/FullEvent';
7
+ import { FullResource } from './types/resource/FullResource';
7
8
  import { LoadingSpinner } from '@openpeepshq/react-ui';
8
9
 
9
10
  export interface PostDetailProps {
@@ -38,6 +39,8 @@ export function PostDetail({ postId, occurrence }: PostDetailProps) {
38
39
  switch (post.type) {
39
40
  case 'article':
40
41
  return <FullArticle post={post} />;
42
+ case 'resource':
43
+ return <FullResource post={post} />;
41
44
  case 'event':
42
45
  return <FullEvent post={post} occurrence={occurrence} />;
43
46
  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';
@@ -62,6 +66,7 @@ export { ParticipantsCard } from './pieces/ParticipantsCard';
62
66
  export type { ParticipantsCardProps } from './pieces/ParticipantsCard';
63
67
  export { FullNote } from './types/note/FullNote';
64
68
  export { FullArticle } from './types/article/FullArticle';
69
+ export { FullResource } from './types/resource/FullResource';
65
70
  export { FullPoll } from './types/poll/FullPoll';
66
71
  export { FullEvent } from './types/event/FullEvent';
67
72
  export { PollContent } from './pieces/PollContent';
@@ -114,6 +114,10 @@ export function PostMenu({ post, deleteCallback }: PostMenuProps) {
114
114
  window.location.assign(`/articles/${post.id}/edit`);
115
115
  return;
116
116
  }
117
+ if (post.data?.type === 'resource') {
118
+ window.location.assign(`/resources/${post.id}/edit`);
119
+ return;
120
+ }
117
121
  openEditPost(post);
118
122
  };
119
123
 
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  CalendarDays,
3
3
  ChartColumnBig,
4
+ Library,
4
5
  Notebook,
5
6
  ScrollText,
6
7
  } from 'lucide-react';
@@ -43,7 +44,7 @@ export function PostTypeSwitcher({
43
44
  const me = useCurrentProfile();
44
45
  const isOwner = Boolean(me?.roles?.some((role) => role.key === 'owner'));
45
46
 
46
- const goto = (path: '/articles/new' | '/events/new') => {
47
+ const goto = (path: '/articles/new' | '/events/new' | '/resources/new') => {
47
48
  const stores = getNewPostStores();
48
49
  if (path === '/articles/new') {
49
50
  stores.article = {
@@ -52,6 +53,13 @@ export function PostTypeSwitcher({
52
53
  visibility: visibility ?? stores.article.visibility,
53
54
  groupId,
54
55
  };
56
+ } else if (path === '/resources/new') {
57
+ stores.resource = {
58
+ ...stores.resource,
59
+ type: 'resource',
60
+ visibility: visibility ?? stores.resource.visibility,
61
+ groupId,
62
+ };
55
63
  } else {
56
64
  stores.event = {
57
65
  ...stores.event,
@@ -107,6 +115,16 @@ export function PostTypeSwitcher({
107
115
  <ScrollText className="size-5" />
108
116
  </Button>
109
117
  ) : null}
118
+ <Button
119
+ compact
120
+ variant="ghost"
121
+ title={t('posts.switcher.resource', {
122
+ defaultValue: 'Add a resource',
123
+ })}
124
+ action={() => goto('/resources/new')}
125
+ >
126
+ <Library className="size-5" />
127
+ </Button>
110
128
  </div>
111
129
  );
112
130
  }