@stream-mdx/react 0.3.0 → 0.5.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +14 -4
  2. package/README.md +65 -14
  3. package/dist/components/bottom-stick-scroll-area.cjs +344 -0
  4. package/dist/components/bottom-stick-scroll-area.d.cts +36 -0
  5. package/dist/components/bottom-stick-scroll-area.d.ts +36 -0
  6. package/dist/components/bottom-stick-scroll-area.mjs +320 -0
  7. package/dist/components/index.cjs +511 -176
  8. package/dist/components/index.d.cts +3 -1
  9. package/dist/components/index.d.ts +3 -1
  10. package/dist/components/index.mjs +358 -26
  11. package/dist/{index-D7px9jug.d.cts → index-BVhp_pcF.d.ts} +4 -1
  12. package/dist/{index-D7px9jug.d.ts → index-EaeouYp2.d.cts} +4 -1
  13. package/dist/index.cjs +2146 -1145
  14. package/dist/index.d.cts +6 -4
  15. package/dist/index.d.ts +6 -4
  16. package/dist/index.mjs +3835 -2836
  17. package/dist/mdx-client.cjs +1 -1
  18. package/dist/mdx-client.mjs +1 -1
  19. package/dist/mdx-coordinator.cjs +28 -7
  20. package/dist/mdx-coordinator.d.cts +2 -2
  21. package/dist/mdx-coordinator.d.ts +2 -2
  22. package/dist/mdx-coordinator.mjs +28 -7
  23. package/dist/renderer/node-views.cjs +273 -24
  24. package/dist/renderer/node-views.d.cts +3 -1
  25. package/dist/renderer/node-views.d.ts +3 -1
  26. package/dist/renderer/node-views.mjs +274 -25
  27. package/dist/renderer/patch-batching.cjs +2 -0
  28. package/dist/renderer/patch-batching.d.cts +1 -1
  29. package/dist/renderer/patch-batching.d.ts +1 -1
  30. package/dist/renderer/patch-batching.mjs +2 -1
  31. package/dist/renderer/patch-commit-scheduler.cjs +82 -30
  32. package/dist/renderer/patch-commit-scheduler.d.cts +15 -3
  33. package/dist/renderer/patch-commit-scheduler.d.ts +15 -3
  34. package/dist/renderer/patch-commit-scheduler.mjs +84 -30
  35. package/dist/renderer/store.cjs +382 -36
  36. package/dist/renderer/store.d.cts +3 -0
  37. package/dist/renderer/store.d.ts +3 -0
  38. package/dist/renderer/store.mjs +382 -36
  39. package/dist/renderer.cjs +3386 -2727
  40. package/dist/renderer.d.cts +15 -12
  41. package/dist/renderer.d.ts +15 -12
  42. package/dist/renderer.mjs +3410 -2751
  43. package/dist/server.cjs +4842 -0
  44. package/dist/server.d.cts +254 -0
  45. package/dist/server.d.ts +254 -0
  46. package/dist/server.mjs +4824 -0
  47. package/dist/{streaming-markdown-Dp1IDgMT.d.ts → streaming-markdown-CEI9eDZm.d.ts} +3 -1
  48. package/dist/{streaming-markdown-DSC4L0xR.d.cts → streaming-markdown-DRisClXb.d.cts} +3 -1
  49. package/dist/streaming-markdown.cjs +3476 -2794
  50. package/dist/streaming-markdown.d.cts +4 -2
  51. package/dist/streaming-markdown.d.ts +4 -2
  52. package/dist/streaming-markdown.mjs +3436 -2754
  53. package/dist/utils/inline-html.d.cts +3 -1
  54. package/dist/utils/inline-html.d.ts +3 -1
  55. package/package.json +19 -3
  56. package/shadcn/README.md +28 -0
  57. package/shadcn/bottom-stick-scroll-area.tsx +358 -0
