UNPKG

@measured/puck

Version:

The open-source visual editor for React

122 lines (119 loc) 3 kB
import { SlotRenderPure, __spreadProps, __spreadValues, init_react_import, migrate, resolveAllData, rootAreaId, rootDroppableId, rootZone, setupZone, transformProps, useSlots, walkTree } from "./chunk-62KOMFGG.mjs"; // bundle/rsc.tsx init_react_import(); // components/ServerRender/index.tsx init_react_import(); import { Fragment, jsx } from "react/jsx-runtime"; function DropZoneRender({ zone, data, areaId = "root", config, metadata = {} }) { let zoneCompound = rootDroppableId; let content = (data == null ? void 0 : data.content) || []; if (!data || !config) { return null; } if (areaId !== rootAreaId && zone !== rootZone) { zoneCompound = `${areaId}:${zone}`; content = setupZone(data, zoneCompound).zones[zoneCompound]; } return /* @__PURE__ */ jsx(Fragment, { children: content.map((item) => { const Component = config.components[item.type]; const props = __spreadProps(__spreadValues({}, item.props), { puck: { renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ jsx( DropZoneRender, { zone: zone2, data, areaId: item.props.id, config, metadata } ), metadata, dragRef: null, isEditing: false } }); const renderItem = __spreadProps(__spreadValues({}, item), { props }); const propsWithSlots = useSlots(config, renderItem, (props2) => /* @__PURE__ */ jsx(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata }))); if (Component) { return /* @__PURE__ */ jsx(Component.render, __spreadValues({}, propsWithSlots), renderItem.props.id); } return null; }) }); } function Render({ config, data, metadata = {} }) { var _a; const rootProps = "props" in data.root ? data.root.props : data.root; const title = rootProps.title || ""; const props = __spreadProps(__spreadValues({}, rootProps), { puck: { renderDropZone: ({ zone }) => /* @__PURE__ */ jsx( DropZoneRender, { zone, data, config, metadata } ), isEditing: false, dragRef: null, metadata }, title, editMode: false, id: "puck-root" }); const propsWithSlots = useSlots(config, { type: "root", props }, (props2) => /* @__PURE__ */ jsx(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata }))); if ((_a = config.root) == null ? void 0 : _a.render) { return /* @__PURE__ */ jsx(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ jsx( DropZoneRender, { config, data, zone: rootZone, metadata } ) })); } return /* @__PURE__ */ jsx( DropZoneRender, { config, data, zone: rootZone, metadata } ); } export { Render, migrate, resolveAllData, transformProps, walkTree };