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