@dust-tt/sparkle 0.2.646-rc-3 → 0.2.646
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/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 +34 -0
- 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/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
|
@@ -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
|
+
}
|