@gendive/chatllm 0.6.0 → 0.6.2
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/dist/react/index.js +124 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +124 -1
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.js
CHANGED
|
@@ -1826,6 +1826,8 @@ var INLINE_CODE_REGEX = /`([^`]+)`/g;
|
|
|
1826
1826
|
var BOLD_REGEX = /\*\*([^*]+)\*\*/g;
|
|
1827
1827
|
var ITALIC_REGEX = /(?<!\*)\*([^*]+)\*(?!\*)/g;
|
|
1828
1828
|
var HR_REGEX = /^---+$/gm;
|
|
1829
|
+
var TABLE_ROW_REGEX = /^\|(.+)\|$/;
|
|
1830
|
+
var TABLE_SEPARATOR_REGEX = /^\|[\s\-:|]+\|$/;
|
|
1829
1831
|
var parseSourceLinks = (text) => {
|
|
1830
1832
|
const links = [];
|
|
1831
1833
|
let match;
|
|
@@ -1899,6 +1901,64 @@ var parseInlineElements = (text, key) => {
|
|
|
1899
1901
|
});
|
|
1900
1902
|
return elements;
|
|
1901
1903
|
};
|
|
1904
|
+
var parseTableAlignment = (separatorRow) => {
|
|
1905
|
+
const cells = separatorRow.split("|").filter((cell) => cell.trim() !== "");
|
|
1906
|
+
return cells.map((cell) => {
|
|
1907
|
+
const trimmed = cell.trim();
|
|
1908
|
+
const hasLeftColon = trimmed.startsWith(":");
|
|
1909
|
+
const hasRightColon = trimmed.endsWith(":");
|
|
1910
|
+
if (hasLeftColon && hasRightColon) return "center";
|
|
1911
|
+
if (hasRightColon) return "right";
|
|
1912
|
+
return "left";
|
|
1913
|
+
});
|
|
1914
|
+
};
|
|
1915
|
+
var parseTableRow = (row) => {
|
|
1916
|
+
return row.split("|").slice(1, -1).map((cell) => cell.trim());
|
|
1917
|
+
};
|
|
1918
|
+
var MarkdownTable = ({ data }) => {
|
|
1919
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
1920
|
+
"table",
|
|
1921
|
+
{
|
|
1922
|
+
className: "chatllm-table",
|
|
1923
|
+
style: {
|
|
1924
|
+
width: "100%",
|
|
1925
|
+
borderCollapse: "collapse",
|
|
1926
|
+
margin: "12px 0",
|
|
1927
|
+
fontSize: "14px"
|
|
1928
|
+
},
|
|
1929
|
+
children: [
|
|
1930
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("tr", { children: data.headers.map((header, i) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1931
|
+
"th",
|
|
1932
|
+
{
|
|
1933
|
+
style: {
|
|
1934
|
+
border: "1px solid var(--chatllm-border, #e5e7eb)",
|
|
1935
|
+
padding: "10px 12px",
|
|
1936
|
+
textAlign: data.alignments[i] || "left",
|
|
1937
|
+
backgroundColor: "var(--chatllm-bg-secondary, #f9fafb)",
|
|
1938
|
+
fontWeight: 600,
|
|
1939
|
+
color: "var(--chatllm-text, #374151)"
|
|
1940
|
+
},
|
|
1941
|
+
children: parseInlineElements(header, `th-${i}`)
|
|
1942
|
+
},
|
|
1943
|
+
i
|
|
1944
|
+
)) }) }),
|
|
1945
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("tbody", { children: data.rows.map((row, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("tr", { children: row.map((cell, cellIndex) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1946
|
+
"td",
|
|
1947
|
+
{
|
|
1948
|
+
style: {
|
|
1949
|
+
border: "1px solid var(--chatllm-border, #e5e7eb)",
|
|
1950
|
+
padding: "10px 12px",
|
|
1951
|
+
textAlign: data.alignments[cellIndex] || "left",
|
|
1952
|
+
color: "var(--chatllm-text, #374151)"
|
|
1953
|
+
},
|
|
1954
|
+
children: parseInlineElements(cell, `td-${rowIndex}-${cellIndex}`)
|
|
1955
|
+
},
|
|
1956
|
+
cellIndex
|
|
1957
|
+
)) }, rowIndex)) })
|
|
1958
|
+
]
|
|
1959
|
+
}
|
|
1960
|
+
);
|
|
1961
|
+
};
|
|
1902
1962
|
var CodeBlock = ({ language, code }) => {
|
|
1903
1963
|
const [copied, setCopied] = import_react5.default.useState(false);
|
|
1904
1964
|
const handleCopy = async () => {
|
|
@@ -2036,6 +2096,35 @@ var MarkdownRenderer = ({ content, className }) => {
|
|
|
2036
2096
|
const lines = processedContent.split("\n");
|
|
2037
2097
|
let currentList = null;
|
|
2038
2098
|
let blockquoteLines = [];
|
|
2099
|
+
let tableLines = [];
|
|
2100
|
+
const flushTable = () => {
|
|
2101
|
+
if (tableLines.length >= 2) {
|
|
2102
|
+
const headerLine = tableLines[0];
|
|
2103
|
+
const separatorLine = tableLines[1];
|
|
2104
|
+
const dataLines = tableLines.slice(2);
|
|
2105
|
+
if (TABLE_SEPARATOR_REGEX.test(separatorLine)) {
|
|
2106
|
+
const headers = parseTableRow(headerLine);
|
|
2107
|
+
const alignments = parseTableAlignment(separatorLine);
|
|
2108
|
+
const rows = dataLines.map((line) => parseTableRow(line));
|
|
2109
|
+
elements.push(
|
|
2110
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
2111
|
+
MarkdownTable,
|
|
2112
|
+
{
|
|
2113
|
+
data: { headers, alignments, rows }
|
|
2114
|
+
},
|
|
2115
|
+
`table-${elements.length}`
|
|
2116
|
+
)
|
|
2117
|
+
);
|
|
2118
|
+
} else {
|
|
2119
|
+
tableLines.forEach((line, i) => {
|
|
2120
|
+
elements.push(
|
|
2121
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { style: { margin: "4px 0" }, children: parseInlineElements(line, `p-table-fallback-${i}`) }, `p-table-fallback-${elements.length}-${i}`)
|
|
2122
|
+
);
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
tableLines = [];
|
|
2127
|
+
};
|
|
2039
2128
|
const flushList = () => {
|
|
2040
2129
|
if (currentList) {
|
|
2041
2130
|
if (currentList.type === "ul") {
|
|
@@ -2096,6 +2185,14 @@ var MarkdownRenderer = ({ content, className }) => {
|
|
|
2096
2185
|
);
|
|
2097
2186
|
return;
|
|
2098
2187
|
}
|
|
2188
|
+
if (TABLE_ROW_REGEX.test(line)) {
|
|
2189
|
+
flushList();
|
|
2190
|
+
flushBlockquote();
|
|
2191
|
+
tableLines.push(line);
|
|
2192
|
+
return;
|
|
2193
|
+
} else if (tableLines.length > 0) {
|
|
2194
|
+
flushTable();
|
|
2195
|
+
}
|
|
2099
2196
|
if (HR_REGEX.test(line)) {
|
|
2100
2197
|
flushList();
|
|
2101
2198
|
flushBlockquote();
|
|
@@ -2189,6 +2286,7 @@ var MarkdownRenderer = ({ content, className }) => {
|
|
|
2189
2286
|
});
|
|
2190
2287
|
flushList();
|
|
2191
2288
|
flushBlockquote();
|
|
2289
|
+
flushTable();
|
|
2192
2290
|
return elements;
|
|
2193
2291
|
}, [content]);
|
|
2194
2292
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
@@ -3917,6 +4015,27 @@ var injectStyles = () => {
|
|
|
3917
4015
|
background-color: var(--chatllm-border);
|
|
3918
4016
|
border-radius: 3px;
|
|
3919
4017
|
}
|
|
4018
|
+
|
|
4019
|
+
.chatllm-table {
|
|
4020
|
+
width: 100%;
|
|
4021
|
+
border-collapse: collapse;
|
|
4022
|
+
margin: 12px 0;
|
|
4023
|
+
}
|
|
4024
|
+
|
|
4025
|
+
.chatllm-table th,
|
|
4026
|
+
.chatllm-table td {
|
|
4027
|
+
border: 1px solid var(--chatllm-border, #e5e7eb);
|
|
4028
|
+
padding: 10px 12px;
|
|
4029
|
+
}
|
|
4030
|
+
|
|
4031
|
+
.chatllm-table th {
|
|
4032
|
+
background-color: var(--chatllm-bg-secondary, #f9fafb);
|
|
4033
|
+
font-weight: 600;
|
|
4034
|
+
}
|
|
4035
|
+
|
|
4036
|
+
.chatllm-table tr:hover {
|
|
4037
|
+
background-color: var(--chatllm-bg-hover, #f3f4f6);
|
|
4038
|
+
}
|
|
3920
4039
|
`;
|
|
3921
4040
|
document.head.appendChild(style);
|
|
3922
4041
|
};
|
|
@@ -3991,6 +4110,8 @@ var ChatUI = ({
|
|
|
3991
4110
|
saveEdit,
|
|
3992
4111
|
regenerate,
|
|
3993
4112
|
askOtherModel,
|
|
4113
|
+
setActiveAlternative,
|
|
4114
|
+
activeAlternatives,
|
|
3994
4115
|
updatePersonalization,
|
|
3995
4116
|
models: hookModels
|
|
3996
4117
|
} = useChatUI(hookOptions);
|
|
@@ -4110,7 +4231,9 @@ var ChatUI = ({
|
|
|
4110
4231
|
onEdit: startEdit,
|
|
4111
4232
|
onRegenerate: regenerate,
|
|
4112
4233
|
onQuote: setQuotedText,
|
|
4113
|
-
onAskOtherModel: askOtherModel,
|
|
4234
|
+
onAskOtherModel: (userMessageId, assistantMessageId, targetModel) => askOtherModel(assistantMessageId, targetModel),
|
|
4235
|
+
onSetActiveAlternative: setActiveAlternative,
|
|
4236
|
+
activeAlternatives,
|
|
4114
4237
|
models: hookModels,
|
|
4115
4238
|
copiedId: copiedMessageId,
|
|
4116
4239
|
editingId: editingMessageId
|