-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support React server components via @measured/puck/rsc bundle
Provide a Render component via a separate `rsc` bundle
- Loading branch information
Showing
8 changed files
with
108 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
"use client"; | ||
|
||
import { | ||
ReactElement, | ||
ReactNode, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { CSSProperties } from "react"; | ||
import { rootDroppableId } from "../../lib/root-droppable-id"; | ||
import { Config, Data } from "../../types/Config"; | ||
import { setupZone } from "../../lib/setup-zone"; | ||
|
||
type DropZoneRenderProps = { | ||
zone: string; | ||
data: Data; | ||
config: Config; | ||
areaId?: string; | ||
style?: CSSProperties; | ||
}; | ||
|
||
function DropZoneRender({ | ||
zone, | ||
data, | ||
areaId = "root", | ||
config, | ||
}: DropZoneRenderProps) { | ||
let zoneCompound = rootDroppableId; | ||
let content = data?.content || []; | ||
|
||
if (!data || !config) { | ||
return null; | ||
} | ||
|
||
if (areaId && zone && zone !== rootDroppableId) { | ||
zoneCompound = `${areaId}:${zone}`; | ||
content = setupZone(data, zoneCompound).zones[zoneCompound]; | ||
} | ||
|
||
return ( | ||
<> | ||
{content.map((item) => { | ||
const Component = config.components[item.type]; | ||
|
||
if (Component) { | ||
return ( | ||
<Component.render | ||
key={item.props.id} | ||
{...item.props} | ||
puck={{ | ||
renderDropZone: ({ zone }: { zone: string }) => ( | ||
<DropZoneRender | ||
zone={zone} | ||
data={data} | ||
areaId={item.props.id} | ||
config={config} | ||
/> | ||
), | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
return null; | ||
})} | ||
</> | ||
); | ||
} | ||
|
||
export function Render({ config, data }: { config: Config; data: Data }) { | ||
if (config.root?.render) { | ||
// DEPRECATED | ||
const rootProps = data.root.props || data.root; | ||
|
||
const title = rootProps.title || ""; | ||
|
||
return ( | ||
<config.root.render | ||
{...rootProps} | ||
puck={{ | ||
renderDropZone: ({ zone }: { zone: string }) => ( | ||
<DropZoneRender zone={zone} data={data} config={config} /> | ||
), | ||
}} | ||
title={title} | ||
editMode={false} | ||
id={"puck-root"} | ||
> | ||
<DropZoneRender config={config} data={data} zone={rootDroppableId} /> | ||
</config.root.render> | ||
); | ||
} | ||
|
||
return <DropZoneRender config={config} data={data} zone={rootDroppableId} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Render } from "./components/ServerRender"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters