@amplifyup/sdk 0.1.56 → 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
  };
@@ -4587,23 +4606,32 @@ function AmplifyRendererInner({
4587
4606
  }
4588
4607
  }
4589
4608
  const slotsToPass = Object.keys(slotChildren).length > 0 ? slotChildren : void 0;
4590
- return /* @__PURE__ */ jsx("div", { "data-node-id": node.id, "data-amplifyup-node": "", children: /* @__PURE__ */ jsx(
4591
- ComponentRenderBoundary,
4609
+ return /* @__PURE__ */ jsx(
4610
+ "div",
4592
4611
  {
4593
- componentId: node.componentId,
4594
- 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,
4595
4616
  children: /* @__PURE__ */ jsx(
4596
- LiveNodeRender,
4617
+ ComponentRenderBoundary,
4597
4618
  {
4598
- nodeId: node.id,
4599
4619
  componentId: node.componentId,
4600
- props: nodeRenderProps(node),
4601
- slots: slotsToPass,
4602
- 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
+ )
4603
4631
  }
4604
4632
  )
4605
4633
  }
4606
- ) });
4634
+ );
4607
4635
  };
4608
4636
  const rawTree = pageConfig.layoutTree;
4609
4637
  const layoutTree = Array.isArray(rawTree) ? rawTree : rawTree && typeof rawTree === "object" && rawTree.componentId ? [rawTree] : [];
@@ -4617,9 +4645,9 @@ function AmplifyRendererInner({
4617
4645
  "data-amplifyup-slot": "main",
4618
4646
  "data-slot-source": "page",
4619
4647
  "data-slot-empty": layoutTree.length === 0 ? "true" : void 0,
4620
- 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))
4621
4649
  }
4622
- ) : layoutTree.map((node) => /* @__PURE__ */ jsx("div", { children: renderNode(node) }, node.id)) });
4650
+ ) : layoutTree.map((node) => /* @__PURE__ */ jsx(Fragment$1, { children: renderNode(node) }, node.id)) });
4623
4651
  }
4624
4652
  var AmplifyRenderer = memo(AmplifyRendererInner);
4625
4653
  function defaultPreviewCanvas() {