@kushagradhawan/kookie-blocks 0.1.16 → 0.1.18
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.
- package/dist/cjs/components/code/code-block.js +1 -1
- package/dist/cjs/components/code/code-block.js.map +2 -2
- package/dist/cjs/components/docs/docs-page-header.d.ts +12 -0
- package/dist/cjs/components/docs/docs-page-header.d.ts.map +1 -0
- package/dist/cjs/components/docs/docs-page-header.js +10 -0
- package/dist/cjs/components/docs/docs-page-header.js.map +7 -0
- package/dist/cjs/components/docs/docs-page.d.ts +28 -0
- package/dist/cjs/components/docs/docs-page.d.ts.map +1 -0
- package/dist/cjs/components/docs/docs-page.js +2 -0
- package/dist/cjs/components/docs/docs-page.js.map +7 -0
- package/dist/cjs/components/docs/docs-shell.d.ts +32 -0
- package/dist/cjs/components/docs/docs-shell.d.ts.map +1 -0
- package/dist/cjs/components/docs/docs-shell.js +2 -0
- package/dist/cjs/components/docs/docs-shell.js.map +7 -0
- package/dist/cjs/components/docs/docs-sidebar.d.ts +33 -0
- package/dist/cjs/components/docs/docs-sidebar.d.ts.map +1 -0
- package/dist/cjs/components/docs/docs-sidebar.js +2 -0
- package/dist/cjs/components/docs/docs-sidebar.js.map +7 -0
- package/dist/cjs/components/docs/index.d.ts +7 -0
- package/dist/cjs/components/docs/index.d.ts.map +1 -0
- package/dist/cjs/components/docs/index.js +2 -0
- package/dist/cjs/components/docs/index.js.map +7 -0
- package/dist/cjs/components/docs/table-of-contents.d.ts +12 -0
- package/dist/cjs/components/docs/table-of-contents.d.ts.map +1 -0
- package/dist/cjs/components/docs/table-of-contents.js +2 -0
- package/dist/cjs/components/docs/table-of-contents.js.map +7 -0
- package/dist/cjs/components/docs/types.d.ts +38 -0
- package/dist/cjs/components/docs/types.d.ts.map +1 -0
- package/dist/cjs/components/docs/types.js +2 -0
- package/dist/cjs/components/docs/types.js.map +7 -0
- package/dist/cjs/components/index.d.ts +1 -0
- package/dist/cjs/components/index.d.ts.map +1 -1
- package/dist/cjs/components/index.js +1 -1
- package/dist/cjs/components/index.js.map +2 -2
- package/dist/cjs/components/markdown/create-markdown-components.d.ts.map +1 -1
- package/dist/cjs/components/markdown/create-markdown-components.js +2 -2
- package/dist/cjs/components/markdown/create-markdown-components.js.map +3 -3
- package/dist/cjs/components/markdown/streaming-markdown.d.ts.map +1 -1
- package/dist/cjs/components/markdown/streaming-markdown.js +1 -1
- package/dist/cjs/components/markdown/streaming-markdown.js.map +3 -3
- package/dist/cjs/components/markdown/types.d.ts +7 -0
- package/dist/cjs/components/markdown/types.d.ts.map +1 -1
- package/dist/cjs/components/markdown/types.js +1 -1
- package/dist/cjs/components/markdown/types.js.map +1 -1
- package/dist/esm/components/code/code-block.js +1 -1
- package/dist/esm/components/code/code-block.js.map +2 -2
- package/dist/esm/components/docs/docs-page-header.d.ts +12 -0
- package/dist/esm/components/docs/docs-page-header.d.ts.map +1 -0
- package/dist/esm/components/docs/docs-page-header.js +10 -0
- package/dist/esm/components/docs/docs-page-header.js.map +7 -0
- package/dist/esm/components/docs/docs-page.d.ts +28 -0
- package/dist/esm/components/docs/docs-page.d.ts.map +1 -0
- package/dist/esm/components/docs/docs-page.js +2 -0
- package/dist/esm/components/docs/docs-page.js.map +7 -0
- package/dist/esm/components/docs/docs-shell.d.ts +32 -0
- package/dist/esm/components/docs/docs-shell.d.ts.map +1 -0
- package/dist/esm/components/docs/docs-shell.js +2 -0
- package/dist/esm/components/docs/docs-shell.js.map +7 -0
- package/dist/esm/components/docs/docs-sidebar.d.ts +33 -0
- package/dist/esm/components/docs/docs-sidebar.d.ts.map +1 -0
- package/dist/esm/components/docs/docs-sidebar.js +2 -0
- package/dist/esm/components/docs/docs-sidebar.js.map +7 -0
- package/dist/esm/components/docs/index.d.ts +7 -0
- package/dist/esm/components/docs/index.d.ts.map +1 -0
- package/dist/esm/components/docs/index.js +2 -0
- package/dist/esm/components/docs/index.js.map +7 -0
- package/dist/esm/components/docs/table-of-contents.d.ts +12 -0
- package/dist/esm/components/docs/table-of-contents.d.ts.map +1 -0
- package/dist/esm/components/docs/table-of-contents.js +2 -0
- package/dist/esm/components/docs/table-of-contents.js.map +7 -0
- package/dist/esm/components/docs/types.d.ts +38 -0
- package/dist/esm/components/docs/types.d.ts.map +1 -0
- package/dist/esm/components/docs/types.js +1 -0
- package/dist/esm/components/docs/types.js.map +7 -0
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.d.ts.map +1 -1
- package/dist/esm/components/index.js +1 -1
- package/dist/esm/components/index.js.map +2 -2
- package/dist/esm/components/markdown/create-markdown-components.d.ts.map +1 -1
- package/dist/esm/components/markdown/create-markdown-components.js +2 -2
- package/dist/esm/components/markdown/create-markdown-components.js.map +3 -3
- package/dist/esm/components/markdown/streaming-markdown.d.ts.map +1 -1
- package/dist/esm/components/markdown/streaming-markdown.js +1 -1
- package/dist/esm/components/markdown/streaming-markdown.js.map +3 -3
- package/dist/esm/components/markdown/types.d.ts +7 -0
- package/dist/esm/components/markdown/types.d.ts.map +1 -1
- package/package.json +5 -1
- package/src/components/code/code-block.tsx +1 -1
- package/src/components/docs/docs-page-header.tsx +92 -0
- package/src/components/docs/docs-page.tsx +99 -0
- package/src/components/docs/docs-shell.tsx +114 -0
- package/src/components/docs/docs-sidebar.tsx +180 -0
- package/src/components/docs/index.ts +16 -0
- package/src/components/docs/table-of-contents.tsx +157 -0
- package/src/components/docs/types.ts +45 -0
- package/src/components/index.ts +1 -0
- package/src/components/markdown/create-markdown-components.tsx +38 -24
- package/src/components/markdown/streaming-markdown.tsx +5 -1
- package/src/components/markdown/types.ts +8 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { type ReactNode } from "react";
|
|
2
2
|
import type { Components } from "react-markdown";
|
|
3
|
-
import { Blockquote, Box, Code, Flex, Heading, Text, Table } from "@kushagradhawan/kookie-ui";
|
|
3
|
+
import { Blockquote, Box, Code, Flex, Heading, Text, Table, Separator } from "@kushagradhawan/kookie-ui";
|
|
4
4
|
import { CodeBlock } from "../code";
|
|
5
5
|
import type { MarkdownComponentOptions, MarkdownChildrenProps } from "./types";
|
|
6
6
|
|
|
@@ -56,44 +56,61 @@ function extractCode(children?: ReactNode): string {
|
|
|
56
56
|
* ```
|
|
57
57
|
*/
|
|
58
58
|
export function createMarkdownComponents(options: MarkdownComponentOptions = {}): Components {
|
|
59
|
-
const { codeBlockCollapsible = false, imageComponent, inlineCodeHighContrast = true } = options;
|
|
59
|
+
const { codeBlockCollapsible = false, imageComponent, inlineCodeHighContrast = true, spacing = "spacious" } = options;
|
|
60
|
+
|
|
61
|
+
// Spacing configuration
|
|
62
|
+
const isCompact = spacing === "compact";
|
|
63
|
+
const headingMargins = {
|
|
64
|
+
h1: { top: isCompact ? "1.5rem" : "3rem", bottom: isCompact ? "1rem" : "1.5rem" },
|
|
65
|
+
h2: { top: isCompact ? "2rem" : "3rem", bottom: isCompact ? "0.375rem" : "0.5rem" },
|
|
66
|
+
h3: { top: isCompact ? "1.5rem" : "2rem", bottom: isCompact ? "0.375rem" : "0.5rem" },
|
|
67
|
+
h4: { top: isCompact ? "0.5rem" : "0.625rem", bottom: isCompact ? "0.25rem" : "0.5rem" },
|
|
68
|
+
h5: { top: isCompact ? "0.375rem" : "0.5rem", bottom: isCompact ? "0.25rem" : "0.5rem" },
|
|
69
|
+
h6: { top: isCompact ? "0.375rem" : "0.5rem", bottom: isCompact ? "0.25rem" : "0.5rem" },
|
|
70
|
+
};
|
|
71
|
+
const listMargin = isCompact ? "0.25rem" : "0.5rem";
|
|
72
|
+
const listItemMargin = isCompact ? "0.125rem" : "0.25rem";
|
|
73
|
+
const codeBlockMargin = isCompact ? "1" : "2";
|
|
74
|
+
const hrMargin = isCompact ? "0.375rem" : "0.5rem";
|
|
75
|
+
const paragraphMargin = isCompact ? "0" : "0.5rem";
|
|
76
|
+
const blockquoteMargin = isCompact ? "0.5rem" : "1rem";
|
|
60
77
|
|
|
61
78
|
return {
|
|
62
79
|
// Headings with consistent visual hierarchy (9-6-5-4-3-2)
|
|
63
80
|
h1: ({ children }: MarkdownChildrenProps) => (
|
|
64
|
-
<Heading size="9" weight="medium" as="h1" style={{ marginTop:
|
|
81
|
+
<Heading size="9" weight="medium" as="h1" style={{ marginTop: headingMargins.h1.top, marginBottom: headingMargins.h1.bottom }}>
|
|
65
82
|
{children}
|
|
66
83
|
</Heading>
|
|
67
84
|
),
|
|
68
85
|
h2: ({ children }: MarkdownChildrenProps) => (
|
|
69
|
-
<Heading weight="medium" size="
|
|
86
|
+
<Heading weight="medium" size="7" as="h2" style={{ marginTop: headingMargins.h2.top, marginBottom: headingMargins.h2.bottom }}>
|
|
70
87
|
{children}
|
|
71
88
|
</Heading>
|
|
72
89
|
),
|
|
73
90
|
h3: ({ children }: MarkdownChildrenProps) => (
|
|
74
|
-
<Heading weight="medium" size="5" as="h3" style={{ marginTop:
|
|
91
|
+
<Heading weight="medium" size="5" as="h3" style={{ marginTop: headingMargins.h3.top, marginBottom: headingMargins.h3.bottom }}>
|
|
75
92
|
{children}
|
|
76
93
|
</Heading>
|
|
77
94
|
),
|
|
78
95
|
h4: ({ children }: MarkdownChildrenProps) => (
|
|
79
|
-
<Heading weight="medium" size="4" as="h4" style={{ marginTop:
|
|
96
|
+
<Heading weight="medium" size="4" as="h4" style={{ marginTop: headingMargins.h4.top, marginBottom: headingMargins.h4.bottom }}>
|
|
80
97
|
{children}
|
|
81
98
|
</Heading>
|
|
82
99
|
),
|
|
83
100
|
h5: ({ children }: MarkdownChildrenProps) => (
|
|
84
|
-
<Heading weight="medium" size="3" as="h5" style={{ marginTop:
|
|
101
|
+
<Heading weight="medium" size="3" as="h5" style={{ marginTop: headingMargins.h5.top, marginBottom: headingMargins.h5.bottom }}>
|
|
85
102
|
{children}
|
|
86
103
|
</Heading>
|
|
87
104
|
),
|
|
88
105
|
h6: ({ children }: MarkdownChildrenProps) => (
|
|
89
|
-
<Heading weight="medium" size="2" as="h6" style={{ marginTop:
|
|
106
|
+
<Heading weight="medium" size="2" as="h6" style={{ marginTop: headingMargins.h6.top, marginBottom: headingMargins.h6.bottom }}>
|
|
90
107
|
{children}
|
|
91
108
|
</Heading>
|
|
92
109
|
),
|
|
93
110
|
|
|
94
111
|
// Paragraph text
|
|
95
112
|
p: ({ children }: MarkdownChildrenProps) => (
|
|
96
|
-
<Text size="3" as="p" style={{ lineHeight: "1.6" }}>
|
|
113
|
+
<Text size="3" as="p" style={{ lineHeight: "1.6", marginTop: paragraphMargin, marginBottom: paragraphMargin }}>
|
|
97
114
|
{children}
|
|
98
115
|
</Text>
|
|
99
116
|
),
|
|
@@ -115,7 +132,7 @@ export function createMarkdownComponents(options: MarkdownComponentOptions = {})
|
|
|
115
132
|
}
|
|
116
133
|
|
|
117
134
|
return (
|
|
118
|
-
<Box my=
|
|
135
|
+
<Box my={codeBlockMargin} style={{ minWidth: 0 }}>
|
|
119
136
|
<CodeBlock code={code} language={extractLanguage(className)} collapsible={codeBlockCollapsible} />
|
|
120
137
|
</Box>
|
|
121
138
|
);
|
|
@@ -123,15 +140,19 @@ export function createMarkdownComponents(options: MarkdownComponentOptions = {})
|
|
|
123
140
|
|
|
124
141
|
// Lists
|
|
125
142
|
ul: ({ children }: MarkdownChildrenProps) => (
|
|
126
|
-
<ul style={{ marginTop:
|
|
143
|
+
<ul style={{ marginTop: listMargin, marginBottom: listMargin, lineHeight: "1.6", paddingLeft: "1.5rem", listStyleType: "disc" }}>{children}</ul>
|
|
127
144
|
),
|
|
128
145
|
ol: ({ children }: MarkdownChildrenProps) => (
|
|
129
|
-
<ol style={{ marginTop:
|
|
146
|
+
<ol style={{ marginTop: listMargin, marginBottom: listMargin, lineHeight: "1.6", paddingLeft: "1.5rem", listStyleType: "decimal" }}>{children}</ol>
|
|
130
147
|
),
|
|
131
|
-
li: ({ children }: MarkdownChildrenProps) => <li style={{ marginBottom:
|
|
148
|
+
li: ({ children }: MarkdownChildrenProps) => <li style={{ marginBottom: listItemMargin, lineHeight: "1.6" }}>{children}</li>,
|
|
132
149
|
|
|
133
150
|
// Blockquote
|
|
134
|
-
blockquote: ({ children }: MarkdownChildrenProps) =>
|
|
151
|
+
blockquote: ({ children }: MarkdownChildrenProps) => (
|
|
152
|
+
<Blockquote size="1" my={blockquoteMargin}>
|
|
153
|
+
{children}
|
|
154
|
+
</Blockquote>
|
|
155
|
+
),
|
|
135
156
|
|
|
136
157
|
// Links
|
|
137
158
|
a: ({ href, children }: { href?: string; children?: ReactNode }) => (
|
|
@@ -150,16 +171,9 @@ export function createMarkdownComponents(options: MarkdownComponentOptions = {})
|
|
|
150
171
|
|
|
151
172
|
// Horizontal rule
|
|
152
173
|
hr: () => (
|
|
153
|
-
<
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
marginTop: "0.5rem",
|
|
157
|
-
marginBottom: "0.5rem",
|
|
158
|
-
height: "1px",
|
|
159
|
-
width: "100%",
|
|
160
|
-
opacity: 0.5,
|
|
161
|
-
}}
|
|
162
|
-
/>
|
|
174
|
+
<Box style={{ marginTop: hrMargin, marginBottom: hrMargin }}>
|
|
175
|
+
<Separator orientation="horizontal" light />
|
|
176
|
+
</Box>
|
|
163
177
|
),
|
|
164
178
|
|
|
165
179
|
// Pre wrapper (pass through to let code handle it)
|
|
@@ -4,12 +4,16 @@ import React, { memo, useMemo, type ReactNode } from "react";
|
|
|
4
4
|
import ReactMarkdown, { type Components } from "react-markdown";
|
|
5
5
|
import remarkGfm from "remark-gfm";
|
|
6
6
|
import rehypeRaw from "rehype-raw";
|
|
7
|
-
import
|
|
7
|
+
import hardenReactMarkdownModule from "harden-react-markdown";
|
|
8
8
|
import { Box, Flex } from "@kushagradhawan/kookie-ui";
|
|
9
9
|
import { createMarkdownComponents } from "./create-markdown-components";
|
|
10
10
|
import { completeUnterminatedMarkdown, parseMarkdownIntoBlocks } from "./utils/markdown-streaming";
|
|
11
11
|
import type { MarkdownComponentOptions } from "./types";
|
|
12
12
|
|
|
13
|
+
// Handle different export formats
|
|
14
|
+
const hardenReactMarkdown =
|
|
15
|
+
typeof hardenReactMarkdownModule === "function" ? hardenReactMarkdownModule : (hardenReactMarkdownModule as any).default || hardenReactMarkdownModule;
|
|
16
|
+
|
|
13
17
|
const HardenedMarkdown = hardenReactMarkdown(ReactMarkdown);
|
|
14
18
|
|
|
15
19
|
const LINK_PREFIXES = ["https://", "http://", "/"];
|
|
@@ -20,6 +20,14 @@ export type MarkdownComponentOptions = {
|
|
|
20
20
|
* @default true
|
|
21
21
|
*/
|
|
22
22
|
inlineCodeHighContrast?: boolean;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Spacing density for markdown elements
|
|
26
|
+
* - "compact": Tighter spacing, ideal for chat/conversational interfaces
|
|
27
|
+
* - "spacious": More breathing room, ideal for documentation/articles
|
|
28
|
+
* @default "spacious"
|
|
29
|
+
*/
|
|
30
|
+
spacing?: "compact" | "spacious";
|
|
23
31
|
};
|
|
24
32
|
|
|
25
33
|
/**
|