@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.js CHANGED
@@ -440,9 +440,14 @@ function isFieldEnvelope(value) {
440
440
  const rec = value;
441
441
  return typeof rec.name === "string" && "value" in rec && !("url" in rec);
442
442
  }
443
+ function isPageResourceSentinel(value) {
444
+ return !!value && typeof value === "object" && !Array.isArray(value) && typeof value.__amplifyupPageResource === "string";
445
+ }
443
446
  function isPortableImageShape(value) {
444
447
  if (!value || typeof value !== "object" || Array.isArray(value)) return false;
445
- return "url" in value;
448
+ if ("url" in value) return true;
449
+ const rec = value;
450
+ return rec._type === "image" || rec.asset != null;
446
451
  }
447
452
  function isIdentifierKey(key) {
448
453
  return IDENTIFIER_KEYS.has(key);
@@ -549,6 +554,10 @@ function toFieldEnvelopes(source, prefix = "", scope) {
549
554
  continue;
550
555
  }
551
556
  const path = joinPath(prefix, key);
557
+ if (isPageResourceSentinel(raw)) {
558
+ out[key] = withLeaf({ value: raw, name: path }, ctx);
559
+ continue;
560
+ }
552
561
  if (isFieldEnvelope(raw)) {
553
562
  const inner = raw.value;
554
563
  if (isRecordList(inner)) {
@@ -854,7 +863,7 @@ function mergeEventContext(properties, attached) {
854
863
  };
855
864
  }
856
865
  var PAGE_RESOURCE_MARKER = "__amplifyupPageResource";
857
- function isPageResourceSentinel(value) {
866
+ function isPageResourceSentinel2(value) {
858
867
  return !!value && typeof value === "object" && !Array.isArray(value) && typeof value[PAGE_RESOURCE_MARKER] === "string";
859
868
  }
860
869
  function getByDotPath(source, path) {
@@ -870,7 +879,7 @@ function getByDotPath(source, path) {
870
879
  return cur;
871
880
  }
872
881
  function hydratePageResourceValue(value, fields) {
873
- if (!isPageResourceSentinel(value)) return value;
882
+ if (!isPageResourceSentinel2(value)) return value;
874
883
  if (!fields) return null;
875
884
  if (value.path) return getByDotPath(fields, value.path) ?? null;
876
885
  return fields;
@@ -882,7 +891,7 @@ function hydrateFieldsBag(bag, fields) {
882
891
  const env = val;
883
892
  out[key] = {
884
893
  name: env.name,
885
- value: isPageResourceSentinel(env.value) ? hydratePageResourceValue(env.value, fields) : env.value
894
+ value: isPageResourceSentinel2(env.value) ? hydratePageResourceValue(env.value, fields) : env.value
886
895
  };
887
896
  continue;
888
897
  }
@@ -890,7 +899,7 @@ function hydrateFieldsBag(bag, fields) {
890
899
  out[key] = hydrateFieldsBag(val, fields);
891
900
  continue;
892
901
  }
893
- out[key] = isPageResourceSentinel(val) ? hydratePageResourceValue(val, fields) : val;
902
+ out[key] = isPageResourceSentinel2(val) ? hydratePageResourceValue(val, fields) : val;
894
903
  }
895
904
  return out;
896
905
  }
@@ -903,7 +912,7 @@ function hydratePageResourceProps(props, fields) {
903
912
  }
904
913
  for (const [key, val] of Object.entries(out)) {
905
914
  if (key === "fields") continue;
906
- if (isPageResourceSentinel(val)) {
915
+ if (isPageResourceSentinel2(val)) {
907
916
  out[key] = hydratePageResourceValue(val, fields);
908
917
  }
909
918
  }
@@ -5164,6 +5173,38 @@ function imageSrc(value) {
5164
5173
  if (isPortableImageValue(value)) return value.url.trim();
5165
5174
  return "";
5166
5175
  }
5176
+ function leafText(field) {
5177
+ if (isFieldEnvelope(field)) return field.value;
5178
+ return field;
5179
+ }
5180
+ function coerceImageField(field, value, name) {
5181
+ if (isFieldEnvelope(field)) return { field, value, name };
5182
+ if (!isBrandedFields(field) || !field || typeof field !== "object") {
5183
+ return { field: void 0, value, name };
5184
+ }
5185
+ const bag = field;
5186
+ const urlField = bag.url;
5187
+ const urlName = isFieldEnvelope(urlField) && typeof urlField.name === "string" ? urlField.name.replace(/\.url$/, "") : "";
5188
+ const editName = urlName || name || "";
5189
+ if (!editName) return { field: void 0, value, name };
5190
+ const ref = isFieldEnvelope(urlField) ? urlField.ref : void 0;
5191
+ const width = leafText(bag.width);
5192
+ const height = leafText(bag.height);
5193
+ return {
5194
+ field: {
5195
+ value: {
5196
+ url: String(leafText(urlField) ?? ""),
5197
+ alt: leafText(bag.alt),
5198
+ ...typeof width === "number" ? { width } : {},
5199
+ ...typeof height === "number" ? { height } : {}
5200
+ },
5201
+ name: editName,
5202
+ ...ref ? { ref } : {}
5203
+ },
5204
+ value,
5205
+ name: editName
5206
+ };
5207
+ }
5167
5208
  function Image(props) {
5168
5209
  const {
5169
5210
  field,
@@ -5176,15 +5217,22 @@ function Image(props) {
5176
5217
  ...imgProps
5177
5218
  } = props;
5178
5219
  const context = React2.useContext(ComponentContext);
5179
- const hasField = isFieldEnvelope(field);
5220
+ const coerced = coerceImageField(field, value, name);
5221
+ const boundField = coerced.field;
5222
+ const hasField = isFieldEnvelope(boundField);
5180
5223
  const hasValue = hasOwnProp(props, "value");
5181
- const { editName, fieldValue, ref } = useBoundField(field, value, name, "Image");
5224
+ const { editName, fieldValue, ref } = useBoundField(
5225
+ boundField,
5226
+ coerced.value,
5227
+ coerced.name,
5228
+ "Image"
5229
+ );
5182
5230
  const composerEdit = useComposerEditMode();
5183
- warnProjectionProps("Image", hasField, hasValue, name);
5184
- if (warnNotScalarField("Image", field, fieldValue)) {
5231
+ warnProjectionProps("Image", hasField || isBrandedFields(field), hasValue, coerced.name || name);
5232
+ if (!isBrandedFields(field) && warnNotScalarField("Image", boundField, fieldValue)) {
5185
5233
  return null;
5186
5234
  }
5187
- if (!hasField && !hasValue && !name) {
5235
+ if (!hasField && !hasValue && !name && !editName) {
5188
5236
  return null;
5189
5237
  }
5190
5238
  const src = imageSrc(fieldValue);
@@ -5192,7 +5240,7 @@ function Image(props) {
5192
5240
  const alt = altProp ?? portable?.alt ?? "";
5193
5241
  const width = widthProp ?? portable?.width;
5194
5242
  const height = heightProp ?? portable?.height;
5195
- const fieldAttrs = composerEdit && editName && canComposerBind(field, ref, editName) ? {
5243
+ const fieldAttrs = composerEdit && editName && canComposerBind(boundField, ref, editName) ? {
5196
5244
  "data-amplifyup-field": editName,
5197
5245
  "data-amplifyup-field-type": "image",
5198
5246
  "data-amplifyup-node-id": context?.layoutNodeId || void 0,
@@ -5205,8 +5253,25 @@ function Image(props) {
5205
5253
  '[AmplifyUp SDK] Image value={\u2026} requires name="\u2026" for computed values'
5206
5254
  );
5207
5255
  }
5208
- if (!src) {
5209
- if (!composerEdit || !fieldAttrs) return null;
5256
+ const img = src ? /* @__PURE__ */ jsxRuntime.jsx(
5257
+ "img",
5258
+ {
5259
+ ...imgProps,
5260
+ src,
5261
+ alt,
5262
+ className: fieldAttrs ? void 0 : className,
5263
+ width,
5264
+ height,
5265
+ style: fieldAttrs ? {
5266
+ display: "block",
5267
+ width: "100%",
5268
+ height: "100%",
5269
+ objectFit: "cover",
5270
+ pointerEvents: "none"
5271
+ } : typeof imgProps.style === "object" && imgProps.style ? imgProps.style : void 0
5272
+ }
5273
+ ) : null;
5274
+ if (fieldAttrs) {
5210
5275
  return /* @__PURE__ */ jsxRuntime.jsx(
5211
5276
  "span",
5212
5277
  {
@@ -5221,30 +5286,15 @@ function Image(props) {
5221
5286
  minHeight: height ? void 0 : 80,
5222
5287
  width: width || "100%",
5223
5288
  height: height || void 0,
5224
- background: "color-mix(in srgb, currentColor 8%, transparent)",
5225
- outline: "2px dashed hsl(82 100% 45%)",
5226
- outlineOffset: 2,
5227
- cursor: "pointer"
5228
- }
5289
+ cursor: "pointer",
5290
+ background: src ? void 0 : "color-mix(in srgb, currentColor 8%, transparent)"
5291
+ },
5292
+ children: img
5229
5293
  }
5230
5294
  );
5231
5295
  }
5232
- return /* @__PURE__ */ jsxRuntime.jsx(
5233
- "img",
5234
- {
5235
- ...imgProps,
5236
- ...fieldAttrs,
5237
- src,
5238
- alt,
5239
- className,
5240
- width,
5241
- height,
5242
- style: {
5243
- ...typeof imgProps.style === "object" && imgProps.style ? imgProps.style : {},
5244
- ...composerEdit && fieldAttrs ? { cursor: "pointer" } : null
5245
- }
5246
- }
5247
- );
5296
+ if (!src) return null;
5297
+ return img;
5248
5298
  }
5249
5299
  var usePathname = null;
5250
5300
  if (typeof window !== "undefined") {