@amplifyup/sdk 0.1.55 → 0.1.57

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
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import React, { createContext, memo, useState, useEffect, useContext, Fragment as Fragment$1, Component, useRef, useSyncExternalStore } from 'react';
2
+ import React, { createContext, memo, useState, useEffect, Fragment as Fragment$1, useContext, Component, useRef, useSyncExternalStore } from 'react';
3
3
  import { marked } from 'marked';
4
4
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
5
5
 
@@ -2809,7 +2809,7 @@ Available Console Commands:
2809
2809
  if (typeof document === "undefined") return;
2810
2810
  this.teardownComposerDragDrop();
2811
2811
  const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
2812
- const componentSelector = "[data-amplifyup-component], [data-component-id]";
2812
+ const componentSelector = "[data-amplifyup-component], [data-component-id], [data-amplifyup-node], [data-node-id]";
2813
2813
  const clearDragOverState = () => {
2814
2814
  this.clearComposerDragHighlight();
2815
2815
  };
@@ -2858,6 +2858,7 @@ Available Console Commands:
2858
2858
  if (!target?.closest) return;
2859
2859
  const component = target.closest(componentSelector);
2860
2860
  const slot = target.closest(slotSelector);
2861
+ const pageSlot = slot && slot.getAttribute("data-slot-source") === "page" ? slot : null;
2861
2862
  if (this.highlightComponentsEnabled && component) {
2862
2863
  if (!component.classList.contains("amplifyup-component-hover")) {
2863
2864
  clearComponentHover();
@@ -2869,7 +2870,7 @@ Available Console Commands:
2869
2870
  return;
2870
2871
  }
2871
2872
  clearComponentHover();
2872
- if (this.showZonesEnabled && slot) {
2873
+ if (this.showZonesEnabled && slot && !pageSlot) {
2873
2874
  if (!slot.classList.contains("amplifyup-slot-hover")) {
2874
2875
  clearSlotHover();
2875
2876
  slot.classList.add("amplifyup-slot-hover");
@@ -2999,16 +3000,18 @@ Available Console Commands:
2999
3000
  const lines = [];
3000
3001
  if (highlightComponents) {
3001
3002
  lines.push(
3002
- "[data-amplifyup-component], [data-component-id] {",
3003
+ "[data-amplifyup-component], [data-component-id], [data-amplifyup-node], [data-node-id] {",
3003
3004
  " cursor: pointer !important;",
3004
3005
  "}",
3005
- "[data-amplifyup-component].amplifyup-selected, [data-component-id].amplifyup-selected {",
3006
+ "[data-amplifyup-component].amplifyup-selected, [data-component-id].amplifyup-selected, [data-amplifyup-node].amplifyup-selected, [data-node-id].amplifyup-selected {",
3006
3007
  ` outline: 2px solid ${primary} !important;`,
3007
3008
  " outline-offset: -2px !important;",
3008
3009
  " box-shadow: inset 0 0 0 1px hsl(82 100% 52% / 0.25) !important;",
3009
3010
  "}",
3010
3011
  "[data-amplifyup-component].amplifyup-component-hover:not(.amplifyup-selected),",
3011
- "[data-component-id].amplifyup-component-hover:not(.amplifyup-selected) {",
3012
+ "[data-component-id].amplifyup-component-hover:not(.amplifyup-selected),",
3013
+ "[data-amplifyup-node].amplifyup-component-hover:not(.amplifyup-selected),",
3014
+ "[data-node-id].amplifyup-component-hover:not(.amplifyup-selected) {",
3012
3015
  ` outline: 2px solid ${primary} !important;`,
3013
3016
  " outline-offset: -2px !important;",
3014
3017
  "}"
@@ -3211,7 +3214,7 @@ Available Console Commands:
3211
3214
  let current = element;
3212
3215
  let sawPageSlot = false;
3213
3216
  while (current) {
3214
- if (current.hasAttribute("data-amplifyup-component") || current.hasAttribute("data-component-id") || current.hasAttribute("data-amplifyup-slot") || current.hasAttribute("data-slot-id")) {
3217
+ if (current.hasAttribute("data-amplifyup-component") || current.hasAttribute("data-component-id") || current.hasAttribute("data-amplifyup-slot") || current.hasAttribute("data-slot-id") || current.hasAttribute("data-node-id") || current.hasAttribute("data-amplifyup-node")) {
3215
3218
  hierarchy.push(current);
3216
3219
  if (current.getAttribute("data-slot-source") === "page") {
3217
3220
  sawPageSlot = true;
@@ -3236,13 +3239,14 @@ Available Console Commands:
3236
3239
  const componentId = element.getAttribute("data-amplifyup-component") || element.getAttribute("data-component-id");
3237
3240
  const slotName = componentId ? null : element.getAttribute("data-amplifyup-slot") || element.getAttribute("data-slot-id");
3238
3241
  const componentName = element.getAttribute("data-component-name");
3242
+ const nodeId = element.getAttribute("data-node-id") || element.closest("[data-node-id]")?.getAttribute("data-node-id") || null;
3239
3243
  const hierarchyInfo = hierarchy.map((el, index) => {
3240
3244
  const elComponentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
3241
3245
  const elSlotName = el.getAttribute("data-amplifyup-slot") || el.getAttribute("data-slot-id");
3242
3246
  const elComponentName = el.getAttribute("data-component-name");
3243
3247
  const isSlot = !elComponentId && !!elSlotName;
3244
3248
  const isPageSlot = isSlot && el.getAttribute("data-slot-source") === "page";
3245
- const nodeId = el.getAttribute("data-node-id") || (isSlot ? el.getAttribute("data-parent-node-id") : null);
3249
+ const nodeId2 = el.getAttribute("data-node-id") || (isSlot ? el.getAttribute("data-parent-node-id") : null);
3246
3250
  return {
3247
3251
  index,
3248
3252
  componentId: elComponentId,
@@ -3250,7 +3254,7 @@ Available Console Commands:
3250
3254
  slotName: isSlot ? elSlotName : null,
3251
3255
  isSlot,
3252
3256
  isPageSlot,
3253
- nodeId
3257
+ nodeId: nodeId2
3254
3258
  };
3255
3259
  });
3256
3260
  const rect = element.getBoundingClientRect ? element.getBoundingClientRect() : null;
@@ -3260,6 +3264,7 @@ Available Console Commands:
3260
3264
  componentId,
3261
3265
  componentName,
3262
3266
  slotName,
3267
+ nodeId,
3263
3268
  hierarchy: hierarchyInfo,
3264
3269
  selectedIndex: hierarchy.length - 1,
3265
3270
  ...bounds && { bounds },
@@ -3289,22 +3294,27 @@ Available Console Commands:
3289
3294
  }
3290
3295
  const doc = document;
3291
3296
  if (highlightComponents) {
3292
- const componentElements = doc.querySelectorAll("[data-amplifyup-component], [data-component-id]");
3297
+ const componentElements = doc.querySelectorAll(
3298
+ "[data-amplifyup-component], [data-component-id], [data-amplifyup-node], [data-node-id]"
3299
+ );
3293
3300
  console.log("[AmplifyUp SDK] Found", componentElements.length, "components to highlight");
3294
3301
  componentElements.forEach((el) => {
3295
3302
  const htmlEl = el;
3296
3303
  const componentId = htmlEl.getAttribute("data-amplifyup-component") || htmlEl.getAttribute("data-component-id");
3297
- if (!componentId) return;
3304
+ const isLayoutNode = htmlEl.hasAttribute("data-node-id") || htmlEl.hasAttribute("data-amplifyup-node");
3305
+ if (!componentId && !isLayoutNode) return;
3298
3306
  if (htmlEl.classList.contains("amplifyup-component-highlight")) return;
3299
- const component = this.componentRegistry.find((c) => c.component_id === componentId);
3307
+ const component = componentId ? this.componentRegistry.find((c) => c.component_id === componentId) : void 0;
3300
3308
  htmlEl.classList.add("amplifyup-component-highlight");
3301
- htmlEl.setAttribute("data-component-id", componentId);
3302
- htmlEl.setAttribute("data-component-name", component?.component_name || componentId);
3309
+ if (componentId) {
3310
+ htmlEl.setAttribute("data-component-id", componentId);
3311
+ htmlEl.setAttribute("data-component-name", component?.component_name || componentId);
3312
+ }
3303
3313
  const hierarchy = this.buildComponentHierarchy(htmlEl);
3304
3314
  const handleClick = (e) => {
3305
3315
  e.stopPropagation();
3306
3316
  this.sendSelectionMessage(htmlEl, hierarchy);
3307
- if (window.parent && window.parent !== window) {
3317
+ if (componentId && window.parent && window.parent !== window) {
3308
3318
  window.parent.postMessage({ type: "CHECK_COMPONENT_DELETABLE", componentId }, "*");
3309
3319
  }
3310
3320
  };
@@ -3345,6 +3355,15 @@ Available Console Commands:
3345
3355
  htmlEl.classList.add("amplifyup-slot-highlight");
3346
3356
  const hierarchy = this.buildComponentHierarchy(htmlEl);
3347
3357
  const handleClick = (e) => {
3358
+ const clickTarget = e.target;
3359
+ if (htmlEl.getAttribute("data-slot-source") === "page" && clickTarget?.closest) {
3360
+ const nested = clickTarget.closest(
3361
+ "[data-node-id], [data-amplifyup-node], [data-amplifyup-component], [data-component-id]"
3362
+ );
3363
+ if (nested && nested !== htmlEl && htmlEl.contains(nested)) {
3364
+ return;
3365
+ }
3366
+ }
3348
3367
  e.stopPropagation();
3349
3368
  this.sendSelectionMessage(htmlEl, hierarchy, isEmpty);
3350
3369
  };
@@ -3679,13 +3698,31 @@ function htmlHasVisualChrome(html) {
3679
3698
  );
3680
3699
  }
3681
3700
  function canInlineEdit(name, value) {
3682
- if (isLikelyNonTextFieldName(name)) return false;
3701
+ if (!name || isLikelyNonTextFieldName(name)) return false;
3683
3702
  if (value !== void 0 && value !== null && typeof value === "object") {
3684
3703
  return false;
3685
3704
  }
3686
3705
  if (typeof value === "boolean") return false;
3687
3706
  return true;
3688
3707
  }
3708
+ function canInlineEditRichText(name, value) {
3709
+ if (!name || isLikelyNonTextFieldName(name)) return false;
3710
+ if (typeof value === "boolean") return false;
3711
+ if (value !== void 0 && value !== null && typeof value === "object" && !Array.isArray(value)) {
3712
+ return false;
3713
+ }
3714
+ return true;
3715
+ }
3716
+ function inferEditName(explicitName, contextProps, sourceValue) {
3717
+ if (explicitName) return explicitName;
3718
+ if (!contextProps) return "";
3719
+ const keys = Object.keys(contextProps).filter(
3720
+ (key) => Object.is(contextProps[key], sourceValue)
3721
+ );
3722
+ if (keys.length === 1) return keys[0];
3723
+ if (keys.length === 0 || isComposerEmptyText(sourceValue)) return "";
3724
+ return keys[0];
3725
+ }
3689
3726
  function subscribeComposerEdit(onStoreChange) {
3690
3727
  if (typeof window === "undefined") return () => {
3691
3728
  };
@@ -3880,9 +3917,11 @@ function ComposerInlineHtml({
3880
3917
  const finishEdit = () => {
3881
3918
  const el = elRef.current;
3882
3919
  if (!el) return;
3883
- const next = (el.innerText ?? "").replace(/\u00a0/g, " ").replace(/\n+$/g, "");
3884
- if (next.trim() === sourceTextRef.current) return;
3885
- commitComposerField(layoutNodeId, componentId, name, next.trim());
3920
+ const nextHtml = el.innerHTML;
3921
+ const nextText = (el.innerText ?? "").replace(/\u00a0/g, " ").replace(/\n+$/g, "").trim();
3922
+ if (nextText === sourceTextRef.current && nextHtml === html) return;
3923
+ const commitValue = htmlHasVisualChrome(html) || /<[a-z][\s\S]*>/i.test(html) ? nextHtml : nextText;
3924
+ commitComposerField(layoutNodeId, componentId, name, commitValue);
3886
3925
  };
3887
3926
  return React.createElement(Tag, {
3888
3927
  ref: elRef,
@@ -3924,15 +3963,10 @@ function formatFieldValue(value) {
3924
3963
  }
3925
3964
  function warnProjectionProps(component, name, hasExplicitValue) {
3926
3965
  if (process.env.NODE_ENV === "production") return;
3927
- if (hasExplicitValue && name) {
3928
- console.warn(
3929
- `[AmplifyUp SDK] ${component}: pass either value={\u2026} or deprecated name="\u2026", not both. Prefer value={\u2026} and omit name.`
3930
- );
3931
- return;
3932
- }
3966
+ if (hasExplicitValue) return;
3933
3967
  if (name) {
3934
3968
  console.warn(
3935
- `[AmplifyUp SDK] ${component} \`name\` is deprecated and will be removed. Prefer value={${name}} from your component props and omit name.`
3969
+ `[AmplifyUp SDK] ${component} \`name\` is deprecated and will be removed. Prefer value={${name}} from your component props.`
3936
3970
  );
3937
3971
  }
3938
3972
  }
@@ -3972,7 +4006,7 @@ function Field(props) {
3972
4006
  const composerEdit = useComposerEditMode();
3973
4007
  const hasExplicitValue = hasOwnProp(props, "value");
3974
4008
  const sourceValue = hasExplicitValue ? value : name ? context?.props?.[name] : void 0;
3975
- const editName = hasExplicitValue ? "" : name || "";
4009
+ const editName = inferEditName(name, context?.props, sourceValue);
3976
4010
  const fieldValue = useFieldOverlay(
3977
4011
  context?.layoutNodeId,
3978
4012
  editName,
@@ -3986,6 +4020,20 @@ function Field(props) {
3986
4020
  return fallback ? /* @__PURE__ */ jsx(Fragment, { children: fallback }) : null;
3987
4021
  }
3988
4022
  if (render) {
4023
+ if (composerEdit && editName && context && canInlineEdit(editName, fieldValue)) {
4024
+ return /* @__PURE__ */ jsx(
4025
+ ComposerInlineField,
4026
+ {
4027
+ name: editName,
4028
+ value: fieldValue,
4029
+ fallback,
4030
+ className,
4031
+ render,
4032
+ layoutNodeId: context.layoutNodeId,
4033
+ componentId: context.componentId
4034
+ }
4035
+ );
4036
+ }
3989
4037
  return /* @__PURE__ */ jsx("span", { className, style: { display: "contents" }, children: render(fieldValue) });
3990
4038
  }
3991
4039
  if (Array.isArray(fieldValue)) {
@@ -4039,7 +4087,7 @@ function RichText(props) {
4039
4087
  const hasValueProp = hasOwnProp(props, "value");
4040
4088
  const hasExplicitValue = hasValueProp || childrenValue !== void 0;
4041
4089
  const sourceValue = hasValueProp ? value : childrenValue !== void 0 ? childrenValue : name ? context?.props?.[name] : void 0;
4042
- const editName = hasExplicitValue ? "" : name || "";
4090
+ const editName = inferEditName(name, context?.props, sourceValue);
4043
4091
  const fieldValue = useFieldOverlay(
4044
4092
  context?.layoutNodeId,
4045
4093
  editName,
@@ -4052,7 +4100,7 @@ function RichText(props) {
4052
4100
  return fallback ? /* @__PURE__ */ jsx(Fragment, { children: fallback }) : null;
4053
4101
  }
4054
4102
  warnProjectionProps("RichText", name, hasExplicitValue);
4055
- const canEdit = !!editName && !!context && canInlineEdit(editName, fieldValue);
4103
+ const canEdit = !!context && canInlineEditRichText(editName, fieldValue);
4056
4104
  if (isComposerEmptyText(fieldValue)) {
4057
4105
  if (composerEdit && canEdit && !isReactNodeFallback(fallback) && !classNameIsBlock(className)) {
4058
4106
  return /* @__PURE__ */ jsx(
@@ -4084,17 +4132,6 @@ function RichText(props) {
4084
4132
  if (!html) {
4085
4133
  return fallback ? /* @__PURE__ */ jsx(Tag, { className, children: fallback }) : null;
4086
4134
  }
4087
- if (composerEdit && htmlHasVisualChrome(html)) {
4088
- return /* @__PURE__ */ jsx(
4089
- Tag,
4090
- {
4091
- className,
4092
- "data-amplifyup-field": editName || void 0,
4093
- "data-amplifyup-node-id": context?.layoutNodeId || void 0,
4094
- dangerouslySetInnerHTML: { __html: html }
4095
- }
4096
- );
4097
- }
4098
4135
  if (composerEdit && canEdit) {
4099
4136
  return /* @__PURE__ */ jsx(
4100
4137
  ComposerInlineHtml,
@@ -4135,7 +4172,7 @@ function Image(props) {
4135
4172
  const sourceValue = hasExplicitValue ? value : name ? context?.props?.[name] : void 0;
4136
4173
  const fieldValue = useFieldOverlay(
4137
4174
  context?.layoutNodeId,
4138
- hasExplicitValue ? "" : name || "",
4175
+ inferEditName(name, context?.props, sourceValue),
4139
4176
  sourceValue
4140
4177
  );
4141
4178
  warnProjectionProps("Image", name, hasExplicitValue);
@@ -4569,23 +4606,32 @@ function AmplifyRendererInner({
4569
4606
  }
4570
4607
  }
4571
4608
  const slotsToPass = Object.keys(slotChildren).length > 0 ? slotChildren : void 0;
4572
- return /* @__PURE__ */ jsx("div", { "data-node-id": node.id, "data-amplifyup-node": "", children: /* @__PURE__ */ jsx(
4573
- ComponentRenderBoundary,
4609
+ return /* @__PURE__ */ jsx(
4610
+ "div",
4574
4611
  {
4575
- componentId: node.componentId,
4576
- nodeId: node.id,
4612
+ "data-node-id": node.id,
4613
+ "data-amplifyup-node": "",
4614
+ "data-component-id": node.componentId,
4615
+ "data-amplifyup-component": node.componentId,
4577
4616
  children: /* @__PURE__ */ jsx(
4578
- LiveNodeRender,
4617
+ ComponentRenderBoundary,
4579
4618
  {
4580
- nodeId: node.id,
4581
4619
  componentId: node.componentId,
4582
- props: nodeRenderProps(node),
4583
- slots: slotsToPass,
4584
- renderComponent
4620
+ nodeId: node.id,
4621
+ children: /* @__PURE__ */ jsx(
4622
+ LiveNodeRender,
4623
+ {
4624
+ nodeId: node.id,
4625
+ componentId: node.componentId,
4626
+ props: nodeRenderProps(node),
4627
+ slots: slotsToPass,
4628
+ renderComponent
4629
+ }
4630
+ )
4585
4631
  }
4586
4632
  )
4587
4633
  }
4588
- ) });
4634
+ );
4589
4635
  };
4590
4636
  const rawTree = pageConfig.layoutTree;
4591
4637
  const layoutTree = Array.isArray(rawTree) ? rawTree : rawTree && typeof rawTree === "object" && rawTree.componentId ? [rawTree] : [];
@@ -4599,9 +4645,9 @@ function AmplifyRendererInner({
4599
4645
  "data-amplifyup-slot": "main",
4600
4646
  "data-slot-source": "page",
4601
4647
  "data-slot-empty": layoutTree.length === 0 ? "true" : void 0,
4602
- children: layoutTree.map((node) => /* @__PURE__ */ jsx("div", { children: renderNode(node) }, node.id))
4648
+ children: layoutTree.map((node) => /* @__PURE__ */ jsx(Fragment$1, { children: renderNode(node) }, node.id))
4603
4649
  }
4604
- ) : layoutTree.map((node) => /* @__PURE__ */ jsx("div", { children: renderNode(node) }, node.id)) });
4650
+ ) : layoutTree.map((node) => /* @__PURE__ */ jsx(Fragment$1, { children: renderNode(node) }, node.id)) });
4605
4651
  }
4606
4652
  var AmplifyRenderer = memo(AmplifyRendererInner);
4607
4653
  function defaultPreviewCanvas() {