@amplifyup/sdk 0.1.64 → 0.1.66

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.
package/dist/react.mjs CHANGED
@@ -434,9 +434,14 @@ function isFieldEnvelope(value) {
434
434
  const rec = value;
435
435
  return typeof rec.name === "string" && "value" in rec && !("url" in rec);
436
436
  }
437
+ function isPageResourceSentinel(value) {
438
+ return !!value && typeof value === "object" && !Array.isArray(value) && typeof value.__amplifyupPageResource === "string";
439
+ }
437
440
  function isPortableImageShape(value) {
438
441
  if (!value || typeof value !== "object" || Array.isArray(value)) return false;
439
- return "url" in value;
442
+ if ("url" in value) return true;
443
+ const rec = value;
444
+ return rec._type === "image" || rec.asset != null;
440
445
  }
441
446
  function isIdentifierKey(key) {
442
447
  return IDENTIFIER_KEYS.has(key);
@@ -543,6 +548,10 @@ function toFieldEnvelopes(source, prefix = "", scope) {
543
548
  continue;
544
549
  }
545
550
  const path = joinPath(prefix, key);
551
+ if (isPageResourceSentinel(raw)) {
552
+ out[key] = withLeaf({ value: raw, name: path }, ctx);
553
+ continue;
554
+ }
546
555
  if (isFieldEnvelope(raw)) {
547
556
  const inner = raw.value;
548
557
  if (isRecordList(inner)) {
@@ -848,7 +857,7 @@ function mergeEventContext(properties, attached) {
848
857
  };
849
858
  }
850
859
  var PAGE_RESOURCE_MARKER = "__amplifyupPageResource";
851
- function isPageResourceSentinel(value) {
860
+ function isPageResourceSentinel2(value) {
852
861
  return !!value && typeof value === "object" && !Array.isArray(value) && typeof value[PAGE_RESOURCE_MARKER] === "string";
853
862
  }
854
863
  function getByDotPath(source, path) {
@@ -864,7 +873,7 @@ function getByDotPath(source, path) {
864
873
  return cur;
865
874
  }
866
875
  function hydratePageResourceValue(value, fields) {
867
- if (!isPageResourceSentinel(value)) return value;
876
+ if (!isPageResourceSentinel2(value)) return value;
868
877
  if (!fields) return null;
869
878
  if (value.path) return getByDotPath(fields, value.path) ?? null;
870
879
  return fields;
@@ -876,7 +885,7 @@ function hydrateFieldsBag(bag, fields) {
876
885
  const env = val;
877
886
  out[key] = {
878
887
  name: env.name,
879
- value: isPageResourceSentinel(env.value) ? hydratePageResourceValue(env.value, fields) : env.value
888
+ value: isPageResourceSentinel2(env.value) ? hydratePageResourceValue(env.value, fields) : env.value
880
889
  };
881
890
  continue;
882
891
  }
@@ -884,7 +893,7 @@ function hydrateFieldsBag(bag, fields) {
884
893
  out[key] = hydrateFieldsBag(val, fields);
885
894
  continue;
886
895
  }
887
- out[key] = isPageResourceSentinel(val) ? hydratePageResourceValue(val, fields) : val;
896
+ out[key] = isPageResourceSentinel2(val) ? hydratePageResourceValue(val, fields) : val;
888
897
  }
889
898
  return out;
890
899
  }
@@ -897,7 +906,7 @@ function hydratePageResourceProps(props, fields) {
897
906
  }
898
907
  for (const [key, val] of Object.entries(out)) {
899
908
  if (key === "fields") continue;
900
- if (isPageResourceSentinel(val)) {
909
+ if (isPageResourceSentinel2(val)) {
901
910
  out[key] = hydratePageResourceValue(val, fields);
902
911
  }
903
912
  }
@@ -5158,6 +5167,38 @@ function imageSrc(value) {
5158
5167
  if (isPortableImageValue(value)) return value.url.trim();
5159
5168
  return "";
5160
5169
  }
5170
+ function leafText(field) {
5171
+ if (isFieldEnvelope(field)) return field.value;
5172
+ return field;
5173
+ }
5174
+ function coerceImageField(field, value, name) {
5175
+ if (isFieldEnvelope(field)) return { field, value, name };
5176
+ if (!isBrandedFields(field) || !field || typeof field !== "object") {
5177
+ return { field: void 0, value, name };
5178
+ }
5179
+ const bag = field;
5180
+ const urlField = bag.url;
5181
+ const urlName = isFieldEnvelope(urlField) && typeof urlField.name === "string" ? urlField.name.replace(/\.url$/, "") : "";
5182
+ const editName = urlName || name || "";
5183
+ if (!editName) return { field: void 0, value, name };
5184
+ const ref = isFieldEnvelope(urlField) ? urlField.ref : void 0;
5185
+ const width = leafText(bag.width);
5186
+ const height = leafText(bag.height);
5187
+ return {
5188
+ field: {
5189
+ value: {
5190
+ url: String(leafText(urlField) ?? ""),
5191
+ alt: leafText(bag.alt),
5192
+ ...typeof width === "number" ? { width } : {},
5193
+ ...typeof height === "number" ? { height } : {}
5194
+ },
5195
+ name: editName,
5196
+ ...ref ? { ref } : {}
5197
+ },
5198
+ value,
5199
+ name: editName
5200
+ };
5201
+ }
5161
5202
  function Image(props) {
5162
5203
  const {
5163
5204
  field,
@@ -5170,15 +5211,22 @@ function Image(props) {
5170
5211
  ...imgProps
5171
5212
  } = props;
5172
5213
  const context = useContext(ComponentContext);
5173
- const hasField = isFieldEnvelope(field);
5214
+ const coerced = coerceImageField(field, value, name);
5215
+ const boundField = coerced.field;
5216
+ const hasField = isFieldEnvelope(boundField);
5174
5217
  const hasValue = hasOwnProp(props, "value");
5175
- const { editName, fieldValue, ref } = useBoundField(field, value, name, "Image");
5218
+ const { editName, fieldValue, ref } = useBoundField(
5219
+ boundField,
5220
+ coerced.value,
5221
+ coerced.name,
5222
+ "Image"
5223
+ );
5176
5224
  const composerEdit = useComposerEditMode();
5177
- warnProjectionProps("Image", hasField, hasValue, name);
5178
- if (warnNotScalarField("Image", field, fieldValue)) {
5225
+ warnProjectionProps("Image", hasField || isBrandedFields(field), hasValue, coerced.name || name);
5226
+ if (!isBrandedFields(field) && warnNotScalarField("Image", boundField, fieldValue)) {
5179
5227
  return null;
5180
5228
  }
5181
- if (!hasField && !hasValue && !name) {
5229
+ if (!hasField && !hasValue && !name && !editName) {
5182
5230
  return null;
5183
5231
  }
5184
5232
  const src = imageSrc(fieldValue);
@@ -5186,7 +5234,7 @@ function Image(props) {
5186
5234
  const alt = altProp ?? portable?.alt ?? "";
5187
5235
  const width = widthProp ?? portable?.width;
5188
5236
  const height = heightProp ?? portable?.height;
5189
- const fieldAttrs = composerEdit && editName && canComposerBind(field, ref, editName) ? {
5237
+ const fieldAttrs = composerEdit && editName && canComposerBind(boundField, ref, editName) ? {
5190
5238
  "data-amplifyup-field": editName,
5191
5239
  "data-amplifyup-field-type": "image",
5192
5240
  "data-amplifyup-node-id": context?.layoutNodeId || void 0,
@@ -5199,8 +5247,25 @@ function Image(props) {
5199
5247
  '[AmplifyUp SDK] Image value={\u2026} requires name="\u2026" for computed values'
5200
5248
  );
5201
5249
  }
5202
- if (!src) {
5203
- if (!composerEdit || !fieldAttrs) return null;
5250
+ const img = src ? /* @__PURE__ */ jsx(
5251
+ "img",
5252
+ {
5253
+ ...imgProps,
5254
+ src,
5255
+ alt,
5256
+ className: fieldAttrs ? void 0 : className,
5257
+ width,
5258
+ height,
5259
+ style: fieldAttrs ? {
5260
+ display: "block",
5261
+ width: "100%",
5262
+ height: "100%",
5263
+ objectFit: "cover",
5264
+ pointerEvents: "none"
5265
+ } : typeof imgProps.style === "object" && imgProps.style ? imgProps.style : void 0
5266
+ }
5267
+ ) : null;
5268
+ if (fieldAttrs) {
5204
5269
  return /* @__PURE__ */ jsx(
5205
5270
  "span",
5206
5271
  {
@@ -5215,30 +5280,15 @@ function Image(props) {
5215
5280
  minHeight: height ? void 0 : 80,
5216
5281
  width: width || "100%",
5217
5282
  height: height || void 0,
5218
- background: "color-mix(in srgb, currentColor 8%, transparent)",
5219
- outline: "2px dashed hsl(82 100% 45%)",
5220
- outlineOffset: 2,
5221
- cursor: "pointer"
5222
- }
5283
+ cursor: "pointer",
5284
+ background: src ? void 0 : "color-mix(in srgb, currentColor 8%, transparent)"
5285
+ },
5286
+ children: img
5223
5287
  }
5224
5288
  );
5225
5289
  }
5226
- return /* @__PURE__ */ jsx(
5227
- "img",
5228
- {
5229
- ...imgProps,
5230
- ...fieldAttrs,
5231
- src,
5232
- alt,
5233
- className,
5234
- width,
5235
- height,
5236
- style: {
5237
- ...typeof imgProps.style === "object" && imgProps.style ? imgProps.style : {},
5238
- ...composerEdit && fieldAttrs ? { cursor: "pointer" } : null
5239
- }
5240
- }
5241
- );
5290
+ if (!src) return null;
5291
+ return img;
5242
5292
  }
5243
5293
  var usePathname = null;
5244
5294
  if (typeof window !== "undefined") {