@dust-tt/sparkle 0.2.645 → 0.2.646-rc-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.
Files changed (94) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/esm/components/DataTable.d.ts +3 -13
  3. package/dist/esm/components/DataTable.d.ts.map +1 -1
  4. package/dist/esm/components/DataTable.js +8 -9
  5. package/dist/esm/components/DataTable.js.map +1 -1
  6. package/dist/esm/components/markdown/BlockquoteBlock.d.ts +3 -1
  7. package/dist/esm/components/markdown/BlockquoteBlock.d.ts.map +1 -1
  8. package/dist/esm/components/markdown/BlockquoteBlock.js +7 -3
  9. package/dist/esm/components/markdown/BlockquoteBlock.js.map +1 -1
  10. package/dist/esm/components/markdown/CodeBlockWithExtendedSupport.d.ts +4 -2
  11. package/dist/esm/components/markdown/CodeBlockWithExtendedSupport.d.ts.map +1 -1
  12. package/dist/esm/components/markdown/CodeBlockWithExtendedSupport.js +11 -6
  13. package/dist/esm/components/markdown/CodeBlockWithExtendedSupport.js.map +1 -1
  14. package/dist/esm/components/markdown/HeaderBlocks.d.ts +24 -0
  15. package/dist/esm/components/markdown/HeaderBlocks.d.ts.map +1 -0
  16. package/dist/esm/components/markdown/HeaderBlocks.js +54 -0
  17. package/dist/esm/components/markdown/HeaderBlocks.js.map +1 -0
  18. package/dist/esm/components/markdown/InputBlock.d.ts +10 -0
  19. package/dist/esm/components/markdown/InputBlock.d.ts.map +1 -0
  20. package/dist/esm/components/markdown/InputBlock.js +26 -0
  21. package/dist/esm/components/markdown/InputBlock.js.map +1 -0
  22. package/dist/esm/components/markdown/LinkBlock.d.ts +10 -0
  23. package/dist/esm/components/markdown/LinkBlock.d.ts.map +1 -0
  24. package/dist/esm/components/markdown/LinkBlock.js +11 -0
  25. package/dist/esm/components/markdown/LinkBlock.js.map +1 -0
  26. package/dist/esm/components/markdown/List.d.ts +17 -3
  27. package/dist/esm/components/markdown/List.d.ts.map +1 -1
  28. package/dist/esm/components/markdown/List.js +21 -7
  29. package/dist/esm/components/markdown/List.js.map +1 -1
  30. package/dist/esm/components/markdown/Markdown.d.ts +2 -9
  31. package/dist/esm/components/markdown/Markdown.d.ts.map +1 -1
  32. package/dist/esm/components/markdown/Markdown.js +45 -66
  33. package/dist/esm/components/markdown/Markdown.js.map +1 -1
  34. package/dist/esm/components/markdown/ParagraphBlock.d.ts +3 -1
  35. package/dist/esm/components/markdown/ParagraphBlock.d.ts.map +1 -1
  36. package/dist/esm/components/markdown/ParagraphBlock.js +7 -3
  37. package/dist/esm/components/markdown/ParagraphBlock.js.map +1 -1
  38. package/dist/esm/components/markdown/PreBlock.d.ts +3 -1
  39. package/dist/esm/components/markdown/PreBlock.d.ts.map +1 -1
  40. package/dist/esm/components/markdown/PreBlock.js +7 -3
  41. package/dist/esm/components/markdown/PreBlock.js.map +1 -1
  42. package/dist/esm/components/markdown/TableBlock.d.ts +17 -11
  43. package/dist/esm/components/markdown/TableBlock.d.ts.map +1 -1
  44. package/dist/esm/components/markdown/TableBlock.js +18 -14
  45. package/dist/esm/components/markdown/TableBlock.js.map +1 -1
  46. package/dist/esm/components/markdown/TextFormattingBlocks.d.ts +10 -0
  47. package/dist/esm/components/markdown/TextFormattingBlocks.d.ts.map +1 -0
  48. package/dist/esm/components/markdown/TextFormattingBlocks.js +12 -0
  49. package/dist/esm/components/markdown/TextFormattingBlocks.js.map +1 -0
  50. package/dist/esm/components/markdown/index.d.ts +4 -0
  51. package/dist/esm/components/markdown/index.d.ts.map +1 -1
  52. package/dist/esm/components/markdown/index.js +4 -0
  53. package/dist/esm/components/markdown/index.js.map +1 -1
  54. package/dist/esm/components/markdown/types.d.ts +13 -0
  55. package/dist/esm/components/markdown/types.d.ts.map +1 -0
  56. package/dist/esm/components/markdown/types.js +2 -0
  57. package/dist/esm/components/markdown/types.js.map +1 -0
  58. package/dist/esm/components/markdown/useAnimatedText.d.ts +2 -0
  59. package/dist/esm/components/markdown/useAnimatedText.d.ts.map +1 -0
  60. package/dist/esm/components/markdown/useAnimatedText.js +31 -0
  61. package/dist/esm/components/markdown/useAnimatedText.js.map +1 -0
  62. package/dist/esm/components/markdown/utils.d.ts +11 -0
  63. package/dist/esm/components/markdown/utils.d.ts.map +1 -1
  64. package/dist/esm/components/markdown/utils.js +21 -0
  65. package/dist/esm/components/markdown/utils.js.map +1 -1
  66. package/dist/esm/stories/DataTable.stories.d.ts +0 -1
  67. package/dist/esm/stories/DataTable.stories.d.ts.map +1 -1
  68. package/dist/esm/stories/DataTable.stories.js +0 -188
  69. package/dist/esm/stories/DataTable.stories.js.map +1 -1
  70. package/dist/esm/styles/global.css +0 -12
  71. package/dist/esm/styles/global_with_tw_base.css +0 -12
  72. package/dist/esm/styles/tailwind.css +0 -11
  73. package/dist/sparkle.css +0 -34
  74. package/package.json +2 -1
  75. package/src/components/DataTable.tsx +2 -31
  76. package/src/components/markdown/BlockquoteBlock.tsx +36 -29
  77. package/src/components/markdown/CodeBlockWithExtendedSupport.tsx +142 -131
  78. package/src/components/markdown/HeaderBlocks.tsx +160 -0
  79. package/src/components/markdown/InputBlock.tsx +60 -0
  80. package/src/components/markdown/LinkBlock.tsx +36 -0
  81. package/src/components/markdown/List.tsx +53 -30
  82. package/src/components/markdown/Markdown.tsx +108 -171
  83. package/src/components/markdown/ParagraphBlock.tsx +18 -12
  84. package/src/components/markdown/PreBlock.tsx +28 -18
  85. package/src/components/markdown/TableBlock.tsx +125 -95
  86. package/src/components/markdown/TextFormattingBlocks.tsx +31 -0
  87. package/src/components/markdown/index.ts +4 -0
  88. package/src/components/markdown/types.ts +5 -0
  89. package/src/components/markdown/useAnimatedText.ts +36 -0
  90. package/src/components/markdown/utils.ts +37 -0
  91. package/src/stories/DataTable.stories.tsx +0 -235
  92. package/src/styles/global.css +0 -12
  93. package/src/styles/global_with_tw_base.css +0 -12
  94. package/src/styles/tailwind.css +0 -11
