@dust-tt/sparkle 0.2.644 → 0.2.646-rc-1

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 (77) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/esm/components/DataTable.d.ts +3 -6
  3. package/dist/esm/components/DataTable.d.ts.map +1 -1
  4. package/dist/esm/components/DataTable.js +8 -8
  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 +0 -8
  31. package/dist/esm/components/markdown/Markdown.d.ts.map +1 -1
  32. package/dist/esm/components/markdown/Markdown.js +39 -62
  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/utils.d.ts +11 -0
  59. package/dist/esm/components/markdown/utils.d.ts.map +1 -1
  60. package/dist/esm/components/markdown/utils.js +21 -0
  61. package/dist/esm/components/markdown/utils.js.map +1 -1
  62. package/package.json +1 -1
  63. package/src/components/DataTable.tsx +2 -18
  64. package/src/components/markdown/BlockquoteBlock.tsx +36 -29
  65. package/src/components/markdown/CodeBlockWithExtendedSupport.tsx +142 -131
  66. package/src/components/markdown/HeaderBlocks.tsx +160 -0
  67. package/src/components/markdown/InputBlock.tsx +60 -0
  68. package/src/components/markdown/LinkBlock.tsx +36 -0
  69. package/src/components/markdown/List.tsx +53 -30
  70. package/src/components/markdown/Markdown.tsx +97 -169
  71. package/src/components/markdown/ParagraphBlock.tsx +18 -12
  72. package/src/components/markdown/PreBlock.tsx +28 -18
  73. package/src/components/markdown/TableBlock.tsx +125 -95
  74. package/src/components/markdown/TextFormattingBlocks.tsx +31 -0
  75. package/src/components/markdown/index.ts +4 -0
  76. package/src/components/markdown/types.ts +5 -0
  77. package/src/components/markdown/utils.ts +37 -0
@@ -0,0 +1,31 @@
1
+ import React, { memo } from "react";
2
+
3
+ import { sameNodePosition } from "@sparkle/components/markdown/utils";
4
+
5
+ import { MarkdownNode } from "./types";
6
+
7
+ interface StrongBlockProps {
8
+ children: React.ReactNode;
9
+ node?: MarkdownNode;
10
+ }
11
+
12
+ export const MemoStrongBlock = memo(
13
+ ({ children }: StrongBlockProps) => {
14
+ return (
15
+ <strong className="s-font-semibold s-text-foreground dark:s-text-foreground-night">
16
+ {children}
17
+ </strong>
18
+ );
19
+ },
20
+ (prev, next) => sameNodePosition(prev.node, next.node)
21
+ );
22
+
23
+ MemoStrongBlock.displayName = "StrongBlock";
24
+
25
+ export const MemoHorizontalRuleBlock = memo(() => {
26
+ return (
27
+ <div className="s-my-6 s-border-b s-border-primary-150 dark:s-border-primary-150-night" />
28
+ );
29
+ });
30
+
31
+ MemoHorizontalRuleBlock.displayName = "HorizontalRuleBlock";
@@ -1,8 +1,12 @@
1
1
  export * from "./CodeBlock";
2
2
  export * from "./CodeBlockWithExtendedSupport";
3
3
  export * from "./ContentBlockWrapper";
4
+ export * from "./HeaderBlocks";
5
+ export * from "./InputBlock";
6
+ export * from "./LinkBlock";
4
7
  export * from "./Markdown";
5
8
  export * from "./MarkdownContentContext";
6
9
  export * from "./PrettyJsonViewer";
7
10
  export * from "./TableBlock";
11
+ export * from "./TextFormattingBlocks";
8
12
  export * from "./utils";
@@ -0,0 +1,5 @@
1
+ type MarkdownPoint = { line?: number; column?: number };
2
+ type MarkdownPosition = { start?: MarkdownPoint; end?: MarkdownPoint };
3
+ export type MarkdownNode = {
4
+ position?: MarkdownPosition;
5
+ };
@@ -1,3 +1,5 @@
1
+ import { MarkdownNode } from "./types";
2
+
1
3
  export function sanitizeContent(str: string): string {
2
4
  // (1) Add closing backticks if they are missing such that we render a code block or inline
3
5
  // element during streaming.
@@ -39,3 +41,38 @@ export function detectLanguage(children: React.ReactNode) {
39
41
 
40
42
  return "text";
41
43
  }
44
+
45
+ export function sameNodePosition(
46
+ prev?: MarkdownNode,
47
+ next?: MarkdownNode
48
+ ): boolean {
49
+ if (!(prev?.position || next?.position)) {
50
+ return true;
51
+ }
52
+ if (!(prev?.position && next?.position)) {
53
+ return false;
54
+ }
55
+
56
+ const prevStart = prev.position.start;
57
+ const nextStart = next.position.start;
58
+ const prevEnd = prev.position.end;
59
+ const nextEnd = next.position.end;
60
+
61
+ return (
62
+ prevStart?.line === nextStart?.line &&
63
+ prevStart?.column === nextStart?.column &&
64
+ prevEnd?.line === nextEnd?.line &&
65
+ prevEnd?.column === nextEnd?.column
66
+ );
67
+ }
68
+
69
+ export function sameTextStyling(
70
+ prev: { textColor?: string; textSize?: string; forcedTextSize?: string },
71
+ next: { textColor?: string; textSize?: string; forcedTextSize?: string }
72
+ ): boolean {
73
+ return (
74
+ prev.textColor === next.textColor &&
75
+ prev.textSize === next.textSize &&
76
+ prev.forcedTextSize === next.forcedTextSize
77
+ );
78
+ }