markstream-react 0.0.56-beta.2 → 0.0.56-beta.4

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 CHANGED
@@ -128,7 +128,8 @@ export default function Page() {
128
128
  | Feature | Package |
129
129
  | --- | --- |
130
130
  | Shiki code blocks | `stream-markdown` |
131
- | Monaco editor code blocks | `stream-monaco` |
131
+ | Enhanced code blocks (recommended) | `stream-diffs` |
132
+ | Monaco editor code blocks | `stream-monaco` (fallback) |
132
133
  | Mermaid diagrams | `mermaid` |
133
134
  | KaTeX math | `katex` |
134
135
  | D2 diagrams | `@terrastruct/d2` |
@@ -140,6 +141,51 @@ KaTeX still needs its CSS in your app when math rendering is enabled:
140
141
  import 'katex/dist/katex.min.css'
141
142
  ```
142
143
 
144
+ ## Enhanced Code Blocks
145
+
146
+ Code blocks use a dual-runtime loader across all Markstream packages: `stream-diffs` is preferred (smaller, no `monaco-editor`), `stream-monaco` is the automatic fallback, and a plain `<pre>` is rendered when neither is installed.
147
+
148
+ Install the recommended runtime:
149
+
150
+ ```bash
151
+ pnpm add stream-diffs
152
+ # or, to keep the legacy Monaco surface as the fallback:
153
+ pnpm add stream-monaco
154
+ ```
155
+
156
+ `CodeBlockNode` renders a single code block with the header, toolbar, and a `stream-diffs` File / FileDiff surface. Use it directly for one-off blocks, or let `MarkdownRender` resolve it automatically for code blocks in your Markdown:
157
+
158
+ ```tsx
159
+ import type { CodeBlockMonacoOptions } from 'markstream-react'
160
+ import { CodeBlockNode } from 'markstream-react'
161
+
162
+ const node = {
163
+ type: 'code_block',
164
+ language: 'ts',
165
+ code: 'const answer = 42',
166
+ raw: 'const answer = 42',
167
+ }
168
+
169
+ // fontSize / lineHeight / tabSize also drive the streaming <pre> fallback so
170
+ // the enhanced surface swaps in without a visual jump.
171
+ const monacoOptions: CodeBlockMonacoOptions = {
172
+ fontSize: 14,
173
+ lineHeight: 21,
174
+ tabSize: 4,
175
+ fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace',
176
+ wordWrap: 'off',
177
+ theme: 'vitesse-dark',
178
+ renderSideBySide: true,
179
+ MAX_HEIGHT: 640,
180
+ }
181
+
182
+ export function CodeBlock() {
183
+ return <CodeBlockNode node={node} monacoOptions={monacoOptions} isDark />
184
+ }
185
+ ```
186
+
187
+ Component-level options: `isDark` / `darkTheme` / `lightTheme` for theming, `showLineNumbers`, `showHeader`, and `stream` / `loading` for streaming states. `monacoOptions` also covers diff blocks (`renderSideBySide`, `diffHunkActionsOnHover`, `onDiffHunkAction`, `diffHideUnchangedRegions`).
188
+
143
189
  ## Tailwind
144
190
 
145
191
  Non-Tailwind projects should import the precompiled CSS: