react-native-nitro-markdown 0.2.1 → 0.3.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/README.md +217 -101
- package/lib/commonjs/MarkdownContext.js +3 -7
- package/lib/commonjs/MarkdownContext.js.map +1 -1
- package/lib/commonjs/default-markdown-renderer.js +4 -7
- package/lib/commonjs/default-markdown-renderer.js.map +1 -1
- package/lib/commonjs/headless.js +12 -1
- package/lib/commonjs/headless.js.map +1 -1
- package/lib/commonjs/index.js +35 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/markdown.js +88 -37
- package/lib/commonjs/markdown.js.map +1 -1
- package/lib/commonjs/renderers/blockquote.js +1 -1
- package/lib/commonjs/renderers/blockquote.js.map +1 -1
- package/lib/commonjs/renderers/code.js +15 -8
- package/lib/commonjs/renderers/code.js.map +1 -1
- package/lib/commonjs/renderers/heading.js +2 -1
- package/lib/commonjs/renderers/heading.js.map +1 -1
- package/lib/commonjs/renderers/horizontal-rule.js +4 -2
- package/lib/commonjs/renderers/horizontal-rule.js.map +1 -1
- package/lib/commonjs/renderers/image.js +13 -9
- package/lib/commonjs/renderers/image.js.map +1 -1
- package/lib/commonjs/renderers/link.js +1 -3
- package/lib/commonjs/renderers/link.js.map +1 -1
- package/lib/commonjs/renderers/list.js +11 -7
- package/lib/commonjs/renderers/list.js.map +1 -1
- package/lib/commonjs/renderers/math.js +23 -47
- package/lib/commonjs/renderers/math.js.map +1 -1
- package/lib/commonjs/renderers/paragraph.js +0 -5
- package/lib/commonjs/renderers/paragraph.js.map +1 -1
- package/lib/commonjs/renderers/table.js +127 -120
- package/lib/commonjs/renderers/table.js.map +1 -1
- package/lib/commonjs/theme.js +146 -13
- package/lib/commonjs/theme.js.map +1 -1
- package/lib/module/MarkdownContext.js +3 -8
- package/lib/module/MarkdownContext.js.map +1 -1
- package/lib/module/default-markdown-renderer.js +1 -4
- package/lib/module/default-markdown-renderer.js.map +1 -1
- package/lib/module/headless.js +10 -0
- package/lib/module/headless.js.map +1 -1
- package/lib/module/index.js +2 -20
- package/lib/module/index.js.map +1 -1
- package/lib/module/markdown.js +89 -38
- package/lib/module/markdown.js.map +1 -1
- package/lib/module/renderers/blockquote.js +1 -1
- package/lib/module/renderers/blockquote.js.map +1 -1
- package/lib/module/renderers/code.js +15 -8
- package/lib/module/renderers/code.js.map +1 -1
- package/lib/module/renderers/heading.js +2 -1
- package/lib/module/renderers/heading.js.map +1 -1
- package/lib/module/renderers/horizontal-rule.js +4 -2
- package/lib/module/renderers/horizontal-rule.js.map +1 -1
- package/lib/module/renderers/image.js +13 -9
- package/lib/module/renderers/image.js.map +1 -1
- package/lib/module/renderers/link.js +1 -3
- package/lib/module/renderers/link.js.map +1 -1
- package/lib/module/renderers/list.js +11 -7
- package/lib/module/renderers/list.js.map +1 -1
- package/lib/module/renderers/math.js +24 -48
- package/lib/module/renderers/math.js.map +1 -1
- package/lib/module/renderers/paragraph.js +0 -5
- package/lib/module/renderers/paragraph.js.map +1 -1
- package/lib/module/renderers/table.js +128 -121
- package/lib/module/renderers/table.js.map +1 -1
- package/lib/module/theme.js +144 -12
- package/lib/module/theme.js.map +1 -1
- package/lib/typescript/commonjs/MarkdownContext.d.ts +45 -6
- package/lib/typescript/commonjs/MarkdownContext.d.ts.map +1 -1
- package/lib/typescript/commonjs/default-markdown-renderer.d.ts +1 -1
- package/lib/typescript/commonjs/default-markdown-renderer.d.ts.map +1 -1
- package/lib/typescript/commonjs/headless.d.ts +8 -1
- package/lib/typescript/commonjs/headless.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +4 -16
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/markdown.d.ts +20 -2
- package/lib/typescript/commonjs/markdown.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/code.d.ts +6 -2
- package/lib/typescript/commonjs/renderers/code.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/heading.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/horizontal-rule.d.ts +6 -1
- package/lib/typescript/commonjs/renderers/horizontal-rule.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/image.d.ts +2 -0
- package/lib/typescript/commonjs/renderers/image.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/link.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/list.d.ts +4 -0
- package/lib/typescript/commonjs/renderers/list.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/math.d.ts +3 -4
- package/lib/typescript/commonjs/renderers/math.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/paragraph.d.ts +0 -5
- package/lib/typescript/commonjs/renderers/paragraph.d.ts.map +1 -1
- package/lib/typescript/commonjs/renderers/table.d.ts +2 -0
- package/lib/typescript/commonjs/renderers/table.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme.d.ts +41 -28
- package/lib/typescript/commonjs/theme.d.ts.map +1 -1
- package/lib/typescript/module/MarkdownContext.d.ts +45 -6
- package/lib/typescript/module/MarkdownContext.d.ts.map +1 -1
- package/lib/typescript/module/default-markdown-renderer.d.ts +1 -1
- package/lib/typescript/module/default-markdown-renderer.d.ts.map +1 -1
- package/lib/typescript/module/headless.d.ts +8 -1
- package/lib/typescript/module/headless.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +4 -16
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/markdown.d.ts +20 -2
- package/lib/typescript/module/markdown.d.ts.map +1 -1
- package/lib/typescript/module/renderers/code.d.ts +6 -2
- package/lib/typescript/module/renderers/code.d.ts.map +1 -1
- package/lib/typescript/module/renderers/heading.d.ts.map +1 -1
- package/lib/typescript/module/renderers/horizontal-rule.d.ts +6 -1
- package/lib/typescript/module/renderers/horizontal-rule.d.ts.map +1 -1
- package/lib/typescript/module/renderers/image.d.ts +2 -0
- package/lib/typescript/module/renderers/image.d.ts.map +1 -1
- package/lib/typescript/module/renderers/link.d.ts.map +1 -1
- package/lib/typescript/module/renderers/list.d.ts +4 -0
- package/lib/typescript/module/renderers/list.d.ts.map +1 -1
- package/lib/typescript/module/renderers/math.d.ts +3 -4
- package/lib/typescript/module/renderers/math.d.ts.map +1 -1
- package/lib/typescript/module/renderers/paragraph.d.ts +0 -5
- package/lib/typescript/module/renderers/paragraph.d.ts.map +1 -1
- package/lib/typescript/module/renderers/table.d.ts +2 -0
- package/lib/typescript/module/renderers/table.d.ts.map +1 -1
- package/lib/typescript/module/theme.d.ts +41 -28
- package/lib/typescript/module/theme.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/MarkdownContext.ts +66 -9
- package/src/default-markdown-renderer.tsx +1 -6
- package/src/headless.ts +11 -1
- package/src/index.ts +24 -19
- package/src/markdown.tsx +125 -43
- package/src/renderers/blockquote.tsx +1 -2
- package/src/renderers/code.tsx +36 -12
- package/src/renderers/heading.tsx +1 -1
- package/src/renderers/horizontal-rule.tsx +7 -4
- package/src/renderers/image.tsx +24 -9
- package/src/renderers/link.tsx +1 -6
- package/src/renderers/list.tsx +11 -5
- package/src/renderers/math.tsx +20 -43
- package/src/renderers/paragraph.tsx +0 -6
- package/src/renderers/table.tsx +185 -160
- package/src/theme.ts +203 -12
package/src/renderers/table.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useMemo,
|
|
3
3
|
useRef,
|
|
4
|
-
|
|
4
|
+
useReducer,
|
|
5
5
|
useCallback,
|
|
6
|
-
useEffect,
|
|
7
6
|
type FC,
|
|
8
7
|
type ComponentType,
|
|
8
|
+
type ReactNode,
|
|
9
9
|
} from "react";
|
|
10
10
|
import {
|
|
11
11
|
View,
|
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
ScrollView,
|
|
15
15
|
type StyleProp,
|
|
16
16
|
type TextStyle,
|
|
17
|
+
type ViewStyle,
|
|
18
|
+
type LayoutChangeEvent,
|
|
17
19
|
} from "react-native";
|
|
18
20
|
|
|
19
21
|
import type { MarkdownNode } from "../headless";
|
|
@@ -31,33 +33,28 @@ const extractTableData = (node: MarkdownNode): TableData => {
|
|
|
31
33
|
const rows: MarkdownNode[][] = [];
|
|
32
34
|
const alignments: (string | undefined)[] = [];
|
|
33
35
|
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
headers.push(cell);
|
|
43
|
-
alignments.push(cell.align);
|
|
36
|
+
for (const child of node.children ?? []) {
|
|
37
|
+
if (child.type === "table_head") {
|
|
38
|
+
for (const row of child.children ?? []) {
|
|
39
|
+
if (row.type === "table_row") {
|
|
40
|
+
for (const cell of row.children ?? []) {
|
|
41
|
+
headers.push(cell);
|
|
42
|
+
alignments.push(cell.align);
|
|
43
|
+
}
|
|
44
44
|
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (cell.type === "table_cell") {
|
|
55
|
-
rowCells.push(cell);
|
|
45
|
+
}
|
|
46
|
+
} else if (child.type === "table_body") {
|
|
47
|
+
for (const row of child.children ?? []) {
|
|
48
|
+
if (row.type === "table_row") {
|
|
49
|
+
const rowCells: MarkdownNode[] = [];
|
|
50
|
+
for (const cell of row.children ?? []) {
|
|
51
|
+
rowCells.push(cell);
|
|
52
|
+
}
|
|
53
|
+
rows.push(rowCells);
|
|
56
54
|
}
|
|
57
|
-
}
|
|
58
|
-
if (rowCells.length > 0) rows.push(rowCells);
|
|
55
|
+
}
|
|
59
56
|
}
|
|
60
|
-
}
|
|
57
|
+
}
|
|
61
58
|
|
|
62
59
|
return { headers, rows, alignments };
|
|
63
60
|
};
|
|
@@ -65,11 +62,23 @@ const extractTableData = (node: MarkdownNode): TableData => {
|
|
|
65
62
|
interface TableRendererProps {
|
|
66
63
|
node: MarkdownNode;
|
|
67
64
|
Renderer: ComponentType<NodeRendererProps>;
|
|
65
|
+
style?: ViewStyle;
|
|
68
66
|
}
|
|
69
67
|
|
|
68
|
+
type ColumnWidthsAction = {
|
|
69
|
+
type: "SET_WIDTHS";
|
|
70
|
+
payload: number[];
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const columnWidthsReducer = (state: number[], action: ColumnWidthsAction) => {
|
|
74
|
+
if (action.type === "SET_WIDTHS") return action.payload;
|
|
75
|
+
return state;
|
|
76
|
+
};
|
|
77
|
+
|
|
70
78
|
export const TableRenderer: FC<TableRendererProps> = ({
|
|
71
79
|
node,
|
|
72
80
|
Renderer,
|
|
81
|
+
style,
|
|
73
82
|
}) => {
|
|
74
83
|
const { theme } = useMarkdownContext();
|
|
75
84
|
const { headers, rows, alignments } = useMemo(
|
|
@@ -80,159 +89,169 @@ export const TableRenderer: FC<TableRendererProps> = ({
|
|
|
80
89
|
const columnCount = headers.length;
|
|
81
90
|
const styles = useMemo(() => createTableStyles(theme), [theme]);
|
|
82
91
|
|
|
83
|
-
const [columnWidths,
|
|
92
|
+
const [columnWidths, dispatch] = useReducer(columnWidthsReducer, []);
|
|
84
93
|
const measuredWidths = useRef<Map<string, number>>(new Map());
|
|
85
|
-
const
|
|
94
|
+
const measuredCells = useRef<Set<string>>(new Set());
|
|
95
|
+
const widthsCalculated = useRef(false);
|
|
86
96
|
|
|
87
|
-
const
|
|
88
|
-
|
|
97
|
+
const onCellLayout = useCallback(
|
|
98
|
+
(cellKey: string, width: number) => {
|
|
99
|
+
measuredWidths.current.set(cellKey, width);
|
|
100
|
+
measuredCells.current.add(cellKey);
|
|
89
101
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
102
|
+
const expectedCells = new Set<string>();
|
|
103
|
+
for (let col = 0; col < columnCount; col++) {
|
|
104
|
+
expectedCells.add(`header-${col}`);
|
|
105
|
+
}
|
|
93
106
|
for (let row = 0; row < rows.length; row++) {
|
|
94
|
-
|
|
95
|
-
|
|
107
|
+
for (let col = 0; col < columnCount; col++) {
|
|
108
|
+
expectedCells.add(`cell-${row}-${col}`);
|
|
109
|
+
}
|
|
96
110
|
}
|
|
97
|
-
// Apply padding and min-width
|
|
98
|
-
finalWidths[col] = Math.max(maxWidth + 32, 100);
|
|
99
|
-
}
|
|
100
111
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
112
|
+
const allCellsMeasured = [...expectedCells].every((key) =>
|
|
113
|
+
measuredCells.current.has(key)
|
|
114
|
+
);
|
|
115
|
+
if (!allCellsMeasured || widthsCalculated.current) return;
|
|
104
116
|
|
|
105
|
-
|
|
106
|
-
if (columnCount === 0) return;
|
|
117
|
+
const maxWidths: number[] = new Array(columnCount).fill(0);
|
|
107
118
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
119
|
+
for (let col = 0; col < columnCount; col++) {
|
|
120
|
+
const headerWidth = measuredWidths.current.get(`header-${col}`);
|
|
121
|
+
if (headerWidth && headerWidth > 0) {
|
|
122
|
+
maxWidths[col] = Math.max(maxWidths[col], headerWidth);
|
|
123
|
+
}
|
|
113
124
|
|
|
114
|
-
|
|
115
|
-
|
|
125
|
+
for (let row = 0; row < rows.length; row++) {
|
|
126
|
+
const cellWidth = measuredWidths.current.get(`cell-${row}-${col}`);
|
|
127
|
+
if (cellWidth && cellWidth > 0) {
|
|
128
|
+
maxWidths[col] = Math.max(maxWidths[col], cellWidth);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
116
131
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
measuredWidths.current.set(key, width);
|
|
132
|
+
maxWidths[col] = Math.max(maxWidths[col] + 8, 60);
|
|
133
|
+
}
|
|
120
134
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
135
|
+
widthsCalculated.current = true;
|
|
136
|
+
dispatch({ type: "SET_WIDTHS", payload: maxWidths });
|
|
137
|
+
},
|
|
138
|
+
[columnCount, rows.length]
|
|
139
|
+
);
|
|
126
140
|
|
|
127
|
-
const
|
|
141
|
+
const getAlignment = (
|
|
142
|
+
index: number
|
|
143
|
+
): "flex-start" | "center" | "flex-end" => {
|
|
128
144
|
const align = alignments[index];
|
|
129
|
-
if (align === "center")
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return { alignItems: "flex-end", textAlign: "right" } as const;
|
|
133
|
-
return { alignItems: "flex-start", textAlign: "left" } as const;
|
|
145
|
+
if (align === "center") return "center";
|
|
146
|
+
if (align === "right") return "flex-end";
|
|
147
|
+
return "flex-start";
|
|
134
148
|
};
|
|
135
149
|
|
|
136
150
|
if (columnCount === 0) return null;
|
|
137
151
|
|
|
152
|
+
const hasWidths = columnWidths.length === columnCount;
|
|
153
|
+
|
|
138
154
|
return (
|
|
139
|
-
<View style={styles.container}>
|
|
140
|
-
{
|
|
141
|
-
<View style={styles.
|
|
142
|
-
|
|
143
|
-
|
|
155
|
+
<View style={[styles.container, style]}>
|
|
156
|
+
<View style={styles.measurementContainer}>
|
|
157
|
+
<View style={styles.measurementRow}>
|
|
158
|
+
{headers.map((cell, colIndex) => (
|
|
159
|
+
<View
|
|
160
|
+
key={`measure-header-${colIndex}`}
|
|
161
|
+
style={styles.measurementCell}
|
|
162
|
+
onLayout={(e: LayoutChangeEvent) => {
|
|
163
|
+
onCellLayout(`header-${colIndex}`, e.nativeEvent.layout.width);
|
|
164
|
+
}}
|
|
165
|
+
>
|
|
166
|
+
<CellContent node={cell} Renderer={Renderer} styles={styles} />
|
|
167
|
+
</View>
|
|
168
|
+
))}
|
|
169
|
+
</View>
|
|
170
|
+
{rows.map((row, rowIndex) => (
|
|
171
|
+
<View key={`measure-row-${rowIndex}`} style={styles.measurementRow}>
|
|
172
|
+
{row.map((cell, colIndex) => (
|
|
144
173
|
<View
|
|
145
|
-
key={`
|
|
146
|
-
|
|
147
|
-
|
|
174
|
+
key={`measure-cell-${rowIndex}-${colIndex}`}
|
|
175
|
+
style={styles.measurementCell}
|
|
176
|
+
onLayout={(e: LayoutChangeEvent) => {
|
|
177
|
+
onCellLayout(
|
|
178
|
+
`cell-${rowIndex}-${colIndex}`,
|
|
179
|
+
e.nativeEvent.layout.width
|
|
180
|
+
);
|
|
181
|
+
}}
|
|
148
182
|
>
|
|
149
183
|
<CellContent node={cell} Renderer={Renderer} styles={styles} />
|
|
150
184
|
</View>
|
|
151
185
|
))}
|
|
152
186
|
</View>
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
187
|
+
))}
|
|
188
|
+
</View>
|
|
189
|
+
|
|
190
|
+
{hasWidths && (
|
|
191
|
+
<ScrollView
|
|
192
|
+
horizontal
|
|
193
|
+
showsHorizontalScrollIndicator
|
|
194
|
+
style={styles.tableScroll}
|
|
195
|
+
bounces={false}
|
|
196
|
+
>
|
|
197
|
+
<View style={styles.table}>
|
|
198
|
+
<View style={styles.headerRow}>
|
|
199
|
+
{headers.map((cell, colIndex) => (
|
|
156
200
|
<View
|
|
157
|
-
key={`
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
201
|
+
key={`header-${colIndex}`}
|
|
202
|
+
style={[
|
|
203
|
+
styles.headerCell,
|
|
204
|
+
{
|
|
205
|
+
width: columnWidths[colIndex],
|
|
206
|
+
alignItems: getAlignment(colIndex),
|
|
207
|
+
},
|
|
208
|
+
colIndex === columnCount - 1 && styles.lastCell,
|
|
209
|
+
]}
|
|
162
210
|
>
|
|
163
211
|
<CellContent
|
|
164
212
|
node={cell}
|
|
165
213
|
Renderer={Renderer}
|
|
166
214
|
styles={styles}
|
|
215
|
+
textStyle={styles.headerText}
|
|
167
216
|
/>
|
|
168
217
|
</View>
|
|
169
218
|
))}
|
|
170
219
|
</View>
|
|
171
|
-
))}
|
|
172
|
-
</View>
|
|
173
|
-
)}
|
|
174
220
|
|
|
175
|
-
|
|
176
|
-
horizontal
|
|
177
|
-
showsHorizontalScrollIndicator={true}
|
|
178
|
-
bounces={false}
|
|
179
|
-
style={styles.tableScroll}
|
|
180
|
-
>
|
|
181
|
-
<View style={styles.table}>
|
|
182
|
-
{/* Header */}
|
|
183
|
-
<View style={styles.headerRow}>
|
|
184
|
-
{headers.map((cell, i) => (
|
|
221
|
+
{rows.map((row, rowIndex) => (
|
|
185
222
|
<View
|
|
186
|
-
key={`
|
|
223
|
+
key={`row-${rowIndex}`}
|
|
187
224
|
style={[
|
|
188
|
-
styles.
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
i === columnCount - 1 && styles.lastCell,
|
|
225
|
+
styles.bodyRow,
|
|
226
|
+
rowIndex === rows.length - 1 && styles.lastRow,
|
|
227
|
+
rowIndex % 2 === 1 && styles.oddRow,
|
|
192
228
|
]}
|
|
193
229
|
>
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
230
|
+
{row.map((cell, colIndex) => (
|
|
231
|
+
<View
|
|
232
|
+
key={`cell-${rowIndex}-${colIndex}`}
|
|
233
|
+
style={[
|
|
234
|
+
styles.bodyCell,
|
|
235
|
+
{
|
|
236
|
+
width: columnWidths[colIndex],
|
|
237
|
+
alignItems: getAlignment(colIndex),
|
|
238
|
+
},
|
|
239
|
+
colIndex === columnCount - 1 && styles.lastCell,
|
|
240
|
+
]}
|
|
241
|
+
>
|
|
242
|
+
<CellContent
|
|
243
|
+
node={cell}
|
|
244
|
+
Renderer={Renderer}
|
|
245
|
+
styles={styles}
|
|
246
|
+
textStyle={styles.cellText}
|
|
247
|
+
/>
|
|
248
|
+
</View>
|
|
249
|
+
))}
|
|
200
250
|
</View>
|
|
201
251
|
))}
|
|
202
252
|
</View>
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
{rows.map((row, ri) => (
|
|
206
|
-
<View
|
|
207
|
-
key={`r-${ri}`}
|
|
208
|
-
style={[
|
|
209
|
-
styles.bodyRow,
|
|
210
|
-
ri === rows.length - 1 && styles.lastRow,
|
|
211
|
-
ri % 2 === 1 && styles.oddRow,
|
|
212
|
-
]}
|
|
213
|
-
>
|
|
214
|
-
{row.map((cell, ci) => (
|
|
215
|
-
<View
|
|
216
|
-
key={`c-${ri}-${ci}`}
|
|
217
|
-
style={[
|
|
218
|
-
styles.bodyCell,
|
|
219
|
-
{ width: columnWidths[ci] || 120 },
|
|
220
|
-
getAlignStyle(ci),
|
|
221
|
-
ci === columnCount - 1 && styles.lastCell,
|
|
222
|
-
]}
|
|
223
|
-
>
|
|
224
|
-
<CellContent
|
|
225
|
-
node={cell}
|
|
226
|
-
Renderer={Renderer}
|
|
227
|
-
styles={styles}
|
|
228
|
-
textStyle={styles.cellText}
|
|
229
|
-
/>
|
|
230
|
-
</View>
|
|
231
|
-
))}
|
|
232
|
-
</View>
|
|
233
|
-
))}
|
|
234
|
-
</View>
|
|
235
|
-
</ScrollView>
|
|
253
|
+
</ScrollView>
|
|
254
|
+
)}
|
|
236
255
|
</View>
|
|
237
256
|
);
|
|
238
257
|
};
|
|
@@ -264,37 +283,39 @@ const CellContent: FC<{
|
|
|
264
283
|
|
|
265
284
|
const createTableStyles = (theme: MarkdownTheme) => {
|
|
266
285
|
const colors = theme?.colors || {};
|
|
286
|
+
const borderRadius = theme?.borderRadius || { m: 8 };
|
|
287
|
+
|
|
267
288
|
return StyleSheet.create({
|
|
268
289
|
container: {
|
|
269
|
-
marginVertical:
|
|
290
|
+
marginVertical: theme.spacing.s,
|
|
270
291
|
},
|
|
271
|
-
|
|
292
|
+
measurementContainer: {
|
|
272
293
|
position: "absolute",
|
|
273
|
-
top: 0,
|
|
274
|
-
left: 0,
|
|
275
294
|
opacity: 0,
|
|
276
|
-
|
|
295
|
+
pointerEvents: "none",
|
|
296
|
+
left: -9999,
|
|
297
|
+
},
|
|
298
|
+
measurementRow: {
|
|
299
|
+
flexDirection: "row",
|
|
277
300
|
},
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
alignSelf: "flex-start",
|
|
301
|
+
measurementCell: {
|
|
302
|
+
paddingVertical: 10,
|
|
303
|
+
paddingHorizontal: 12,
|
|
282
304
|
},
|
|
283
305
|
tableScroll: {
|
|
284
|
-
|
|
285
|
-
borderWidth: 1,
|
|
286
|
-
borderColor: colors.tableBorder || "#374151",
|
|
306
|
+
flexGrow: 0,
|
|
287
307
|
},
|
|
288
308
|
table: {
|
|
309
|
+
borderRadius: borderRadius.m,
|
|
310
|
+
overflow: "hidden",
|
|
311
|
+
borderWidth: 1,
|
|
312
|
+
borderColor: colors.tableBorder || "#374151",
|
|
289
313
|
backgroundColor: colors.surface || "#111827",
|
|
290
314
|
},
|
|
291
|
-
row: {
|
|
292
|
-
flexDirection: "row",
|
|
293
|
-
},
|
|
294
315
|
headerRow: {
|
|
295
316
|
flexDirection: "row",
|
|
296
317
|
backgroundColor: colors.tableHeader || "#1f2937",
|
|
297
|
-
borderBottomWidth:
|
|
318
|
+
borderBottomWidth: 1,
|
|
298
319
|
borderBottomColor: colors.tableBorder || "#374151",
|
|
299
320
|
},
|
|
300
321
|
bodyRow: {
|
|
@@ -309,14 +330,18 @@ const createTableStyles = (theme: MarkdownTheme) => {
|
|
|
309
330
|
borderBottomWidth: 0,
|
|
310
331
|
},
|
|
311
332
|
headerCell: {
|
|
312
|
-
|
|
313
|
-
|
|
333
|
+
flexShrink: 0,
|
|
334
|
+
paddingVertical: 10,
|
|
335
|
+
paddingHorizontal: 12,
|
|
336
|
+
minWidth: 60,
|
|
314
337
|
borderRightWidth: 1,
|
|
315
338
|
borderRightColor: colors.tableBorder || "#374151",
|
|
316
339
|
},
|
|
317
340
|
bodyCell: {
|
|
318
|
-
|
|
319
|
-
|
|
341
|
+
flexShrink: 0,
|
|
342
|
+
paddingVertical: 10,
|
|
343
|
+
paddingHorizontal: 12,
|
|
344
|
+
minWidth: 60,
|
|
320
345
|
borderRightWidth: 1,
|
|
321
346
|
borderRightColor: colors.tableBorder || "#374151",
|
|
322
347
|
justifyContent: "center",
|
|
@@ -327,14 +352,14 @@ const createTableStyles = (theme: MarkdownTheme) => {
|
|
|
327
352
|
headerText: {
|
|
328
353
|
color: colors.tableHeaderText || "#9ca3af",
|
|
329
354
|
fontSize: 12,
|
|
330
|
-
fontWeight: "
|
|
331
|
-
|
|
332
|
-
letterSpacing: 1,
|
|
355
|
+
fontWeight: "600",
|
|
356
|
+
fontFamily: theme.fontFamilies?.regular,
|
|
333
357
|
},
|
|
334
358
|
cellText: {
|
|
335
359
|
color: colors.text || "#e5e7eb",
|
|
336
360
|
fontSize: 14,
|
|
337
361
|
lineHeight: 20,
|
|
362
|
+
fontFamily: theme.fontFamilies?.regular,
|
|
338
363
|
},
|
|
339
364
|
cellContentWrapper: {
|
|
340
365
|
flexDirection: "row",
|