@@ -0,0 +1,160 @@
1
+ import React, { memo } from "react";
2
+
3
+ import { cn } from "@sparkle/lib/utils";
4
+
5
+ import { MarkdownNode } from "./types";
6
+ import { sameNodePosition, sameTextStyling } from "./utils";
7
+
8
+ export const markdownHeaderClasses = {
9
+ h1: "s-heading-2xl",
10
+ h2: "s-heading-xl",
11
+ h3: "s-heading-lg",
12
+ h4: "s-text-base s-font-semibold",
13
+ h5: "s-text-sm s-font-semibold",
14
+ h6: "s-text-sm s-font-regular s-italic",
15
+ };
16
+
17
+ interface HeaderBlockProps {
18
+ children: React.ReactNode;
19
+ textColor?: string;
20
+ forcedTextSize?: string;
21
+ node?: MarkdownNode;
22
+ }
23
+
24
+ export const MemoH1Block = memo(
25
+ ({ children, textColor, forcedTextSize }: HeaderBlockProps) => {
26
+ return (
27
+ <h1
28
+ className={cn(
29
+ "s-pb-2 s-pt-4",
30
+ forcedTextSize ? forcedTextSize : markdownHeaderClasses.h1,
31
+ textColor
32
+ )}
33
+ >
34
+ {children}
35
+ </h1>
36
+ );
37
+ },
38
+ (prev, next) => {
39
+ return (
40
+ sameNodePosition(prev.node, next.node) && sameTextStyling(prev, next)
41
+ );
42
+ }
43
+ );
44
+
45
+ MemoH1Block.displayName = "H1Block";
46
+
47
+ export const MemoH2Block = memo(
48
+ ({ children, textColor, forcedTextSize }: HeaderBlockProps) => {
49
+ return (
50
+ <h2
51
+ className={cn(
52
+ "s-pb-2 s-pt-4",
53
+ forcedTextSize ? forcedTextSize : markdownHeaderClasses.h2,
54
+ textColor
55
+ )}
56
+ >
57
+ {children}
58
+ </h2>
59
+ );
60
+ },
61
+ (prev, next) => {
62
+ return (
63
+ sameNodePosition(prev.node, next.node) && sameTextStyling(prev, next)
64
+ );
65
+ }
66
+ );
67
+
68
+ MemoH2Block.displayName = "H2Block";
69
+
70
+ export const MemoH3Block = memo(
71
+ ({ children, textColor, forcedTextSize }: HeaderBlockProps) => {
72
+ return (
73
+ <h3
74
+ className={cn(
75
+ "s-pb-2 s-pt-4",
76
+ forcedTextSize ? forcedTextSize : markdownHeaderClasses.h3,
77
+ textColor
78
+ )}
79
+ >
80
+ {children}
81
+ </h3>
82
+ );
83
+ },
84
+ (prev, next) => {
85
+ return (
86
+ sameNodePosition(prev.node, next.node) && sameTextStyling(prev, next)
87
+ );
88
+ }
89
+ );
90
+
91
+ MemoH3Block.displayName = "H3Block";
92
+
93
+ export const MemoH4Block = memo(
94
+ ({ children, textColor, forcedTextSize }: HeaderBlockProps) => {
95
+ return (
96
+ <h4
97
+ className={cn(
98
+ "s-pb-2 s-pt-3",
99
+ forcedTextSize ? forcedTextSize : markdownHeaderClasses.h4,
100
+ textColor
101
+ )}
102
+ >
103
+ {children}
104
+ </h4>
105
+ );
106
+ },
107
+ (prev, next) => {
108
+ return (
109
+ sameNodePosition(prev.node, next.node) && sameTextStyling(prev, next)
110
+ );
111
+ }
112
+ );
113
+
114
+ MemoH4Block.displayName = "H4Block";
115
+
116
+ export const MemoH5Block = memo(
117
+ ({ children, textColor, forcedTextSize }: HeaderBlockProps) => {
118
+ return (
119
+ <h5
120
+ className={cn(
121
+ "s-pb-1.5 s-pt-2.5",
122
+ forcedTextSize ? forcedTextSize : markdownHeaderClasses.h5,
123
+ textColor
124
+ )}
125
+ >
126
+ {children}
127
+ </h5>
128
+ );
129
+ },
130
+ (prev, next) => {
131
+ return (
132
+ sameNodePosition(prev.node, next.node) && sameTextStyling(prev, next)
133
+ );
134
+ }
135
+ );
136
+
137
+ MemoH5Block.displayName = "H5Block";
138
+
139
+ export const MemoH6Block = memo(
140
+ ({ children, textColor, forcedTextSize }: HeaderBlockProps) => {
141
+ return (
142
+ <h6
143
+ className={cn(
144
+ "s-pb-1.5 s-pt-2.5",
145
+ forcedTextSize ? forcedTextSize : markdownHeaderClasses.h6,
146
+ textColor
147
+ )}
148
+ >
149
+ {children}
150
+ </h6>
151
+ );
152
+ },
153
+ (prev, next) => {
154
+ return (
155
+ sameNodePosition(prev.node, next.node) && sameTextStyling(prev, next)
156
+ );
157
+ }
158
+ );
159
+
160
+ MemoH6Block.displayName = "H6Block";
@@ -0,0 +1,60 @@
1
+ import React, { memo } from "react";
2
+ import type { ReactMarkdownProps } from "react-markdown/lib/ast-to-react";
3
+
4
+ import { Checkbox } from "@sparkle/components";
5
+
6
+ import { MarkdownNode } from "./types";
7
+ import { sameNodePosition } from "./utils";
8
+
9
+ type InputBlockProps = Omit<
10
+ React.InputHTMLAttributes<HTMLInputElement>,
11
+ "ref"
12
+ > &
13
+ ReactMarkdownProps & {
14
+ ref?: React.Ref<HTMLInputElement>;
15
+ node?: MarkdownNode;
16
+ };
17
+
18
+ export const MemoInputBlock = memo(
19
+ ({ type, checked, className, onChange, ref, ...props }: InputBlockProps) => {
20
+ const inputRef = React.useRef<HTMLInputElement>(null);
21
+ React.useImperativeHandle(ref, () => inputRef.current!);
22
+
23
+ if (type !== "checkbox") {
24
+ return (
25
+ <input
26
+ ref={inputRef}
27
+ type={type}
28
+ checked={checked}
29
+ className={className}
30
+ {...props}
31
+ />
32
+ );
33
+ }
34
+
35
+ const handleCheckedChange = (isChecked: boolean) => {
36
+ onChange?.({
37
+ target: { type: "checkbox", checked: isChecked },
38
+ } as React.ChangeEvent<HTMLInputElement>);
39
+ };
40
+
41
+ return (
42
+ <div className="s-inline-flex s-items-center">
43
+ <Checkbox
44
+ ref={inputRef as React.Ref<HTMLButtonElement>}
45
+ size="xs"
46
+ checked={checked}
47
+ className="s-translate-y-[3px]"
48
+ onCheckedChange={handleCheckedChange}
49
+ />
50
+ </div>
51
+ );
52
+ },
53
+ (prev, next) =>
54
+ sameNodePosition(prev.node, next.node) &&
55
+ prev.type === next.type &&
56
+ prev.checked === next.checked &&
57
+ prev.className === next.className
58
+ );
59
+
60
+ MemoInputBlock.displayName = "InputBlock";
@@ -0,0 +1,36 @@
1
+ import React, { memo } from "react";
2
+
3
+ import { sameNodePosition } from "@sparkle/components/markdown/utils";
4
+ import { cn } from "@sparkle/lib/utils";
5
+
6
+ import { MarkdownNode } from "./types";
7
+
8
+ interface LinkBlockProps {
9
+ href?: string;
10
+ children: React.ReactNode;
11
+ node?: MarkdownNode;
12
+ }
13
+
14
+ export const MemoLinkBlock = memo(
15
+ ({ href, children }: LinkBlockProps) => {
16
+ return (
17
+ <a
18
+ href={href}
19
+ target="_blank"
20
+ rel="noopener noreferrer"
21
+ className={cn(
22
+ "s-break-all s-font-semibold s-transition-all s-duration-200 s-ease-in-out hover:s-underline",
23
+ "s-text-highlight dark:s-text-highlight-night",
24
+ "hover:s-text-highlight-400 dark:hover:s-text-highlight-400-night",
25
+ "active:s-text-highlight-dark dark:active:s-text-highlight-dark-night"
26
+ )}
27
+ >
28
+ {children}
29
+ </a>
30
+ );
31
+ },
32
+ (prev, next) =>
33
+ sameNodePosition(prev.node, next.node) && prev.href === next.href
34
+ );
35
+
36
+ MemoLinkBlock.displayName = "LinkBlock";
@@ -1,21 +1,36 @@
1
1
  import { cva } from "class-variance-authority";
