@amplifyup/sdk 0.1.14 → 0.1.16

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, useState, useEffect, useContext } from 'react';
2
+ import { createContext, useState, useEffect, Fragment as Fragment$1, useContext } from 'react';
3
3
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
4
4
 
5
5
  /* @amplifyup/sdk - https://amplifyup.ai */
@@ -1223,6 +1223,11 @@ Available Console Commands:
1223
1223
  `[data-node-id="${nodeId}"]`
1224
1224
  );
1225
1225
  }
1226
+ if (!element && slotName) {
1227
+ element = document.querySelector(
1228
+ `[data-slot-source="page"][data-slot-id="${slotName}"], [data-slot-source="page"][data-amplifyup-slot="${slotName}"]`
1229
+ );
1230
+ }
1226
1231
  if (!element && slotName) {
1227
1232
  element = document.querySelector(
1228
1233
  `[data-amplifyup-slot="${slotName}"], [data-slot-id="${slotName}"]`
@@ -1255,12 +1260,28 @@ Available Console Commands:
1255
1260
  height: rect.height
1256
1261
  };
1257
1262
  if (window.parent && window.parent !== window) {
1263
+ const hierarchyEls = this.buildComponentHierarchy(element);
1258
1264
  window.parent.postMessage({
1259
1265
  type: "ELEMENT_POSITION",
1260
1266
  componentId: componentId || null,
1261
1267
  slotName: slotName || null,
1262
1268
  nodeId: nodeId || null,
1263
- isPageSlot: !!isPageSlot,
1269
+ isPageSlot: !!isPageSlot || element.getAttribute("data-slot-source") === "page",
1270
+ hierarchy: hierarchyEls.map((el, index) => {
1271
+ const elComponentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
1272
+ const elSlotName = el.getAttribute("data-amplifyup-slot") || el.getAttribute("data-slot-id");
1273
+ const isSlot = !elComponentId && !!elSlotName;
1274
+ const pageSlot = isSlot && el.getAttribute("data-slot-source") === "page";
1275
+ return {
1276
+ index,
1277
+ componentId: elComponentId,
1278
+ componentName: pageSlot ? "Page" : el.getAttribute("data-component-name"),
1279
+ slotName: isSlot ? elSlotName : null,
1280
+ isSlot,
1281
+ isPageSlot: pageSlot,
1282
+ nodeId: el.getAttribute("data-node-id") || (isSlot ? el.getAttribute("data-parent-node-id") : null)
1283
+ };
1284
+ }),
1264
1285
  position,
1265
1286
  bounds
1266
1287
  }, "*");
@@ -1817,13 +1838,24 @@ Available Console Commands:
1817
1838
  buildComponentHierarchy(element) {
1818
1839
  const hierarchy = [];
1819
1840
  let current = element;
1841
+ let sawPageSlot = false;
1820
1842
  while (current) {
1821
1843
  if (current.hasAttribute("data-amplifyup-component") || current.hasAttribute("data-component-id") || current.hasAttribute("data-amplifyup-slot") || current.hasAttribute("data-slot-id")) {
1822
1844
  hierarchy.push(current);
1845
+ if (current.getAttribute("data-slot-source") === "page") {
1846
+ sawPageSlot = true;
1847
+ }
1823
1848
  }
1824
1849
  current = current.parentElement;
1825
1850
  }
1826
- return hierarchy.reverse();
1851
+ const ordered = hierarchy.reverse();
1852
+ if (!sawPageSlot) {
1853
+ const pageSlot = element.closest('[data-slot-source="page"]');
1854
+ if (pageSlot && !ordered.includes(pageSlot)) {
1855
+ ordered.unshift(pageSlot);
1856
+ }
1857
+ }
1858
+ return ordered;
1827
1859
  }
1828
1860
  /**
1829
1861
  * Send selection message to orchestrator (includes element bounds for overlay positioning).
@@ -2000,7 +2032,8 @@ function AmplifyRenderer({
2000
2032
  pageConfig: serverPageConfig,
2001
2033
  loadingComponent,
2002
2034
  errorComponent,
2003
- emptyComponent
2035
+ emptyComponent,
2036
+ composerPreview
2004
2037
  }) {
2005
2038
  const clientHook = useAmplifyUp();
2006
2039
  const pageConfig = serverPageConfig || clientHook.pageConfig || null;
@@ -2282,7 +2315,7 @@ function AmplifyRenderer({
2282
2315
  "data-zone-id": slot.zoneId || void 0,
2283
2316
  "data-parent-node-id": node.id,
2284
2317
  "data-parent-component-id": node.componentId,
2285
- children: safeChildren.filter(Boolean).map((child) => renderNode(child))
2318
+ children: safeChildren.filter(Boolean).map((child) => /* @__PURE__ */ jsx(Fragment$1, { children: renderNode(child) }, child.id))
2286
2319
  },
2287
2320
  slot.slotId
2288
2321
  );
@@ -2306,7 +2339,7 @@ function AmplifyRenderer({
2306
2339
  if (layoutTree.length === 0) {
2307
2340
  return /* @__PURE__ */ jsx("main", { children: emptyComponent || /* @__PURE__ */ jsx("div", { className: "container mx-auto px-4 py-16", children: /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: "No content configured for this page." }) }) });
2308
2341
  }
2309
- return /* @__PURE__ */ jsx("main", { children: isComposerPreview() ? /* @__PURE__ */ jsx(
2342
+ return /* @__PURE__ */ jsx("main", { children: composerPreview || isComposerPreview() ? /* @__PURE__ */ jsx(
2310
2343
  "div",
2311
2344
  {
2312
2345
  "data-slot-id": "main",