@dust-tt/sparkle 0.4.20 → 0.4.22

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 (32) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/esm/components/markdown/BlockquoteBlock.d.ts +3 -1
  3. package/dist/esm/components/markdown/BlockquoteBlock.d.ts.map +1 -1
  4. package/dist/esm/components/markdown/BlockquoteBlock.js +9 -5
  5. package/dist/esm/components/markdown/BlockquoteBlock.js.map +1 -1
  6. package/dist/esm/components/markdown/ContentBlockWrapper.d.ts +1 -1
  7. package/dist/esm/components/markdown/ContentBlockWrapper.d.ts.map +1 -1
  8. package/dist/esm/components/markdown/ContentBlockWrapper.js +2 -2
  9. package/dist/esm/components/markdown/ContentBlockWrapper.js.map +1 -1
  10. package/dist/esm/components/markdown/Markdown.d.ts +3 -1
  11. package/dist/esm/components/markdown/Markdown.d.ts.map +1 -1
  12. package/dist/esm/components/markdown/Markdown.js +12 -6
  13. package/dist/esm/components/markdown/Markdown.js.map +1 -1
  14. package/dist/esm/components/markdown/ParagraphBlock.d.ts +5 -2
  15. package/dist/esm/components/markdown/ParagraphBlock.d.ts.map +1 -1
  16. package/dist/esm/components/markdown/ParagraphBlock.js +10 -4
  17. package/dist/esm/components/markdown/ParagraphBlock.js.map +1 -1
  18. package/dist/esm/components/markdown/styles.d.ts +4 -1
  19. package/dist/esm/components/markdown/styles.d.ts.map +1 -1
  20. package/dist/esm/components/markdown/utils.d.ts +5 -0
  21. package/dist/esm/components/markdown/utils.d.ts.map +1 -1
  22. package/dist/esm/components/markdown/utils.js +9 -0
  23. package/dist/esm/components/markdown/utils.js.map +1 -1
  24. package/dist/esm/stories/Markdown.stories.d.ts +2 -0
  25. package/dist/esm/stories/Markdown.stories.d.ts.map +1 -1
  26. package/dist/sparkle.css +4 -4
  27. package/package.json +1 -1
  28. package/src/components/markdown/BlockquoteBlock.tsx +10 -4
  29. package/src/components/markdown/ContentBlockWrapper.tsx +28 -26
  30. package/src/components/markdown/Markdown.tsx +17 -4
  31. package/src/components/markdown/ParagraphBlock.tsx +22 -5
  32. package/src/components/markdown/utils.ts +10 -0
@@ -3,24 +3,41 @@ import React from "react";
3
3
 
4
4
  import { cn } from "@sparkle/lib";
5
5
 
6
- export const paragraphBlockVariants = cva([
7
- "s-whitespace-pre-wrap s-break-words s-font-normal first:s-pt-0 last:s-pb-0",
8
- "s-py-1 @md:s-py-2 @md:s-leading-7",
9
- ]);
6
+ export const paragraphBlockVariants = cva(
7
+ [
8
+ "s-whitespace-pre-wrap s-break-words s-font-normal first:s-pt-0 last:s-pb-0",
9
+ ],
10
+ {
11
+ variants: {
12
+ compactSpacing: {
13
+ true: ["s-py-0"],
14
+ false: ["s-py-1 @md:s-py-2 @md:s-leading-7"],
15
+ },
16
+ },
17
+ }
18
+ );
10
19
 
11
20
  interface ParagraphBlockProps {
12
21
  children: React.ReactNode;
13
22
  textColor: string;
14
23
  textSize: string;
24
+ compactSpacing?: boolean;
15
25
  }
16
26
 
17
27
  export function ParagraphBlock({
18
28
  children,
19
29
  textColor,
20
30
  textSize,
31
+ compactSpacing = false,
21
32
  }: ParagraphBlockProps) {
22
33
  return (
23
- <div className={cn(paragraphBlockVariants(), textSize, textColor)}>
34
+ <div
35
+ className={cn(
36
+ paragraphBlockVariants({ compactSpacing }),
37
+ textSize,
38
+ textColor
39
+ )}
40
+ >
24
41
  {children}
25
42
  </div>
26
43
  );
@@ -40,6 +40,16 @@ export function detectLanguage(children: React.ReactNode) {
40
40
  return "text";
41
41
  }
42
42
 
43
+ /**
44
+ * Converts consecutive newlines (\n\n) into hard breaks to preserve line spacing.
45
+ * Inserts an empty line with a non-breaking space to create visual spacing.
46
+ */
47
+ export function preserveLineBreaks(content: string): string {
48
+ // Replace \n\n with \n&nbsp;\n\n to insert an empty line with content
49
+ // This creates visual spacing between paragraphs
50
+ return content.replace(/\n\n\n\n/g, "\n\n&nbsp;\n\n");
51
+ }
52
+
43
53
  /**
44
54
  * Preprocesses content to escape dollar signs that are likely NOT inlione LaTeX math. This helps
45
55
  * prevent false positives when enabling single $ math rendering.