-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnrichedMarkdownNativeComponent.ts
More file actions
329 lines (297 loc) · 9.08 KB
/
EnrichedMarkdownNativeComponent.ts
File metadata and controls
329 lines (297 loc) · 9.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
import {
codegenNativeComponent,
type ViewProps,
type CodegenTypes,
type ColorValue,
} from 'react-native';
// All block styles extend this interface
interface BaseBlockStyleInternal {
fontSize: CodegenTypes.Float;
fontFamily: string;
fontWeight: string;
color: ColorValue;
marginTop: CodegenTypes.Float;
marginBottom: CodegenTypes.Float;
lineHeight: CodegenTypes.Float;
}
interface ParagraphStyleInternal extends BaseBlockStyleInternal {
textAlign: string;
}
interface HeadingStyleInternal extends BaseBlockStyleInternal {
textAlign: string;
}
interface BlockquoteStyleInternal extends BaseBlockStyleInternal {
borderColor: ColorValue;
borderWidth: CodegenTypes.Float;
gapWidth: CodegenTypes.Float;
backgroundColor: ColorValue;
}
interface ListStyleInternal extends BaseBlockStyleInternal {
bulletColor: ColorValue;
bulletSize: CodegenTypes.Float;
markerWidth: CodegenTypes.Float;
markerColor: ColorValue;
markerFontWeight: string;
gapWidth: CodegenTypes.Float;
marginLeft: CodegenTypes.Float;
}
interface CodeBlockStyleInternal extends BaseBlockStyleInternal {
backgroundColor: ColorValue;
borderColor: ColorValue;
borderRadius: CodegenTypes.Float;
borderWidth: CodegenTypes.Float;
padding: CodegenTypes.Float;
}
interface LinkStyleInternal {
fontFamily: string;
color: ColorValue;
underline: boolean;
}
interface StrongStyleInternal {
fontFamily: string;
fontWeight: string;
color?: ColorValue;
}
interface EmphasisStyleInternal {
fontFamily: string;
fontStyle: string;
color?: ColorValue;
}
interface StrikethroughStyleInternal {
color: ColorValue;
}
interface UnderlineStyleInternal {
color: ColorValue;
}
interface CodeStyleInternal {
fontFamily: string;
fontSize: CodegenTypes.Float;
color: ColorValue;
backgroundColor: ColorValue;
borderColor: ColorValue;
}
interface ImageStyleInternal {
height: CodegenTypes.Float;
borderRadius: CodegenTypes.Float;
marginTop: CodegenTypes.Float;
marginBottom: CodegenTypes.Float;
}
interface InlineImageStyleInternal {
size: CodegenTypes.Float;
}
interface ThematicBreakStyleInternal {
color: ColorValue;
height: CodegenTypes.Float;
marginTop: CodegenTypes.Float;
marginBottom: CodegenTypes.Float;
}
interface TableStyleInternal extends BaseBlockStyleInternal {
headerFontFamily: string;
headerBackgroundColor: ColorValue;
headerTextColor: ColorValue;
rowEvenBackgroundColor: ColorValue;
rowOddBackgroundColor: ColorValue;
borderColor: ColorValue;
borderWidth: CodegenTypes.Float;
borderRadius: CodegenTypes.Float;
cellPaddingHorizontal: CodegenTypes.Float;
cellPaddingVertical: CodegenTypes.Float;
}
interface TaskListStyleInternal {
checkedColor: ColorValue;
borderColor: ColorValue;
checkboxSize: CodegenTypes.Float;
checkboxBorderRadius: CodegenTypes.Float;
checkmarkColor: ColorValue;
checkedTextColor: ColorValue;
checkedStrikethrough: boolean;
}
interface MathStyleInternal {
fontSize: CodegenTypes.Float;
color: ColorValue;
backgroundColor: ColorValue;
padding: CodegenTypes.Float;
marginTop: CodegenTypes.Float;
marginBottom: CodegenTypes.Float;
textAlign: string;
}
interface InlineMathStyleInternal {
color: ColorValue;
}
interface SpoilerParticlesStyleInternal {
density: CodegenTypes.Float;
speed: CodegenTypes.Float;
}
interface SpoilerSolidStyleInternal {
borderRadius: CodegenTypes.Float;
}
interface SpoilerStyleInternal {
color: ColorValue;
particles: SpoilerParticlesStyleInternal;
solid: SpoilerSolidStyleInternal;
}
export interface MarkdownStyleInternal {
paragraph: ParagraphStyleInternal;
h1: HeadingStyleInternal;
h2: HeadingStyleInternal;
h3: HeadingStyleInternal;
h4: HeadingStyleInternal;
h5: HeadingStyleInternal;
h6: HeadingStyleInternal;
blockquote: BlockquoteStyleInternal;
list: ListStyleInternal;
codeBlock: CodeBlockStyleInternal;
link: LinkStyleInternal;
strong: StrongStyleInternal;
em: EmphasisStyleInternal;
strikethrough: StrikethroughStyleInternal;
underline: UnderlineStyleInternal;
code: CodeStyleInternal;
image: ImageStyleInternal;
inlineImage: InlineImageStyleInternal;
thematicBreak: ThematicBreakStyleInternal;
table: TableStyleInternal;
taskList: TaskListStyleInternal;
math: MathStyleInternal;
inlineMath: InlineMathStyleInternal;
spoiler: SpoilerStyleInternal;
}
export interface LinkPressEvent {
url: string;
}
export interface LinkLongPressEvent {
url: string;
}
export interface TaskListItemPressEvent {
index: CodegenTypes.Int32;
checked: boolean;
text: string;
}
export interface ContextMenuItemConfig {
text: string;
icon?: string;
}
export interface OnContextMenuItemPressEvent {
itemText: string;
selectedText: string;
selectionStart: CodegenTypes.Int32;
selectionEnd: CodegenTypes.Int32;
}
/**
* MD4C parser flags configuration.
* Controls how the markdown parser interprets certain syntax.
*/
export interface Md4cFlagsInternal {
/**
* Enable underline syntax support (__text__).
* When enabled, underscores are treated as underline markers.
* When disabled, underscores are treated as emphasis markers (same as asterisks).
* @default false
*/
underline: boolean;
/**
* Enable LaTeX math span parsing ($..$ and $$..$$).
* When disabled, dollar signs are treated as plain text.
* @default true
*/
latexMath: boolean;
}
export interface NativeProps extends ViewProps {
/**
* Markdown content to render.
*/
markdown: string;
/**
* Internal style configuration for markdown elements.
* Always provided with complete defaults via normalizeMarkdownStyle.
* Block styles (paragraph, headings) contain fontSize, fontFamily, fontWeight, and color.
*/
markdownStyle: MarkdownStyleInternal;
/**
* Callback fired when a link is pressed.
* Receives the URL that was tapped.
*/
onLinkPress?: CodegenTypes.BubblingEventHandler<LinkPressEvent>;
/**
* Callback fired when a link is long pressed.
* Receives the URL that was long pressed.
* - iOS: When provided, overrides the system link preview behavior.
* - Android: Handles long press gestures on links.
*/
onLinkLongPress?: CodegenTypes.BubblingEventHandler<LinkLongPressEvent>;
/**
* Callback fired when a task list checkbox is tapped.
* Receives the 0-based task index, current checked state, and the item's plain text.
*/
onTaskListItemPress?: CodegenTypes.BubblingEventHandler<TaskListItemPressEvent>;
/**
* Controls whether the system link preview is shown on long press (iOS only).
*
* When `true` (default), long-pressing a link shows the native iOS link preview.
* When `false`, the system preview is suppressed.
*
* Automatically set to `false` when `onLinkLongPress` is provided (unless explicitly overridden).
*
* Android: No-op (Android doesn't have a system link preview).
*
* @default true
*/
enableLinkPreview?: CodegenTypes.WithDefault<boolean, true>;
/**
* - iOS: Controls text selection and link previews on long press.
* - Android: Controls text selection.
* @default true
*/
selectable?: boolean;
/**
* MD4C parser flags configuration.
* Controls how the markdown parser interprets certain syntax.
*/
md4cFlags: Md4cFlagsInternal;
/**
* Specifies whether fonts should scale to respect Text Size accessibility settings.
* When false, text will not scale with the user's accessibility settings.
* @default true
*/
allowFontScaling?: CodegenTypes.WithDefault<boolean, true>;
/**
* Specifies the largest possible scale a font can reach when allowFontScaling is enabled.
* Possible values:
* - undefined/null (default): inherit from parent or global default (no limit)
* - 0: no limit, ignore parent/global default
* - >= 1: sets the maxFontSizeMultiplier of this node to this value
* @default undefined
*/
maxFontSizeMultiplier?: CodegenTypes.Float;
/**
* When false (default), removes trailing margin from the last element to eliminate bottom spacing.
* When true, keeps the trailing margin from the last element's marginBottom style.
* @default false
*/
allowTrailingMargin?: CodegenTypes.WithDefault<boolean, false>;
/**
* When true, newly appended content fades in during streaming updates.
* Only the tail (new characters beyond the previous content) is animated.
* @default false
*/
streamingAnimation?: CodegenTypes.WithDefault<boolean, false>;
/**
* Controls how spoiler text is displayed before being revealed.
* - 'particles' (default): animated particle overlay.
* - 'solid': opaque rectangle covering the text.
* @default 'particles'
*/
spoilerOverlay?: CodegenTypes.WithDefault<string, 'particles'>;
/**
* Custom items to show in the text selection context menu.
*/
contextMenuItems?: ReadonlyArray<Readonly<ContextMenuItemConfig>>;
/**
* Fired when a custom context menu item is pressed.
* Receives the item label, the currently selected text, and the selection range.
*/
onContextMenuItemPress?: CodegenTypes.BubblingEventHandler<OnContextMenuItemPressEvent>;
}
export default codegenNativeComponent<NativeProps>('EnrichedMarkdown', {
interfaceOnly: true,
});