2
- import React from "react";
2
+ import React, { memo } 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
+
6
14
  export const ulBlockVariants = cva(["s-list-disc s-pb-2 s-pl-6"]);
7
15
 
8
16
  interface UlBlockProps {
9
17
  children: React.ReactNode;
10
18
  textColor: string;
11
19
  textSize: string;
20
+ node?: MarkdownNode;
12
21
  }
13
22
 
14
- export function UlBlock({ children, textColor, textSize }: UlBlockProps) {
15
- return (
16
- <ul className={cn(ulBlockVariants(), textColor, textSize)}>{children}</ul>
17
- );
18
- }
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";
19
34
 
20
35
  export const olBlockVariants = cva(["s-list-decimal s-pb-2 s-pl-6"]);
21
36
 
@@ -24,20 +39,24 @@ interface OlBlockProps {
24
39
  start?: number;
25
40
  textColor: string;
26
41
  textSize: string;
42
+ node?: MarkdownNode;
27
43
  }
28
44
 
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
- }
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";
41
60
 
42
61
  export const liBlockVariants = cva(["s-break-words"]);
43
62
 
@@ -46,17 +65,21 @@ interface LiBlockProps {
46
65
  className?: string;
47
66
  textColor: string;
48
67
  textSize: string;
68
+ node?: MarkdownNode;
49
69
  }
50
70
 
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
- }
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";