@@ -0,0 +1,254 @@
1
+ import { InlineNode, TokenLineV1, CompiledMdxModule, InlineHtmlDescriptor, FormatAnticipationConfig, CodeHighlightingMode, CodeHighlightOutputMode, Block, Patch, CoalescingMetrics } from '@stream-mdx/core';
2
+ import React from 'react';
3
+
4
+ type GenericComponent = React.ComponentType<any>;
5
+ interface TableElements {
6
+ Table: GenericComponent;
7
+ Thead: GenericComponent;
8
+ Tbody: GenericComponent;
9
+ Tr: GenericComponent;
10
+ Th: GenericComponent;
11
+ Td: GenericComponent;
12
+ }
13
+ type HtmlElements = Record<string, GenericComponent>;
14
+ type InlineHtmlRenderer = (descriptor: InlineHtmlDescriptor, context: {
15
+ key?: React.Key;
16
+ defaultRender: () => React.ReactElement | null;
17
+ }) => React.ReactElement | null;
18
+ type InlineHtmlRendererMap = Record<string, InlineHtmlRenderer>;
19
+ interface BlockComponents {
20
+ paragraph: React.FC<{
21
+ inlines: InlineNode[];
22
+ raw?: string;
23
+ meta?: Record<string, unknown>;
24
+ children?: React.ReactNode;
25
+ }>;
26
+ heading: React.FC<{
27
+ level: 1 | 2 | 3 | 4 | 5 | 6;
28
+ inlines: InlineNode[];
29
+ text?: string;
30
+ meta?: Record<string, unknown>;
31
+ }>;
32
+ code: React.FC<{
33
+ html: string;
34
+ meta?: Record<string, unknown>;
35
+ lines?: ReadonlyArray<{
36
+ id: string;
37
+ index: number;
38
+ text: string;
39
+ html?: string | null;
40
+ tokens?: TokenLineV1 | null;
41
+ }>;
42
+ lang?: string;
43
+ preAttrs?: Record<string, string>;
44
+ codeAttrs?: Record<string, string>;
45
+ }>;
46
+ blockquote: React.FC<{
47
+ inlines: InlineNode[];
48
+ renderedContent?: React.ReactNode;
49
+ }>;
50
+ list: React.FC<{
51
+ ordered: boolean;
52
+ items: InlineNode[][];
53
+ }>;
54
+ html: React.FC<{
55
+ __trustedHtml: TrustedHTML | string;
56
+ elements?: Record<string, GenericComponent>;
57
+ }>;
58
+ mdx: React.FC<{
59
+ compiledRef?: {
60
+ id: string;
61
+ };
62
+ compiledModule?: CompiledMdxModule | null;
63
+ status?: "pending" | "compiled" | "error";
64
+ errorMessage?: string;
65
+ raw?: string;
66
+ }>;
67
+ hr: React.FC<React.HTMLAttributes<HTMLHRElement>>;
68
+ table: React.FC<{
69
+ header?: InlineNode[][];
70
+ rows: InlineNode[][][];
71
+ align?: Array<"left" | "center" | "right" | null>;
72
+ elements?: Partial<TableElements>;
73
+ }>;
74
+ [k: string]: GenericComponent;
75
+ }
76
+ type InlineComponents = Record<string, GenericComponent> & {
77
+ text: React.FC<{
78
+ text: string;
79
+ }>;
80
+ strong: React.FC<{
81
+ children: React.ReactNode;
82
+ }>;
83
+ em: React.FC<{
84
+ children: React.ReactNode;
85
+ }>;
86
+ strike?: React.FC<{
87
+ children: React.ReactNode;
88
+ }>;
89
+ code: React.FC<{
90
+ text: string;
91
+ }>;
92
+ link: React.FC<{
93
+ href?: string;
94
+ title?: string;
95
+ children: React.ReactNode;
96
+ }>;
97
+ image: React.FC<{
98
+ src: string;
99
+ alt?: string;
100
+ title?: string;
101
+ }>;
102
+ br: React.FC<Record<string, never>>;
103
+ };
104
+ interface RendererConfig {
105
+ themes?: {
106
+ light: string;
107
+ dark: string;
108
+ };
109
+ highlight?: {
110
+ browserEngine?: "js" | "wasm";
111
+ serverEngine?: "wasm";
112
+ langs?: string[];
113
+ };
114
+ sanitization?: {
115
+ schemaId?: string;
116
+ };
117
+ mdx?: {
118
+ enabled?: boolean;
119
+ compileEndpoint?: string;
120
+ compileStrategy?: "server" | "worker";
121
+ components?: Record<string, GenericComponent>;
122
+ };
123
+ plugins?: {
124
+ footnotes?: boolean;
125
+ html?: boolean;
126
+ mdx?: boolean;
127
+ tables?: boolean;
128
+ callouts?: boolean;
129
+ math?: boolean;
130
+ formatAnticipation?: FormatAnticipationConfig;
131
+ codeHighlighting?: CodeHighlightingMode;
132
+ outputMode?: CodeHighlightOutputMode;
133
+ liveCodeHighlighting?: boolean;
134
+ liveTokenization?: boolean;
135
+ emitHighlightTokens?: boolean;
136
+ emitDiffBlocks?: boolean;
137
+ };
138
+ performance?: {
139
+ frameBudgetMs?: number;
140
+ flushTimeoutMs?: number;
141
+ maxBatchesPerFlush?: number;
142
+ maxLowPriorityBatchesPerFlush?: number;
143
+ lowPriorityFrameBudgetMs?: number;
144
+ urgentQueueThreshold?: number;
145
+ batch?: "rAF" | "microtask" | "timeout";
146
+ historyLimit?: number;
147
+ startupMicrotaskFlushes?: number;
148
+ adaptiveBudgeting?: boolean;
149
+ };
150
+ }
151
+
152
+ /**
153
+ * Component registry that allows customization
154
+ */
155
+ declare class ComponentRegistry {
156
+ private blockComponents;
157
+ private inlineComponents;
158
+ private htmlElements;
159
+ private tableElements;
160
+ private blockComponentMapCache;
161
+ private inlineComponentMapCache;
162
+ constructor(blockComponents?: Partial<BlockComponents>, inlineComponents?: Partial<InlineComponents>);
163
+ /**
164
+ * Update block components
165
+ */
166
+ setBlockComponents(components: Partial<BlockComponents>): void;
167
+ /**
168
+ * Update inline components
169
+ */
170
+ setInlineComponents(components: Partial<InlineComponents>): void;
171
+ /** Update HTML element mapping for html blocks */
172
+ setHtmlElements(map: Partial<HtmlElements>): void;
173
+ /** Update table element mapping for table blocks */
174
+ setTableElements(map: Partial<TableElements>): void;
175
+ /**
176
+ * Get block component
177
+ */
178
+ getBlockComponent(type: string): React.ComponentType<Record<string, unknown>>;
179
+ /**
180
+ * Get inline components
181
+ */
182
+ getInlineComponents(): InlineComponents;
183
+ getBlockComponentMap(): BlockComponents;
184
+ getInlineComponentMap(): InlineComponents;
185
+ getTableElements(): TableElements;
186
+ /**
187
+ * Render a block
188
+ */
189
+ renderBlock(block: Block): React.ReactElement;
190
+ /**
191
+ * Get props for a block based on its type
192
+ */
193
+ private getBlockProps;
194
+ /**
195
+ * Extract heading level from raw markdown
196
+ */
197
+ private extractHeadingLevel;
198
+ }
199
+
200
+ interface NodeRecord {
201
+ id: string;
202
+ type: string;
203
+ parentId: string | null;
204
+ children: string[];
205
+ props: Record<string, unknown>;
206
+ meta?: Record<string, unknown>;
207
+ range?: {
208
+ from: number;
209
+ to: number;
210
+ };
211
+ version: number;
212
+ blockEpoch: number;
213
+ block?: Block;
214
+ }
215
+ interface ApplyPatchesOptions {
216
+ coalesced?: boolean;
217
+ metrics?: CoalescingMetrics | null;
218
+ captureMetrics?: boolean;
219
+ allowEmpty?: boolean;
220
+ }
221
+ interface RendererStore {
222
+ reset(blocks: Block[]): void;
223
+ applyPatches(patches: Patch[], options?: ApplyPatchesOptions): Set<string>;
224
+ getBlocks(): ReadonlyArray<Block>;
225
+ getVersion(): number;
226
+ getNode(id: string): NodeRecord | undefined;
227
+ getNodeWithVersion(id: string): {
228
+ version: number;
229
+ node?: NodeRecord;
230
+ };
231
+ getChildren(id: string): ReadonlyArray<string>;
232
+ getChildrenWithVersion(id: string): {
233
+ version: number;
234
+ children: ReadonlyArray<string>;
235
+ };
236
+ getInvariantViolations(): string[];
237
+ getDebugCounters(): Readonly<Record<string, number>>;
238
+ subscribe(listener: () => void): () => void;
239
+ getLastCoalescingMetrics(): CoalescingMetrics | null;
240
+ }
241
+ declare function createRendererStore(initialBlocks?: Block[]): RendererStore;
242
+
243
+ /**
244
+ * React component for rendering markdown blocks
245
+ */
246
+ declare const MarkdownBlocksRenderer: React.NamedExoticComponent<{
247
+ blocks: ReadonlyArray<Block>;
248
+ componentRegistry: ComponentRegistry;
249
+ className?: string;
250
+ style?: React.CSSProperties;
251
+ store?: ReturnType<typeof createRendererStore>;
252
+ }>;
253
+
254
+ export { type BlockComponents, ComponentRegistry, type HtmlElements, type InlineComponents, type InlineHtmlRenderer, type InlineHtmlRendererMap, MarkdownBlocksRenderer, type RendererConfig, type TableElements, createRendererStore };
@@ -0,0 +1,254 @@
1
+ import { InlineNode, TokenLineV1, CompiledMdxModule, InlineHtmlDescriptor, FormatAnticipationConfig, CodeHighlightingMode, CodeHighlightOutputMode, Block, Patch, CoalescingMetrics } from '@stream-mdx/core';
2
+ import React from 'react';
3
+
4
+ type GenericComponent = React.ComponentType<any>;
5
+ interface TableElements {
6
+ Table: GenericComponent;
7
+ Thead: GenericComponent;
8
+ Tbody: GenericComponent;
9
+ Tr: GenericComponent;
10
+ Th: GenericComponent;
11
+ Td: GenericComponent;
12
+ }
13
+ type HtmlElements = Record<string, GenericComponent>;
14
+ type InlineHtmlRenderer = (descriptor: InlineHtmlDescriptor, context: {
15
+ key?: React.Key;
16
+ defaultRender: () => React.ReactElement | null;
17
+ }) => React.ReactElement | null;
18
+ type InlineHtmlRendererMap = Record<string, InlineHtmlRenderer>;
19
+ interface BlockComponents {
20
+ paragraph: React.FC<{
21
+ inlines: InlineNode[];
22
+ raw?: string;
23
+ meta?: Record<string, unknown>;
24
+ children?: React.ReactNode;
25
+ }>;
26
+ heading: React.FC<{
27
+ level: 1 | 2 | 3 | 4 | 5 | 6;
28
+ inlines: InlineNode[];
29
+ text?: string;
30
+ meta?: Record<string, unknown>;
31
+ }>;
32
+ code: React.FC<{
33
+ html: string;
34
+ meta?: Record<string, unknown>;
35
+ lines?: ReadonlyArray<{
36
+ id: string;
37
+ index: number;
38
+ text: string;
39
+ html?: string | null;
40
+ tokens?: TokenLineV1 | null;
41
+ }>;
42
+ lang?: string;
43
+ preAttrs?: Record<string, string>;
44
+ codeAttrs?: Record<string, string>;
45
+ }>;
46
+ blockquote: React.FC<{
47
+ inlines: InlineNode[];
48
+ renderedContent?: React.ReactNode;
49
+ }>;
50
+ list: React.FC<{
51
+ ordered: boolean;
52
+ items: InlineNode[][];
53
+ }>;
54
+ html: React.FC<{
55
+ __trustedHtml: TrustedHTML | string;
56
+ elements?: Record<string, GenericComponent>;
57
+ }>;
58
+ mdx: React.FC<{
59
+ compiledRef?: {
60
+ id: string;
61
+ };
62
+ compiledModule?: CompiledMdxModule | null;
63
+ status?: "pending" | "compiled" | "error";
64
+ errorMessage?: string;
65
+ raw?: string;
66
+ }>;
67
+ hr: React.FC<React.HTMLAttributes<HTMLHRElement>>;
68
+ table: React.FC<{
69
+ header?: InlineNode[][];
70
+ rows: InlineNode[][][];
71
+ align?: Array<"left" | "center" | "right" | null>;
72
+ elements?: Partial<TableElements>;
73
+ }>;
74
+ [k: string]: GenericComponent;
75
+ }
76
+ type InlineComponents = Record<string, GenericComponent> & {
77
+ text: React.FC<{
78
+ text: string;
79
+ }>;
80
+ strong: React.FC<{
81
+ children: React.ReactNode;
82
+ }>;
83
+ em: React.FC<{
84
+ children: React.ReactNode;
85
+ }>;
86
+ strike?: React.FC<{
87
+ children: React.ReactNode;
88
+ }>;
89
+ code: React.FC<{
90
+ text: string;
91
+ }>;
92
+ link: React.FC<{
93
+ href?: string;
94
+ title?: string;
95
+ children: React.ReactNode;
96
+ }>;
97
+ image: React.FC<{
98
+ src: string;
99
+ alt?: string;
100
+ title?: string;
101
+ }>;
102
+ br: React.FC<Record<string, never>>;
103
+ };
104
+ interface RendererConfig {
105
+ themes?: {
106
+ light: string;
107
+ dark: string;
108
+ };
109
+ highlight?: {
110
+ browserEngine?: "js" | "wasm";
111
+ serverEngine?: "wasm";
112
+ langs?: string[];
113
+ };
114
+ sanitization?: {
115
+ schemaId?: string;
116
+ };
117
+ mdx?: {
118
+ enabled?: boolean;
119
+ compileEndpoint?: string;
120
+ compileStrategy?: "server" | "worker";
121
+ components?: Record<string, GenericComponent>;
122
+ };
123
+ plugins?: {
124
+ footnotes?: boolean;
125
+ html?: boolean;
126
+ mdx?: boolean;
127
+ tables?: boolean;
128
+ callouts?: boolean;
129
+ math?: boolean;
130
+ formatAnticipation?: FormatAnticipationConfig;
131
+ codeHighlighting?: CodeHighlightingMode;
132
+ outputMode?: CodeHighlightOutputMode;
133
+ liveCodeHighlighting?: boolean;
134
+ liveTokenization?: boolean;
135
+ emitHighlightTokens?: boolean;
136
+ emitDiffBlocks?: boolean;
137
+ };
138
+ performance?: {
139
+ frameBudgetMs?: number;
140
+ flushTimeoutMs?: number;
141
+ maxBatchesPerFlush?: number;
142
+ maxLowPriorityBatchesPerFlush?: number;
143
+ lowPriorityFrameBudgetMs?: number;
144
+ urgentQueueThreshold?: number;
145
+ batch?: "rAF" | "microtask" | "timeout";
146
+ historyLimit?: number;
147
+ startupMicrotaskFlushes?: number;
148
+ adaptiveBudgeting?: boolean;
149
+ };
150
+ }
151
+
152
+ /**
153
+ * Component registry that allows customization
154
+ */
155
+ declare class ComponentRegistry {
156
+ private blockComponents;
157
+ private inlineComponents;
158
+ private htmlElements;
159
+ private tableElements;
160
+ private blockComponentMapCache;
161
+ private inlineComponentMapCache;
162
+ constructor(blockComponents?: Partial<BlockComponents>, inlineComponents?: Partial<InlineComponents>);
163
+ /**
164
+ * Update block components
165
+ */
166
+ setBlockComponents(components: Partial<BlockComponents>): void;
167
+ /**
168
+ * Update inline components
169
+ */
170
+ setInlineComponents(components: Partial<InlineComponents>): void;
171
+ /** Update HTML element mapping for html blocks */
172
+ setHtmlElements(map: Partial<HtmlElements>): void;
173
+ /** Update table element mapping for table blocks */
174
+ setTableElements(map: Partial<TableElements>): void;
175
+ /**
176
+ * Get block component
177
+ */
178
+ getBlockComponent(type: string): React.ComponentType<Record<string, unknown>>;
179
+ /**
180
+ * Get inline components
181
+ */
182
+ getInlineComponents(): InlineComponents;
183
+ getBlockComponentMap(): BlockComponents;
184
+ getInlineComponentMap(): InlineComponents;
185
+ getTableElements(): TableElements;
186
+ /**
187
+ * Render a block
188
+ */
189
+ renderBlock(block: Block): React.ReactElement;
190
+ /**
191
+ * Get props for a block based on its type
192
+ */
193
+ private getBlockProps;
194
+ /**
195
+ * Extract heading level from raw markdown
196
+ */
197
+ private extractHeadingLevel;
198
+ }
199
+
200
+ interface NodeRecord {
201
+ id: string;
202
+ type: string;
203
+ parentId: string | null;
204
+ children: string[];
205
+ props: Record<string, unknown>;
206
+ meta?: Record<string, unknown>;
207
+ range?: {
208
+ from: number;
209
+ to: number;
210
+ };
211
+ version: number;
212
+ blockEpoch: number;
213
+ block?: Block;
214
+ }
215
+ interface ApplyPatchesOptions {
216
+ coalesced?: boolean;
217
+ metrics?: CoalescingMetrics | null;
218
+ captureMetrics?: boolean;
219
+ allowEmpty?: boolean;
220
+ }
221
+ interface RendererStore {
222
+ reset(blocks: Block[]): void;
223
+ applyPatches(patches: Patch[], options?: ApplyPatchesOptions): Set<string>;
224
+ getBlocks(): ReadonlyArray<Block>;
225
+ getVersion(): number;
226
+ getNode(id: string): NodeRecord | undefined;
227
+ getNodeWithVersion(id: string): {
228
+ version: number;
229
+ node?: NodeRecord;
230
+ };
231
+ getChildren(id: string): ReadonlyArray<string>;
232
+ getChildrenWithVersion(id: string): {
233
+ version: number;
234
+ children: ReadonlyArray<string>;
235
+ };
236
+ getInvariantViolations(): string[];
237
+ getDebugCounters(): Readonly<Record<string, number>>;
238
+ subscribe(listener: () => void): () => void;
239
+ getLastCoalescingMetrics(): CoalescingMetrics | null;
240
+ }
241
+ declare function createRendererStore(initialBlocks?: Block[]): RendererStore;
242
+
243
+ /**
244
+ * React component for rendering markdown blocks
245
+ */
246
+ declare const MarkdownBlocksRenderer: React.NamedExoticComponent<{
247
+ blocks: ReadonlyArray<Block>;
248
+ componentRegistry: ComponentRegistry;
249
+ className?: string;
250
+ style?: React.CSSProperties;
251
+ store?: ReturnType<typeof createRendererStore>;
252
+ }>;
253
+
254
+ export { type BlockComponents, ComponentRegistry, type HtmlElements, type InlineComponents, type InlineHtmlRenderer, type InlineHtmlRendererMap, MarkdownBlocksRenderer, type RendererConfig, type TableElements, createRendererStore };