@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
@@ -2,7 +2,6 @@
2
2
  import React, { useMemo } from "react";
3
3
  import type { Components } from "react-markdown";
4
4
  import ReactMarkdown from "react-markdown";
5
- import type { ReactMarkdownProps } from "react-markdown/lib/ast-to-react";
6
5
  import type { PluggableList } from "react-markdown/lib/react-markdown";
7
6
  import rehypeKatex from "rehype-katex";
8
7
  import remarkDirective from "remark-directive";
@@ -10,31 +9,43 @@ import remarkGfm from "remark-gfm";
10
9
  import remarkMath from "remark-math";
11
10
  import { visit } from "unist-util-visit";
12
11
 
13
- import { Checkbox, Chip } from "@sparkle/components";
14
- import { BlockquoteBlock } from "@sparkle/components/markdown/BlockquoteBlock";
15
- import { CodeBlockWithExtendedSupport } from "@sparkle/components/markdown/CodeBlockWithExtendedSupport";
16
- import { LiBlock, OlBlock, UlBlock } from "@sparkle/components/markdown/List";
12
+ import { Chip } from "@sparkle/components";
13
+ import { MemoBlockquoteBlock } from "@sparkle/components/markdown/BlockquoteBlock";
14
+ import { MemoCodeBlockWithExtendedSupport } from "@sparkle/components/markdown/CodeBlockWithExtendedSupport";
15
+ import {
16
+ markdownHeaderClasses,
17
+ MemoH1Block,
18
+ MemoH2Block,
19
+ MemoH3Block,
20
+ MemoH4Block,
21
+ MemoH5Block,
22
+ MemoH6Block,
23
+ } from "@sparkle/components/markdown/HeaderBlocks";
24
+ import { MemoInputBlock } from "@sparkle/components/markdown/InputBlock";
25
+ import { MemoLinkBlock } from "@sparkle/components/markdown/LinkBlock";
26
+ import {
27
+ MemoLiBlock,
28
+ MemoOlBlock,
29
+ MemoUlBlock,
30
+ } from "@sparkle/components/markdown/List";
17
31
  import { MarkdownContentContext } from "@sparkle/components/markdown/MarkdownContentContext";
18
- import { ParagraphBlock } from "@sparkle/components/markdown/ParagraphBlock";
19
- import { PreBlock } from "@sparkle/components/markdown/PreBlock";
32
+ import { MemoParagraphBlock } from "@sparkle/components/markdown/ParagraphBlock";
33
+ import { MemoPreBlock } from "@sparkle/components/markdown/PreBlock";
20
34
  import {
21
- TableBlock,
22
- TableBodyBlock,
23
- TableDataBlock,
24
- TableHeadBlock,
25
- TableHeaderBlock,
35
+ MemoTableBlock,
36
+ MemoTableBodyBlock,
37
+ MemoTableDataBlock,
38
+ MemoTableHeadBlock,
39
+ MemoTableHeaderBlock,
26
40
  } from "@sparkle/components/markdown/TableBlock";
41
+ import {
42
+ MemoHorizontalRuleBlock,
43
+ MemoStrongBlock,
44
+ } from "@sparkle/components/markdown/TextFormattingBlocks";
27
45
  import { sanitizeContent } from "@sparkle/components/markdown/utils";
28
46
  import { cn } from "@sparkle/lib/utils";
29
47
 
30
- export const markdownHeaderClasses = {
31
- h1: "s-heading-2xl",
32
- h2: "s-heading-xl",
33
- h3: "s-heading-lg",
34
- h4: "s-text-base s-font-semibold",
35
- h5: "s-text-sm s-font-semibold",
36
- h6: "s-text-sm s-font-regular s-italic",
37
- };
48
+ import { useAnimatedText } from "./useAnimatedText";
38
49
 
