react-native-nitro-markdown 0.1.2 → 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/LICENSE +21 -0
- package/README.md +293 -119
- package/android/src/main/cpp/cpp-adapter.cpp +1 -1
- package/android/src/main/java/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSession.kt +61 -0
- package/android/src/main/java/com/nitromarkdown/NitroMarkdownPackage.kt +5 -1
- package/cpp/bindings/HybridMarkdownParser.cpp +2 -2
- package/cpp/bindings/HybridMarkdownParser.hpp +2 -2
- package/cpp/bindings/HybridMarkdownSession.cpp +0 -0
- package/cpp/core/MarkdownSessionCore.cpp +0 -0
- package/ios/HybridMarkdownSession.swift +64 -0
- package/lib/commonjs/MarkdownContext.js +17 -0
- package/lib/commonjs/MarkdownContext.js.map +1 -0
- package/lib/commonjs/MarkdownSession.js +11 -0
- package/lib/commonjs/MarkdownSession.js.map +1 -0
- package/lib/commonjs/default-markdown-renderer.js +217 -0
- package/lib/commonjs/default-markdown-renderer.js.map +1 -0
- package/lib/commonjs/headless.js +61 -0
- package/lib/commonjs/headless.js.map +1 -0
- package/lib/commonjs/index.js +220 -13
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/markdown-stream.js +32 -0
- package/lib/commonjs/markdown-stream.js.map +1 -0
- package/lib/commonjs/markdown.js +377 -0
- package/lib/commonjs/markdown.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/renderers/blockquote.js +36 -0
- package/lib/commonjs/renderers/blockquote.js.map +1 -0
- package/lib/commonjs/renderers/code.js +99 -0
- package/lib/commonjs/renderers/code.js.map +1 -0
- package/lib/commonjs/renderers/heading.js +63 -0
- package/lib/commonjs/renderers/heading.js.map +1 -0
- package/lib/commonjs/renderers/horizontal-rule.js +29 -0
- package/lib/commonjs/renderers/horizontal-rule.js.map +1 -0
- package/lib/commonjs/renderers/image.js +163 -0
- package/lib/commonjs/renderers/image.js.map +1 -0
- package/lib/commonjs/renderers/link.js +35 -0
- package/lib/commonjs/renderers/link.js.map +1 -0
- package/lib/commonjs/renderers/list.js +118 -0
- package/lib/commonjs/renderers/list.js.map +1 -0
- package/lib/commonjs/renderers/math.js +127 -0
- package/lib/commonjs/renderers/math.js.map +1 -0
- package/lib/commonjs/renderers/paragraph.js +39 -0
- package/lib/commonjs/renderers/paragraph.js.map +1 -0
- package/lib/commonjs/renderers/table.js +290 -0
- package/lib/commonjs/renderers/table.js.map +1 -0
- package/lib/commonjs/specs/MarkdownSession.nitro.js +6 -0
- package/lib/commonjs/specs/MarkdownSession.nitro.js.map +1 -0
- package/lib/commonjs/theme.js +191 -0
- package/lib/commonjs/theme.js.map +1 -0
- package/lib/commonjs/use-markdown-stream.js +71 -0
- package/lib/commonjs/use-markdown-stream.js.map +1 -0
- package/lib/module/MarkdownContext.js +12 -0
- package/lib/module/MarkdownContext.js.map +1 -0
- package/lib/module/MarkdownSession.js +7 -0
- package/lib/module/MarkdownSession.js.map +1 -0
- package/lib/module/default-markdown-renderer.js +212 -0
- package/lib/module/default-markdown-renderer.js.map +1 -0
- package/lib/module/headless.js +54 -0
- package/lib/module/headless.js.map +1 -0
- package/lib/module/index.js +18 -10
- package/lib/module/index.js.map +1 -1
- package/lib/module/markdown-stream.js +27 -0
- package/lib/module/markdown-stream.js.map +1 -0
- package/lib/module/markdown.js +372 -0
- package/lib/module/markdown.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/renderers/blockquote.js +31 -0
- package/lib/module/renderers/blockquote.js.map +1 -0
- package/lib/module/renderers/code.js +93 -0
- package/lib/module/renderers/code.js.map +1 -0
- package/lib/module/renderers/heading.js +58 -0
- package/lib/module/renderers/heading.js.map +1 -0
- package/lib/module/renderers/horizontal-rule.js +24 -0
- package/lib/module/renderers/horizontal-rule.js.map +1 -0
- package/lib/module/renderers/image.js +158 -0
- package/lib/module/renderers/image.js.map +1 -0
- package/lib/module/renderers/link.js +30 -0
- package/lib/module/renderers/link.js.map +1 -0
- package/lib/module/renderers/list.js +111 -0
- package/lib/module/renderers/list.js.map +1 -0
- package/lib/module/renderers/math.js +121 -0
- package/lib/module/renderers/math.js.map +1 -0
- package/lib/module/renderers/paragraph.js +34 -0
- package/lib/module/renderers/paragraph.js.map +1 -0
- package/lib/module/renderers/table.js +285 -0
- package/lib/module/renderers/table.js.map +1 -0
- package/lib/module/specs/MarkdownSession.nitro.js +4 -0
- package/lib/module/specs/MarkdownSession.nitro.js.map +1 -0
- package/lib/module/theme.js +186 -0
- package/lib/module/theme.js.map +1 -0
- package/lib/module/use-markdown-stream.js +66 -0
- package/lib/module/use-markdown-stream.js.map +1 -0
- package/lib/typescript/commonjs/Markdown.nitro.d.ts.map +1 -0
- package/lib/typescript/commonjs/MarkdownContext.d.ts +65 -0
- package/lib/typescript/commonjs/MarkdownContext.d.ts.map +1 -0
- package/lib/typescript/commonjs/MarkdownSession.d.ts +4 -0
- package/lib/typescript/commonjs/MarkdownSession.d.ts.map +1 -0
- package/lib/typescript/commonjs/default-markdown-renderer.d.ts +10 -0
- package/lib/typescript/commonjs/default-markdown-renderer.d.ts.map +1 -0
- package/lib/typescript/commonjs/headless.d.ts +57 -0
- package/lib/typescript/commonjs/headless.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +22 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/markdown-stream.d.ts +15 -0
- package/lib/typescript/commonjs/markdown-stream.d.ts.map +1 -0
- package/lib/typescript/commonjs/markdown.d.ts +47 -0
- package/lib/typescript/commonjs/markdown.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/renderers/blockquote.d.ts +9 -0
- package/lib/typescript/commonjs/renderers/blockquote.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/code.d.ts +19 -0
- package/lib/typescript/commonjs/renderers/code.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/heading.d.ts +10 -0
- package/lib/typescript/commonjs/renderers/heading.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/horizontal-rule.d.ts +8 -0
- package/lib/typescript/commonjs/renderers/horizontal-rule.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/image.d.ts +13 -0
- package/lib/typescript/commonjs/renderers/image.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/link.d.ts +10 -0
- package/lib/typescript/commonjs/renderers/link.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/list.d.ts +26 -0
- package/lib/typescript/commonjs/renderers/list.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/math.d.ts +14 -0
- package/lib/typescript/commonjs/renderers/math.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/paragraph.d.ts +10 -0
- package/lib/typescript/commonjs/renderers/paragraph.d.ts.map +1 -0
- package/lib/typescript/commonjs/renderers/table.d.ts +12 -0
- package/lib/typescript/commonjs/renderers/table.d.ts.map +1 -0
- package/lib/typescript/commonjs/specs/MarkdownSession.nitro.d.ts +12 -0
- package/lib/typescript/commonjs/specs/MarkdownSession.nitro.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme.d.ts +65 -0
- package/lib/typescript/commonjs/theme.d.ts.map +1 -0
- package/lib/typescript/commonjs/use-markdown-stream.d.ts +22 -0
- package/lib/typescript/commonjs/use-markdown-stream.d.ts.map +1 -0
- package/lib/typescript/module/Markdown.nitro.d.ts +13 -0
- package/lib/typescript/module/Markdown.nitro.d.ts.map +1 -0
- package/lib/typescript/module/MarkdownContext.d.ts +65 -0
- package/lib/typescript/module/MarkdownContext.d.ts.map +1 -0
- package/lib/typescript/module/MarkdownSession.d.ts +4 -0
- package/lib/typescript/module/MarkdownSession.d.ts.map +1 -0
- package/lib/typescript/module/default-markdown-renderer.d.ts +10 -0
- package/lib/typescript/module/default-markdown-renderer.d.ts.map +1 -0
- package/lib/typescript/module/headless.d.ts +57 -0
- package/lib/typescript/module/headless.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +22 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/markdown-stream.d.ts +15 -0
- package/lib/typescript/module/markdown-stream.d.ts.map +1 -0
- package/lib/typescript/module/markdown.d.ts +47 -0
- package/lib/typescript/module/markdown.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/renderers/blockquote.d.ts +9 -0
- package/lib/typescript/module/renderers/blockquote.d.ts.map +1 -0
- package/lib/typescript/module/renderers/code.d.ts +19 -0
- package/lib/typescript/module/renderers/code.d.ts.map +1 -0
- package/lib/typescript/module/renderers/heading.d.ts +10 -0
- package/lib/typescript/module/renderers/heading.d.ts.map +1 -0
- package/lib/typescript/module/renderers/horizontal-rule.d.ts +8 -0
- package/lib/typescript/module/renderers/horizontal-rule.d.ts.map +1 -0
- package/lib/typescript/module/renderers/image.d.ts +13 -0
- package/lib/typescript/module/renderers/image.d.ts.map +1 -0
- package/lib/typescript/module/renderers/link.d.ts +10 -0
- package/lib/typescript/module/renderers/link.d.ts.map +1 -0
- package/lib/typescript/module/renderers/list.d.ts +26 -0
- package/lib/typescript/module/renderers/list.d.ts.map +1 -0
- package/lib/typescript/module/renderers/math.d.ts +14 -0
- package/lib/typescript/module/renderers/math.d.ts.map +1 -0
- package/lib/typescript/module/renderers/paragraph.d.ts +10 -0
- package/lib/typescript/module/renderers/paragraph.d.ts.map +1 -0
- package/lib/typescript/module/renderers/table.d.ts +12 -0
- package/lib/typescript/module/renderers/table.d.ts.map +1 -0
- package/lib/typescript/module/specs/MarkdownSession.nitro.d.ts +12 -0
- package/lib/typescript/module/specs/MarkdownSession.nitro.d.ts.map +1 -0
- package/lib/typescript/module/theme.d.ts +65 -0
- package/lib/typescript/module/theme.d.ts.map +1 -0
- package/lib/typescript/module/use-markdown-stream.d.ts +22 -0
- package/lib/typescript/module/use-markdown-stream.d.ts.map +1 -0
- package/nitro.json +5 -2
- package/nitrogen/generated/android/NitroMarkdown+autolinking.cmake +3 -2
- package/nitrogen/generated/android/NitroMarkdown+autolinking.gradle +1 -1
- package/nitrogen/generated/android/NitroMarkdownOnLoad.cpp +17 -5
- package/nitrogen/generated/android/NitroMarkdownOnLoad.hpp +4 -4
- package/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
- package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.cpp +91 -0
- package/nitrogen/generated/android/c++/JHybridMarkdownSessionSpec.hpp +70 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/Func_void.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/HybridMarkdownSessionSpec.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitromarkdown/NitroMarkdownOnLoad.kt +1 -1
- package/nitrogen/generated/ios/NitroMarkdown+autolinking.rb +2 -2
- package/nitrogen/generated/ios/NitroMarkdown-Swift-Cxx-Bridge.cpp +28 -4
- package/nitrogen/generated/ios/NitroMarkdown-Swift-Cxx-Bridge.hpp +72 -6
- package/nitrogen/generated/ios/NitroMarkdown-Swift-Cxx-Umbrella.hpp +11 -4
- package/nitrogen/generated/ios/NitroMarkdownAutolinking.mm +11 -3
- package/nitrogen/generated/ios/NitroMarkdownAutolinking.swift +16 -3
- package/nitrogen/generated/ios/c++/HybridMarkdownSessionSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridMarkdownSessionSpecSwift.hpp +108 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridMarkdownSessionSpec.swift +59 -0
- package/nitrogen/generated/ios/swift/HybridMarkdownSessionSpec_cxx.swift +190 -0
- package/nitrogen/generated/shared/c++/HybridMarkdownParserSpec.cpp +3 -3
- package/nitrogen/generated/shared/c++/HybridMarkdownParserSpec.hpp +4 -4
- package/nitrogen/generated/shared/c++/HybridMarkdownSessionSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridMarkdownSessionSpec.hpp +67 -0
- package/nitrogen/generated/shared/c++/ParserOptions.hpp +22 -14
- package/package.json +45 -7
- package/react-native-nitro-markdown.podspec +5 -5
- package/src/MarkdownContext.ts +98 -0
- package/src/MarkdownSession.ts +8 -0
- package/src/default-markdown-renderer.tsx +261 -0
- package/src/headless.ts +116 -0
- package/src/index.ts +47 -60
- package/src/markdown-stream.tsx +32 -0
- package/src/markdown.tsx +497 -0
- package/src/renderers/blockquote.tsx +30 -0
- package/src/renderers/code.tsx +112 -0
- package/src/renderers/heading.tsx +66 -0
- package/src/renderers/horizontal-rule.tsx +23 -0
- package/src/renderers/image.tsx +175 -0
- package/src/renderers/link.tsx +33 -0
- package/src/renderers/list.tsx +131 -0
- package/src/renderers/math.tsx +141 -0
- package/src/renderers/paragraph.tsx +47 -0
- package/src/renderers/table.tsx +370 -0
- package/src/specs/MarkdownSession.nitro.ts +16 -0
- package/src/theme.ts +243 -0
- package/src/use-markdown-stream.ts +83 -0
- package/ios/NitroMarkdown-Bridging-Header.h +0 -14
- package/lib/commonjs/MarkdownJS.reference.js +0 -114
- package/lib/commonjs/MarkdownJS.reference.js.map +0 -1
- package/lib/module/MarkdownJS.reference.js +0 -107
- package/lib/module/MarkdownJS.reference.js.map +0 -1
- package/lib/typescript/Markdown.nitro.d.ts.map +0 -1
- package/lib/typescript/MarkdownJS.reference.d.ts +0 -33
- package/lib/typescript/MarkdownJS.reference.d.ts.map +0 -1
- package/lib/typescript/index.d.ts +0 -22
- package/lib/typescript/index.d.ts.map +0 -1
- package/src/MarkdownJS.reference.ts +0 -122
- /package/lib/typescript/{Markdown.nitro.d.ts → commonjs/Markdown.nitro.d.ts} +0 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useMemo, useRef, useReducer, useCallback } from "react";
|
|
4
|
+
import { View, Text, StyleSheet, ScrollView } from "react-native";
|
|
5
|
+
import { useMarkdownContext } from "../MarkdownContext.js";
|
|
6
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
const extractTableData = node => {
|
|
8
|
+
const headers = [];
|
|
9
|
+
const rows = [];
|
|
10
|
+
const alignments = [];
|
|
11
|
+
for (const child of node.children ?? []) {
|
|
12
|
+
if (child.type === "table_head") {
|
|
13
|
+
for (const row of child.children ?? []) {
|
|
14
|
+
if (row.type === "table_row") {
|
|
15
|
+
for (const cell of row.children ?? []) {
|
|
16
|
+
headers.push(cell);
|
|
17
|
+
alignments.push(cell.align);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
} else if (child.type === "table_body") {
|
|
22
|
+
for (const row of child.children ?? []) {
|
|
23
|
+
if (row.type === "table_row") {
|
|
24
|
+
const rowCells = [];
|
|
25
|
+
for (const cell of row.children ?? []) {
|
|
26
|
+
rowCells.push(cell);
|
|
27
|
+
}
|
|
28
|
+
rows.push(rowCells);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
headers,
|
|
35
|
+
rows,
|
|
36
|
+
alignments
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const columnWidthsReducer = (state, action) => {
|
|
40
|
+
if (action.type === "SET_WIDTHS") return action.payload;
|
|
41
|
+
return state;
|
|
42
|
+
};
|
|
43
|
+
export const TableRenderer = ({
|
|
44
|
+
node,
|
|
45
|
+
Renderer,
|
|
46
|
+
style
|
|
47
|
+
}) => {
|
|
48
|
+
const {
|
|
49
|
+
theme
|
|
50
|
+
} = useMarkdownContext();
|
|
51
|
+
const {
|
|
52
|
+
headers,
|
|
53
|
+
rows,
|
|
54
|
+
alignments
|
|
55
|
+
} = useMemo(() => extractTableData(node), [node]);
|
|
56
|
+
const columnCount = headers.length;
|
|
57
|
+
const styles = useMemo(() => createTableStyles(theme), [theme]);
|
|
58
|
+
const [columnWidths, dispatch] = useReducer(columnWidthsReducer, []);
|
|
59
|
+
const measuredWidths = useRef(new Map());
|
|
60
|
+
const measuredCells = useRef(new Set());
|
|
61
|
+
const widthsCalculated = useRef(false);
|
|
62
|
+
const onCellLayout = useCallback((cellKey, width) => {
|
|
63
|
+
measuredWidths.current.set(cellKey, width);
|
|
64
|
+
measuredCells.current.add(cellKey);
|
|
65
|
+
const expectedCells = new Set();
|
|
66
|
+
for (let col = 0; col < columnCount; col++) {
|
|
67
|
+
expectedCells.add(`header-${col}`);
|
|
68
|
+
}
|
|
69
|
+
for (let row = 0; row < rows.length; row++) {
|
|
70
|
+
for (let col = 0; col < columnCount; col++) {
|
|
71
|
+
expectedCells.add(`cell-${row}-${col}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const allCellsMeasured = [...expectedCells].every(key => measuredCells.current.has(key));
|
|
75
|
+
if (!allCellsMeasured || widthsCalculated.current) return;
|
|
76
|
+
const maxWidths = new Array(columnCount).fill(0);
|
|
77
|
+
for (let col = 0; col < columnCount; col++) {
|
|
78
|
+
const headerWidth = measuredWidths.current.get(`header-${col}`);
|
|
79
|
+
if (headerWidth && headerWidth > 0) {
|
|
80
|
+
maxWidths[col] = Math.max(maxWidths[col], headerWidth);
|
|
81
|
+
}
|
|
82
|
+
for (let row = 0; row < rows.length; row++) {
|
|
83
|
+
const cellWidth = measuredWidths.current.get(`cell-${row}-${col}`);
|
|
84
|
+
if (cellWidth && cellWidth > 0) {
|
|
85
|
+
maxWidths[col] = Math.max(maxWidths[col], cellWidth);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
maxWidths[col] = Math.max(maxWidths[col] + 8, 60);
|
|
89
|
+
}
|
|
90
|
+
widthsCalculated.current = true;
|
|
91
|
+
dispatch({
|
|
92
|
+
type: "SET_WIDTHS",
|
|
93
|
+
payload: maxWidths
|
|
94
|
+
});
|
|
95
|
+
}, [columnCount, rows.length]);
|
|
96
|
+
const getAlignment = index => {
|
|
97
|
+
const align = alignments[index];
|
|
98
|
+
if (align === "center") return "center";
|
|
99
|
+
if (align === "right") return "flex-end";
|
|
100
|
+
return "flex-start";
|
|
101
|
+
};
|
|
102
|
+
if (columnCount === 0) return null;
|
|
103
|
+
const hasWidths = columnWidths.length === columnCount;
|
|
104
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
105
|
+
style: [styles.container, style],
|
|
106
|
+
children: [/*#__PURE__*/_jsxs(View, {
|
|
107
|
+
style: styles.measurementContainer,
|
|
108
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
109
|
+
style: styles.measurementRow,
|
|
110
|
+
children: headers.map((cell, colIndex) => /*#__PURE__*/_jsx(View, {
|
|
111
|
+
style: styles.measurementCell,
|
|
112
|
+
onLayout: e => {
|
|
113
|
+
onCellLayout(`header-${colIndex}`, e.nativeEvent.layout.width);
|
|
114
|
+
},
|
|
115
|
+
children: /*#__PURE__*/_jsx(CellContent, {
|
|
116
|
+
node: cell,
|
|
117
|
+
Renderer: Renderer,
|
|
118
|
+
styles: styles
|
|
119
|
+
})
|
|
120
|
+
}, `measure-header-${colIndex}`))
|
|
121
|
+
}), rows.map((row, rowIndex) => /*#__PURE__*/_jsx(View, {
|
|
122
|
+
style: styles.measurementRow,
|
|
123
|
+
children: row.map((cell, colIndex) => /*#__PURE__*/_jsx(View, {
|
|
124
|
+
style: styles.measurementCell,
|
|
125
|
+
onLayout: e => {
|
|
126
|
+
onCellLayout(`cell-${rowIndex}-${colIndex}`, e.nativeEvent.layout.width);
|
|
127
|
+
},
|
|
128
|
+
children: /*#__PURE__*/_jsx(CellContent, {
|
|
129
|
+
node: cell,
|
|
130
|
+
Renderer: Renderer,
|
|
131
|
+
styles: styles
|
|
132
|
+
})
|
|
133
|
+
}, `measure-cell-${rowIndex}-${colIndex}`))
|
|
134
|
+
}, `measure-row-${rowIndex}`))]
|
|
135
|
+
}), hasWidths && /*#__PURE__*/_jsx(ScrollView, {
|
|
136
|
+
horizontal: true,
|
|
137
|
+
showsHorizontalScrollIndicator: true,
|
|
138
|
+
style: styles.tableScroll,
|
|
139
|
+
bounces: false,
|
|
140
|
+
children: /*#__PURE__*/_jsxs(View, {
|
|
141
|
+
style: styles.table,
|
|
142
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
143
|
+
style: styles.headerRow,
|
|
144
|
+
children: headers.map((cell, colIndex) => /*#__PURE__*/_jsx(View, {
|
|
145
|
+
style: [styles.headerCell, {
|
|
146
|
+
width: columnWidths[colIndex],
|
|
147
|
+
alignItems: getAlignment(colIndex)
|
|
148
|
+
}, colIndex === columnCount - 1 && styles.lastCell],
|
|
149
|
+
children: /*#__PURE__*/_jsx(CellContent, {
|
|
150
|
+
node: cell,
|
|
151
|
+
Renderer: Renderer,
|
|
152
|
+
styles: styles,
|
|
153
|
+
textStyle: styles.headerText
|
|
154
|
+
})
|
|
155
|
+
}, `header-${colIndex}`))
|
|
156
|
+
}), rows.map((row, rowIndex) => /*#__PURE__*/_jsx(View, {
|
|
157
|
+
style: [styles.bodyRow, rowIndex === rows.length - 1 && styles.lastRow, rowIndex % 2 === 1 && styles.oddRow],
|
|
158
|
+
children: row.map((cell, colIndex) => /*#__PURE__*/_jsx(View, {
|
|
159
|
+
style: [styles.bodyCell, {
|
|
160
|
+
width: columnWidths[colIndex],
|
|
161
|
+
alignItems: getAlignment(colIndex)
|
|
162
|
+
}, colIndex === columnCount - 1 && styles.lastCell],
|
|
163
|
+
children: /*#__PURE__*/_jsx(CellContent, {
|
|
164
|
+
node: cell,
|
|
165
|
+
Renderer: Renderer,
|
|
166
|
+
styles: styles,
|
|
167
|
+
textStyle: styles.cellText
|
|
168
|
+
})
|
|
169
|
+
}, `cell-${rowIndex}-${colIndex}`))
|
|
170
|
+
}, `row-${rowIndex}`))]
|
|
171
|
+
})
|
|
172
|
+
})]
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
const CellContent = ({
|
|
176
|
+
node,
|
|
177
|
+
Renderer,
|
|
178
|
+
styles,
|
|
179
|
+
textStyle
|
|
180
|
+
}) => {
|
|
181
|
+
if (!node.children || node.children.length === 0) {
|
|
182
|
+
return /*#__PURE__*/_jsx(Text, {
|
|
183
|
+
style: textStyle,
|
|
184
|
+
children: node.content ?? ""
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return /*#__PURE__*/_jsx(View, {
|
|
188
|
+
style: styles.cellContentWrapper,
|
|
189
|
+
children: node.children.map((child, idx) => /*#__PURE__*/_jsx(Renderer, {
|
|
190
|
+
node: child,
|
|
191
|
+
depth: 0,
|
|
192
|
+
inListItem: false,
|
|
193
|
+
parentIsText: false
|
|
194
|
+
}, idx))
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
const createTableStyles = theme => {
|
|
198
|
+
const colors = theme?.colors || {};
|
|
199
|
+
const borderRadius = theme?.borderRadius || {
|
|
200
|
+
m: 8
|
|
201
|
+
};
|
|
202
|
+
return StyleSheet.create({
|
|
203
|
+
container: {
|
|
204
|
+
marginVertical: theme.spacing.s
|
|
205
|
+
},
|
|
206
|
+
measurementContainer: {
|
|
207
|
+
position: "absolute",
|
|
208
|
+
opacity: 0,
|
|
209
|
+
pointerEvents: "none",
|
|
210
|
+
left: -9999
|
|
211
|
+
},
|
|
212
|
+
measurementRow: {
|
|
213
|
+
flexDirection: "row"
|
|
214
|
+
},
|
|
215
|
+
measurementCell: {
|
|
216
|
+
paddingVertical: 10,
|
|
217
|
+
paddingHorizontal: 12
|
|
218
|
+
},
|
|
219
|
+
tableScroll: {
|
|
220
|
+
flexGrow: 0
|
|
221
|
+
},
|
|
222
|
+
table: {
|
|
223
|
+
borderRadius: borderRadius.m,
|
|
224
|
+
overflow: "hidden",
|
|
225
|
+
borderWidth: 1,
|
|
226
|
+
borderColor: colors.tableBorder || "#374151",
|
|
227
|
+
backgroundColor: colors.surface || "#111827"
|
|
228
|
+
},
|
|
229
|
+
headerRow: {
|
|
230
|
+
flexDirection: "row",
|
|
231
|
+
backgroundColor: colors.tableHeader || "#1f2937",
|
|
232
|
+
borderBottomWidth: 1,
|
|
233
|
+
borderBottomColor: colors.tableBorder || "#374151"
|
|
234
|
+
},
|
|
235
|
+
bodyRow: {
|
|
236
|
+
flexDirection: "row",
|
|
237
|
+
borderBottomWidth: 1,
|
|
238
|
+
borderBottomColor: colors.tableBorder || "#374151"
|
|
239
|
+
},
|
|
240
|
+
oddRow: {
|
|
241
|
+
backgroundColor: colors.tableRowOdd || "rgba(255,255,255,0.02)"
|
|
242
|
+
},
|
|
243
|
+
lastRow: {
|
|
244
|
+
borderBottomWidth: 0
|
|
245
|
+
},
|
|
246
|
+
headerCell: {
|
|
247
|
+
flexShrink: 0,
|
|
248
|
+
paddingVertical: 10,
|
|
249
|
+
paddingHorizontal: 12,
|
|
250
|
+
minWidth: 60,
|
|
251
|
+
borderRightWidth: 1,
|
|
252
|
+
borderRightColor: colors.tableBorder || "#374151"
|
|
253
|
+
},
|
|
254
|
+
bodyCell: {
|
|
255
|
+
flexShrink: 0,
|
|
256
|
+
paddingVertical: 10,
|
|
257
|
+
paddingHorizontal: 12,
|
|
258
|
+
minWidth: 60,
|
|
259
|
+
borderRightWidth: 1,
|
|
260
|
+
borderRightColor: colors.tableBorder || "#374151",
|
|
261
|
+
justifyContent: "center"
|
|
262
|
+
},
|
|
263
|
+
lastCell: {
|
|
264
|
+
borderRightWidth: 0
|
|
265
|
+
},
|
|
266
|
+
headerText: {
|
|
267
|
+
color: colors.tableHeaderText || "#9ca3af",
|
|
268
|
+
fontSize: 12,
|
|
269
|
+
fontWeight: "600",
|
|
270
|
+
fontFamily: theme.fontFamilies?.regular
|
|
271
|
+
},
|
|
272
|
+
cellText: {
|
|
273
|
+
color: colors.text || "#e5e7eb",
|
|
274
|
+
fontSize: 14,
|
|
275
|
+
lineHeight: 20,
|
|
276
|
+
fontFamily: theme.fontFamilies?.regular
|
|
277
|
+
},
|
|
278
|
+
cellContentWrapper: {
|
|
279
|
+
flexDirection: "row",
|
|
280
|
+
flexWrap: "wrap",
|
|
281
|
+
alignItems: "center"
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
//# sourceMappingURL=table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useMemo","useRef","useReducer","useCallback","View","Text","StyleSheet","ScrollView","useMarkdownContext","jsx","_jsx","jsxs","_jsxs","extractTableData","node","headers","rows","alignments","child","children","type","row","cell","push","align","rowCells","columnWidthsReducer","state","action","payload","TableRenderer","Renderer","style","theme","columnCount","length","styles","createTableStyles","columnWidths","dispatch","measuredWidths","Map","measuredCells","Set","widthsCalculated","onCellLayout","cellKey","width","current","set","add","expectedCells","col","allCellsMeasured","every","key","has","maxWidths","Array","fill","headerWidth","get","Math","max","cellWidth","getAlignment","index","hasWidths","container","measurementContainer","measurementRow","map","colIndex","measurementCell","onLayout","e","nativeEvent","layout","CellContent","rowIndex","horizontal","showsHorizontalScrollIndicator","tableScroll","bounces","table","headerRow","headerCell","alignItems","lastCell","textStyle","headerText","bodyRow","lastRow","oddRow","bodyCell","cellText","content","cellContentWrapper","idx","depth","inListItem","parentIsText","colors","borderRadius","m","create","marginVertical","spacing","s","position","opacity","pointerEvents","left","flexDirection","paddingVertical","paddingHorizontal","flexGrow","overflow","borderWidth","borderColor","tableBorder","backgroundColor","surface","tableHeader","borderBottomWidth","borderBottomColor","tableRowOdd","flexShrink","minWidth","borderRightWidth","borderRightColor","justifyContent","color","tableHeaderText","fontSize","fontWeight","fontFamily","fontFamilies","regular","text","lineHeight","flexWrap"],"sourceRoot":"../../../src","sources":["renderers/table.tsx"],"mappings":";;AAAA,SACEA,OAAO,EACPC,MAAM,EACNC,UAAU,EACVC,WAAW,QAIN,OAAO;AACd,SACEC,IAAI,EACJC,IAAI,EACJC,UAAU,EACVC,UAAU,QAKL,cAAc;AAGrB,SAASC,kBAAkB,QAAgC,uBAAoB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAShF,MAAMC,gBAAgB,GAAIC,IAAkB,IAAgB;EAC1D,MAAMC,OAAuB,GAAG,EAAE;EAClC,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,WAAW,IAAI,SAAS;MACjDW,cAAc,EAAE;IAClB,CAAC;IACD3C,QAAQ,EAAE;MACRyC,gBAAgB,EAAE;IACpB,CAAC;IACDvC,UAAU,EAAE;MACV0C,KAAK,EAAE9B,MAAM,CAAC+B,eAAe,IAAI,SAAS;MAC1CC,QAAQ,EAAE,EAAE;MACZC,UAAU,EAAE,KAAK;MACjBC,UAAU,EAAEvG,KAAK,CAACwG,YAAY,EAAEC;IAClC,CAAC;IACD3C,QAAQ,EAAE;MACRqC,KAAK,EAAE9B,MAAM,CAACqC,IAAI,IAAI,SAAS;MAC/BL,QAAQ,EAAE,EAAE;MACZM,UAAU,EAAE,EAAE;MACdJ,UAAU,EAAEvG,KAAK,CAACwG,YAAY,EAAEC;IAClC,CAAC;IACDzC,kBAAkB,EAAE;MAClBgB,aAAa,EAAE,KAAK;MACpB4B,QAAQ,EAAE,MAAM;MAChBtD,UAAU,EAAE;IACd;EACF,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["specs/MarkdownSession.nitro.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export const defaultMarkdownTheme = {
|
|
4
|
+
colors: {
|
|
5
|
+
text: "#e0e0e0",
|
|
6
|
+
textMuted: "#888",
|
|
7
|
+
heading: "#f0f0f0",
|
|
8
|
+
link: "#60a5fa",
|
|
9
|
+
code: "#fbbf24",
|
|
10
|
+
codeBackground: "#1a1a2e",
|
|
11
|
+
codeLanguage: "#4ade80",
|
|
12
|
+
blockquote: "#3b82f6",
|
|
13
|
+
border: "#252525",
|
|
14
|
+
surface: "#151515",
|
|
15
|
+
surfaceLight: "#1a1a1a",
|
|
16
|
+
accent: "#4ade80",
|
|
17
|
+
tableBorder: "#334155",
|
|
18
|
+
tableHeader: "#0f172a",
|
|
19
|
+
tableHeaderText: "#94a3b8",
|
|
20
|
+
tableRowEven: "#0f172a",
|
|
21
|
+
tableRowOdd: "#1e293b"
|
|
22
|
+
},
|
|
23
|
+
spacing: {
|
|
24
|
+
xs: 4,
|
|
25
|
+
s: 8,
|
|
26
|
+
m: 12,
|
|
27
|
+
l: 16,
|
|
28
|
+
xl: 24
|
|
29
|
+
},
|
|
30
|
+
fontSizes: {
|
|
31
|
+
xs: 12,
|
|
32
|
+
s: 14,
|
|
33
|
+
m: 16,
|
|
34
|
+
l: 18,
|
|
35
|
+
xl: 22,
|
|
36
|
+
h1: 32,
|
|
37
|
+
h2: 26,
|
|
38
|
+
h3: 22,
|
|
39
|
+
h4: 18,
|
|
40
|
+
h5: 16,
|
|
41
|
+
h6: 14
|
|
42
|
+
},
|
|
43
|
+
fontFamilies: {
|
|
44
|
+
regular: undefined,
|
|
45
|
+
heading: undefined,
|
|
46
|
+
mono: undefined
|
|
47
|
+
},
|
|
48
|
+
borderRadius: {
|
|
49
|
+
s: 4,
|
|
50
|
+
m: 8,
|
|
51
|
+
l: 12
|
|
52
|
+
},
|
|
53
|
+
showCodeLanguage: true
|
|
54
|
+
};
|
|
55
|
+
export const minimalMarkdownTheme = {
|
|
56
|
+
colors: {
|
|
57
|
+
text: undefined,
|
|
58
|
+
textMuted: undefined,
|
|
59
|
+
heading: undefined,
|
|
60
|
+
link: "#0066cc",
|
|
61
|
+
code: undefined,
|
|
62
|
+
codeBackground: "transparent",
|
|
63
|
+
codeLanguage: "#888888",
|
|
64
|
+
blockquote: "#cccccc",
|
|
65
|
+
border: "#cccccc",
|
|
66
|
+
surface: "transparent",
|
|
67
|
+
surfaceLight: "transparent",
|
|
68
|
+
accent: "#0066cc",
|
|
69
|
+
tableBorder: "#cccccc",
|
|
70
|
+
tableHeader: "transparent",
|
|
71
|
+
tableHeaderText: undefined,
|
|
72
|
+
tableRowEven: "transparent",
|
|
73
|
+
tableRowOdd: "transparent"
|
|
74
|
+
},
|
|
75
|
+
spacing: {
|
|
76
|
+
xs: 0,
|
|
77
|
+
s: 0,
|
|
78
|
+
m: 0,
|
|
79
|
+
l: 0,
|
|
80
|
+
xl: 0
|
|
81
|
+
},
|
|
82
|
+
fontSizes: {
|
|
83
|
+
xs: 12,
|
|
84
|
+
s: 14,
|
|
85
|
+
m: 16,
|
|
86
|
+
l: 18,
|
|
87
|
+
xl: 22,
|
|
88
|
+
h1: 32,
|
|
89
|
+
h2: 26,
|
|
90
|
+
h3: 22,
|
|
91
|
+
h4: 18,
|
|
92
|
+
h5: 16,
|
|
93
|
+
h6: 14
|
|
94
|
+
},
|
|
95
|
+
fontFamilies: {
|
|
96
|
+
regular: undefined,
|
|
97
|
+
heading: undefined,
|
|
98
|
+
mono: undefined
|
|
99
|
+
},
|
|
100
|
+
borderRadius: {
|
|
101
|
+
s: 0,
|
|
102
|
+
m: 0,
|
|
103
|
+
l: 0
|
|
104
|
+
},
|
|
105
|
+
showCodeLanguage: false
|
|
106
|
+
};
|
|
107
|
+
export const lightMarkdownTheme = {
|
|
108
|
+
colors: {
|
|
109
|
+
text: "#1a1a1a",
|
|
110
|
+
textMuted: "#6b7280",
|
|
111
|
+
heading: "#000000",
|
|
112
|
+
link: "#2563eb",
|
|
113
|
+
code: "#ea580c",
|
|
114
|
+
codeBackground: "#f3f4f6",
|
|
115
|
+
codeLanguage: "#10b981",
|
|
116
|
+
blockquote: "#3b82f6",
|
|
117
|
+
border: "#e5e7eb",
|
|
118
|
+
surface: "#ffffff",
|
|
119
|
+
surfaceLight: "#f9fafb",
|
|
120
|
+
accent: "#10b981",
|
|
121
|
+
tableBorder: "#e5e7eb",
|
|
122
|
+
tableHeader: "#f3f4f6",
|
|
123
|
+
tableHeaderText: "#6b7280",
|
|
124
|
+
tableRowEven: "#ffffff",
|
|
125
|
+
tableRowOdd: "#f9fafb"
|
|
126
|
+
},
|
|
127
|
+
spacing: {
|
|
128
|
+
xs: 4,
|
|
129
|
+
s: 8,
|
|
130
|
+
m: 12,
|
|
131
|
+
l: 16,
|
|
132
|
+
xl: 24
|
|
133
|
+
},
|
|
134
|
+
fontSizes: {
|
|
135
|
+
xs: 12,
|
|
136
|
+
s: 14,
|
|
137
|
+
m: 16,
|
|
138
|
+
l: 18,
|
|
139
|
+
xl: 22,
|
|
140
|
+
h1: 32,
|
|
141
|
+
h2: 26,
|
|
142
|
+
h3: 22,
|
|
143
|
+
h4: 18,
|
|
144
|
+
h5: 16,
|
|
145
|
+
h6: 14
|
|
146
|
+
},
|
|
147
|
+
fontFamilies: {
|
|
148
|
+
regular: undefined,
|
|
149
|
+
heading: undefined,
|
|
150
|
+
mono: undefined
|
|
151
|
+
},
|
|
152
|
+
borderRadius: {
|
|
153
|
+
s: 4,
|
|
154
|
+
m: 8,
|
|
155
|
+
l: 12
|
|
156
|
+
},
|
|
157
|
+
showCodeLanguage: true
|
|
158
|
+
};
|
|
159
|
+
export const darkMarkdownTheme = defaultMarkdownTheme;
|
|
160
|
+
export const mergeThemes = (base, partial) => {
|
|
161
|
+
if (!partial) return base;
|
|
162
|
+
return {
|
|
163
|
+
colors: {
|
|
164
|
+
...base.colors,
|
|
165
|
+
...partial.colors
|
|
166
|
+
},
|
|
167
|
+
spacing: {
|
|
168
|
+
...base.spacing,
|
|
169
|
+
...partial.spacing
|
|
170
|
+
},
|
|
171
|
+
fontSizes: {
|
|
172
|
+
...base.fontSizes,
|
|
173
|
+
...partial.fontSizes
|
|
174
|
+
},
|
|
175
|
+
fontFamilies: {
|
|
176
|
+
...base.fontFamilies,
|
|
177
|
+
...partial.fontFamilies
|
|
178
|
+
},
|
|
179
|
+
borderRadius: {
|
|
180
|
+
...base.borderRadius,
|
|
181
|
+
...partial.borderRadius
|
|
182
|
+
},
|
|
183
|
+
showCodeLanguage: partial.showCodeLanguage ?? base.showCodeLanguage
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=theme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["defaultMarkdownTheme","colors","text","textMuted","heading","link","code","codeBackground","codeLanguage","blockquote","border","surface","surfaceLight","accent","tableBorder","tableHeader","tableHeaderText","tableRowEven","tableRowOdd","spacing","xs","s","m","l","xl","fontSizes","h1","h2","h3","h4","h5","h6","fontFamilies","regular","undefined","mono","borderRadius","showCodeLanguage","minimalMarkdownTheme","lightMarkdownTheme","darkMarkdownTheme","mergeThemes","base","partial"],"sourceRoot":"../../src","sources":["theme.ts"],"mappings":";;AAwDA,OAAO,MAAMA,oBAAmC,GAAG;EACjDC,MAAM,EAAE;IACNC,IAAI,EAAE,SAAS;IACfC,SAAS,EAAE,MAAM;IACjBC,OAAO,EAAE,SAAS;IAClBC,IAAI,EAAE,SAAS;IACfC,IAAI,EAAE,SAAS;IACfC,cAAc,EAAE,SAAS;IACzBC,YAAY,EAAE,SAAS;IACvBC,UAAU,EAAE,SAAS;IACrBC,MAAM,EAAE,SAAS;IACjBC,OAAO,EAAE,SAAS;IAClBC,YAAY,EAAE,SAAS;IACvBC,MAAM,EAAE,SAAS;IACjBC,WAAW,EAAE,SAAS;IACtBC,WAAW,EAAE,SAAS;IACtBC,eAAe,EAAE,SAAS;IAC1BC,YAAY,EAAE,SAAS;IACvBC,WAAW,EAAE;EACf,CAAC;EACDC,OAAO,EAAE;IACPC,EAAE,EAAE,CAAC;IACLC,CAAC,EAAE,CAAC;IACJC,CAAC,EAAE,EAAE;IACLC,CAAC,EAAE,EAAE;IACLC,EAAE,EAAE;EACN,CAAC;EACDC,SAAS,EAAE;IACTL,EAAE,EAAE,EAAE;IACNC,CAAC,EAAE,EAAE;IACLC,CAAC,EAAE,EAAE;IACLC,CAAC,EAAE,EAAE;IACLC,EAAE,EAAE,EAAE;IACNE,EAAE,EAAE,EAAE;IACNC,EAAE,EAAE,EAAE;IACNC,EAAE,EAAE,EAAE;IACNC,EAAE,EAAE,EAAE;IACNC,EAAE,EAAE,EAAE;IACNC,EAAE,EAAE;EACN,CAAC;EACDC,YAAY,EAAE;IACZC,OAAO,EAAEC,S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,CAAC;EACDc,gBAAgB,EAAE;AACpB,CAAC;AAED,OAAO,MAAMG,iBAAiB,GAAGxC,oBAAoB;AAErD,OAAO,MAAMyC,WAAW,GAAGA,CACzBC,IAAmB,EACnBC,OAA8B,KACZ;EAClB,IAAI,CAACA,OAAO,EAAE,OAAOD,IAAI;EACzB,OAAO;IACLzC,MAAM,EAAE;MAAE,GAAGyC,IAAI,CAACzC,MAAM;MAAE,GAAG0C,OAAO,CAAC1C;IAAO,CAAC;IAC7CkB,OAAO,EAAE;MAAE,GAAGuB,IAAI,CAACvB,OAAO;MAAE,GAAGwB,OAAO,CAACxB;IAAQ,CAAC;IAChDM,SAAS,EAAE;MAAE,GAAGiB,IAAI,CAACjB,SAAS;MAAE,GAAGkB,OAAO,CAAClB;IAAU,CAAC;IACtDO,YAAY,EAAE;MAAE,GAAGU,IAAI,CAACV,YAAY;MAAE,GAAGW,OAAO,CAACX;IAAa,CAAC;IAC/DI,YAAY,EAAE;MAAE,GAAGM,IAAI,CAACN,YAAY;MAAE,GAAGO,OAAO,CAACP;IAAa,CAAC;IAC/DC,gBAAgB,EAAEM,OAAO,CAACN,gBAAgB,IAAIK,IAAI,CAACL;EACrD,CAAC;AACH,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useRef, useCallback, useState, useEffect } from "react";
|
|
4
|
+
import { createMarkdownSession } from "./MarkdownSession.js";
|
|
5
|
+
export function useMarkdownSession() {
|
|
6
|
+
const sessionRef = useRef(null);
|
|
7
|
+
if (sessionRef.current === null) {
|
|
8
|
+
sessionRef.current = createMarkdownSession();
|
|
9
|
+
}
|
|
10
|
+
const [isStreaming, setIsStreaming] = useState(false);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const session = sessionRef.current;
|
|
13
|
+
return () => {
|
|
14
|
+
session.clear();
|
|
15
|
+
};
|
|
16
|
+
}, []);
|
|
17
|
+
const stop = useCallback(() => {
|
|
18
|
+
setIsStreaming(false);
|
|
19
|
+
}, []);
|
|
20
|
+
const clear = useCallback(() => {
|
|
21
|
+
stop();
|
|
22
|
+
sessionRef.current.clear();
|
|
23
|
+
sessionRef.current.highlightPosition = 0;
|
|
24
|
+
}, [stop]);
|
|
25
|
+
const setHighlight = useCallback(position => {
|
|
26
|
+
sessionRef.current.highlightPosition = position;
|
|
27
|
+
}, []);
|
|
28
|
+
const getSession = useCallback(() => sessionRef.current, []);
|
|
29
|
+
return {
|
|
30
|
+
getSession,
|
|
31
|
+
isStreaming,
|
|
32
|
+
setIsStreaming,
|
|
33
|
+
stop,
|
|
34
|
+
clear,
|
|
35
|
+
setHighlight
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function useStream(timestamps) {
|
|
39
|
+
const engine = useMarkdownSession();
|
|
40
|
+
const [isPlaying, setIsPlaying] = useState(false);
|
|
41
|
+
const sortedKeys = useRef([]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (timestamps) {
|
|
44
|
+
sortedKeys.current = Object.keys(timestamps).map(Number).sort((a, b) => a - b);
|
|
45
|
+
}
|
|
46
|
+
}, [timestamps]);
|
|
47
|
+
const sync = useCallback(currentTimeMs => {
|
|
48
|
+
if (!timestamps) return;
|
|
49
|
+
let wordIdx = 0;
|
|
50
|
+
for (const idx of sortedKeys.current) {
|
|
51
|
+
if (currentTimeMs >= timestamps[idx]) {
|
|
52
|
+
wordIdx = idx + 1;
|
|
53
|
+
} else {
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
engine.setHighlight(wordIdx);
|
|
58
|
+
}, [timestamps, engine]);
|
|
59
|
+
return {
|
|
60
|
+
...engine,
|
|
61
|
+
isPlaying,
|
|
62
|
+
setIsPlaying,
|
|
63
|
+
sync
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=use-markdown-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useRef","useCallback","useState","useEffect","createMarkdownSession","useMarkdownSession","sessionRef","current","isStreaming","setIsStreaming","session","clear","stop","highlightPosition","setHighlight","position","getSession","useStream","timestamps","engine","isPlaying","setIsPlaying","sortedKeys","Object","keys","map","Number","sort","a","b","sync","currentTimeMs","wordIdx","idx"],"sourceRoot":"../../src","sources":["use-markdown-stream.ts"],"mappings":";;AAAA,SAASA,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,SAAS,QAAQ,OAAO;AAChE,SAASC,qBAAqB,QAAQ,sBAAmB;AAIzD,OAAO,SAASC,kBAAkBA,CAAA,EAAG;EACnC,MAAMC,UAAU,GAAGN,MAAM,CAAyB,IAAI,CAAC;EACvD,IAAIM,UAAU,CAACC,OAAO,KAAK,IAAI,EAAE;IAC/BD,UAAU,CAACC,OAAO,GAAGH,qBAAqB,CAAC,CAAC;EAC9C;EAEA,MAAM,CAACI,WAAW,EAAEC,cAAc,CAAC,GAAGP,QAAQ,CAAC,KAAK,CAAC;EAErDC,SAAS,CAAC,MAAM;IACd,MAAMO,OAAO,GAAGJ,UAAU,CAACC,OAAQ;IACnC,OAAO,MAAM;MACXG,OAAO,CAACC,KAAK,CAAC,CAAC;IACjB,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,MAAMC,IAAI,GAAGX,WAAW,CAAC,MAAM;IAC7BQ,cAAc,CAAC,KAAK,CAAC;EACvB,CAAC,EAAE,EAAE,CAAC;EAEN,MAAME,KAAK,GAAGV,WAAW,CAAC,MAAM;IAC9BW,IAAI,CAAC,CAAC;IACNN,UAAU,CAACC,OAAO,CAAEI,KAAK,CAAC,CAAC;IAC3BL,UAAU,CAACC,OAAO,CAAEM,iBAAiB,GAAG,CAAC;EAC3C,CAAC,EAAE,CAACD,IAAI,CAAC,CAAC;EAEV,MAAME,YAAY,GAAGb,WAAW,CAAEc,QAAgB,IAAK;IACrDT,UAAU,CAACC,OAAO,CAAEM,iBAAiB,GAAGE,QAAQ;EAClD,CAAC,EAAE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ro.d.ts","sourceRoot":"","sources":["../../../src/Markdown.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,cACf,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC;IACpD,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAAC;CAChE"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type ReactNode, type ComponentType } from "react";
|
|
2
|
+
import { type MarkdownTheme, type NodeStyleOverrides, type StylingStrategy } from "./theme";
|
|
3
|
+
import type { MarkdownNode } from "./headless";
|
|
4
|
+
export interface NodeRendererProps {
|
|
5
|
+
node: MarkdownNode;
|
|
6
|
+
depth: number;
|
|
7
|
+
inListItem: boolean;
|
|
8
|
+
parentIsText?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface BaseCustomRendererProps {
|
|
11
|
+
node: MarkdownNode;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
Renderer: ComponentType<NodeRendererProps>;
|
|
14
|
+
}
|
|
15
|
+
export interface EnhancedRendererProps extends BaseCustomRendererProps {
|
|
16
|
+
level?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
17
|
+
href?: string;
|
|
18
|
+
title?: string;
|
|
19
|
+
url?: string;
|
|
20
|
+
alt?: string;
|
|
21
|
+
content?: string;
|
|
22
|
+
language?: string;
|
|
23
|
+
ordered?: boolean;
|
|
24
|
+
start?: number;
|
|
25
|
+
checked?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface HeadingRendererProps extends BaseCustomRendererProps {
|
|
28
|
+
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
29
|
+
}
|
|
30
|
+
export interface LinkRendererProps extends BaseCustomRendererProps {
|
|
31
|
+
href: string;
|
|
32
|
+
title?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ImageRendererProps extends BaseCustomRendererProps {
|
|
35
|
+
url: string;
|
|
36
|
+
alt?: string;
|
|
37
|
+
title?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface CodeBlockRendererProps extends BaseCustomRendererProps {
|
|
40
|
+
content: string;
|
|
41
|
+
language?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface InlineCodeRendererProps extends BaseCustomRendererProps {
|
|
44
|
+
content: string;
|
|
45
|
+
}
|
|
46
|
+
export interface ListRendererProps extends BaseCustomRendererProps {
|
|
47
|
+
ordered: boolean;
|
|
48
|
+
start?: number;
|
|
49
|
+
}
|
|
50
|
+
export interface TaskListItemRendererProps extends BaseCustomRendererProps {
|
|
51
|
+
checked: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface CustomRendererProps extends EnhancedRendererProps {
|
|
54
|
+
}
|
|
55
|
+
export type CustomRenderer = (props: EnhancedRendererProps) => ReactNode | undefined;
|
|
56
|
+
export type CustomRenderers = Partial<Record<MarkdownNode["type"], CustomRenderer>>;
|
|
57
|
+
export interface MarkdownContextValue {
|
|
58
|
+
renderers: CustomRenderers;
|
|
59
|
+
theme: MarkdownTheme;
|
|
60
|
+
styles?: NodeStyleOverrides;
|
|
61
|
+
stylingStrategy: StylingStrategy;
|
|
62
|
+
}
|
|
63
|
+
export declare const MarkdownContext: import("react").Context<MarkdownContextValue>;
|
|
64
|
+
export declare const useMarkdownContext: () => MarkdownContextValue;
|
|
65
|
+
//# sourceMappingURL=MarkdownContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MarkdownContext.d.ts","sourceRoot":"","sources":["../../../src/MarkdownContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,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