@amplifyup/sdk 0.1.58 → 0.1.60

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
@@ -2348,6 +2348,38 @@ Available Console Commands:
2348
2348
  return;
2349
2349
  }
2350
2350
  try {
2351
+ if (event.data?.type === "AMPLIFYUP_RICHTEXT_EDITING") {
2352
+ document.querySelectorAll(".amplifyup-richtext-editing").forEach((el) => {
2353
+ el.classList.remove("amplifyup-richtext-editing");
2354
+ el.style.minHeight = "";
2355
+ el.style.height = "";
2356
+ el.style.display = "";
2357
+ });
2358
+ if (event.data.active && event.data.fieldName) {
2359
+ if (!document.getElementById("amplifyup-richtext-editing-style")) {
2360
+ const style = document.createElement("style");
2361
+ style.id = "amplifyup-richtext-editing-style";
2362
+ style.textContent = "[data-amplifyup-field].amplifyup-richtext-editing{outline:none!important;visibility:hidden!important;display:block!important;box-sizing:border-box!important;}";
2363
+ document.head.appendChild(style);
2364
+ }
2365
+ const editRoot = event.data.layoutNodeId ? document.querySelector(
2366
+ `[data-node-id="${event.data.layoutNodeId}"], [data-amplifyup-node-id="${event.data.layoutNodeId}"]`
2367
+ ) || document : document;
2368
+ const editField = editRoot.querySelector(
2369
+ `[data-amplifyup-field="${event.data.fieldName}"]`
2370
+ );
2371
+ if (editField) {
2372
+ editField.classList.add("amplifyup-richtext-editing");
2373
+ const editHeight = Number(event.data.height) || 0;
2374
+ if (editHeight > 0) {
2375
+ editField.style.display = "block";
2376
+ editField.style.minHeight = `${editHeight}px`;
2377
+ editField.style.height = `${editHeight}px`;
2378
+ }
2379
+ }
2380
+ }
2381
+ return;
2382
+ }
2351
2383
  if (event.data?.type === "AMPLIFYUP_FIELD_PATCH") {
2352
2384
  window.dispatchEvent(
2353
2385
  new CustomEvent("amplifyup:field-patch", { detail: event.data })
@@ -3878,6 +3910,7 @@ function ComposerInlineField({
3878
3910
  ref: elRef,
3879
3911
  className,
3880
3912
  "data-amplifyup-field": name,
3913
+ "data-amplifyup-field-type": rich ? "richtext" : "text",
3881
3914
  "data-amplifyup-node-id": layoutNodeId || void 0,
3882
3915
  "data-amplifyup-empty-hint": showHint ? "true" : void 0,
3883
3916
  contentEditable: !rich && !showRendered,
@@ -3973,6 +4006,7 @@ function ComposerInlineHtml({
3973
4006
  ref: elRef,
3974
4007
  className,
3975
4008
  "data-amplifyup-field": name,
4009
+ "data-amplifyup-field-type": "richtext",
3976
4010
  "data-amplifyup-node-id": layoutNodeId || void 0,
3977
4011
  dangerouslySetInnerHTML: { __html: html },
3978
4012
  onMouseDown: (event) => {
@@ -4223,6 +4257,8 @@ function Image(props) {
4223
4257
  inferEditName(name, context?.props, sourceValue),
4224
4258
  sourceValue
4225
4259
  );
4260
+ const composerEdit = useComposerEditMode();
4261
+ const editName = inferEditName(name, context?.props, sourceValue);
4226
4262
  warnProjectionProps("Image", name, hasExplicitValue);
4227
4263
  if (!context && !hasExplicitValue) {
4228
4264
  console.warn(
@@ -4231,15 +4267,42 @@ function Image(props) {
4231
4267
  return null;
4232
4268
  }
4233
4269
  const src = imageSrc(fieldValue);
4234
- if (!src) return null;
4235
4270
  const portable = isPortableImageValue(fieldValue) ? fieldValue : null;
4236
4271
  const alt = altProp ?? portable?.alt ?? "";
4237
4272
  const width = widthProp ?? portable?.width;
4238
4273
  const height = heightProp ?? portable?.height;
4274
+ const fieldAttrs = composerEdit && editName ? {
4275
+ "data-amplifyup-field": editName,
4276
+ "data-amplifyup-field-type": "image",
4277
+ "data-amplifyup-node-id": context?.layoutNodeId || void 0
4278
+ } : null;
4279
+ if (!src) {
4280
+ if (!composerEdit || !fieldAttrs) return null;
4281
+ return /* @__PURE__ */ jsx(
4282
+ "span",
4283
+ {
4284
+ ...fieldAttrs,
4285
+ className,
4286
+ role: "img",
4287
+ "aria-label": alt || editName || "Image",
4288
+ style: {
4289
+ display: "inline-block",
4290
+ minWidth: width ? void 0 : 48,
4291
+ minHeight: height ? void 0 : 48,
4292
+ width: width || void 0,
4293
+ height: height || void 0,
4294
+ background: "color-mix(in srgb, currentColor 8%, transparent)",
4295
+ outline: "1px dashed color-mix(in srgb, currentColor 40%, transparent)",
4296
+ outlineOffset: 2
4297
+ }
4298
+ }
4299
+ );
4300
+ }
4239
4301
  return /* @__PURE__ */ jsx(
4240
4302
  "img",
4241
4303
  {
4242
4304
  ...imgProps,
4305
+ ...fieldAttrs,
4243
4306
  src,
4244
4307
  alt,
4245
4308
  className,