11import React from "react" ;
22
3+ import {
4+ Block ,
5+ BlockBase ,
6+ Heading1Block ,
7+ Heading2Block ,
8+ Heading3Block ,
9+ ParagraphBlock ,
10+ BulletedListItemBlock ,
11+ NumberedListItemBlock ,
12+ CodeBlock ,
13+ ImageBlock ,
14+ TableBlock ,
15+ QuoteBlock ,
16+ DividerBlock ,
17+ ToDoBlock ,
18+ ToggleBlock ,
19+ ColumnListBlock ,
20+ EquationBlock ,
21+ } from "@/models/generated" ;
22+
323import { useRenderer } from "../context/RendererContext" ;
424
525import { DevWrapper } from "./dev/DevWrapper" ;
@@ -56,7 +76,7 @@ export type BlockComponents = {
5676} ;
5777
5878interface BlockRendererProps {
59- block : any ;
79+ block : Block ;
6080 depth ?: number ;
6181 components ?: BlockComponents ;
6282}
@@ -80,92 +100,127 @@ export const BlockRenderer: React.FC<BlockRendererProps> = ({
80100 // Paragraph block
81101 if ( block ?. type === "paragraph" ) {
82102 const ParagraphComponent = components ?. paragraph || ParagraphBlockRenderer ;
83- return wrapWithDev ( < ParagraphComponent { ...commonProps } /> ) ;
103+ return wrapWithDev (
104+ < ParagraphComponent { ...commonProps } block = { block as ParagraphBlock } />
105+ ) ;
84106 }
85107
86108 // Heading blocks
87- if ( block ?. type === "heading_1" ) {
109+ if (
110+ block ?. type === "heading_1" ||
111+ block ?. type === "heading_2" ||
112+ block ?. type === "heading_3"
113+ ) {
88114 const HeadingComponent = components ?. heading_1 || HeadingBlockRenderer ;
89- return wrapWithDev ( < HeadingComponent { ...commonProps } level = { 1 } /> ) ;
90- }
91- if ( block ?. type === "heading_2" ) {
92- const HeadingComponent = components ?. heading_2 || HeadingBlockRenderer ;
93- return wrapWithDev ( < HeadingComponent { ...commonProps } level = { 2 } /> ) ;
94- }
95- if ( block ?. type === "heading_3" ) {
96- const HeadingComponent = components ?. heading_3 || HeadingBlockRenderer ;
97- return wrapWithDev ( < HeadingComponent { ...commonProps } level = { 3 } /> ) ;
115+ return wrapWithDev (
116+ < HeadingComponent
117+ { ...commonProps }
118+ block = { block as Heading1Block | Heading2Block | Heading3Block }
119+ />
120+ ) ;
98121 }
122+ // if (block?.type === "heading_2") {
123+ // const HeadingComponent = components?.heading_2 || HeadingBlockRenderer;
124+ // return wrapWithDev(<HeadingComponent {...commonProps} level={2} />);
125+ // }
126+ // if (block?.type === "heading_3") {
127+ // const HeadingComponent = components?.heading_3 || HeadingBlockRenderer;
128+ // return wrapWithDev(<HeadingComponent {...commonProps} level={3} />);
129+ // }
99130
100131 // List item blocks
101132 if ( block ?. type === "bulleted_list_item" ) {
102133 const BulletedListItemComponent =
103134 components ?. bulleted_list_item || ListItemBlockRenderer ;
104135 return wrapWithDev (
105- < BulletedListItemComponent { ...commonProps } type = "bulleted" />
136+ < BulletedListItemComponent
137+ { ...commonProps }
138+ block = { block as BulletedListItemBlock }
139+ />
106140 ) ;
107141 }
108142 if ( block ?. type === "numbered_list_item" ) {
109143 const NumberedListItemComponent =
110144 components ?. numbered_list_item || ListItemBlockRenderer ;
111145 return wrapWithDev (
112- < NumberedListItemComponent { ...commonProps } type = "numbered" />
146+ < NumberedListItemComponent
147+ { ...commonProps }
148+ block = { block as NumberedListItemBlock }
149+ />
113150 ) ;
114151 }
115152
116153 // Code block
117154 if ( block ?. type === "code" ) {
118155 const CodeComponent = components ?. code || CodeBlockRenderer ;
119- return wrapWithDev ( < CodeComponent { ...commonProps } /> ) ;
156+ return wrapWithDev (
157+ < CodeComponent { ...commonProps } block = { block as CodeBlock } />
158+ ) ;
120159 }
121160
122161 // Image block
123162 if ( block ?. type === "image" ) {
124163 const ImageComponent = components ?. image || ImageBlockRenderer ;
125- return wrapWithDev ( < ImageComponent { ...commonProps } /> ) ;
164+ return wrapWithDev (
165+ < ImageComponent { ...commonProps } block = { block as ImageBlock } />
166+ ) ;
126167 }
127168
128169 // Table blocks
129170 if ( block ?. type === "table" ) {
130171 const TableComponent = components ?. table || TableBlockRenderer ;
131- return wrapWithDev ( < TableComponent { ...commonProps } /> ) ;
172+ return wrapWithDev (
173+ < TableComponent { ...commonProps } block = { block as TableBlock } />
174+ ) ;
132175 }
133176
134177 // Quote block
135178 if ( block ?. type === "quote" ) {
136179 const QuoteComponent = components ?. quote || QuoteBlockRenderer ;
137- return wrapWithDev ( < QuoteComponent { ...commonProps } /> ) ;
180+ return wrapWithDev (
181+ < QuoteComponent { ...commonProps } block = { block as QuoteBlock } />
182+ ) ;
138183 }
139184
140185 // Divider block
141186 if ( block ?. type === "divider" ) {
142187 const DividerComponent = components ?. divider || DividerBlockRenderer ;
143- return wrapWithDev ( < DividerComponent { ...commonProps } /> ) ;
188+ return wrapWithDev (
189+ < DividerComponent { ...commonProps } block = { block as DividerBlock } />
190+ ) ;
144191 }
145192
146193 // To-do block
147194 if ( block ?. type === "to_do" ) {
148195 const ToDoComponent = components ?. to_do || ToDoBlockRenderer ;
149- return wrapWithDev ( < ToDoComponent { ...commonProps } /> ) ;
196+ return wrapWithDev (
197+ < ToDoComponent { ...commonProps } block = { block as ToDoBlock } />
198+ ) ;
150199 }
151200
152201 // Toggle block
153202 if ( block ?. type === "toggle" ) {
154203 const ToggleComponent = components ?. toggle || ToggleBlockRenderer ;
155- return wrapWithDev ( < ToggleComponent { ...commonProps } /> ) ;
204+ return wrapWithDev (
205+ < ToggleComponent { ...commonProps } block = { block as ToggleBlock } />
206+ ) ;
156207 }
157208
158209 // Column list and column blocks
159210 if ( block ?. type === "column_list" ) {
160211 const ColumnListComponent =
161212 components ?. column_list || ColumnListBlockRenderer ;
162- return wrapWithDev ( < ColumnListComponent { ...commonProps } /> ) ;
213+ return wrapWithDev (
214+ < ColumnListComponent { ...commonProps } block = { block as ColumnListBlock } />
215+ ) ;
163216 }
164217
165218 // Equation block
166219 if ( block ?. type === "equation" ) {
167220 const EquationComponent = components ?. equation || EquationBlockRenderer ;
168- return wrapWithDev ( < EquationComponent { ...commonProps } /> ) ;
221+ return wrapWithDev (
222+ < EquationComponent { ...commonProps } block = { block as EquationBlock } />
223+ ) ;
169224 }
170225
171226 // Fallback for unsupported block types
0 commit comments