@brett_lamy/docstream 1.0.0 → 1.1.0
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/README.md +102 -0
- package/package.json +5 -1
- package/src/demo/DemoViewer.tsx +705 -0
- package/src/demo/context.ts +13 -0
- package/src/demo/glob.ts +188 -0
- package/src/demo/index.ts +15 -0
- package/src/demo/markdown.ts +102 -0
- package/src/demo/types.ts +53 -0
- package/src/docs/CollapsibleCode.tsx +54 -0
- package/src/docs/DocsRenderer.tsx +147 -36
- package/src/docs/PageActions.tsx +219 -0
- package/src/docs/controls.tsx +138 -0
- package/src/docs/copy.tsx +82 -0
- package/src/docs/tabs-sync.ts +61 -0
- package/src/gitbook/ast.ts +35 -0
- package/src/gitbook/index.ts +1 -1
- package/src/gitbook/parse.ts +48 -1
- package/src/gitbook/serialize.ts +16 -1
- package/src/index.ts +35 -2
- package/src/playground/PlaygroundStreamdown.tsx +14 -3
- package/src/playground/ReactCodePreview.tsx +8 -37
- package/src/streamdown.tsx +21 -3
- package/src/styles.css +917 -1
package/src/index.ts
CHANGED
|
@@ -1,7 +1,40 @@
|
|
|
1
1
|
export { PlaygroundStreamdown as GitbookStreamdown } from "./playground/PlaygroundStreamdown"
|
|
2
2
|
export type { PlaygroundStreamdownProps as GitbookStreamdownProps } from "./playground/PlaygroundStreamdown"
|
|
3
3
|
export { DocsRenderer, MarkdownContent } from "./docs/DocsRenderer"
|
|
4
|
-
export type { LivePreviewProps, LivePreviewRenderer, SourceReferenceRenderer } from "./docs/DocsRenderer"
|
|
4
|
+
export type { DocRenderOptions, LivePreviewProps, LivePreviewRenderer, SourceReferenceRenderer } from "./docs/DocsRenderer"
|
|
5
|
+
export { DocPageActions } from "./docs/PageActions"
|
|
6
|
+
export type { DocPageAction, DocPageActionsOptions, DocPageActionsProps } from "./docs/PageActions"
|
|
7
|
+
export { CollapsibleCode } from "./docs/CollapsibleCode"
|
|
8
|
+
export type { CollapsibleCodeProps } from "./docs/CollapsibleCode"
|
|
9
|
+
export { CopyButton, copyText } from "./docs/copy"
|
|
10
|
+
export { getSyncedTab, setSyncedTab, useSyncedTab } from "./docs/tabs-sync"
|
|
11
|
+
export {
|
|
12
|
+
DemoBlock,
|
|
13
|
+
DemoFullscreen,
|
|
14
|
+
DemoViewer,
|
|
15
|
+
DocstreamDemoContext,
|
|
16
|
+
createGlobDemoResolver,
|
|
17
|
+
defaultDemoMarkdown,
|
|
18
|
+
demoComponentFrom,
|
|
19
|
+
demoFromSearch,
|
|
20
|
+
demoHref,
|
|
21
|
+
resolveDemosToMarkdown,
|
|
22
|
+
sortDemoFiles,
|
|
23
|
+
useDemoResolver,
|
|
24
|
+
} from "./demo"
|
|
25
|
+
export type {
|
|
26
|
+
DemoComponent,
|
|
27
|
+
DemoComponentProps,
|
|
28
|
+
DemoFile,
|
|
29
|
+
DemoFullscreenProps,
|
|
30
|
+
DemoMeta,
|
|
31
|
+
DemoResolver,
|
|
32
|
+
DemoVariant,
|
|
33
|
+
DemoViewerProps,
|
|
34
|
+
GlobDemoResolverOptions,
|
|
35
|
+
ResolveDemosOptions,
|
|
36
|
+
ResolvedDemo,
|
|
37
|
+
} from "./demo"
|
|
5
38
|
export { CitationSources, DocstreamRefContext, InlineReference } from "./docs/reference"
|
|
6
39
|
export type { CitationPreview, CitationPreviewResolver, DocstreamRefContextValue } from "./docs/reference"
|
|
7
40
|
export { ReplayEmbed, ReplayPreview } from "./replay"
|
|
@@ -45,7 +78,7 @@ export type {
|
|
|
45
78
|
SourceProvenance,
|
|
46
79
|
SourceReferenceClient,
|
|
47
80
|
} from "./source"
|
|
48
|
-
export { parseMarkdown, parseBlocks, trimPartialInlineToken } from "./gitbook/parse"
|
|
81
|
+
export { parseDemoVariants, parseMarkdown, parseBlocks, trimPartialInlineToken } from "./gitbook/parse"
|
|
49
82
|
export { serializeBlocks, serializeMarkdown } from "./gitbook/serialize"
|
|
50
83
|
export {
|
|
51
84
|
footnoteDefinitions,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useMemo } from "react"
|
|
2
2
|
|
|
3
|
-
import { DocsRenderer, type LivePreviewRenderer } from "../docs/DocsRenderer"
|
|
3
|
+
import { DocsRenderer, type DocRenderOptions, type LivePreviewRenderer, type SourceReferenceRenderer } from "../docs/DocsRenderer"
|
|
4
4
|
import { parseMarkdown, trimPartialInlineToken } from "../gitbook/parse"
|
|
5
5
|
import { ReactCodePreview } from "./ReactCodePreview"
|
|
6
6
|
|
|
7
|
-
export interface PlaygroundStreamdownProps {
|
|
7
|
+
export interface PlaygroundStreamdownProps extends DocRenderOptions {
|
|
8
8
|
children?: string
|
|
9
|
+
sourceRenderer?: SourceReferenceRenderer
|
|
9
10
|
className?: string
|
|
10
11
|
isAnimating?: boolean
|
|
11
12
|
isStreaming?: boolean
|
|
@@ -23,6 +24,9 @@ export function PlaygroundStreamdown({
|
|
|
23
24
|
isAnimating,
|
|
24
25
|
isStreaming = false,
|
|
25
26
|
markdown,
|
|
27
|
+
sourceRenderer,
|
|
28
|
+
demoResolver,
|
|
29
|
+
pageActions,
|
|
26
30
|
}: PlaygroundStreamdownProps) {
|
|
27
31
|
const content = markdown ?? children ?? ""
|
|
28
32
|
const doc = useMemo(
|
|
@@ -46,7 +50,14 @@ export function PlaygroundStreamdown({
|
|
|
46
50
|
data-docstream=""
|
|
47
51
|
data-streaming={isStreaming ? "" : undefined}
|
|
48
52
|
>
|
|
49
|
-
<DocsRenderer
|
|
53
|
+
<DocsRenderer
|
|
54
|
+
doc={doc}
|
|
55
|
+
markdown={content}
|
|
56
|
+
liveRenderer={liveRenderer}
|
|
57
|
+
sourceRenderer={sourceRenderer}
|
|
58
|
+
demoResolver={demoResolver}
|
|
59
|
+
pageActions={isStreaming ? false : pageActions}
|
|
60
|
+
/>
|
|
50
61
|
</div>
|
|
51
62
|
)
|
|
52
63
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useEffect,
|
|
2
|
-
import {
|
|
1
|
+
import { useEffect, useMemo, useState, type CSSProperties, type ReactNode } from "react"
|
|
2
|
+
import { CollapsibleCode } from "../docs/CollapsibleCode"
|
|
3
3
|
import {
|
|
4
4
|
createAlmostNodeWorkspace,
|
|
5
5
|
createReactDemoFiles,
|
|
@@ -65,10 +65,6 @@ function frameHeight(height: number | string): CSSProperties {
|
|
|
65
65
|
return { height: typeof height === "number" ? `${height}px` : height }
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
function positiveLineCount(value: number, fallback: number): number {
|
|
69
|
-
return Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback
|
|
70
|
-
}
|
|
71
|
-
|
|
72
68
|
function sourceLanguage(path: string): string | null {
|
|
73
69
|
const extension = path.split(".").pop()?.toLowerCase()
|
|
74
70
|
return extension && extension !== path ? extension : null
|
|
@@ -112,18 +108,11 @@ export function ReactDemo({
|
|
|
112
108
|
const [state, setState] = useState<PreviewState>(inline ? "ready" : autoStart ? "starting" : "idle")
|
|
113
109
|
const [url, setUrl] = useState<string | null>(null)
|
|
114
110
|
const [error, setError] = useState<string | null>(null)
|
|
115
|
-
const [codeExpanded, setCodeExpanded] = useState(false)
|
|
116
|
-
const codePanelId = useId()
|
|
117
111
|
const displayedCodeFile = codeFile ?? entry
|
|
118
112
|
const code = useMemo(
|
|
119
113
|
() => codeProp ?? sourceText(files, displayedCodeFile),
|
|
120
114
|
[codeProp, displayedCodeFile, files],
|
|
121
115
|
)
|
|
122
|
-
const collapsedLines = positiveLineCount(collapsedCodeLines, 3)
|
|
123
|
-
const expandedLines = Math.max(
|
|
124
|
-
collapsedLines,
|
|
125
|
-
positiveLineCount(expandedCodeLines, 30),
|
|
126
|
-
)
|
|
127
116
|
|
|
128
117
|
useEffect(() => {
|
|
129
118
|
if (inline) return
|
|
@@ -228,30 +217,12 @@ export function ReactDemo({
|
|
|
228
217
|
</div>
|
|
229
218
|
)}
|
|
230
219
|
{code !== null ? (
|
|
231
|
-
<
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
} as CSSProperties}
|
|
238
|
-
>
|
|
239
|
-
<HighlightedCode
|
|
240
|
-
code={code}
|
|
241
|
-
language={language ?? sourceLanguage(displayedCodeFile)}
|
|
242
|
-
lineNumbers
|
|
243
|
-
/>
|
|
244
|
-
</pre>
|
|
245
|
-
<button
|
|
246
|
-
type="button"
|
|
247
|
-
className="docs-react-demo-code-toggle"
|
|
248
|
-
aria-controls={codePanelId}
|
|
249
|
-
aria-expanded={codeExpanded}
|
|
250
|
-
onClick={() => setCodeExpanded((value) => !value)}
|
|
251
|
-
>
|
|
252
|
-
{codeExpanded ? "Hide Code" : "View Code"}
|
|
253
|
-
</button>
|
|
254
|
-
</div>
|
|
220
|
+
<CollapsibleCode
|
|
221
|
+
code={code}
|
|
222
|
+
language={language ?? sourceLanguage(displayedCodeFile)}
|
|
223
|
+
collapsedLines={collapsedCodeLines}
|
|
224
|
+
expandedLines={expandedCodeLines}
|
|
225
|
+
/>
|
|
255
226
|
) : null}
|
|
256
227
|
</section>
|
|
257
228
|
)
|
package/src/streamdown.tsx
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { useMemo } from "react"
|
|
2
|
-
import { DocsRenderer } from "./docs/DocsRenderer"
|
|
2
|
+
import { DocsRenderer, type DocRenderOptions, type LivePreviewRenderer, type SourceReferenceRenderer } from "./docs/DocsRenderer"
|
|
3
3
|
import { parseMarkdown, trimPartialInlineToken } from "./gitbook/parse"
|
|
4
4
|
|
|
5
5
|
// Re-exported so markdown-only consumers of ./streamdown can wire chip
|
|
6
6
|
// click handling without importing the heavy root entry.
|
|
7
7
|
export { CitationSources, DocstreamRefContext, InlineReference } from "./docs/reference"
|
|
8
|
+
export { DocPageActions } from "./docs/PageActions"
|
|
9
|
+
export type { DocPageAction, DocPageActionsOptions, DocPageActionsProps } from "./docs/PageActions"
|
|
10
|
+
export type { DocRenderOptions } from "./docs/DocsRenderer"
|
|
11
|
+
export { DocstreamDemoContext, DemoFullscreen, DemoViewer } from "./demo"
|
|
12
|
+
export type { DemoFile, DemoMeta, DemoResolver, DemoVariant } from "./demo"
|
|
8
13
|
export type { CitationPreview, CitationPreviewResolver, DocstreamRefContextValue } from "./docs/reference"
|
|
9
14
|
|
|
10
|
-
export interface GitbookStreamdownProps {
|
|
15
|
+
export interface GitbookStreamdownProps extends DocRenderOptions {
|
|
11
16
|
children?: string
|
|
17
|
+
liveRenderer?: LivePreviewRenderer
|
|
18
|
+
sourceRenderer?: SourceReferenceRenderer
|
|
12
19
|
className?: string
|
|
13
20
|
isAnimating?: boolean
|
|
14
21
|
isStreaming?: boolean
|
|
@@ -21,6 +28,10 @@ export function GitbookStreamdown({
|
|
|
21
28
|
isAnimating,
|
|
22
29
|
isStreaming = false,
|
|
23
30
|
markdown,
|
|
31
|
+
liveRenderer,
|
|
32
|
+
sourceRenderer,
|
|
33
|
+
demoResolver,
|
|
34
|
+
pageActions,
|
|
24
35
|
}: GitbookStreamdownProps) {
|
|
25
36
|
const content = markdown ?? children ?? ""
|
|
26
37
|
const gitbookDoc = useMemo(
|
|
@@ -35,7 +46,14 @@ export function GitbookStreamdown({
|
|
|
35
46
|
data-docstream=""
|
|
36
47
|
data-streaming={isStreaming ? "" : undefined}
|
|
37
48
|
>
|
|
38
|
-
<DocsRenderer
|
|
49
|
+
<DocsRenderer
|
|
50
|
+
doc={gitbookDoc}
|
|
51
|
+
markdown={content}
|
|
52
|
+
liveRenderer={liveRenderer}
|
|
53
|
+
sourceRenderer={sourceRenderer}
|
|
54
|
+
demoResolver={demoResolver}
|
|
55
|
+
pageActions={isStreaming ? false : pageActions}
|
|
56
|
+
/>
|
|
39
57
|
</div>
|
|
40
58
|
)
|
|
41
59
|
}
|