39
50
  const sizes = {
40
51
  p: "s-copy-sm @sm:s-text-base @sm:s-leading-7",
@@ -56,6 +67,7 @@ function showUnsupportedDirective() {
56
67
  export function Markdown({
57
68
  content,
58
69
  isStreaming = false,
70
+ shouldHaveStreamingAnimation = false,
59
71
  textColor = "s-text-foreground dark:s-text-foreground-night",
60
72
  forcedTextSize,
61
73
  isLastMessage = false,
@@ -64,6 +76,7 @@ export function Markdown({
64
76
  }: {
65
77
  content: string;
66
78
  isStreaming?: boolean;
79
+ shouldHaveStreamingAnimation?: boolean;
67
80
  textColor?: string;
68
81
  isLastMessage?: boolean;
69
82
  forcedTextSize?: string;
@@ -72,6 +85,11 @@ export function Markdown({
72
85
  }) {
73
86
  const processedContent = useMemo(() => sanitizeContent(content), [content]);
74
87
 
88
+ const markdownContent = useAnimatedText(
89
+ processedContent,
90
+ isStreaming && shouldHaveStreamingAnimation
91
+ );
92
+
75
93
  // Note on re-renderings. A lot of effort has been put into preventing rerendering across markdown
76
94
  // AST parsing rounds (happening at each token being streamed).
77
95
  //
@@ -89,123 +107,113 @@ export function Markdown({
89
107
  // Memoize markdown components to avoid unnecessary re-renders that disrupt text selection
90
108
  const markdownComponents: Components = useMemo(() => {
91
109
  return {
92
- pre: ({ children }) => <PreBlock>{children}</PreBlock>,
93
- a: LinkBlock,
94
- ul: ({ children }) => (
95
- <UlBlock
110
+ pre: ({ children, node }) => (
111
+ <MemoPreBlock node={node}>{children}</MemoPreBlock>
112
+ ),
113
+ a: MemoLinkBlock,
114
+ ul: ({ children, node }) => (
115
+ <MemoUlBlock
96
116
  textSize={forcedTextSize ? forcedTextSize : sizes.p}
97
117
  textColor={textColor}
118
+ node={node}
98
119
  >
99
120
  {children}
100
- </UlBlock>
121
+ </MemoUlBlock>
101
122
  ),
102
- ol: ({ children, start }) => (
103
- <OlBlock
123
+ ol: ({ children, start, node }) => (
124
+ <MemoOlBlock
104
125
  start={start}
105
126
  textColor={textColor}
106
127
  textSize={forcedTextSize ? forcedTextSize : sizes.p}
128
+ node={node}
107
129
  >
108
130
  {children}
109
- </OlBlock>
131
+ </MemoOlBlock>
110
132
  ),
111
- li: ({ children }) => (
112
- <LiBlock
133
+ li: ({ children, node }) => (
134
+ <MemoLiBlock
113
135
  textColor={textColor}
114
136
  textSize={forcedTextSize ? forcedTextSize : sizes.p}
137
+ node={node}
115
138
  >
116
139
  {children}
117
- </LiBlock>
140
+ </MemoLiBlock>
118
141
  ),
119
- p: ({ children }) => (
120
- <ParagraphBlock
142
+ p: ({ children, node }) => (
143
+ <MemoParagraphBlock
121
144
  textColor={textColor}
122
145
  textSize={forcedTextSize ? forcedTextSize : sizes.p}
146
+ node={node}
123
147
  >
124
148
  {children}
125
- </ParagraphBlock>
149
+ </MemoParagraphBlock>
126
150
  ),
127
- table: TableBlock,
128
- thead: TableHeadBlock,
129
- tbody: TableBodyBlock,
130
- th: TableHeaderBlock,
131
- td: TableDataBlock,
132
- h1: ({ children }) => (
133
- <h1
134
- className={cn(
135
- "s-pb-2 s-pt-4",
136
- forcedTextSize ? forcedTextSize : sizes.h1,
137
- textColor
138
- )}
151
+ table: MemoTableBlock,
152
+ thead: MemoTableHeadBlock,
153
+ tbody: MemoTableBodyBlock,
154
+ th: MemoTableHeaderBlock,
155
+ td: MemoTableDataBlock,
156
+ h1: ({ children, node }) => (
157
+ <MemoH1Block
158
+ textColor={textColor}
159
+ forcedTextSize={forcedTextSize}
160
+ node={node}
139
161
  >
140
162
  {children}
141
- </h1>
163
+ </MemoH1Block>
142
164
  ),
143
- h2: ({ children }) => (
144
- <h2
145
- className={cn(
146
- "s-pb-2 s-pt-4",
147
- forcedTextSize ? forcedTextSize : sizes.h2,
148
- textColor
149
- )}
165
+ h2: ({ children, node }) => (
166
+ <MemoH2Block
167
+ textColor={textColor}
168
+ forcedTextSize={forcedTextSize}
169
+ node={node}
150
170
  >
151
171
  {children}
152
- </h2>
172
+ </MemoH2Block>
153
173
  ),
154
- h3: ({ children }) => (
155
- <h3
156
- className={cn(
157
- "s-pb-2 s-pt-4",
158
- forcedTextSize ? forcedTextSize : sizes.h3,
159
- textColor
160
- )}
174
+ h3: ({ children, node }) => (
175
+ <MemoH3Block
176
+ textColor={textColor}
177
+ forcedTextSize={forcedTextSize}
178
+ node={node}
161
179
  >
162
180
  {children}
163
- </h3>
181
+ </MemoH3Block>
164
182
  ),
165
- h4: ({ children }) => (
166
- <h4
167
- className={cn(
168
- "s-pb-2 s-pt-3",
169
- forcedTextSize ? forcedTextSize : sizes.h4,
170
- textColor
171
- )}
183
+ h4: ({ children, node }) => (
184
+ <MemoH4Block
185
+ textColor={textColor}
186
+ forcedTextSize={forcedTextSize}
187
+ node={node}
172
188
  >
173
189
  {children}
174
- </h4>
190
+ </MemoH4Block>
175
191
  ),
176
- h5: ({ children }) => (
177
- <h5
178
- className={cn(
179
- "s-pb-1.5 s-pt-2.5",
180
- forcedTextSize ? forcedTextSize : sizes.h5,
181
- textColor
182
- )}
192
+ h5: ({ children, node }) => (
193
+ <MemoH5Block
194
+ textColor={textColor}
195
+ forcedTextSize={forcedTextSize}
196
+ node={node}
183
197
  >
184
198
  {children}
185
- </h5>
199
+ </MemoH5Block>
186
200
  ),
187
- h6: ({ children }) => (
188
- <h6
189
- className={cn(
190
- "s-pb-1.5 s-pt-2.5",
191
- forcedTextSize ? forcedTextSize : sizes.h6,
192
- textColor
193
- )}
201
+ h6: ({ children, node }) => (
202
+ <MemoH6Block
203
+ textColor={textColor}
204
+ forcedTextSize={forcedTextSize}
205
+ node={node}
194
206
  >
195
207
  {children}
196
- </h6>
197
- ),
198
- strong: ({ children }) => (
199
- <strong className="s-font-semibold s-text-foreground dark:s-text-foreground-night">
200
- {children}
201
- </strong>
208
+ </MemoH6Block>
202
209
  ),
203
- input: Input,
204
- blockquote: BlockquoteBlock,
205
- hr: () => (
206
- <div className="s-my-6 s-border-b s-border-primary-150 dark:s-border-primary-150-night" />
210
+ strong: ({ children, node }) => (
211
+ <MemoStrongBlock node={node}>{children}</MemoStrongBlock>
207
212
  ),
208
- code: CodeBlockWithExtendedSupport,
213
+ input: MemoInputBlock,
214
+ blockquote: MemoBlockquoteBlock,
215
+ hr: MemoHorizontalRuleBlock,
216
+ code: MemoCodeBlockWithExtendedSupport,
209
217
  ...additionalMarkdownComponents,
210
218
  };
211
219
  }, [textColor, additionalMarkdownComponents]);
@@ -225,7 +233,7 @@ export function Markdown({
225
233
 
226
234
  try {
227
235
  return (
228
- <div className={cn("s-w-full", isStreaming ? "s-blinking-cursor" : "")}>
236
+ <div className={cn("s-w-full")}>
229
237
  <MarkdownContentContext.Provider
230
238
  value={{
231
239
  content: processedContent,
@@ -239,14 +247,14 @@ export function Markdown({
239
247
  remarkPlugins={markdownPlugins}
240
248
  rehypePlugins={rehypePlugins}
241
249
  >
242
- {processedContent}
250
+ {markdownContent}
243
251
  </ReactMarkdown>
244
252
  </MarkdownContentContext.Provider>
245
253
  </div>
246
254
  );
247
255
  } catch (error) {
248
256
  return (
249
- <div className={cn("s-w-full", isStreaming ? "s-blinking-cursor" : "")}>
257
+ <div className={cn("s-w-full")}>
250
258
  <Chip color="warning">
251
259
  There was an error parsing this markdown content
252
260
  </Chip>
@@ -255,74 +263,3 @@ export function Markdown({
255
263
  );
256
264
  }
257
265
  }
258
-
259
- function LinkBlock({
260
- href,
261
- children,
262
- }: {
263
- href?: string;
264
- children: React.ReactNode;
265
- }) {
266
- return (
267
- <a
268
- href={href}
269
- target="_blank"
270
- rel="noopener noreferrer"
271
- className={cn(
272
- "s-break-all s-font-semibold s-transition-all s-duration-200 s-ease-in-out hover:s-underline",
273
- "s-text-highlight dark:s-text-highlight-night",
274
- "hover:s-text-highlight-400 dark:hover:s-text-highlight-400-night",
275
- "active:s-text-highlight-dark dark:active:s-text-highlight-dark-night"
276
- )}
277
- >
278
- {children}
279
- </a>
280
- );
281
- }
282
-
283
- type InputProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, "ref"> &
284
- ReactMarkdownProps & {
285
- ref?: React.Ref<HTMLInputElement>;
286
- };
287
-
288
- function Input({
289
- type,
290
- checked,
291
- className,
292
- onChange,
293
- ref,
294
- ...props
295
- }: InputProps) {
296
- const inputRef = React.useRef<HTMLInputElement>(null);
297
- React.useImperativeHandle(ref, () => inputRef.current!);
298
-
299
- if (type !== "checkbox") {
300
- return (
301
- <input
302
- ref={inputRef}
303
- type={type}
304
- checked={checked}
305
- className={className}
306
- {...props}
307
- />
308
- );
309
- }
310
-
311
- const handleCheckedChange = (isChecked: boolean) => {
312
- onChange?.({
313
- target: { type: "checkbox", checked: isChecked },
314
- } as React.ChangeEvent<HTMLInputElement>);
315
- };
316
-
317
- return (
318
- <div className="s-inline-flex s-items-center">
319
- <Checkbox
320
- ref={inputRef as React.Ref<HTMLButtonElement>}
321
- size="xs"
322
- checked={checked}
323
- className="s-translate-y-[3px]"
324
- onCheckedChange={handleCheckedChange}
325
- />
326
- </div>
327
- );
328
- }
@@ -1,8 +1,11 @@
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 { MarkdownNode } from "./types";
7
+ import { sameNodePosition, sameTextStyling } from "./utils";
8
+
6
9
  export const paragraphBlockVariants = cva([
7
10
  "s-whitespace-pre-wrap s-break-words s-font-normal first:s-pt-0 last:s-pb-0",
8
11
  "s-py-1 @md:s-py-2 @md:s-leading-7",
@@ -12,16 +15,19 @@ interface ParagraphBlockProps {
12
15
  children: React.ReactNode;
13
16
  textColor: string;
14
17
  textSize: string;
18
+ node?: MarkdownNode;
15
19
  }
16
20
 
17
- export function ParagraphBlock({
18
- children,
19
- textColor,
20
- textSize,
21
- }: ParagraphBlockProps) {
22
- return (
23
- <div className={cn(paragraphBlockVariants(), textSize, textColor)}>
24
- {children}
25
- </div>
26
- );
27
- }
21
+ export const MemoParagraphBlock = memo(
22
+ ({ children, textColor, textSize }: ParagraphBlockProps) => {
23
+ return (
24
+ <div className={cn(paragraphBlockVariants(), textSize, textColor)}>
25
+ {children}
26
+ </div>
27
+ );
28
+ },
29
+ (prev, next) =>
30
+ sameNodePosition(prev.node, next.node) && sameTextStyling(prev, next)
31
+ );
32
+
33
+ MemoParagraphBlock.displayName = "ParagraphBlock";
@@ -1,5 +1,8 @@
1
1
  import { cva } from "class-variance-authority";
2
- import React from "react";
2
+ import React, { memo } from "react";
3
+
4
+ import { MarkdownNode } from "./types";
5
+ import { sameNodePosition } from "./utils";
3
6
 
4
7
  export const preBlockVariants = cva(
5
8
  [
@@ -18,25 +21,32 @@ export const preBlockVariants = cva(
18
21
  interface PreBlockProps {
19
22
  children: React.ReactNode;
20
23
  variant?: "surface";
24
+ node?: MarkdownNode;
21
25
  }
22
26
 
23
- export function PreBlock({ children, variant = "surface" }: PreBlockProps) {
24
- const validChildrenContent =
25
- Array.isArray(children) && children[0]
26
- ? children[0].props.children[0]
27
- : null;
28
-
29
- let fallbackData: string | null = null;
30
- if (!validChildrenContent) {
31
- fallbackData =
27
+ export const MemoPreBlock = memo(
28
+ ({ children, variant = "surface" }: PreBlockProps) => {
29
+ const validChildrenContent =
32
30
  Array.isArray(children) && children[0]
33
- ? children[0].props?.node?.data?.meta
31
+ ? children[0].props.children[0]
34
32
  : null;
35
- }
36
33
 
37
- return (
38
- <pre className={preBlockVariants({ variant })}>
39
- {validChildrenContent ? children : fallbackData || children}
40
- </pre>
41
- );
42
- }
34
+ let fallbackData: string | null = null;
35
+ if (!validChildrenContent) {
36
+ fallbackData =
37
+ Array.isArray(children) && children[0]
38
+ ? children[0].props?.node?.data?.meta
39
+ : null;
40
+ }
41
+
42
+ return (
43
+ <pre className={preBlockVariants({ variant })}>
44
+ {validChildrenContent ? children : fallbackData || children}
45
+ </pre>
46
+ );
47
+ },
48
+ (prev, next) =>
49
+ sameNodePosition(prev.node, next.node) && prev.variant === next.variant
50
+ );
51
+
52
+ MemoPreBlock.displayName = "PreBlock";