@amplifyup/sdk 0.1.15 → 0.1.17

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.d.mts CHANGED
@@ -248,6 +248,8 @@ declare class AmplifyUpSDK {
248
248
  /** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
249
249
  private setupComposerDragDrop;
250
250
  private teardownComposerDragDrop;
251
+ private clearComposerSelection;
252
+ private markComposerSelection;
251
253
  /** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
252
254
  private injectComposerHighlightStyles;
253
255
  /**
@@ -258,9 +260,6 @@ declare class AmplifyUpSDK {
258
260
  * Disable component highlighting
259
261
  */
260
262
  private disableHighlighting;
261
- /**
262
- * Build component hierarchy for ancestor selection
263
- */
264
263
  private buildComponentHierarchy;
265
264
  /**
266
265
  * Send selection message to orchestrator (includes element bounds for overlay positioning).
package/dist/index.d.ts CHANGED
@@ -248,6 +248,8 @@ declare class AmplifyUpSDK {
248
248
  /** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
249
249
  private setupComposerDragDrop;
250
250
  private teardownComposerDragDrop;
251
+ private clearComposerSelection;
252
+ private markComposerSelection;
251
253
  /** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
252
254
  private injectComposerHighlightStyles;
253
255
  /**
@@ -258,9 +260,6 @@ declare class AmplifyUpSDK {
258
260
  * Disable component highlighting
259
261
  */
260
262
  private disableHighlighting;
261
- /**
262
- * Build component hierarchy for ancestor selection
263
- */
264
263
  private buildComponentHierarchy;
265
264
  /**
266
265
  * Send selection message to orchestrator (includes element bounds for overlay positioning).
package/dist/index.js CHANGED
@@ -1199,6 +1199,10 @@ Available Console Commands:
1199
1199
  this.clearComposerDragHighlight();
1200
1200
  return;
1201
1201
  }
1202
+ if (event.data?.type === "CLEAR_SELECTION") {
1203
+ this.clearComposerSelection();
1204
+ return;
1205
+ }
1202
1206
  if (event.data?.type === "GET_ELEMENT_POSITION") {
1203
1207
  const { componentId, slotName, nodeId, isPageSlot } = event.data;
1204
1208
  let element = null;
@@ -1240,6 +1244,7 @@ Available Console Commands:
1240
1244
  found: !!element
1241
1245
  });
1242
1246
  if (element) {
1247
+ this.markComposerSelection(element);
1243
1248
  const rect = element.getBoundingClientRect();
1244
1249
  const position = {
1245
1250
  x: rect.left + rect.width / 2,
@@ -1307,6 +1312,7 @@ Available Console Commands:
1307
1312
  break;
1308
1313
  case "SHOW_COMPONENT_TOOLTIP":
1309
1314
  case "HIDE_ALL_TOOLTIPS":
1315
+ this.clearComposerSelection();
1310
1316
  break;
1311
1317
  case "ENABLE_EVENT_SELECTION":
1312
1318
  console.log("[AmplifyUp SDK] Enable event selection mode:", message.enabled);
@@ -1544,29 +1550,46 @@ Available Console Commands:
1544
1550
  */
1545
1551
  enableHighlighting(componentRegistry, highlightComponents, showZones) {
1546
1552
  if (typeof document === "undefined") return;
1553
+ const previouslySelected = Array.from(
1554
+ document.querySelectorAll(".amplifyup-selected")
1555
+ );
1547
1556
  this.componentRegistry = componentRegistry;
1548
1557
  this.highlightingEnabled = true;
1549
1558
  this.highlightComponentsEnabled = highlightComponents;
1550
1559
  this.showZonesEnabled = showZones;
1551
- this.disableHighlighting();
1560
+ this.disableHighlighting({ clearSelection: false });
1552
1561
  this.highlightingEnabled = true;
1553
1562
  this.injectComposerHighlightStyles(highlightComponents, showZones);
1554
1563
  if (highlightComponents || showZones) {
1555
1564
  this.applyComponentHighlights(highlightComponents, showZones);
1556
1565
  this.setupMutationObserver();
1557
- }
1558
- if (showZones) {
1559
1566
  this.setupComposerDragDrop();
1560
1567
  }
1568
+ previouslySelected.forEach((el) => {
1569
+ if (document.contains(el)) {
1570
+ el.classList.add("amplifyup-selected");
1571
+ }
1572
+ });
1561
1573
  }
1562
1574
  /** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
1563
1575
  setupComposerDragDrop() {
1564
1576
  if (typeof document === "undefined") return;
1565
1577
  this.teardownComposerDragDrop();
1566
1578
  const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
1579
+ const componentSelector = "[data-amplifyup-component], [data-component-id]";
1567
1580
  const clearDragOverState = () => {
1568
1581
  this.clearComposerDragHighlight();
1569
1582
  };
1583
+ const clearComponentHover = () => {
1584
+ document.querySelectorAll(".amplifyup-component-hover").forEach((el) => {
1585
+ el.classList.remove("amplifyup-component-hover");
1586
+ });
1587
+ };
1588
+ const clearSlotHover = () => {
1589
+ document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
1590
+ el.classList.remove("amplifyup-slot-hover");
1591
+ });
1592
+ };
1570
1593
  const dragenter = (e) => {
1571
1594
  e.preventDefault();
1572
1595
  };
@@ -1597,31 +1620,59 @@ Available Console Commands:
1597
1620
  this.postDropOnSlot(slot);
1598
1621
  };
1599
1622
  const mouseover = (e) => {
1600
- if (!this.showZonesEnabled) return;
1623
+ if (!this.highlightComponentsEnabled && !this.showZonesEnabled) return;
1601
1624
  const target = e.target;
1602
- const slot = target?.closest?.(slotSelector);
1603
- if (!slot) return;
1604
- document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
1605
- el.classList.remove("amplifyup-slot-hover");
1606
- });
1607
- slot.classList.add("amplifyup-slot-hover");
1625
+ if (!target?.closest) return;
1626
+ const component = target.closest(componentSelector);
1627
+ const slot = target.closest(slotSelector);
1628
+ if (this.highlightComponentsEnabled && component) {
1629
+ if (!component.classList.contains("amplifyup-component-hover")) {
1630
+ clearComponentHover();
1631
+ component.classList.add("amplifyup-component-hover");
1632
+ }
1633
+ if (slot && !component.contains(slot)) {
1634
+ clearSlotHover();
1635
+ }
1636
+ return;
1637
+ }
1638
+ clearComponentHover();
1639
+ if (this.showZonesEnabled && slot) {
1640
+ if (!slot.classList.contains("amplifyup-slot-hover")) {
1641
+ clearSlotHover();
1642
+ slot.classList.add("amplifyup-slot-hover");
1643
+ }
1644
+ }
1608
1645
  };
1609
1646
  const mouseout = (e) => {
1610
- if (!this.showZonesEnabled) return;
1647
+ if (!this.highlightComponentsEnabled && !this.showZonesEnabled) return;
1611
1648
  const related = e.relatedTarget;
1612
- if (!related?.closest?.(slotSelector)) {
1613
- document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
1614
- el.classList.remove("amplifyup-slot-hover");
1615
- });
1649
+ if (this.highlightComponentsEnabled) {
1650
+ if (!related?.closest?.(componentSelector)) {
1651
+ clearComponentHover();
1652
+ }
1653
+ }
1654
+ if (this.showZonesEnabled) {
1655
+ if (!related?.closest?.(slotSelector)) {
1656
+ clearSlotHover();
1657
+ }
1616
1658
  }
1617
1659
  };
1618
- document.addEventListener("dragenter", dragenter, false);
1619
- document.addEventListener("dragover", dragover, false);
1620
- document.addEventListener("dragleave", dragleave, false);
1621
- document.addEventListener("drop", drop, false);
1622
1660
  document.addEventListener("mouseover", mouseover, true);
1623
1661
  document.addEventListener("mouseout", mouseout, true);
1624
- this.composerDragHandlers = { dragenter, dragover, dragleave, drop, mouseover, mouseout };
1662
+ if (this.showZonesEnabled) {
1663
+ document.addEventListener("dragenter", dragenter, false);
1664
+ document.addEventListener("dragover", dragover, false);
1665
+ document.addEventListener("dragleave", dragleave, false);
1666
+ document.addEventListener("drop", drop, false);
1667
+ }
1668
+ this.composerDragHandlers = {
1669
+ dragenter,
1670
+ dragover,
1671
+ dragleave,
1672
+ drop,
1673
+ mouseover,
1674
+ mouseout
1675
+ };
1625
1676
  }
1626
1677
  teardownComposerDragDrop() {
1627
1678
  if (!this.composerDragHandlers || typeof document === "undefined") return;
@@ -1644,6 +1695,20 @@ Available Console Commands:
1644
1695
  document.querySelectorAll("[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover").forEach((el) => {
1645
1696
  el.classList.remove("amplifyup-slot-hover");
1646
1697
  });
1698
+ document.querySelectorAll(".amplifyup-component-hover").forEach((el) => {
1699
+ el.classList.remove("amplifyup-component-hover");
1700
+ });
1701
+ }
1702
+ clearComposerSelection() {
1703
+ if (typeof document === "undefined") return;
1704
+ document.querySelectorAll(
1705
+ "[data-slot-id].amplifyup-selected, [data-amplifyup-slot].amplifyup-selected, [data-amplifyup-component].amplifyup-selected, [data-component-id].amplifyup-selected"
1706
+ ).forEach((el) => el.classList.remove("amplifyup-selected"));
1707
+ }
1708
+ markComposerSelection(element) {
1709
+ if (typeof document === "undefined") return;
1710
+ this.clearComposerSelection();
1711
+ element.classList.add("amplifyup-selected");
1647
1712
  }
1648
1713
  /** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
1649
1714
  injectComposerHighlightStyles(highlightComponents, showZones) {
@@ -1651,16 +1716,29 @@ Available Console Commands:
1651
1716
  if (!highlightComponents && !showZones) return;
1652
1717
  const existing = document.getElementById("amplifyup-preview-highlights");
1653
1718
  if (existing) existing.remove();
1719
+ const primary = "hsl(82 92% 42%)";
1654
1720
  const lines = [];
1655
1721
  if (highlightComponents) {
1656
1722
  lines.push(
1657
1723
  "[data-amplifyup-component], [data-component-id] {",
1658
- " outline: 1px dashed rgba(59, 130, 246, 0.8) !important;",
1659
- " outline-offset: 2px !important;",
1660
1724
  " cursor: pointer !important;",
1661
1725
  "}",
1662
- "[data-amplifyup-component]:hover, [data-component-id]:hover {",
1663
- " outline-color: rgba(59, 130, 246, 1) !important;",
1726
+ "[data-amplifyup-component].amplifyup-selected, [data-component-id].amplifyup-selected {",
1727
+ ` outline: 2px solid ${primary} !important;`,
1728
+ " outline-offset: -2px !important;",
1729
+ " box-shadow: inset 0 0 0 1px hsl(82 92% 42% / 0.25) !important;",
1730
+ "}",
1731
+ "[data-amplifyup-component].amplifyup-component-hover:not(.amplifyup-selected),",
1732
+ "[data-component-id].amplifyup-component-hover:not(.amplifyup-selected) {",
1733
+ ` outline: 2px solid ${primary} !important;`,
1734
+ " outline-offset: -2px !important;",
1735
+ "}"
1736
+ );
1737
+ }
1738
+ if (highlightComponents || showZones) {
1739
+ lines.push(
1740
+ "[data-slot-id].amplifyup-selected, [data-amplifyup-slot].amplifyup-selected {",
1741
+ " background-color: rgba(245, 245, 220, 0.35) !important;",
1664
1742
  "}"
1665
1743
  );
1666
1744
  }
@@ -1795,8 +1873,9 @@ Available Console Commands:
1795
1873
  /**
1796
1874
  * Disable component highlighting
1797
1875
  */
1798
- disableHighlighting() {
1876
+ disableHighlighting(opts) {
1799
1877
  if (typeof document === "undefined") return;
1878
+ const clearSelection = opts?.clearSelection !== false;
1800
1879
  this.highlightingEnabled = false;
1801
1880
  this.teardownComposerDragDrop();
1802
1881
  if (this.mutationObserver) {
@@ -1825,10 +1904,10 @@ Available Console Commands:
1825
1904
  delete htmlEl._amplifyupSlotHandlers;
1826
1905
  htmlEl.classList.remove("amplifyup-slot-highlight");
1827
1906
  });
1907
+ if (clearSelection) {
1908
+ this.clearComposerSelection();
1909
+ }
1828
1910
  }
1829
- /**
1830
- * Build component hierarchy for ancestor selection
1831
- */
1832
1911
  buildComponentHierarchy(element) {
1833
1912
  const hierarchy = [];
1834
1913
  let current = element;
@@ -1892,6 +1971,7 @@ Available Console Commands:
1892
1971
  window.parent.postMessage(message, "*");
1893
1972
  console.log("[AmplifyUp SDK] Sent selection message:", message);
1894
1973
  }
1974
+ this.markComposerSelection(element);
1895
1975
  }
1896
1976
  /**
1897
1977
  * Send component tree to orchestrator