@orion-studios/payload-studio 0.5.0-beta.15 → 0.5.0-beta.17

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.
@@ -773,6 +773,19 @@ function getRelationID(value) {
773
773
  }
774
774
  return null;
775
775
  }
776
+ function getMediaURL(value) {
777
+ if (!value || typeof value !== "object") {
778
+ return "";
779
+ }
780
+ const typed = value;
781
+ if (typeof typed.url === "string" && typed.url.trim().length > 0) {
782
+ return typed.url.trim();
783
+ }
784
+ if (typeof typed.filename === "string" && typed.filename.trim().length > 0) {
785
+ return `/api/media/file/${encodeURIComponent(typed.filename)}`;
786
+ }
787
+ return "";
788
+ }
776
789
  function extractUploadedMedia(value) {
777
790
  const candidate = value && typeof value === "object" && "doc" in value ? value.doc : value;
778
791
  if (!candidate || typeof candidate !== "object") {
@@ -1438,6 +1451,25 @@ function BuilderPageEditor({ initialDoc, pageID }) {
1438
1451
  setUploadingTarget(null);
1439
1452
  }
1440
1453
  };
1454
+ const withHeroMediaFallbacks = (sourceLayout) => sourceLayout.map((block) => {
1455
+ if (!block || typeof block !== "object") {
1456
+ return block;
1457
+ }
1458
+ const nextBlock = { ...block };
1459
+ const blockType = normalizeText(nextBlock.blockType);
1460
+ if (blockType !== "hero") {
1461
+ return nextBlock;
1462
+ }
1463
+ const existingBackgroundImageURL = normalizeText(nextBlock.backgroundImageURL).trim();
1464
+ if (existingBackgroundImageURL.length > 0) {
1465
+ return nextBlock;
1466
+ }
1467
+ const mediaURL = getMediaURL(nextBlock.media);
1468
+ if (mediaURL.length > 0) {
1469
+ nextBlock.backgroundImageURL = mediaURL;
1470
+ }
1471
+ return nextBlock;
1472
+ });
1441
1473
  const toPersistedLayout = (sourceLayout) => sourceLayout.map((block) => {
1442
1474
  if (!block || typeof block !== "object") {
1443
1475
  return block;
@@ -1601,13 +1633,14 @@ function BuilderPageEditor({ initialDoc, pageID }) {
1601
1633
  setSaveError("");
1602
1634
  setSaveMessage("");
1603
1635
  try {
1604
- const persistedLayout = toPersistedLayout(layout);
1636
+ const normalizedLayout = withHeroMediaFallbacks(layout);
1637
+ const persistedLayout = toPersistedLayout(normalizedLayout);
1605
1638
  const response = await fetch(`/api/pages/${pageID}`, {
1606
1639
  body: JSON.stringify({
1607
1640
  _status: status,
1608
1641
  layout: persistedLayout,
1609
1642
  studioDocument: layoutToStudioDocument(
1610
- layout,
1643
+ normalizedLayout,
1611
1644
  title,
1612
1645
  {
1613
1646
  pageWidthDefault: pageDefaults.pageWidthDefault
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-studios/payload-studio",
3
- "version": "0.5.0-beta.15",
3
+ "version": "0.5.0-beta.17",
4
4
  "description": "Unified Payload CMS toolkit for Orion Studios",
5
5
  "types": "./dist/index.d.ts",
6
6
  "exports": {