44 lines
1.7 KiB
JavaScript
44 lines
1.7 KiB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
|
|
import { Fragment } from 'react';
|
|
/**
|
|
* Generic, server-side block renderer.
|
|
*
|
|
* Iterates a document's blocks and renders each via the client's component
|
|
* map. Unknown blocks are skipped (null), never thrown. Block-specific logic is
|
|
* delegated to the client's optional `enhanceProps` — the plugin itself is
|
|
* block-agnostic.
|
|
*
|
|
* The client owns components and block schemas (they pass `components` and
|
|
* define blocks in their config); the plugin owns only the iteration and
|
|
* wiring. No wrapper markup is added — spacing/layout belong to the client's
|
|
* components.
|
|
*
|
|
* Nested blocks: a block that needs to render child blocks should render its
|
|
* own <RenderBlocks> and import the registry itself, rather than receiving the
|
|
* component map as a prop. Passing the map as a prop breaks React Server
|
|
* Components — functions (client components) can't cross the server→client
|
|
* boundary via props.
|
|
*/ export function RenderBlocks({ blocks, components, enhanceProps }) {
|
|
if (!blocks || !Array.isArray(blocks) || blocks.length === 0) {
|
|
return null;
|
|
}
|
|
return /*#__PURE__*/ _jsx(Fragment, {
|
|
children: blocks.map((block, index)=>{
|
|
const Component = components[block.blockType];
|
|
if (!Component) {
|
|
return null;
|
|
}
|
|
const extra = enhanceProps ? enhanceProps({
|
|
allBlocks: blocks,
|
|
block,
|
|
index
|
|
}) : {};
|
|
return /*#__PURE__*/ _jsx(Component, {
|
|
...block,
|
|
...extra
|
|
}, index);
|
|
})
|
|
});
|
|
} //# sourceMappingURL=RenderBlocks.js.map
|
|
|
|
//# sourceMappingURL=RenderBlocks.js.map
|