@delmaredigital/payload-puck 0.6.20 → 0.6.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useState } from 'react';
4
4
  import { useParams, useSearchParams } from 'next/navigation';
5
+ import { mapPayloadFieldsToRootProps } from '../api/utils/mapRootProps.js';
5
6
  /**
6
7
  * Ready-to-use Puck editor page component
7
8
  *
@@ -190,7 +191,7 @@ import { useParams, useSearchParams } from 'next/navigation';
190
191
  });
191
192
  }
192
193
  // Default puck data if none exists
193
- const initialData = page.puckData || {
194
+ const basePuckData = page.puckData || {
194
195
  root: {
195
196
  props: {
196
197
  title: page.title || 'New Page'
@@ -199,6 +200,20 @@ import { useParams, useSearchParams } from 'next/navigation';
199
200
  content: [],
200
201
  zones: {}
201
202
  };
203
+ // Hydrate root.props from Payload fields — ensures saved values like pageLayout,
204
+ // isHomepage, conversion settings etc. are reflected in the editor UI even if
205
+ // they weren't stored in puckData (Puck may strip props that match defaults)
206
+ const payloadRootProps = mapPayloadFieldsToRootProps(page);
207
+ const initialData = {
208
+ ...basePuckData,
209
+ root: {
210
+ ...basePuckData.root,
211
+ props: {
212
+ ...basePuckData.root?.props,
213
+ ...payloadRootProps
214
+ }
215
+ }
216
+ };
202
217
  return /*#__PURE__*/ _jsx(PuckEditor, {
203
218
  pageId: page.id,
204
219
  initialData: initialData,
@@ -74,7 +74,17 @@ import { useAiPrompts } from '../ai/hooks/useAiPrompts.js';
74
74
  // Preview modal state
75
75
  const [isPreviewOpen, setIsPreviewOpen] = useState(false);
76
76
  // Preview dark mode state (for toggling dark/light in preview iframe)
77
- const [previewDarkMode, setPreviewDarkMode] = useState(initialPreviewDarkMode);
77
+ // If not explicitly set, derive from the active layout's editorDarkMode setting
78
+ const initialDarkMode = useMemo(()=>{
79
+ if (initialPreviewDarkMode) return true;
80
+ if (!layouts || layouts.length === 0) return false;
81
+ // Check the initial data's pageLayout to find the active layout
82
+ const pageLayout = initialData?.root?.props?.[layoutKey];
83
+ const activeLayout = layouts.find((l)=>l.value === pageLayout) ?? layouts[0];
84
+ return activeLayout?.editorDarkMode ?? false;
85
+ }, []) // eslint-disable-line react-hooks/exhaustive-deps -- only compute once on mount
86
+ ;
87
+ const [previewDarkMode, setPreviewDarkMode] = useState(initialDarkMode);
78
88
  // Inject slug into initial data if not present
79
89
  const dataWithSlug = useMemo(()=>{
80
90
  const data = initialData;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.6.20";
1
+ export declare const VERSION = "0.6.22";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Auto-generated by scripts/generate-version.js - do not edit manually
2
- export const VERSION = '0.6.20';
2
+ export const VERSION = '0.6.22';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delmaredigital/payload-puck",
3
- "version": "0.6.20",
3
+ "version": "0.6.22",
4
4
  "description": "Puck visual page builder plugin for Payload CMS",
5
5
  "type": "module",
6
6
  "license": "MIT",