|
1 | 1 | import React from "react"; |
2 | 2 |
|
| 3 | +import { useRenderer } from "../context/RendererContext"; |
| 4 | + |
| 5 | +import { DevWrapper } from "./dev/DevWrapper"; |
3 | 6 | import { ParagraphBlockRenderer } from "./blocks/ParagraphBlockRenderer"; |
4 | 7 | import { HeadingBlockRenderer } from "./blocks/HeadingBlockRenderer"; |
5 | 8 | import { ListItemBlockRenderer } from "./blocks/ListItemBlockRenderer"; |
@@ -56,104 +59,113 @@ interface BlockRendererProps { |
56 | 59 | block: any; |
57 | 60 | depth?: number; |
58 | 61 | components?: BlockComponents; |
59 | | - resolveImageUrl?: (url: string) => Promise<string>; |
60 | 62 | } |
61 | 63 |
|
62 | 64 | export const BlockRenderer: React.FC<BlockRendererProps> = ({ |
63 | 65 | block, |
64 | 66 | depth = 0, |
65 | 67 | components, |
66 | | - resolveImageUrl, |
67 | 68 | }) => { |
| 69 | + const { devMode = false } = useRenderer(); |
68 | 70 | const commonProps = { block, depth, components }; |
69 | 71 |
|
| 72 | + // Helper function to wrap component with DevWrapper if devMode is enabled |
| 73 | + const wrapWithDev = (component: React.ReactElement) => { |
| 74 | + if (devMode) { |
| 75 | + return <DevWrapper block={block}>{component}</DevWrapper>; |
| 76 | + } |
| 77 | + return component; |
| 78 | + }; |
| 79 | + |
70 | 80 | // Paragraph block |
71 | 81 | if (block?.type === "paragraph") { |
72 | 82 | const ParagraphComponent = components?.paragraph || ParagraphBlockRenderer; |
73 | | - return <ParagraphComponent {...commonProps} />; |
| 83 | + return wrapWithDev(<ParagraphComponent {...commonProps} />); |
74 | 84 | } |
75 | 85 |
|
76 | 86 | // Heading blocks |
77 | 87 | if (block?.type === "heading_1") { |
78 | 88 | const HeadingComponent = components?.heading_1 || HeadingBlockRenderer; |
79 | | - return <HeadingComponent {...commonProps} level={1} />; |
| 89 | + return wrapWithDev(<HeadingComponent {...commonProps} level={1} />); |
80 | 90 | } |
81 | 91 | if (block?.type === "heading_2") { |
82 | 92 | const HeadingComponent = components?.heading_2 || HeadingBlockRenderer; |
83 | | - return <HeadingComponent {...commonProps} level={2} />; |
| 93 | + return wrapWithDev(<HeadingComponent {...commonProps} level={2} />); |
84 | 94 | } |
85 | 95 | if (block?.type === "heading_3") { |
86 | 96 | const HeadingComponent = components?.heading_3 || HeadingBlockRenderer; |
87 | | - return <HeadingComponent {...commonProps} level={3} />; |
| 97 | + return wrapWithDev(<HeadingComponent {...commonProps} level={3} />); |
88 | 98 | } |
89 | 99 |
|
90 | 100 | // List item blocks |
91 | 101 | if (block?.type === "bulleted_list_item") { |
92 | 102 | const BulletedListItemComponent = |
93 | 103 | components?.bulleted_list_item || ListItemBlockRenderer; |
94 | | - return <BulletedListItemComponent {...commonProps} type="bulleted" />; |
| 104 | + return wrapWithDev( |
| 105 | + <BulletedListItemComponent {...commonProps} type="bulleted" /> |
| 106 | + ); |
95 | 107 | } |
96 | 108 | if (block?.type === "numbered_list_item") { |
97 | 109 | const NumberedListItemComponent = |
98 | 110 | components?.numbered_list_item || ListItemBlockRenderer; |
99 | | - return <NumberedListItemComponent {...commonProps} type="numbered" />; |
| 111 | + return wrapWithDev( |
| 112 | + <NumberedListItemComponent {...commonProps} type="numbered" /> |
| 113 | + ); |
100 | 114 | } |
101 | 115 |
|
102 | 116 | // Code block |
103 | 117 | if (block?.type === "code") { |
104 | 118 | const CodeComponent = components?.code || CodeBlockRenderer; |
105 | | - return <CodeComponent {...commonProps} />; |
| 119 | + return wrapWithDev(<CodeComponent {...commonProps} />); |
106 | 120 | } |
107 | 121 |
|
108 | 122 | // Image block |
109 | 123 | if (block?.type === "image") { |
110 | 124 | const ImageComponent = components?.image || ImageBlockRenderer; |
111 | | - return ( |
112 | | - <ImageComponent {...commonProps} resolveImageUrl={resolveImageUrl} /> |
113 | | - ); |
| 125 | + return wrapWithDev(<ImageComponent {...commonProps} />); |
114 | 126 | } |
115 | 127 |
|
116 | 128 | // Table blocks |
117 | 129 | if (block?.type === "table") { |
118 | 130 | const TableComponent = components?.table || TableBlockRenderer; |
119 | | - return <TableComponent {...commonProps} />; |
| 131 | + return wrapWithDev(<TableComponent {...commonProps} />); |
120 | 132 | } |
121 | 133 |
|
122 | 134 | // Quote block |
123 | 135 | if (block?.type === "quote") { |
124 | 136 | const QuoteComponent = components?.quote || QuoteBlockRenderer; |
125 | | - return <QuoteComponent {...commonProps} />; |
| 137 | + return wrapWithDev(<QuoteComponent {...commonProps} />); |
126 | 138 | } |
127 | 139 |
|
128 | 140 | // Divider block |
129 | 141 | if (block?.type === "divider") { |
130 | 142 | const DividerComponent = components?.divider || DividerBlockRenderer; |
131 | | - return <DividerComponent {...commonProps} />; |
| 143 | + return wrapWithDev(<DividerComponent {...commonProps} />); |
132 | 144 | } |
133 | 145 |
|
134 | 146 | // To-do block |
135 | 147 | if (block?.type === "to_do") { |
136 | 148 | const ToDoComponent = components?.to_do || ToDoBlockRenderer; |
137 | | - return <ToDoComponent {...commonProps} />; |
| 149 | + return wrapWithDev(<ToDoComponent {...commonProps} />); |
138 | 150 | } |
139 | 151 |
|
140 | 152 | // Toggle block |
141 | 153 | if (block?.type === "toggle") { |
142 | 154 | const ToggleComponent = components?.toggle || ToggleBlockRenderer; |
143 | | - return <ToggleComponent {...commonProps} />; |
| 155 | + return wrapWithDev(<ToggleComponent {...commonProps} />); |
144 | 156 | } |
145 | 157 |
|
146 | 158 | // Column list and column blocks |
147 | 159 | if (block?.type === "column_list") { |
148 | 160 | const ColumnListComponent = |
149 | 161 | components?.column_list || ColumnListBlockRenderer; |
150 | | - return <ColumnListComponent {...commonProps} />; |
| 162 | + return wrapWithDev(<ColumnListComponent {...commonProps} />); |
151 | 163 | } |
152 | 164 |
|
153 | 165 | // Equation block |
154 | 166 | if (block?.type === "equation") { |
155 | 167 | const EquationComponent = components?.equation || EquationBlockRenderer; |
156 | | - return <EquationComponent {...commonProps} />; |
| 168 | + return wrapWithDev(<EquationComponent {...commonProps} />); |
157 | 169 | } |
158 | 170 |
|
159 | 171 | // Fallback for unsupported block types |
|
0 commit comments