@dust-tt/sparkle 0.2.646-rc-4 → 0.2.647
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/cjs/index.js +1 -1
- package/dist/esm/components/DataTable.d.ts +13 -3
- package/dist/esm/components/DataTable.d.ts.map +1 -1
- package/dist/esm/components/DataTable.js +9 -8
- package/dist/esm/components/DataTable.js.map +1 -1
- package/dist/esm/components/markdown/BlockquoteBlock.d.ts +1 -3
- package/dist/esm/components/markdown/BlockquoteBlock.d.ts.map +1 -1
- package/dist/esm/components/markdown/BlockquoteBlock.js +3 -7
- package/dist/esm/components/markdown/BlockquoteBlock.js.map +1 -1
- package/dist/esm/components/markdown/CodeBlockWithExtendedSupport.d.ts +2 -4
- package/dist/esm/components/markdown/CodeBlockWithExtendedSupport.d.ts.map +1 -1
- package/dist/esm/components/markdown/CodeBlockWithExtendedSupport.js +6 -11
- package/dist/esm/components/markdown/CodeBlockWithExtendedSupport.js.map +1 -1
- package/dist/esm/components/markdown/List.d.ts +3 -17
- package/dist/esm/components/markdown/List.d.ts.map +1 -1
- package/dist/esm/components/markdown/List.js +7 -21
- package/dist/esm/components/markdown/List.js.map +1 -1
- package/dist/esm/components/markdown/Markdown.d.ts +9 -2
- package/dist/esm/components/markdown/Markdown.d.ts.map +1 -1
- package/dist/esm/components/markdown/Markdown.js +66 -45
- package/dist/esm/components/markdown/Markdown.js.map +1 -1
- package/dist/esm/components/markdown/ParagraphBlock.d.ts +1 -3
- package/dist/esm/components/markdown/ParagraphBlock.d.ts.map +1 -1
- package/dist/esm/components/markdown/ParagraphBlock.js +3 -7
- package/dist/esm/components/markdown/ParagraphBlock.js.map +1 -1
- package/dist/esm/components/markdown/PreBlock.d.ts +1 -3
- package/dist/esm/components/markdown/PreBlock.d.ts.map +1 -1
- package/dist/esm/components/markdown/PreBlock.js +3 -7
- package/dist/esm/components/markdown/PreBlock.js.map +1 -1
- package/dist/esm/components/markdown/TableBlock.d.ts +11 -17
- package/dist/esm/components/markdown/TableBlock.d.ts.map +1 -1
- package/dist/esm/components/markdown/TableBlock.js +14 -18
- package/dist/esm/components/markdown/TableBlock.js.map +1 -1
- package/dist/esm/components/markdown/index.d.ts +0 -4
- package/dist/esm/components/markdown/index.d.ts.map +1 -1
- package/dist/esm/components/markdown/index.js +0 -4
- package/dist/esm/components/markdown/index.js.map +1 -1
- package/dist/esm/components/markdown/utils.d.ts +0 -11
- package/dist/esm/components/markdown/utils.d.ts.map +1 -1
- package/dist/esm/components/markdown/utils.js +0 -21
- package/dist/esm/components/markdown/utils.js.map +1 -1
- package/dist/esm/icons/actions/Atom.js +1 -1
- package/dist/esm/icons/actions/Atom.js.map +1 -1
- package/dist/esm/icons/app/ArrowDownDash.d.ts +5 -0
- package/dist/esm/icons/app/ArrowDownDash.d.ts.map +1 -0
- package/dist/esm/icons/app/ArrowDownDash.js +6 -0
- package/dist/esm/icons/app/ArrowDownDash.js.map +1 -0
- package/dist/esm/icons/app/Atom.js +1 -1
- package/dist/esm/icons/app/Atom.js.map +1 -1
- package/dist/esm/icons/app/index.d.ts +1 -0
- package/dist/esm/icons/app/index.d.ts.map +1 -1
- package/dist/esm/icons/app/index.js +1 -0
- package/dist/esm/icons/app/index.js.map +1 -1
- package/dist/esm/icons/src/app/arrow-down-dash.svg +3 -0
- package/dist/esm/logo/platforms/Discord.d.ts.map +1 -1
- package/dist/esm/logo/platforms/Discord.js +2 -2
- package/dist/esm/logo/platforms/Discord.js.map +1 -1
- package/dist/esm/logo/src/platforms/Discord.svg +3 -0
- package/dist/esm/stories/DataTable.stories.d.ts +1 -0
- package/dist/esm/stories/DataTable.stories.d.ts.map +1 -1
- package/dist/esm/stories/DataTable.stories.js +188 -0
- package/dist/esm/stories/DataTable.stories.js.map +1 -1
- package/dist/esm/styles/global.css +12 -0
- package/dist/esm/styles/global_with_tw_base.css +12 -0
- package/dist/esm/styles/tailwind.css +11 -0
- package/dist/sparkle.css +390 -348
- package/package.json +1 -2
- package/src/components/DataTable.tsx +31 -2
- package/src/components/markdown/BlockquoteBlock.tsx +29 -36
- package/src/components/markdown/CodeBlockWithExtendedSupport.tsx +131 -142
- package/src/components/markdown/List.tsx +30 -53
- package/src/components/markdown/Markdown.tsx +171 -108
- package/src/components/markdown/ParagraphBlock.tsx +12 -18
- package/src/components/markdown/PreBlock.tsx +18 -28
- package/src/components/markdown/TableBlock.tsx +95 -125
- package/src/components/markdown/index.ts +0 -4
- package/src/components/markdown/utils.ts +0 -37
- package/src/icons/actions/Atom.tsx +1 -1
- package/src/icons/app/ArrowDownDash.tsx +18 -0
- package/src/icons/app/Atom.tsx +1 -1
- package/src/icons/app/index.ts +1 -0
- package/src/icons/src/app/arrow-down-dash.svg +3 -0
- package/src/logo/platforms/Discord.tsx +6 -8
- package/src/logo/src/platforms/Discord.svg +3 -0
- package/src/stories/DataTable.stories.tsx +235 -0
- package/src/styles/global.css +12 -0
- package/src/styles/global_with_tw_base.css +12 -0
- package/src/styles/tailwind.css +11 -0
- package/dist/esm/components/markdown/HeaderBlocks.d.ts +0 -24
- package/dist/esm/components/markdown/HeaderBlocks.d.ts.map +0 -1
- package/dist/esm/components/markdown/HeaderBlocks.js +0 -54
- package/dist/esm/components/markdown/HeaderBlocks.js.map +0 -1
- package/dist/esm/components/markdown/InputBlock.d.ts +0 -10
- package/dist/esm/components/markdown/InputBlock.d.ts.map +0 -1
- package/dist/esm/components/markdown/InputBlock.js +0 -26
- package/dist/esm/components/markdown/InputBlock.js.map +0 -1
- package/dist/esm/components/markdown/LinkBlock.d.ts +0 -10
- package/dist/esm/components/markdown/LinkBlock.d.ts.map +0 -1
- package/dist/esm/components/markdown/LinkBlock.js +0 -11
- package/dist/esm/components/markdown/LinkBlock.js.map +0 -1
- package/dist/esm/components/markdown/TextFormattingBlocks.d.ts +0 -10
- package/dist/esm/components/markdown/TextFormattingBlocks.d.ts.map +0 -1
- package/dist/esm/components/markdown/TextFormattingBlocks.js +0 -12
- package/dist/esm/components/markdown/TextFormattingBlocks.js.map +0 -1
- package/dist/esm/components/markdown/types.d.ts +0 -13
- package/dist/esm/components/markdown/types.d.ts.map +0 -1
- package/dist/esm/components/markdown/types.js +0 -2
- package/dist/esm/components/markdown/types.js.map +0 -1
- package/dist/esm/components/markdown/useAnimatedText.d.ts +0 -2
- package/dist/esm/components/markdown/useAnimatedText.d.ts.map +0 -1
- package/dist/esm/components/markdown/useAnimatedText.js +0 -31
- package/dist/esm/components/markdown/useAnimatedText.js.map +0 -1
- package/src/components/markdown/HeaderBlocks.tsx +0 -160
- package/src/components/markdown/InputBlock.tsx +0 -60
- package/src/components/markdown/LinkBlock.tsx +0 -36
- package/src/components/markdown/TextFormattingBlocks.tsx +0 -31
- package/src/components/markdown/types.ts +0 -5
- package/src/components/markdown/useAnimatedText.ts +0 -36
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dust-tt/sparkle",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.647",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "rm -rf dist && npm run tailwind && npm run build:esm && npm run build:cjs",
|
|
6
6
|
"tailwind": "tailwindcss -i ./src/styles/tailwind.css -o dist/sparkle.css",
|
|
@@ -118,7 +118,6 @@
|
|
|
118
118
|
"class-variance-authority": "^0.7.1",
|
|
119
119
|
"clsx": "^2.1.1",
|
|
120
120
|
"emoji-mart": "^5.5.2",
|
|
121
|
-
"framer-motion": "^12.23.22",
|
|
122
121
|
"lottie-react": "^2.4.0",
|
|
123
122
|
"lottie-web": "^5.12.2",
|
|
124
123
|
"mermaid": "^11.4.1",
|
|
@@ -961,12 +961,14 @@ export interface DataTableMoreButtonProps {
|
|
|
961
961
|
React.ComponentPropsWithoutRef<typeof DropdownMenu>,
|
|
962
962
|
"modal"
|
|
963
963
|
>;
|
|
964
|
+
disabled?: boolean;
|
|
964
965
|
}
|
|
965
966
|
|
|
966
967
|
DataTable.MoreButton = function MoreButton({
|
|
967
968
|
className,
|
|
968
969
|
menuItems,
|
|
969
970
|
dropdownMenuProps,
|
|
971
|
+
disabled,
|
|
970
972
|
}: DataTableMoreButtonProps) {
|
|
971
973
|
if (!menuItems?.length) {
|
|
972
974
|
return null;
|
|
@@ -984,11 +986,15 @@ DataTable.MoreButton = function MoreButton({
|
|
|
984
986
|
icon={MoreIcon}
|
|
985
987
|
size="mini"
|
|
986
988
|
variant="ghost-secondary"
|
|
987
|
-
|
|
989
|
+
disabled={disabled}
|
|
990
|
+
className={cn(
|
|
991
|
+
disabled && "s-cursor-not-allowed s-opacity-50",
|
|
992
|
+
className
|
|
993
|
+
)}
|
|
988
994
|
/>
|
|
989
995
|
</DropdownMenuTrigger>
|
|
990
996
|
|
|
991
|
-
<DropdownMenuContent align="end">
|
|
997
|
+
<DropdownMenuContent align="end" hidden={disabled}>
|
|
992
998
|
<DropdownMenuGroup>
|
|
993
999
|
{menuItems.map((item, index) => renderMenuItem(item, index))}
|
|
994
1000
|
</DropdownMenuGroup>
|
|
@@ -1032,6 +1038,11 @@ interface CellContentProps extends React.TdHTMLAttributes<HTMLDivElement> {
|
|
|
1032
1038
|
children?: ReactNode;
|
|
1033
1039
|
description?: string;
|
|
1034
1040
|
grow?: boolean;
|
|
1041
|
+
disabled?: boolean;
|
|
1042
|
+
avatarStack?: {
|
|
1043
|
+
items: { name: string; visual?: string | React.ReactNode }[];
|
|
1044
|
+
nbVisibleItems?: number;
|
|
1045
|
+
};
|
|
1035
1046
|
}
|
|
1036
1047
|
|
|
1037
1048
|
DataTable.CellContent = function CellContent({
|
|
@@ -1044,6 +1055,8 @@ DataTable.CellContent = function CellContent({
|
|
|
1044
1055
|
iconClassName,
|
|
1045
1056
|
description,
|
|
1046
1057
|
grow = false,
|
|
1058
|
+
disabled,
|
|
1059
|
+
avatarStack,
|
|
1047
1060
|
...props
|
|
1048
1061
|
}: CellContentProps) {
|
|
1049
1062
|
return (
|
|
@@ -1051,8 +1064,10 @@ DataTable.CellContent = function CellContent({
|
|
|
1051
1064
|
className={cn(
|
|
1052
1065
|
"s-flex s-items-center",
|
|
1053
1066
|
grow ? "s-flex-grow" : "",
|
|
1067
|
+
disabled && "s-cursor-not-allowed s-opacity-50",
|
|
1054
1068
|
className
|
|
1055
1069
|
)}
|
|
1070
|
+
aria-disabled={disabled || undefined}
|
|
1056
1071
|
{...props}
|
|
1057
1072
|
>
|
|
1058
1073
|
{avatarUrl && avatarTooltipLabel && (
|
|
@@ -1076,6 +1091,14 @@ DataTable.CellContent = function CellContent({
|
|
|
1076
1091
|
isRounded={roundedAvatar ?? false}
|
|
1077
1092
|
/>
|
|
1078
1093
|
)}
|
|
1094
|
+
{avatarStack && (
|
|
1095
|
+
<Avatar.Stack
|
|
1096
|
+
avatars={avatarStack.items}
|
|
1097
|
+
nbVisibleItems={avatarStack.nbVisibleItems}
|
|
1098
|
+
size="xs"
|
|
1099
|
+
isRounded={roundedAvatar ?? false}
|
|
1100
|
+
/>
|
|
1101
|
+
)}
|
|
1079
1102
|
{icon && (
|
|
1080
1103
|
<Icon
|
|
1081
1104
|
visual={icon}
|
|
@@ -1117,6 +1140,7 @@ interface BasicCellContentProps extends React.TdHTMLAttributes<HTMLDivElement> {
|
|
|
1117
1140
|
label: string | number;
|
|
1118
1141
|
tooltip?: string | number;
|
|
1119
1142
|
textToCopy?: string | number;
|
|
1143
|
+
disabled?: boolean;
|
|
1120
1144
|
}
|
|
1121
1145
|
|
|
1122
1146
|
DataTable.BasicCellContent = function BasicCellContent({
|
|
@@ -1124,6 +1148,7 @@ DataTable.BasicCellContent = function BasicCellContent({
|
|
|
1124
1148
|
tooltip,
|
|
1125
1149
|
className,
|
|
1126
1150
|
textToCopy,
|
|
1151
|
+
disabled,
|
|
1127
1152
|
...props
|
|
1128
1153
|
}: BasicCellContentProps) {
|
|
1129
1154
|
const [isCopied, copyToClipboard] = useCopyToClipboard();
|
|
@@ -1150,8 +1175,10 @@ DataTable.BasicCellContent = function BasicCellContent({
|
|
|
1150
1175
|
cellHeight,
|
|
1151
1176
|
"s-group s-flex s-items-center s-gap-2 s-text-sm",
|
|
1152
1177
|
"s-text-muted-foreground dark:s-text-muted-foreground-night",
|
|
1178
|
+
disabled && "s-cursor-not-allowed s-opacity-50",
|
|
1153
1179
|
className
|
|
1154
1180
|
)}
|
|
1181
|
+
aria-disabled={disabled || undefined}
|
|
1155
1182
|
{...props}
|
|
1156
1183
|
>
|
|
1157
1184
|
<span className="s-truncate">{label}</span>
|
|
@@ -1177,8 +1204,10 @@ DataTable.BasicCellContent = function BasicCellContent({
|
|
|
1177
1204
|
cellHeight,
|
|
1178
1205
|
"s-group s-flex s-items-center s-gap-2 s-text-sm",
|
|
1179
1206
|
"s-text-muted-foreground dark:s-text-muted-foreground-night",
|
|
1207
|
+
disabled && "s-cursor-not-allowed s-opacity-50",
|
|
1180
1208
|
className
|
|
1181
1209
|
)}
|
|
1210
|
+
aria-disabled={disabled || undefined}
|
|
1182
1211
|
{...props}
|
|
1183
1212
|
>
|
|
1184
1213
|
<span className="s-truncate">{label}</span>
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { cva } from "class-variance-authority";
|
|
2
|
-
import React
|
|
2
|
+
import React from "react";
|
|
3
3
|
|
|
4
4
|
import { ContentBlockWrapper } from "@sparkle/components";
|
|
5
5
|
|
|
6
|
-
import { MarkdownNode } from "./types";
|
|
7
|
-
import { sameNodePosition } from "./utils";
|
|
8
|
-
|
|
9
6
|
export const blockquoteVariants = cva(
|
|
10
7
|
["s-w-full s-text-base s-italic s-rounded-2xl s-py-3 s-pl-5 s-pr-12"],
|
|
11
8
|
{
|
|
@@ -23,37 +20,33 @@ export const blockquoteVariants = cva(
|
|
|
23
20
|
interface BlockquoteBlockProps {
|
|
24
21
|
children: React.ReactNode;
|
|
25
22
|
variant?: "surface";
|
|
26
|
-
node?: MarkdownNode;
|
|
27
23
|
}
|
|
28
24
|
|
|
29
|
-
export
|
|
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
|
-
MemoBlockquoteBlock.displayName = "BlockquoteBlock";
|
|
25
|
+
export function BlockquoteBlock({
|
|
26
|
+
children,
|
|
27
|
+
variant = "surface",
|
|
28
|
+
}: BlockquoteBlockProps) {
|
|
29
|
+
const elementAt1 = React.Children.toArray(children)[1];
|
|
30
|
+
const childrenContent =
|
|
31
|
+
elementAt1 && React.isValidElement(elementAt1)
|
|
32
|
+
? elementAt1.props.children
|
|
33
|
+
: null;
|
|
34
|
+
|
|
35
|
+
// Convert array content to string if necessary
|
|
36
|
+
const contentAsString = Array.isArray(childrenContent)
|
|
37
|
+
? childrenContent.join("")
|
|
38
|
+
: childrenContent;
|
|
39
|
+
|
|
40
|
+
// Only pass content if it exists
|
|
41
|
+
const clipboardContent = contentAsString
|
|
42
|
+
? { "text/plain": contentAsString }
|
|
43
|
+
: undefined;
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<ContentBlockWrapper content={clipboardContent} className="s-my-2">
|
|
47
|
+
<blockquote className={blockquoteVariants({ variant })}>
|
|
48
|
+
{children}
|
|
49
|
+
</blockquote>
|
|
50
|
+
</ContentBlockWrapper>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mermaid from "mermaid";
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { useContext, useEffect, useRef, useState } from "react";
|
|
3
3
|
import {
|
|
4
4
|
amber,
|
|
5
5
|
blue,
|
|
@@ -25,8 +25,6 @@ import {
|
|
|
25
25
|
JsonValueType,
|
|
26
26
|
PrettyJsonViewer,
|
|
27
27
|
} from "@sparkle/components/markdown/PrettyJsonViewer";
|
|
28
|
-
import { MarkdownNode } from "@sparkle/components/markdown/types";
|
|
29
|
-
import { sameNodePosition } from "@sparkle/components/markdown/utils";
|
|
30
28
|
import { CommandLineIcon, SparklesIcon } from "@sparkle/icons/app";
|
|
31
29
|
import { cn } from "@sparkle/lib/utils";
|
|
32
30
|
|
|
@@ -315,159 +313,150 @@ export function StyledMermaidGraph({
|
|
|
315
313
|
);
|
|
316
314
|
}
|
|
317
315
|
|
|
318
|
-
export
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
if (language === "mermaid") {
|
|
357
|
-
const checkValidMermaid = async () => {
|
|
358
|
-
try {
|
|
359
|
-
await mermaid.parse(validChildrenContent);
|
|
360
|
-
setIsValidMermaid(true);
|
|
361
|
-
setShowMermaid(true);
|
|
362
|
-
} catch (e) {
|
|
363
|
-
setIsValidMermaid(false);
|
|
364
|
-
setShowMermaid(false);
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
void checkValidMermaid();
|
|
368
|
-
}
|
|
369
|
-
if (language === "json") {
|
|
316
|
+
export function CodeBlockWithExtendedSupport({
|
|
317
|
+
children,
|
|
318
|
+
className,
|
|
319
|
+
inline,
|
|
320
|
+
}: {
|
|
321
|
+
children?: React.ReactNode;
|
|
322
|
+
className?: string;
|
|
323
|
+
inline?: boolean;
|
|
324
|
+
}) {
|
|
325
|
+
const validChildrenContent = String(children).trim();
|
|
326
|
+
const [showMermaid, setShowMermaid] = useState<boolean>(false);
|
|
327
|
+
const [isValidMermaid, setIsValidMermaid] = useState<boolean>(false);
|
|
328
|
+
const [showPrettyJson, setShowPrettyJson] = useState<boolean>(false);
|
|
329
|
+
const [parsedJson, setParsedJson] = useState<JsonValueType | null>(null);
|
|
330
|
+
const { isStreaming } = useContext(MarkdownContentContext);
|
|
331
|
+
|
|
332
|
+
// Detect language from className
|
|
333
|
+
const language = className?.split("-")[1];
|
|
334
|
+
|
|
335
|
+
// Only create getContentToDownload when we actually want to enable downloads
|
|
336
|
+
const getContentToDownload: GetContentToDownloadFunction | undefined =
|
|
337
|
+
!inline &&
|
|
338
|
+
validChildrenContent &&
|
|
339
|
+
(language === "csv" || language === "json")
|
|
340
|
+
? async () => ({
|
|
341
|
+
content: validChildrenContent,
|
|
342
|
+
filename: `dust_output_${Date.now()}`,
|
|
343
|
+
type: language === "csv" ? "text/csv" : "application/json",
|
|
344
|
+
})
|
|
345
|
+
: undefined;
|
|
346
|
+
|
|
347
|
+
// Check for valid Mermaid and JSON.
|
|
348
|
+
useEffect(() => {
|
|
349
|
+
if (isStreaming || !validChildrenContent) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (language === "mermaid") {
|
|
353
|
+
const checkValidMermaid = async () => {
|
|
370
354
|
try {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
setShowPrettyJson(prettyJsonPreference);
|
|
355
|
+
await mermaid.parse(validChildrenContent);
|
|
356
|
+
setIsValidMermaid(true);
|
|
357
|
+
setShowMermaid(true);
|
|
375
358
|
} catch (e) {
|
|
376
|
-
|
|
377
|
-
|
|
359
|
+
setIsValidMermaid(false);
|
|
360
|
+
setShowMermaid(false);
|
|
378
361
|
}
|
|
362
|
+
};
|
|
363
|
+
void checkValidMermaid();
|
|
364
|
+
}
|
|
365
|
+
if (language === "json") {
|
|
366
|
+
try {
|
|
367
|
+
const parsed = JSON.parse(validChildrenContent);
|
|
368
|
+
setParsedJson(parsed);
|
|
369
|
+
const prettyJsonPreference = getPrettyJsonPreference();
|
|
370
|
+
setShowPrettyJson(prettyJsonPreference);
|
|
371
|
+
} catch (e) {
|
|
372
|
+
setParsedJson(null);
|
|
373
|
+
setShowPrettyJson(false);
|
|
379
374
|
}
|
|
380
|
-
}, [isStreaming, language, validChildrenContent]);
|
|
381
|
-
|
|
382
|
-
if (inline) {
|
|
383
|
-
return (
|
|
384
|
-
<CodeBlock className={className} inline={inline}>
|
|
385
|
-
{children}
|
|
386
|
-
</CodeBlock>
|
|
387
|
-
);
|
|
388
375
|
}
|
|
376
|
+
}, [isStreaming, language, validChildrenContent]);
|
|
389
377
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
className="s-font-sans"
|
|
398
|
-
size="xs"
|
|
399
|
-
variant={"outline"}
|
|
400
|
-
label={showMermaid ? "Markdown" : "Mermaid"}
|
|
401
|
-
icon={showMermaid ? CommandLineIcon : SparklesIcon}
|
|
402
|
-
onClick={() => setShowMermaid(!showMermaid)}
|
|
403
|
-
tooltip={showMermaid ? "Switch to Markdown" : "Switch to Mermaid"}
|
|
404
|
-
/>
|
|
405
|
-
}
|
|
406
|
-
>
|
|
407
|
-
{showMermaid ? (
|
|
408
|
-
<MermaidGraph chart={validChildrenContent} />
|
|
409
|
-
) : (
|
|
410
|
-
<CodeBlock className={className} inline={inline}>
|
|
411
|
-
{children}
|
|
412
|
-
</CodeBlock>
|
|
413
|
-
)}
|
|
414
|
-
</ContentBlockWrapper>
|
|
415
|
-
);
|
|
416
|
-
}
|
|
378
|
+
if (inline) {
|
|
379
|
+
return (
|
|
380
|
+
<CodeBlock className={className} inline={inline}>
|
|
381
|
+
{children}
|
|
382
|
+
</CodeBlock>
|
|
383
|
+
);
|
|
384
|
+
}
|
|
417
385
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
) : (
|
|
446
|
-
<CodeBlock className={className} inline={inline}>
|
|
447
|
-
{children}
|
|
448
|
-
</CodeBlock>
|
|
449
|
-
)}
|
|
450
|
-
</ContentBlockWrapper>
|
|
451
|
-
);
|
|
452
|
-
}
|
|
386
|
+
if (isValidMermaid) {
|
|
387
|
+
return (
|
|
388
|
+
<ContentBlockWrapper
|
|
389
|
+
content={validChildrenContent}
|
|
390
|
+
getContentToDownload={getContentToDownload}
|
|
391
|
+
actions={
|
|
392
|
+
<Button
|
|
393
|
+
className="s-font-sans"
|
|
394
|
+
size="xs"
|
|
395
|
+
variant={"outline"}
|
|
396
|
+
label={showMermaid ? "Markdown" : "Mermaid"}
|
|
397
|
+
icon={showMermaid ? CommandLineIcon : SparklesIcon}
|
|
398
|
+
onClick={() => setShowMermaid(!showMermaid)}
|
|
399
|
+
tooltip={showMermaid ? "Switch to Markdown" : "Switch to Mermaid"}
|
|
400
|
+
/>
|
|
401
|
+
}
|
|
402
|
+
>
|
|
403
|
+
{showMermaid ? (
|
|
404
|
+
<MermaidGraph chart={validChildrenContent} />
|
|
405
|
+
) : (
|
|
406
|
+
<CodeBlock className={className} inline={inline}>
|
|
407
|
+
{children}
|
|
408
|
+
</CodeBlock>
|
|
409
|
+
)}
|
|
410
|
+
</ContentBlockWrapper>
|
|
411
|
+
);
|
|
412
|
+
}
|
|
453
413
|
|
|
414
|
+
if (parsedJson !== null) {
|
|
454
415
|
return (
|
|
455
416
|
<ContentBlockWrapper
|
|
456
417
|
content={validChildrenContent}
|
|
457
418
|
getContentToDownload={getContentToDownload}
|
|
458
|
-
|
|
419
|
+
actions={
|
|
420
|
+
<Button
|
|
421
|
+
className="s-font-sans"
|
|
422
|
+
size="xs"
|
|
423
|
+
variant={"outline"}
|
|
424
|
+
label={showPrettyJson ? "Raw JSON" : "Pretty JSON"}
|
|
425
|
+
icon={showPrettyJson ? CommandLineIcon : SparklesIcon}
|
|
426
|
+
onClick={() => {
|
|
427
|
+
const newValue = !showPrettyJson;
|
|
428
|
+
setShowPrettyJson(newValue);
|
|
429
|
+
setPrettyJsonPreference(newValue);
|
|
430
|
+
}}
|
|
431
|
+
tooltip={
|
|
432
|
+
showPrettyJson ? "Switch to Raw JSON" : "Switch to Pretty View"
|
|
433
|
+
}
|
|
434
|
+
/>
|
|
435
|
+
}
|
|
459
436
|
displayActions="hover"
|
|
437
|
+
buttonDisplay="inside"
|
|
460
438
|
>
|
|
461
|
-
|
|
462
|
-
{
|
|
463
|
-
|
|
439
|
+
{showPrettyJson ? (
|
|
440
|
+
<PrettyJsonViewer data={parsedJson} />
|
|
441
|
+
) : (
|
|
442
|
+
<CodeBlock className={className} inline={inline}>
|
|
443
|
+
{children}
|
|
444
|
+
</CodeBlock>
|
|
445
|
+
)}
|
|
464
446
|
</ContentBlockWrapper>
|
|
465
447
|
);
|
|
466
|
-
}
|
|
467
|
-
(prev, next) =>
|
|
468
|
-
sameNodePosition(prev.node, next.node) &&
|
|
469
|
-
prev.className === next.className &&
|
|
470
|
-
prev.inline === next.inline
|
|
471
|
-
);
|
|
448
|
+
}
|
|
472
449
|
|
|
473
|
-
|
|
450
|
+
return (
|
|
451
|
+
<ContentBlockWrapper
|
|
452
|
+
content={validChildrenContent}
|
|
453
|
+
getContentToDownload={getContentToDownload}
|
|
454
|
+
buttonDisplay="inside"
|
|
455
|
+
displayActions="hover"
|
|
456
|
+
>
|
|
457
|
+
<CodeBlock className={className} inline={inline}>
|
|
458
|
+
{children}
|
|
459
|
+
</CodeBlock>
|
|
460
|
+
</ContentBlockWrapper>
|
|
461
|
+
);
|
|
462
|
+
}
|
|
@@ -1,36 +1,21 @@
|
|
|
1
1
|
import { cva } from "class-variance-authority";
|
|
2
|
-
import React
|
|
2
|
+
import React from "react";
|
|
3
3
|
|
|
4
4
|
import { cn } from "@sparkle/lib";
|
|
5
5
|
|
|
6
|
-
import { sameNodePosition, sameTextStyling } from "./utils";
|
|
7
|
-
|
|
8
|
-
type MarkdownPoint = { line?: number; column?: number };
|
|
9
|
-
type MarkdownPosition = { start?: MarkdownPoint; end?: MarkdownPoint };
|
|
10
|
-
type MarkdownNode = {
|
|
11
|
-
position?: MarkdownPosition;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
6
|
export const ulBlockVariants = cva(["s-list-disc s-pb-2 s-pl-6"]);
|
|
15
7
|
|
|
16
8
|
interface UlBlockProps {
|
|
17
9
|
children: React.ReactNode;
|
|
18
10
|
textColor: string;
|
|
19
11
|
textSize: string;
|
|
20
|
-
node?: MarkdownNode;
|
|
21
12
|
}
|
|
22
13
|
|
|
23
|
-
export
|
|
24
|
-
(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
(prev, next) =>
|
|
30
|
-
sameNodePosition(prev.node, next.node) && sameTextStyling(prev, next)
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
MemoUlBlock.displayName = "UlBlock";
|
|
14
|
+
export function UlBlock({ children, textColor, textSize }: UlBlockProps) {
|
|
15
|
+
return (
|
|
16
|
+
<ul className={cn(ulBlockVariants(), textColor, textSize)}>{children}</ul>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
34
19
|
|
|
35
20
|
export const olBlockVariants = cva(["s-list-decimal s-pb-2 s-pl-6"]);
|
|
36
21
|
|
|
@@ -39,24 +24,20 @@ interface OlBlockProps {
|
|
|
39
24
|
start?: number;
|
|
40
25
|
textColor: string;
|
|
41
26
|
textSize: string;
|
|
42
|
-
node?: MarkdownNode;
|
|
43
27
|
}
|
|
44
28
|
|
|
45
|
-
export
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
MemoOlBlock.displayName = "OlBlock";
|
|
29
|
+
export function OlBlock({
|
|
30
|
+
children,
|
|
31
|
+
start,
|
|
32
|
+
textColor,
|
|
33
|
+
textSize,
|
|
34
|
+
}: OlBlockProps) {
|
|
35
|
+
return (
|
|
36
|
+
<ol start={start} className={cn(olBlockVariants(), textColor, textSize)}>
|
|
37
|
+
{children}
|
|
38
|
+
</ol>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
60
41
|
|
|
61
42
|
export const liBlockVariants = cva(["s-break-words"]);
|
|
62
43
|
|
|
@@ -65,21 +46,17 @@ interface LiBlockProps {
|
|
|
65
46
|
className?: string;
|
|
66
47
|
textColor: string;
|
|
67
48
|
textSize: string;
|
|
68
|
-
node?: MarkdownNode;
|
|
69
49
|
}
|
|
70
50
|
|
|
71
|
-
export
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
MemoLiBlock.displayName = "LiBlock";
|
|
51
|
+
export function LiBlock({
|
|
52
|
+
children,
|
|
53
|
+
className,
|
|
54
|
+
textColor,
|
|
55
|
+
textSize,
|
|
56
|
+
}: LiBlockProps) {
|
|
57
|
+
return (
|
|
58
|
+
<li className={cn(liBlockVariants(), textColor, textSize, className)}>
|
|
59
|
+
{children}
|
|
60
|
+
</li>
|
|
61
|
+
);
|
|
62
|
+
}
|