@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.
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { createContext, memo, useState, useEffect, useContext, Fragment as Fragment$1, Component } from 'react';
2
+ import { createContext, memo, useState, useEffect, Fragment as Fragment$1, useContext, Component } from 'react';
3
3
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
4
4
  import 'marked';
5
5
 
@@ -2414,7 +2414,7 @@ Available Console Commands:
2414
2414
  if (typeof document === "undefined") return;
2415
2415
  this.teardownComposerDragDrop();
2416
2416
  const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
2417
- const componentSelector = "[data-amplifyup-component], [data-component-id]";
2417
+ const componentSelector = "[data-amplifyup-component], [data-component-id], [data-amplifyup-node], [data-node-id]";
2418
2418
  const clearDragOverState = () => {
2419
2419
  this.clearComposerDragHighlight();
2420
2420
  };
@@ -2463,6 +2463,7 @@ Available Console Commands:
2463
2463
  if (!target?.closest) return;
2464
2464
  const component = target.closest(componentSelector);
2465
2465
  const slot = target.closest(slotSelector);
2466
+ const pageSlot = slot && slot.getAttribute("data-slot-source") === "page" ? slot : null;
2466
2467
  if (this.highlightComponentsEnabled && component) {
2467
2468
  if (!component.classList.contains("amplifyup-component-hover")) {
2468
2469
  clearComponentHover();
@@ -2474,7 +2475,7 @@ Available Console Commands:
2474
2475
  return;
2475
2476
  }
2476
2477
  clearComponentHover();
2477
- if (this.showZonesEnabled && slot) {
2478
+ if (this.showZonesEnabled && slot && !pageSlot) {
2478
2479
  if (!slot.classList.contains("amplifyup-slot-hover")) {
2479
2480
  clearSlotHover();
2480
2481
  slot.classList.add("amplifyup-slot-hover");
@@ -2604,16 +2605,18 @@ Available Console Commands:
2604
2605
  const lines = [];
2605
2606
  if (highlightComponents) {
2606
2607
  lines.push(
2607
- "[data-amplifyup-component], [data-component-id] {",
2608
+ "[data-amplifyup-component], [data-component-id], [data-amplifyup-node], [data-node-id] {",
2608
2609
  " cursor: pointer !important;",
2609
2610
  "}",
2610
- "[data-amplifyup-component].amplifyup-selected, [data-component-id].amplifyup-selected {",
2611
+ "[data-amplifyup-component].amplifyup-selected, [data-component-id].amplifyup-selected, [data-amplifyup-node].amplifyup-selected, [data-node-id].amplifyup-selected {",
2611
2612
  ` outline: 2px solid ${primary} !important;`,
2612
2613
  " outline-offset: -2px !important;",
2613
2614
  " box-shadow: inset 0 0 0 1px hsl(82 100% 52% / 0.25) !important;",
2614
2615
  "}",
2615
2616
  "[data-amplifyup-component].amplifyup-component-hover:not(.amplifyup-selected),",
2616
- "[data-component-id].amplifyup-component-hover:not(.amplifyup-selected) {",
2617
+ "[data-component-id].amplifyup-component-hover:not(.amplifyup-selected),",
2618
+ "[data-amplifyup-node].amplifyup-component-hover:not(.amplifyup-selected),",
2619
+ "[data-node-id].amplifyup-component-hover:not(.amplifyup-selected) {",
2617
2620
  ` outline: 2px solid ${primary} !important;`,
2618
2621
  " outline-offset: -2px !important;",
2619
2622
  "}"
@@ -2816,7 +2819,7 @@ Available Console Commands:
2816
2819
  let current = element;
2817
2820
  let sawPageSlot = false;
2818
2821
  while (current) {
2819
- if (current.hasAttribute("data-amplifyup-component") || current.hasAttribute("data-component-id") || current.hasAttribute("data-amplifyup-slot") || current.hasAttribute("data-slot-id")) {
2822
+ 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")) {
2820
2823
  hierarchy.push(current);
2821
2824
  if (current.getAttribute("data-slot-source") === "page") {
2822
2825
  sawPageSlot = true;
@@ -2841,13 +2844,14 @@ Available Console Commands:
2841
2844
  const componentId = element.getAttribute("data-amplifyup-component") || element.getAttribute("data-component-id");
2842
2845
  const slotName = componentId ? null : element.getAttribute("data-amplifyup-slot") || element.getAttribute("data-slot-id");
2843
2846
  const componentName = element.getAttribute("data-component-name");
2847
+ const nodeId = element.getAttribute("data-node-id") || element.closest("[data-node-id]")?.getAttribute("data-node-id") || null;
2844
2848
  const hierarchyInfo = hierarchy.map((el, index) => {
2845
2849
  const elComponentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
2846
2850
  const elSlotName = el.getAttribute("data-amplifyup-slot") || el.getAttribute("data-slot-id");
2847
2851
  const elComponentName = el.getAttribute("data-component-name");
2848
2852
  const isSlot = !elComponentId && !!elSlotName;
2849
2853
  const isPageSlot = isSlot && el.getAttribute("data-slot-source") === "page";
2850
- const nodeId = el.getAttribute("data-node-id") || (isSlot ? el.getAttribute("data-parent-node-id") : null);
2854
+ const nodeId2 = el.getAttribute("data-node-id") || (isSlot ? el.getAttribute("data-parent-node-id") : null);
2851
2855
  return {
2852
2856
  index,
2853
2857
  componentId: elComponentId,
@@ -2855,7 +2859,7 @@ Available Console Commands:
2855
2859
  slotName: isSlot ? elSlotName : null,
2856
2860
  isSlot,
2857
2861
  isPageSlot,
2858
- nodeId
2862
+ nodeId: nodeId2
2859
2863
  };
2860
2864
  });
2861
2865
  const rect = element.getBoundingClientRect ? element.getBoundingClientRect() : null;
@@ -2865,6 +2869,7 @@ Available Console Commands:
2865
2869
  componentId,
2866
2870
  componentName,
2867
2871
  slotName,
2872
+ nodeId,
2868
2873
  hierarchy: hierarchyInfo,
2869
2874
  selectedIndex: hierarchy.length - 1,
2870
2875
  ...bounds && { bounds },
@@ -2894,22 +2899,27 @@ Available Console Commands:
2894
2899
  }
2895
2900
  const doc = document;
2896
2901
  if (highlightComponents) {
2897
- const componentElements = doc.querySelectorAll("[data-amplifyup-component], [data-component-id]");
2902
+ const componentElements = doc.querySelectorAll(
2903
+ "[data-amplifyup-component], [data-component-id], [data-amplifyup-node], [data-node-id]"
2904
+ );
2898
2905
  console.log("[AmplifyUp SDK] Found", componentElements.length, "components to highlight");
2899
2906
  componentElements.forEach((el) => {
2900
2907
  const htmlEl = el;
2901
2908
  const componentId = htmlEl.getAttribute("data-amplifyup-component") || htmlEl.getAttribute("data-component-id");
2902
- if (!componentId) return;
2909
+ const isLayoutNode = htmlEl.hasAttribute("data-node-id") || htmlEl.hasAttribute("data-amplifyup-node");
2910
+ if (!componentId && !isLayoutNode) return;
2903
2911
  if (htmlEl.classList.contains("amplifyup-component-highlight")) return;
2904
- const component = this.componentRegistry.find((c) => c.component_id === componentId);
2912
+ const component = componentId ? this.componentRegistry.find((c) => c.component_id === componentId) : void 0;
2905
2913
  htmlEl.classList.add("amplifyup-component-highlight");
2906
- htmlEl.setAttribute("data-component-id", componentId);
2907
- htmlEl.setAttribute("data-component-name", component?.component_name || componentId);
2914
+ if (componentId) {
2915
+ htmlEl.setAttribute("data-component-id", componentId);
2916
+ htmlEl.setAttribute("data-component-name", component?.component_name || componentId);
2917
+ }
2908
2918
  const hierarchy = this.buildComponentHierarchy(htmlEl);
2909
2919
  const handleClick = (e) => {
2910
2920
  e.stopPropagation();
2911
2921
  this.sendSelectionMessage(htmlEl, hierarchy);
2912
- if (window.parent && window.parent !== window) {
2922
+ if (componentId && window.parent && window.parent !== window) {
2913
2923
  window.parent.postMessage({ type: "CHECK_COMPONENT_DELETABLE", componentId }, "*");
2914
2924
  }
2915
2925
  };
@@ -2950,6 +2960,15 @@ Available Console Commands:
2950
2960
  htmlEl.classList.add("amplifyup-slot-highlight");
2951
2961
  const hierarchy = this.buildComponentHierarchy(htmlEl);
2952
2962
  const handleClick = (e) => {
2963
+ const clickTarget = e.target;
2964
+ if (htmlEl.getAttribute("data-slot-source") === "page" && clickTarget?.closest) {
2965
+ const nested = clickTarget.closest(
2966
+ "[data-node-id], [data-amplifyup-node], [data-amplifyup-component], [data-component-id]"
2967
+ );
2968
+ if (nested && nested !== htmlEl && htmlEl.contains(nested)) {
2969
+ return;
2970
+ }
2971
+ }
2953
2972
  e.stopPropagation();
2954
2973
  this.sendSelectionMessage(htmlEl, hierarchy, isEmpty);
2955
2974
  };
@@ -3463,23 +3482,32 @@ function AmplifyRendererInner({
3463
3482
  }
3464
3483
  }
3465
3484
  const slotsToPass = Object.keys(slotChildren).length > 0 ? slotChildren : void 0;
3466
- return /* @__PURE__ */ jsx("div", { "data-node-id": node.id, "data-amplifyup-node": "", children: /* @__PURE__ */ jsx(
3467
- ComponentRenderBoundary,
3485
+ return /* @__PURE__ */ jsx(
3486
+ "div",
3468
3487
  {
3469
- componentId: node.componentId,
3470
- nodeId: node.id,
3488
+ "data-node-id": node.id,
3489
+ "data-amplifyup-node": "",
3490
+ "data-component-id": node.componentId,
3491
+ "data-amplifyup-component": node.componentId,
3471
3492
  children: /* @__PURE__ */ jsx(
3472
- LiveNodeRender,
3493
+ ComponentRenderBoundary,
3473
3494
  {
3474
- nodeId: node.id,
3475
3495
  componentId: node.componentId,
3476
- props: nodeRenderProps(node),
3477
- slots: slotsToPass,
3478
- renderComponent
3496
+ nodeId: node.id,
3497
+ children: /* @__PURE__ */ jsx(
3498
+ LiveNodeRender,
3499
+ {
3500
+ nodeId: node.id,
3501
+ componentId: node.componentId,
3502
+ props: nodeRenderProps(node),
3503
+ slots: slotsToPass,
3504
+ renderComponent
3505
+ }
3506
+ )
3479
3507
  }
3480
3508
  )
3481
3509
  }
3482
- ) });
3510
+ );
3483
3511
  };
3484
3512
  const rawTree = pageConfig.layoutTree;
3485
3513
  const layoutTree = Array.isArray(rawTree) ? rawTree : rawTree && typeof rawTree === "object" && rawTree.componentId ? [rawTree] : [];
@@ -3493,9 +3521,9 @@ function AmplifyRendererInner({
3493
3521
  "data-amplifyup-slot": "main",
3494
3522
  "data-slot-source": "page",
3495
3523
  "data-slot-empty": layoutTree.length === 0 ? "true" : void 0,
3496
- children: layoutTree.map((node) => /* @__PURE__ */ jsx("div", { children: renderNode(node) }, node.id))
3524
+ children: layoutTree.map((node) => /* @__PURE__ */ jsx(Fragment$1, { children: renderNode(node) }, node.id))
3497
3525
  }
3498
- ) : layoutTree.map((node) => /* @__PURE__ */ jsx("div", { children: renderNode(node) }, node.id)) });
3526
+ ) : layoutTree.map((node) => /* @__PURE__ */ jsx(Fragment$1, { children: renderNode(node) }, node.id)) });
3499
3527
  }
3500
3528
  var AmplifyRenderer = memo(AmplifyRendererInner);
3501
3529