@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.
Files changed (94) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/esm/components/DataTable.d.ts +13 -3
  3. package/dist/esm/components/DataTable.d.ts.map +1 -1
  4. package/dist/esm/components/DataTable.js +9 -8
  5. package/dist/esm/components/DataTable.js.map +1 -1
  6. package/dist/esm/components/markdown/BlockquoteBlock.d.ts +1 -3
  7. package/dist/esm/components/markdown/BlockquoteBlock.d.ts.map +1 -1
  8. package/dist/esm/components/markdown/BlockquoteBlock.js +3 -7
  9. package/dist/esm/components/markdown/BlockquoteBlock.js.map +1 -1
  10. package/dist/esm/components/markdown/CodeBlockWithExtendedSupport.d.ts +2 -4
  11. package/dist/esm/components/markdown/CodeBlockWithExtendedSupport.d.ts.map +1 -1
  12. package/dist/esm/components/markdown/CodeBlockWithExtendedSupport.js +6 -11
  13. package/dist/esm/components/markdown/CodeBlockWithExtendedSupport.js.map +1 -1
  14. package/dist/esm/components/markdown/List.d.ts +3 -17
  15. package/dist/esm/components/markdown/List.d.ts.map +1 -1
  16. package/dist/esm/components/markdown/List.js +7 -21
  17. package/dist/esm/components/markdown/List.js.map +1 -1
  18. package/dist/esm/components/markdown/Markdown.d.ts +9 -2
  19. package/dist/esm/components/markdown/Markdown.d.ts.map +1 -1
  20. package/dist/esm/components/markdown/Markdown.js +66 -45
  21. package/dist/esm/components/markdown/Markdown.js.map +1 -1
  22. package/dist/esm/components/markdown/ParagraphBlock.d.ts +1 -3
  23. package/dist/esm/components/markdown/ParagraphBlock.d.ts.map +1 -1
  24. package/dist/esm/components/markdown/ParagraphBlock.js +3 -7
  25. package/dist/esm/components/markdown/ParagraphBlock.js.map +1 -1
  26. package/dist/esm/components/markdown/PreBlock.d.ts +1 -3
  27. package/dist/esm/components/markdown/PreBlock.d.ts.map +1 -1
  28. package/dist/esm/components/markdown/PreBlock.js +3 -7
  29. package/dist/esm/components/markdown/PreBlock.js.map +1 -1
  30. package/dist/esm/components/markdown/TableBlock.d.ts +11 -17
  31. package/dist/esm/components/markdown/TableBlock.d.ts.map +1 -1
  32. package/dist/esm/components/markdown/TableBlock.js +14 -18
  33. package/dist/esm/components/markdown/TableBlock.js.map +1 -1
  34. package/dist/esm/components/markdown/index.d.ts +0 -4
  35. package/dist/esm/components/markdown/index.d.ts.map +1 -1
  36. package/dist/esm/components/markdown/index.js +0 -4
  37. package/dist/esm/components/markdown/index.js.map +1 -1
  38. package/dist/esm/components/markdown/utils.d.ts +0 -11
  39. package/dist/esm/components/markdown/utils.d.ts.map +1 -1
  40. package/dist/esm/components/markdown/utils.js +0 -21
  41. package/dist/esm/components/markdown/utils.js.map +1 -1
  42. package/dist/esm/stories/DataTable.stories.d.ts +1 -0
  43. package/dist/esm/stories/DataTable.stories.d.ts.map +1 -1
  44. package/dist/esm/stories/DataTable.stories.js +188 -0
  45. package/dist/esm/stories/DataTable.stories.js.map +1 -1
  46. package/dist/esm/styles/global.css +12 -0
  47. package/dist/esm/styles/global_with_tw_base.css +12 -0
  48. package/dist/esm/styles/tailwind.css +11 -0
  49. package/dist/sparkle.css +34 -0
  50. package/package.json +1 -2
  51. package/src/components/DataTable.tsx +31 -2
  52. package/src/components/markdown/BlockquoteBlock.tsx +29 -36
  53. package/src/components/markdown/CodeBlockWithExtendedSupport.tsx +131 -142
  54. package/src/components/markdown/List.tsx +30 -53
  55. package/src/components/markdown/Markdown.tsx +171 -108
  56. package/src/components/markdown/ParagraphBlock.tsx +12 -18
  57. package/src/components/markdown/PreBlock.tsx +18 -28
  58. package/src/components/markdown/TableBlock.tsx +95 -125
  59. package/src/components/markdown/index.ts +0 -4
  60. package/src/components/markdown/utils.ts +0 -37
  61. package/src/stories/DataTable.stories.tsx +235 -0
  62. package/src/styles/global.css +12 -0
  63. package/src/styles/global_with_tw_base.css +12 -0
  64. package/src/styles/tailwind.css +11 -0
  65. package/dist/esm/components/markdown/HeaderBlocks.d.ts +0 -24
  66. package/dist/esm/components/markdown/HeaderBlocks.d.ts.map +0 -1
  67. package/dist/esm/components/markdown/HeaderBlocks.js +0 -54
  68. package/dist/esm/components/markdown/HeaderBlocks.js.map +0 -1
  69. package/dist/esm/components/markdown/InputBlock.d.ts +0 -10
  70. package/dist/esm/components/markdown/InputBlock.d.ts.map +0 -1
  71. package/dist/esm/components/markdown/InputBlock.js +0 -26
  72. package/dist/esm/components/markdown/InputBlock.js.map +0 -1
  73. package/dist/esm/components/markdown/LinkBlock.d.ts +0 -10
  74. package/dist/esm/components/markdown/LinkBlock.d.ts.map +0 -1
  75. package/dist/esm/components/markdown/LinkBlock.js +0 -11
  76. package/dist/esm/components/markdown/LinkBlock.js.map +0 -1
  77. package/dist/esm/components/markdown/TextFormattingBlocks.d.ts +0 -10
  78. package/dist/esm/components/markdown/TextFormattingBlocks.d.ts.map +0 -1
  79. package/dist/esm/components/markdown/TextFormattingBlocks.js +0 -12
  80. package/dist/esm/components/markdown/TextFormattingBlocks.js.map +0 -1
  81. package/dist/esm/components/markdown/types.d.ts +0 -13
  82. package/dist/esm/components/markdown/types.d.ts.map +0 -1
  83. package/dist/esm/components/markdown/types.js +0 -2
  84. package/dist/esm/components/markdown/types.js.map +0 -1
  85. package/dist/esm/components/markdown/useAnimatedText.d.ts +0 -2
  86. package/dist/esm/components/markdown/useAnimatedText.d.ts.map +0 -1
  87. package/dist/esm/components/markdown/useAnimatedText.js +0 -31
  88. package/dist/esm/components/markdown/useAnimatedText.js.map +0 -1
  89. package/src/components/markdown/HeaderBlocks.tsx +0 -160
  90. package/src/components/markdown/InputBlock.tsx +0 -60
  91. package/src/components/markdown/LinkBlock.tsx +0 -36
  92. package/src/components/markdown/TextFormattingBlocks.tsx +0 -31
  93. package/src/components/markdown/types.ts +0 -5
  94. package/src/components/markdown/useAnimatedText.ts +0 -36
