@openpeepshq/rn-components 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -5
- package/src/components/conversations/ConversationMessageBubble.test.tsx +158 -0
- package/src/components/conversations/ConversationMessageBubble.tsx +43 -25
- package/src/components/jams/JamCallParticipant.tsx +84 -16
- package/src/components/jams/JamChatMessage.test.tsx +139 -0
- package/src/components/jams/JamChatMessage.tsx +13 -0
- package/src/components/jams/JamPeopleDrawer.test.tsx +77 -3
- package/src/components/jams/JamPeopleDrawer.tsx +94 -3
- package/src/components/jams/JamReactionMenu.tsx +10 -31
- package/src/components/jams/JamRoom.tsx +15 -0
- package/src/components/markdown/OpenpeepsMarkdown.tsx +10 -3
- package/src/components/markdown/theme.test.ts +78 -0
- package/src/components/markdown/theme.ts +30 -12
- package/src/components/post/CompactReplyParent.test.tsx +337 -0
- package/src/components/post/CompactReplyParent.tsx +21 -5
- package/src/components/post/TruncatedMarkdown.test.tsx +201 -0
- package/src/components/post/TruncatedMarkdown.tsx +98 -10
- package/src/components/post/pieces/PostActions.test.tsx +27 -19
- package/src/components/post/pieces/PostActions.tsx +7 -11
- package/src/components/post/pieces/ReactionButton.tsx +41 -0
- package/src/components/post/pieces/ReactionPicker.test.tsx +80 -161
- package/src/components/post/pieces/ReactionPicker.tsx +32 -33
- package/src/components/post/pieces/index.ts +1 -0
- package/src/components/preview-link/local/WelcomePreview.tsx +1 -0
- package/src/components/resources/CategoryPathPicker.tsx +8 -2
- package/src/components/resources/ResourceCard.test.tsx +48 -4
- package/src/components/resources/ResourceCard.tsx +8 -2
- package/src/components/resources/ResourceLibrary.test.tsx +40 -2
- package/src/components/resources/ResourceLibrary.tsx +11 -6
- package/src/lib/moduleResolverRootGuard.test.ts +281 -0
|
@@ -24,14 +24,21 @@ const mockParticipants: unknown[] = [];
|
|
|
24
24
|
let mockIsModerator = false;
|
|
25
25
|
let mockHasWaitingRoom = false;
|
|
26
26
|
let mockWaitingProfiles: unknown[] = [];
|
|
27
|
+
let mockBannedIds: string[] = [];
|
|
28
|
+
const mockPressHandlers: Array<() => void> = [];
|
|
27
29
|
|
|
28
30
|
jest.mock('react-native', () => ({
|
|
29
31
|
View: (props: { children?: unknown }) =>
|
|
30
32
|
React.createElement('View', null, props.children),
|
|
31
33
|
ScrollView: (props: { children?: unknown }) =>
|
|
32
34
|
React.createElement('ScrollView', null, props.children),
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
// Records every press handler in render order so a test can fire the
|
|
36
|
+
// "Removed" header toggle (the only Pressable when the drawer has no
|
|
37
|
+
// participants / waiting room — see the round-15 suggestion-2 case).
|
|
38
|
+
Pressable: (props: { children?: unknown; onPress?: () => void }) => {
|
|
39
|
+
if (props.onPress) mockPressHandlers.push(props.onPress);
|
|
40
|
+
return React.createElement('Pressable', null, props.children);
|
|
41
|
+
},
|
|
35
42
|
Text: (props: { children?: unknown }) =>
|
|
36
43
|
React.createElement('Text', null, props.children),
|
|
37
44
|
}));
|
|
@@ -79,6 +86,20 @@ jest.mock('@openpeepshq/react', () => ({
|
|
|
79
86
|
waitingProfiles: mockWaitingProfiles,
|
|
80
87
|
admittingId: null,
|
|
81
88
|
admit: () => {},
|
|
89
|
+
// Mirror the real hook's banned-sublist contract (the drawer reads
|
|
90
|
+
// bannedIds/liftingId/liftBan when isModerator is true); empty keeps the
|
|
91
|
+
// "Removed" section hidden so these assertions stay on the Observers pin.
|
|
92
|
+
bannedIds: mockBannedIds,
|
|
93
|
+
liftingId: null,
|
|
94
|
+
liftBan: () => {},
|
|
95
|
+
}),
|
|
96
|
+
// The "Removed" sublist row resolves each banned id through
|
|
97
|
+
// `openpeepsApi.useProfile(id).data`; returning `undefined` exercises the
|
|
98
|
+
// unresolved fallback (the full profile id) that round-15 suggestion 2 pins.
|
|
99
|
+
useOpenpeeps: () => ({
|
|
100
|
+
openpeepsApi: {
|
|
101
|
+
useProfile: () => ({ data: undefined }),
|
|
102
|
+
},
|
|
82
103
|
}),
|
|
83
104
|
}));
|
|
84
105
|
|
|
@@ -92,6 +113,8 @@ jest.mock('../icons/index', () => {
|
|
|
92
113
|
React.createElement(name, props);
|
|
93
114
|
return {
|
|
94
115
|
AudioLinesIcon: make('AudioLinesIcon'),
|
|
116
|
+
ChevronDownIcon: make('ChevronDownIcon'),
|
|
117
|
+
ChevronRightIcon: make('ChevronRightIcon'),
|
|
95
118
|
EyeOnIcon: make('EyeOnIcon'),
|
|
96
119
|
HandIcon: make('HandIcon'),
|
|
97
120
|
MicIcon: make('MicIcon'),
|
|
@@ -146,14 +169,28 @@ jest.mock('../ui/themed-text', () => ({
|
|
|
146
169
|
},
|
|
147
170
|
}));
|
|
148
171
|
|
|
172
|
+
// The package ships ESM-only source (see the jest.config.cjs notes); the
|
|
173
|
+
// drawer only calls Toast.show for lift-ban errors, which these cases never
|
|
174
|
+
// reach, so an inert mock keeps the suite parseable.
|
|
175
|
+
jest.mock('react-native-toast-message', () => {
|
|
176
|
+
const Toast = { show: jest.fn() };
|
|
177
|
+
return { __esModule: true, default: Toast };
|
|
178
|
+
});
|
|
179
|
+
|
|
149
180
|
const { JamPeopleDrawer } = require('./JamPeopleDrawer');
|
|
150
181
|
|
|
151
|
-
const renderDrawer = (
|
|
182
|
+
const renderDrawer = (
|
|
183
|
+
sessions: number,
|
|
184
|
+
waitingRoom: boolean = false,
|
|
185
|
+
bannedIds: string[] = []
|
|
186
|
+
) => {
|
|
152
187
|
mockSessions = sessions;
|
|
153
188
|
mockIsModerator = waitingRoom;
|
|
154
189
|
mockHasWaitingRoom = waitingRoom;
|
|
155
190
|
mockWaitingProfiles = waitingRoom ? [{ id: 'w1' }] : [];
|
|
191
|
+
mockBannedIds = bannedIds;
|
|
156
192
|
mockRenderedTexts.length = 0;
|
|
193
|
+
mockPressHandlers.length = 0;
|
|
157
194
|
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
158
195
|
ReactTestRenderer.act(() => {
|
|
159
196
|
tree = ReactTestRenderer.create(
|
|
@@ -214,3 +251,40 @@ describe('JamPeopleDrawer observers section (RN)', () => {
|
|
|
214
251
|
expect(texts).not.toContain('external observer');
|
|
215
252
|
});
|
|
216
253
|
});
|
|
254
|
+
|
|
255
|
+
describe('JamPeopleDrawer "Removed" sublist fallback (RN, issue #303 round-15 suggestion 2)', () => {
|
|
256
|
+
// Independent of the observers renderDrawer: the fallback case needs a
|
|
257
|
+
// moderator with a non-empty banned list but no waiting room / participants,
|
|
258
|
+
// which the observers helper (isModerator === waitingRoom) cannot express.
|
|
259
|
+
const renderBannedDrawer = (bannedIds: string[]) => {
|
|
260
|
+
mockIsModerator = true;
|
|
261
|
+
mockHasWaitingRoom = false;
|
|
262
|
+
mockWaitingProfiles = [];
|
|
263
|
+
mockBannedIds = bannedIds;
|
|
264
|
+
mockRenderedTexts.length = 0;
|
|
265
|
+
mockPressHandlers.length = 0;
|
|
266
|
+
let tree!: ReactTestRenderer.ReactTestRenderer;
|
|
267
|
+
ReactTestRenderer.act(() => {
|
|
268
|
+
tree = ReactTestRenderer.create(
|
|
269
|
+
React.createElement(JamPeopleDrawer, { open: true, onClose: () => {} })
|
|
270
|
+
);
|
|
271
|
+
});
|
|
272
|
+
// The section is collapsed by default; fire the header toggle (the only
|
|
273
|
+
// Pressable with an onPress when there are no participants / waiting room)
|
|
274
|
+
// so the rows mount and their name fallbacks render.
|
|
275
|
+
ReactTestRenderer.act(() => {
|
|
276
|
+
mockPressHandlers.forEach((onPress) => onPress());
|
|
277
|
+
});
|
|
278
|
+
return tree;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
it('shows the full profile id for an unresolved row, not a truncated slice', () => {
|
|
282
|
+
// The useProfile mock returns undefined for every id, so the row hits the
|
|
283
|
+
// unresolved fallback. Asserting the FULL id is present catches the old
|
|
284
|
+
// raw-slice behavior (the first 8 chars only) — a 36-char id cannot appear
|
|
285
|
+
// when only 8 chars are rendered.
|
|
286
|
+
renderBannedDrawer(['banned-2x-0000-0000-0000-000000000000']);
|
|
287
|
+
const text = mockRenderedTexts.join(' ');
|
|
288
|
+
expect(text).toContain('banned-2x-0000-0000-0000-000000000000');
|
|
289
|
+
});
|
|
290
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ScrollView, View } from 'react-native';
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Pressable, ScrollView, View } from 'react-native';
|
|
3
|
+
import Toast from 'react-native-toast-message';
|
|
3
4
|
import { useParticipants, useRoomContext } from '@livekit/react-native';
|
|
4
5
|
import type { Participant } from 'livekit-client';
|
|
5
6
|
import { useTranslation } from 'react-i18next';
|
|
@@ -9,9 +10,12 @@ import {
|
|
|
9
10
|
parseParticipantMetadata,
|
|
10
11
|
useJamExternalSessions,
|
|
11
12
|
useJamPeople,
|
|
13
|
+
useOpenpeeps,
|
|
12
14
|
} from '@openpeepshq/react';
|
|
13
15
|
import {
|
|
14
16
|
AudioLinesIcon,
|
|
17
|
+
ChevronDownIcon,
|
|
18
|
+
ChevronRightIcon,
|
|
15
19
|
EyeOnIcon,
|
|
16
20
|
HandIcon,
|
|
17
21
|
MicIcon,
|
|
@@ -119,6 +123,7 @@ const JamObserversSection = ({ count }: { count: number }) => {
|
|
|
119
123
|
*/
|
|
120
124
|
export const JamPeopleDrawer = ({ open, onClose }: JamPeopleDrawerProps) => {
|
|
121
125
|
const { t } = useTranslation();
|
|
126
|
+
const [bannedExpanded, setBannedExpanded] = useState(false);
|
|
122
127
|
const room = useRoomContext();
|
|
123
128
|
const participants = useParticipants();
|
|
124
129
|
const externalSessions = useJamExternalSessions();
|
|
@@ -133,7 +138,14 @@ export const JamPeopleDrawer = ({ open, onClose }: JamPeopleDrawerProps) => {
|
|
|
133
138
|
waitingProfiles,
|
|
134
139
|
admittingId,
|
|
135
140
|
admit,
|
|
136
|
-
|
|
141
|
+
bannedIds,
|
|
142
|
+
liftingId,
|
|
143
|
+
liftBan,
|
|
144
|
+
} = useJamPeople({
|
|
145
|
+
room,
|
|
146
|
+
participants,
|
|
147
|
+
onLiftError: (text1) => Toast.show({ type: 'error', text1 }),
|
|
148
|
+
});
|
|
137
149
|
|
|
138
150
|
if (!open) return null;
|
|
139
151
|
|
|
@@ -208,6 +220,45 @@ export const JamPeopleDrawer = ({ open, onClose }: JamPeopleDrawerProps) => {
|
|
|
208
220
|
</View>
|
|
209
221
|
</View>
|
|
210
222
|
) : null}
|
|
223
|
+
|
|
224
|
+
{isModerator && bannedIds.length > 0 ? (
|
|
225
|
+
<View>
|
|
226
|
+
<Pressable
|
|
227
|
+
accessibilityRole="button"
|
|
228
|
+
accessibilityState={{ expanded: bannedExpanded }}
|
|
229
|
+
onPress={() => setBannedExpanded((current) => !current)}
|
|
230
|
+
>
|
|
231
|
+
<View className="flex-row items-center justify-between gap-2">
|
|
232
|
+
<SectionHeading>
|
|
233
|
+
{`${t('jams.people.banned')} (${bannedIds.length})`}
|
|
234
|
+
</SectionHeading>
|
|
235
|
+
{bannedExpanded ? (
|
|
236
|
+
<ChevronDownIcon
|
|
237
|
+
size={16}
|
|
238
|
+
className="text-muted-foreground"
|
|
239
|
+
/>
|
|
240
|
+
) : (
|
|
241
|
+
<ChevronRightIcon
|
|
242
|
+
size={16}
|
|
243
|
+
className="text-muted-foreground"
|
|
244
|
+
/>
|
|
245
|
+
)}
|
|
246
|
+
</View>
|
|
247
|
+
</Pressable>
|
|
248
|
+
{bannedExpanded ? (
|
|
249
|
+
<View className="mt-1 gap-2">
|
|
250
|
+
{bannedIds.map((profileId) => (
|
|
251
|
+
<BannedProfileRow
|
|
252
|
+
key={profileId}
|
|
253
|
+
profileId={profileId}
|
|
254
|
+
lifting={liftingId === profileId}
|
|
255
|
+
onLift={() => liftBan(profileId)}
|
|
256
|
+
/>
|
|
257
|
+
))}
|
|
258
|
+
</View>
|
|
259
|
+
) : null}
|
|
260
|
+
</View>
|
|
261
|
+
) : null}
|
|
211
262
|
</ScrollView>
|
|
212
263
|
</JamDrawer>
|
|
213
264
|
);
|
|
@@ -227,3 +278,43 @@ function WaitingRoomAvatar({ profile }: { profile: JamWaitingProfile }) {
|
|
|
227
278
|
/>
|
|
228
279
|
);
|
|
229
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* A banned-sublist row. Splits into its own component so the per-id
|
|
283
|
+
* `useProfile(id)` only fires when the row is actually mounted — i.e. when the
|
|
284
|
+
* moderator expands the "Removed" sublist — instead of a full profile-directory
|
|
285
|
+
* fetch up front.
|
|
286
|
+
*/
|
|
287
|
+
const BannedProfileRow = ({
|
|
288
|
+
profileId,
|
|
289
|
+
lifting,
|
|
290
|
+
onLift,
|
|
291
|
+
}: {
|
|
292
|
+
profileId: string;
|
|
293
|
+
lifting: boolean;
|
|
294
|
+
onLift: () => void;
|
|
295
|
+
}) => {
|
|
296
|
+
const t = useTranslation().t;
|
|
297
|
+
const { openpeepsApi } = useOpenpeeps();
|
|
298
|
+
const profile = openpeepsApi.useProfile(profileId).data;
|
|
299
|
+
return (
|
|
300
|
+
<View className="flex-row items-center justify-between gap-2">
|
|
301
|
+
<View className="min-w-0 flex-1 flex-row items-center gap-2 opacity-60">
|
|
302
|
+
{profile ? (
|
|
303
|
+
<ProfileAvatar profile={profile} className="size-8" />
|
|
304
|
+
) : null}
|
|
305
|
+
<ThemedText numberOfLines={1} className="shrink text-sm">
|
|
306
|
+
{profile ? profileName(profile) : profileId}
|
|
307
|
+
</ThemedText>
|
|
308
|
+
</View>
|
|
309
|
+
<Button
|
|
310
|
+
variant="outline"
|
|
311
|
+
size="icon"
|
|
312
|
+
onPress={onLift}
|
|
313
|
+
disabled={lifting}
|
|
314
|
+
accessibilityLabel={t('jams.people.unban')}
|
|
315
|
+
>
|
|
316
|
+
<UserRoundCheckIcon size={16} className="text-foreground" />
|
|
317
|
+
</Button>
|
|
318
|
+
</View>
|
|
319
|
+
);
|
|
320
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ScrollView, View } from 'react-native';
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
4
|
import {
|
|
5
5
|
SKIN_TONE_OPTIONS,
|
|
@@ -10,33 +10,12 @@ import {
|
|
|
10
10
|
isDefaultEmoji,
|
|
11
11
|
useJamReactionPreferences,
|
|
12
12
|
} from '@openpeepshq/react';
|
|
13
|
-
import {
|
|
14
|
-
import { cn } from '../../lib/utils';
|
|
13
|
+
import { ReactionButton } from '../post/pieces/ReactionButton';
|
|
15
14
|
|
|
16
15
|
export interface JamReactionMenuProps {
|
|
17
16
|
onSelect: (emoji: string) => void | Promise<void>;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
const EmojiButton = ({
|
|
21
|
-
emoji,
|
|
22
|
-
title,
|
|
23
|
-
active,
|
|
24
|
-
onPress,
|
|
25
|
-
}: {
|
|
26
|
-
emoji: string;
|
|
27
|
-
title: string;
|
|
28
|
-
active?: boolean;
|
|
29
|
-
onPress: () => void;
|
|
30
|
-
}) => (
|
|
31
|
-
<Pressable
|
|
32
|
-
accessibilityLabel={title}
|
|
33
|
-
onPress={onPress}
|
|
34
|
-
className={cn('shrink-0 rounded-md p-2', active && 'bg-border')}
|
|
35
|
-
>
|
|
36
|
-
<ThemedText className="text-lg">{emoji}</ThemedText>
|
|
37
|
-
</Pressable>
|
|
38
|
-
);
|
|
39
|
-
|
|
40
19
|
/**
|
|
41
20
|
* Reaction picker: a quick row of default emojis (with the preferred skin
|
|
42
21
|
* tone applied), recently used emojis and a skin-tone selector. The web "all
|
|
@@ -73,9 +52,9 @@ export const JamReactionMenu = ({ onSelect }: JamReactionMenuProps) => {
|
|
|
73
52
|
contentContainerClassName="flex-row items-center gap-x-1"
|
|
74
53
|
>
|
|
75
54
|
{defaultEmojis.map((emoji) => (
|
|
76
|
-
<
|
|
55
|
+
<ReactionButton
|
|
77
56
|
key={emoji}
|
|
78
|
-
|
|
57
|
+
reaction={emoji}
|
|
79
58
|
title={emoji}
|
|
80
59
|
onPress={() => void onSelect(emoji)}
|
|
81
60
|
/>
|
|
@@ -84,9 +63,9 @@ export const JamReactionMenu = ({ onSelect }: JamReactionMenuProps) => {
|
|
|
84
63
|
<>
|
|
85
64
|
<View className="mx-1 h-8 w-px shrink-0 bg-border" />
|
|
86
65
|
{recentDisplayEmojis.map((emoji) => (
|
|
87
|
-
<
|
|
66
|
+
<ReactionButton
|
|
88
67
|
key={emoji}
|
|
89
|
-
|
|
68
|
+
reaction={emoji}
|
|
90
69
|
title={emoji}
|
|
91
70
|
onPress={() => void onSelect(emoji)}
|
|
92
71
|
/>
|
|
@@ -94,8 +73,8 @@ export const JamReactionMenu = ({ onSelect }: JamReactionMenuProps) => {
|
|
|
94
73
|
</>
|
|
95
74
|
) : null}
|
|
96
75
|
<View className="mx-1 h-8 w-px shrink-0 bg-border" />
|
|
97
|
-
<
|
|
98
|
-
|
|
76
|
+
<ReactionButton
|
|
77
|
+
reaction={getSkinToneEmoji(skinTone)}
|
|
99
78
|
title={t('jams.reactions.skinToneTitle')}
|
|
100
79
|
active={showSkinToneSelector}
|
|
101
80
|
onPress={() => setShowSkinToneSelector((open) => !open)}
|
|
@@ -105,9 +84,9 @@ export const JamReactionMenu = ({ onSelect }: JamReactionMenuProps) => {
|
|
|
105
84
|
{showSkinToneSelector ? (
|
|
106
85
|
<View className="mt-2 flex-row gap-1 border-t border-border pt-2">
|
|
107
86
|
{SKIN_TONE_OPTIONS.map((option) => (
|
|
108
|
-
<
|
|
87
|
+
<ReactionButton
|
|
109
88
|
key={option.tone}
|
|
110
|
-
|
|
89
|
+
reaction={option.emoji}
|
|
111
90
|
title={t('jams.reactions.skinToneTitle')}
|
|
112
91
|
active={skinTone === option.tone}
|
|
113
92
|
onPress={() => handleSetSkinTone(option.tone)}
|
|
@@ -43,6 +43,7 @@ const JamRoomInner = () => {
|
|
|
43
43
|
autoRsvpError,
|
|
44
44
|
shouldAutoRsvp,
|
|
45
45
|
capacityBlock,
|
|
46
|
+
removedFromJam,
|
|
46
47
|
canDirectJoin,
|
|
47
48
|
canRequestJoin,
|
|
48
49
|
handleJoin,
|
|
@@ -124,6 +125,20 @@ const JamRoomInner = () => {
|
|
|
124
125
|
);
|
|
125
126
|
}
|
|
126
127
|
|
|
128
|
+
if (removedFromJam) {
|
|
129
|
+
return (
|
|
130
|
+
<JamRoomPanel title={jamEvent.name}>
|
|
131
|
+
<ThemedText className="text-center text-sm">
|
|
132
|
+
{t('jams.room.removedFromJam')}
|
|
133
|
+
</ThemedText>
|
|
134
|
+
<JamRoomPanelLink
|
|
135
|
+
label={t('jams.room.viewEvent')}
|
|
136
|
+
onPress={() => router.navigate({ type: 'post', id: jamPost.id })}
|
|
137
|
+
/>
|
|
138
|
+
</JamRoomPanel>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
127
142
|
if (capacityBlock.blocked) {
|
|
128
143
|
return (
|
|
129
144
|
<JamCapacityGate
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import { useNavigation } from '@react-navigation/native';
|
|
6
6
|
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
|
7
7
|
import React, { ReactNode, useMemo } from 'react';
|
|
8
|
-
import { Linking, View } from 'react-native';
|
|
8
|
+
import { Linking, StyleProp, TextStyle, View } from 'react-native';
|
|
9
9
|
import Markdown, {
|
|
10
10
|
MarkdownIt,
|
|
11
11
|
tokensToAST,
|
|
@@ -27,16 +27,23 @@ import { PreviewLink } from '../preview-link';
|
|
|
27
27
|
import { useOpenPeepsTheme } from '../../theme/OpenPeepsThemeProvider';
|
|
28
28
|
import { recordOutboundClick } from '@openpeepshq/react';
|
|
29
29
|
|
|
30
|
-
export type OpenpeepsMarkdownProps = MarkdownRenderProps
|
|
30
|
+
export type OpenpeepsMarkdownProps = MarkdownRenderProps & {
|
|
31
|
+
/** Text metrics override merged over the theme's paragraph/list styles. */
|
|
32
|
+
baseTextStyle?: StyleProp<TextStyle>;
|
|
33
|
+
};
|
|
31
34
|
|
|
32
35
|
export const OpenpeepsMarkdown = ({
|
|
33
36
|
source,
|
|
34
37
|
mentions = [],
|
|
35
38
|
linkPreviewMode = 'none',
|
|
36
39
|
newTab = false,
|
|
40
|
+
baseTextStyle,
|
|
37
41
|
}: OpenpeepsMarkdownProps) => {
|
|
38
42
|
const { colors } = useOpenPeepsTheme();
|
|
39
|
-
const styles = useMemo(
|
|
43
|
+
const styles = useMemo(
|
|
44
|
+
() => markdownTheme(colors, { baseTextStyle }),
|
|
45
|
+
[colors, baseTextStyle]
|
|
46
|
+
);
|
|
40
47
|
|
|
41
48
|
const navigation =
|
|
42
49
|
useNavigation<NativeStackNavigationProp<MainStackParamList>>();
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract for `markdownTheme` (issue #2074): the optional `baseTextStyle` is
|
|
3
|
+
* merged over every text-bearing style (`body`, `paragraph`, `list`,
|
|
4
|
+
* `listItem`) and nothing is altered when it is not provided. This is the one
|
|
5
|
+
* function every markdown surface's text metrics flow through, so a silent
|
|
6
|
+
* regression in the merge must be caught here directly (the component tests
|
|
7
|
+
* mock `../markdown` and never exercise it).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
jest.mock('react-native', () => ({
|
|
11
|
+
StyleSheet: {
|
|
12
|
+
flatten: (s: unknown) => (Array.isArray(s) ? Object.assign({}, ...s) : s),
|
|
13
|
+
},
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
import { markdownTheme } from './theme';
|
|
17
|
+
import { mapColors } from '../../theme/defaults';
|
|
18
|
+
|
|
19
|
+
// Real light-theme defaults (nativewind-free), so the assertions check the
|
|
20
|
+
// hex values the app actually ships — a test with an invented color would
|
|
21
|
+
// keep passing if the real default drifted.
|
|
22
|
+
const colors = mapColors(false);
|
|
23
|
+
|
|
24
|
+
const TEXT_STYLES = ['body', 'paragraph', 'list', 'listItem'] as const;
|
|
25
|
+
|
|
26
|
+
test('without baseTextStyle the base 16/24 foreground text styles survive', () => {
|
|
27
|
+
const theme = markdownTheme(colors);
|
|
28
|
+
for (const name of TEXT_STYLES) {
|
|
29
|
+
const style = theme[name] as Record<string, unknown>;
|
|
30
|
+
// The real light default foreground (theme/defaults.ts), not a test-only hex.
|
|
31
|
+
expect(style.color).toBe('#0a0a0b');
|
|
32
|
+
// `body` carries only the color; the block styles carry the 16/24 metrics.
|
|
33
|
+
if (name !== 'body') {
|
|
34
|
+
expect(style.fontSize).toBe(16);
|
|
35
|
+
expect(style.lineHeight).toBe(24);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('baseTextStyle merges over every text-bearing style, keeping defaults', () => {
|
|
41
|
+
const theme = markdownTheme(colors, {
|
|
42
|
+
baseTextStyle: { fontSize: 14, lineHeight: 20, color: '#71717a' },
|
|
43
|
+
});
|
|
44
|
+
for (const name of TEXT_STYLES) {
|
|
45
|
+
const style = theme[name] as Record<string, unknown>;
|
|
46
|
+
expect(style).toMatchObject({
|
|
47
|
+
fontSize: 14,
|
|
48
|
+
lineHeight: 20,
|
|
49
|
+
color: '#71717a',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('a partial override only replaces the keys it provides', () => {
|
|
55
|
+
const theme = markdownTheme(colors, {
|
|
56
|
+
baseTextStyle: { fontSize: 12 },
|
|
57
|
+
});
|
|
58
|
+
for (const name of TEXT_STYLES) {
|
|
59
|
+
const style = theme[name] as Record<string, unknown>;
|
|
60
|
+
expect(style.fontSize).toBe(12);
|
|
61
|
+
// lineHeight 24 and the real default foreground are untouched.
|
|
62
|
+
if (name !== 'body') {
|
|
63
|
+
expect(style.lineHeight).toBe(24);
|
|
64
|
+
}
|
|
65
|
+
expect(style.color).toBe(colors.foreground);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('non-text-bearing styles are left untouched by baseTextStyle', () => {
|
|
70
|
+
const themed = markdownTheme(colors, {
|
|
71
|
+
baseTextStyle: { fontSize: 14, color: '#71717a' },
|
|
72
|
+
});
|
|
73
|
+
const plain = markdownTheme(colors);
|
|
74
|
+
expect(themed.link).toEqual(plain.link);
|
|
75
|
+
expect(themed.blockquote).toEqual(plain.blockquote);
|
|
76
|
+
expect(themed.code_inline).toEqual(plain.code_inline);
|
|
77
|
+
expect(themed.heading1).toEqual(plain.heading1);
|
|
78
|
+
});
|
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
import { StyleSheet } from 'react-native';
|
|
1
|
+
import { StyleProp, TextStyle, StyleSheet } from 'react-native';
|
|
2
2
|
import { OpenPeepsTheme } from '../../theme/types';
|
|
3
3
|
|
|
4
|
+
export interface MarkdownThemeOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Text metrics override (e.g. `text-sm` → `{fontSize: 14, lineHeight: 20}`)
|
|
7
|
+
* merged over the theme's paragraph/list styles for compact contexts that
|
|
8
|
+
* must stay smaller than the base 16/24 markdown.
|
|
9
|
+
*/
|
|
10
|
+
baseTextStyle?: StyleProp<TextStyle>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const mergeTextStyles = (
|
|
14
|
+
base: TextStyle,
|
|
15
|
+
override?: StyleProp<TextStyle>
|
|
16
|
+
): TextStyle => ({ ...base, ...(StyleSheet.flatten(override) as TextStyle) });
|
|
17
|
+
|
|
4
18
|
export const markdownTheme = (
|
|
5
|
-
colors: OpenPeepsTheme['colors']
|
|
19
|
+
colors: OpenPeepsTheme['colors'],
|
|
20
|
+
{ baseTextStyle }: MarkdownThemeOptions = {}
|
|
6
21
|
): StyleSheet.NamedStyles<unknown> => {
|
|
7
22
|
return {
|
|
8
23
|
body: {
|
|
9
|
-
color: colors.foreground,
|
|
24
|
+
...mergeTextStyles({ color: colors.foreground }, baseTextStyle),
|
|
10
25
|
},
|
|
11
26
|
link: {
|
|
12
27
|
color: colors.primary,
|
|
@@ -23,19 +38,22 @@ export const markdownTheme = (
|
|
|
23
38
|
fontSize: 20,
|
|
24
39
|
},
|
|
25
40
|
paragraph: {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
41
|
+
...mergeTextStyles(
|
|
42
|
+
{ color: colors.foreground, lineHeight: 24, fontSize: 16 },
|
|
43
|
+
baseTextStyle
|
|
44
|
+
),
|
|
29
45
|
},
|
|
30
46
|
list: {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
47
|
+
...mergeTextStyles(
|
|
48
|
+
{ color: colors.foreground, lineHeight: 24, fontSize: 16 },
|
|
49
|
+
baseTextStyle
|
|
50
|
+
),
|
|
34
51
|
},
|
|
35
52
|
listItem: {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
53
|
+
...mergeTextStyles(
|
|
54
|
+
{ color: colors.foreground, lineHeight: 24, fontSize: 16 },
|
|
55
|
+
baseTextStyle
|
|
56
|
+
),
|
|
39
57
|
},
|
|
40
58
|
blockquote: {
|
|
41
59
|
backgroundColor: colors.background,
|