@amplifyup/sdk 0.1.13 → 0.1.15

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/index.mjs CHANGED
@@ -1213,6 +1213,11 @@ Available Console Commands:
1213
1213
  `[data-node-id="${nodeId}"]`
1214
1214
  );
1215
1215
  }
1216
+ if (!element && slotName) {
1217
+ element = document.querySelector(
1218
+ `[data-slot-source="page"][data-slot-id="${slotName}"], [data-slot-source="page"][data-amplifyup-slot="${slotName}"]`
1219
+ );
1220
+ }
1216
1221
  if (!element && slotName) {
1217
1222
  element = document.querySelector(
1218
1223
  `[data-amplifyup-slot="${slotName}"], [data-slot-id="${slotName}"]`
@@ -1245,12 +1250,28 @@ Available Console Commands:
1245
1250
  height: rect.height
1246
1251
  };
1247
1252
  if (window.parent && window.parent !== window) {
1253
+ const hierarchyEls = this.buildComponentHierarchy(element);
1248
1254
  window.parent.postMessage({
1249
1255
  type: "ELEMENT_POSITION",
1250
1256
  componentId: componentId || null,
1251
1257
  slotName: slotName || null,
1252
1258
  nodeId: nodeId || null,
1253
- isPageSlot: !!isPageSlot,
1259
+ isPageSlot: !!isPageSlot || element.getAttribute("data-slot-source") === "page",
1260
+ hierarchy: hierarchyEls.map((el, index) => {
1261
+ const elComponentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
1262
+ const elSlotName = el.getAttribute("data-amplifyup-slot") || el.getAttribute("data-slot-id");
1263
+ const isSlot = !elComponentId && !!elSlotName;
1264
+ const pageSlot = isSlot && el.getAttribute("data-slot-source") === "page";
1265
+ return {
1266
+ index,
1267
+ componentId: elComponentId,
1268
+ componentName: pageSlot ? "Page" : el.getAttribute("data-component-name"),
1269
+ slotName: isSlot ? elSlotName : null,
1270
+ isSlot,
1271
+ isPageSlot: pageSlot,
1272
+ nodeId: el.getAttribute("data-node-id") || (isSlot ? el.getAttribute("data-parent-node-id") : null)
1273
+ };
1274
+ }),
1254
1275
  position,
1255
1276
  bounds
1256
1277
  }, "*");
@@ -1807,13 +1828,24 @@ Available Console Commands:
1807
1828
  buildComponentHierarchy(element) {
1808
1829
  const hierarchy = [];
1809
1830
  let current = element;
1831
+ let sawPageSlot = false;
1810
1832
  while (current) {
1811
1833
  if (current.hasAttribute("data-amplifyup-component") || current.hasAttribute("data-component-id") || current.hasAttribute("data-amplifyup-slot") || current.hasAttribute("data-slot-id")) {
1812
1834
  hierarchy.push(current);
1835
+ if (current.getAttribute("data-slot-source") === "page") {
1836
+ sawPageSlot = true;
1837
+ }
1813
1838
  }
1814
1839
  current = current.parentElement;
1815
1840
  }
1816
- return hierarchy.reverse();
1841
+ const ordered = hierarchy.reverse();
1842
+ if (!sawPageSlot) {
1843
+ const pageSlot = element.closest('[data-slot-source="page"]');
1844
+ if (pageSlot && !ordered.includes(pageSlot)) {
1845
+ ordered.unshift(pageSlot);
1846
+ }
1847
+ }
1848
+ return ordered;
1817
1849
  }
1818
1850
  /**
1819
1851
  * Send selection message to orchestrator (includes element bounds for overlay positioning).