@@ -1,5 +1,5 @@
1
1
  import mermaid from "mermaid";
2
- import React, { memo, useContext, useEffect, useRef, useState } from "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 const MemoCodeBlockWithExtendedSupport = memo(
319
- ({
320
- children,
321
- className,
322
- inline,
323
- }: {
324
- children?: React.ReactNode;
325
- className?: string;
326
- inline?: boolean;
327
- node?: MarkdownNode;
328
- }) => {
329
- const validChildrenContent = String(children).trim();
330
- const [showMermaid, setShowMermaid] = useState<boolean>(false);
331
- const [isValidMermaid, setIsValidMermaid] = useState<boolean>(false);
332
- const [showPrettyJson, setShowPrettyJson] = useState<boolean>(false);
333
- const [parsedJson, setParsedJson] = useState<JsonValueType | null>(null);
334
- const { isStreaming } = useContext(MarkdownContentContext);
335
-
336
- // Detect language from className
337
- const language = className?.split("-")[1];
338
-
339
- // Only create getContentToDownload when we actually want to enable downloads
340
- const getContentToDownload: GetContentToDownloadFunction | undefined =
341
- !inline &&
342
- validChildrenContent &&
343
- (language === "csv" || language === "json")
344
- ? async () => ({
345
- content: validChildrenContent,
346
- filename: `dust_output_${Date.now()}`,
347
- type: language === "csv" ? "text/csv" : "application/json",
348
- })
349
- : undefined;
350
-
351
- // Check for valid Mermaid and JSON.
352
- useEffect(() => {
353
- if (isStreaming || !validChildrenContent) {
354
- return;
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
- const parsed = JSON.parse(validChildrenContent);
372
- setParsedJson(parsed);
373
- const prettyJsonPreference = getPrettyJsonPreference();
374
- setShowPrettyJson(prettyJsonPreference);
355
+ await mermaid.parse(validChildrenContent);
356
+ setIsValidMermaid(true);
357
+ setShowMermaid(true);
375
358
  } catch (e) {
376
- setParsedJson(null);
377
- setShowPrettyJson(false);
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
- if (isValidMermaid) {
391
- return (
392
- <ContentBlockWrapper
393
- content={validChildrenContent}
394
- getContentToDownload={getContentToDownload}
395
- actions={
396
- <Button
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
- if (parsedJson !== null) {
419
- return (
420
- <ContentBlockWrapper
421
- content={validChildrenContent}
422
- getContentToDownload={getContentToDownload}
423
- actions={
424
- <Button
425
- className="s-font-sans"
426
- size="xs"
427
- variant={"outline"}
428
- label={showPrettyJson ? "Raw JSON" : "Pretty JSON"}
429
- icon={showPrettyJson ? CommandLineIcon : SparklesIcon}
430
- onClick={() => {
431
- const newValue = !showPrettyJson;
432
- setShowPrettyJson(newValue);
433
- setPrettyJsonPreference(newValue);
434
- }}
435
- tooltip={
436
- showPrettyJson ? "Switch to Raw JSON" : "Switch to Pretty View"
437
- }
438
- />
439
- }
440
- displayActions="hover"
441
- buttonDisplay="inside"
442
- >
443
- {showPrettyJson ? (
444
- <PrettyJsonViewer data={parsedJson} />
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
- buttonDisplay="inside"
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
- <CodeBlock className={className} inline={inline}>
462
- {children}
463
- </CodeBlock>
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
- MemoCodeBlockWithExtendedSupport.displayName = "CodeBlockWithExtendedSupport";
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, { memo } from "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 const MemoUlBlock = memo(
24
- ({ children, textColor, textSize }: UlBlockProps) => {
25
- return (
26
- <ul className={cn(ulBlockVariants(), textColor, textSize)}>{children}</ul>
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 const MemoOlBlock = memo(
46
- ({ children, start, textColor, textSize }: OlBlockProps) => {
47
- return (
48
- <ol start={start} className={cn(olBlockVariants(), textColor, textSize)}>
49
- {children}
50
- </ol>
51
- );
52
- },
53
- (prev, next) =>
54
- sameNodePosition(prev.node, next.node) &&
55
- prev.start === next.start &&
56
- sameTextStyling(prev, next)
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 const MemoLiBlock = memo(
72
- ({ children, className, textColor, textSize }: LiBlockProps) => {
73
- return (
74
- <li className={cn(liBlockVariants(), textColor, textSize, className)}>
75
- {children}
76
- </li>
77
- );
78
- },
79
- (prev, next) =>
80
- sameNodePosition(prev.node, next.node) &&
81
- prev.className === next.className &&
82
- sameTextStyling(prev, next)
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
+ }