@amplifyup/sdk 0.1.16 → 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/react.js CHANGED
@@ -1207,6 +1207,10 @@ Available Console Commands:
1207
1207
  this.clearComposerDragHighlight();
1208
1208
  return;
1209
1209
  }
1210
+ if (event.data?.type === "CLEAR_SELECTION") {
1211
+ this.clearComposerSelection();
1212
+ return;
1213
+ }
1210
1214
  if (event.data?.type === "GET_ELEMENT_POSITION") {
1211
1215
  const { componentId, slotName, nodeId, isPageSlot } = event.data;
1212
1216
  let element = null;
@@ -1248,6 +1252,7 @@ Available Console Commands:
1248
1252
  found: !!element
1249
1253
  });
1250
1254
  if (element) {
1255
+ this.markComposerSelection(element);
1251
1256
  const rect = element.getBoundingClientRect();
1252
1257
  const position = {
1253
1258
  x: rect.left + rect.width / 2,
@@ -1315,6 +1320,7 @@ Available Console Commands:
1315
1320
  break;
1316
1321
  case "SHOW_COMPONENT_TOOLTIP":
1317
1322
  case "HIDE_ALL_TOOLTIPS":
1323
+ this.clearComposerSelection();
1318
1324
  break;
1319
1325
  case "ENABLE_EVENT_SELECTION":
1320
1326
  console.log("[AmplifyUp SDK] Enable event selection mode:", message.enabled);
@@ -1552,29 +1558,46 @@ Available Console Commands:
1552
1558
  */
1553
1559
  enableHighlighting(componentRegistry, highlightComponents, showZones) {
1554
1560
  if (typeof document === "undefined") return;
1561
+ const previouslySelected = Array.from(
1562
+ document.querySelectorAll(".amplifyup-selected")
1563
+ );
1555
1564
  this.componentRegistry = componentRegistry;
1556
1565
  this.highlightingEnabled = true;
1557
1566
  this.highlightComponentsEnabled = highlightComponents;
1558
1567
  this.showZonesEnabled = showZones;
1559
- this.disableHighlighting();
1568
+ this.disableHighlighting({ clearSelection: false });
1560
1569
  this.highlightingEnabled = true;
1561
1570
  this.injectComposerHighlightStyles(highlightComponents, showZones);
1562
1571
  if (highlightComponents || showZones) {
1563
1572
  this.applyComponentHighlights(highlightComponents, showZones);
1564
1573
  this.setupMutationObserver();
1565
- }
1566
- if (showZones) {
1567
1574
  this.setupComposerDragDrop();
1568
1575
  }
1576
+ previouslySelected.forEach((el) => {
1577
+ if (document.contains(el)) {
1578
+ el.classList.add("amplifyup-selected");
1579
+ }
1580
+ });
1569
1581
  }
1570
1582
  /** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
1571
1583
  setupComposerDragDrop() {
1572
1584
  if (typeof document === "undefined") return;
1573
1585
  this.teardownComposerDragDrop();
1574
1586
  const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
1587
+ const componentSelector = "[data-amplifyup-component], [data-component-id]";
1575
1588
  const clearDragOverState = () => {
1576
1589
  this.clearComposerDragHighlight();
1577
1590
  };
1591
+ const clearComponentHover = () => {
1592
+ document.querySelectorAll(".amplifyup-component-hover").forEach((el) => {
1593
+ el.classList.remove("amplifyup-component-hover");
1594
+ });
1595
+ };
1596
+ const clearSlotHover = () => {
1597
+ document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
1598
+ el.classList.remove("amplifyup-slot-hover");
1599
+ });
1600
+ };
1578
1601
  const dragenter = (e) => {
1579
1602
  e.preventDefault();
1580
1603
  };
@@ -1605,31 +1628,59 @@ Available Console Commands:
1605
1628
  this.postDropOnSlot(slot);
1606
1629
  };
1607
1630
  const mouseover = (e) => {
1608
- if (!this.showZonesEnabled) return;
1631
+ if (!this.highlightComponentsEnabled && !this.showZonesEnabled) return;
1609
1632
  const target = e.target;
1610
- const slot = target?.closest?.(slotSelector);
1611
- if (!slot) return;
1612
- document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
1613
- el.classList.remove("amplifyup-slot-hover");
1614
- });
1615
- slot.classList.add("amplifyup-slot-hover");
1633
+ if (!target?.closest) return;
1634
+ const component = target.closest(componentSelector);
1635
+ const slot = target.closest(slotSelector);
1636
+ if (this.highlightComponentsEnabled && component) {
1637
+ if (!component.classList.contains("amplifyup-component-hover")) {
1638
+ clearComponentHover();
1639
+ component.classList.add("amplifyup-component-hover");
1640
+ }
1641
+ if (slot && !component.contains(slot)) {
1642
+ clearSlotHover();
1643
+ }
1644
+ return;
1645
+ }
1646
+ clearComponentHover();
1647
+ if (this.showZonesEnabled && slot) {
1648
+ if (!slot.classList.contains("amplifyup-slot-hover")) {
1649
+ clearSlotHover();
1650
+ slot.classList.add("amplifyup-slot-hover");
1651
+ }
1652
+ }
1616
1653
  };
1617
1654
  const mouseout = (e) => {
1618
- if (!this.showZonesEnabled) return;
1655
+ if (!this.highlightComponentsEnabled && !this.showZonesEnabled) return;
1619
1656
  const related = e.relatedTarget;
1620
- if (!related?.closest?.(slotSelector)) {
1621
- document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
1622
- el.classList.remove("amplifyup-slot-hover");
1623
- });
1657
+ if (this.highlightComponentsEnabled) {
1658
+ if (!related?.closest?.(componentSelector)) {
1659
+ clearComponentHover();
1660
+ }
1661
+ }
1662
+ if (this.showZonesEnabled) {
1663
+ if (!related?.closest?.(slotSelector)) {
1664
+ clearSlotHover();
1665
+ }
1624
1666
  }
1625
1667
  };
1626
- document.addEventListener("dragenter", dragenter, false);
1627
- document.addEventListener("dragover", dragover, false);
1628
- document.addEventListener("dragleave", dragleave, false);
1629
- document.addEventListener("drop", drop, false);
1630
1668
  document.addEventListener("mouseover", mouseover, true);
1631
1669
  document.addEventListener("mouseout", mouseout, true);
1632
- this.composerDragHandlers = { dragenter, dragover, dragleave, drop, mouseover, mouseout };
1670
+ if (this.showZonesEnabled) {
1671
+ document.addEventListener("dragenter", dragenter, false);
1672
+ document.addEventListener("dragover", dragover, false);
1673
+ document.addEventListener("dragleave", dragleave, false);
1674
+ document.addEventListener("drop", drop, false);
1675
+ }
1676
+ this.composerDragHandlers = {
1677
+ dragenter,
1678
+ dragover,
1679
+ dragleave,
1680
+ drop,
1681
+ mouseover,
1682
+ mouseout
1683
+ };
1633
1684
  }
1634
1685
  teardownComposerDragDrop() {
1635
1686
  if (!this.composerDragHandlers || typeof document === "undefined") return;
@@ -1652,6 +1703,20 @@ Available Console Commands:
1652
1703
  document.querySelectorAll("[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover").forEach((el) => {
1653
1704
  el.classList.remove("amplifyup-slot-hover");
1654
1705
  });
1706
+ document.querySelectorAll(".amplifyup-component-hover").forEach((el) => {
1707
+ el.classList.remove("amplifyup-component-hover");
1708
+ });
1709
+ }
1710
+ clearComposerSelection() {
1711
+ if (typeof document === "undefined") return;
1712
+ document.querySelectorAll(
1713
+ "[data-slot-id].amplifyup-selected, [data-amplifyup-slot].amplifyup-selected, [data-amplifyup-component].amplifyup-selected, [data-component-id].amplifyup-selected"
1714
+ ).forEach((el) => el.classList.remove("amplifyup-selected"));
1715
+ }
1716
+ markComposerSelection(element) {
1717
+ if (typeof document === "undefined") return;
1718
+ this.clearComposerSelection();
1719
+ element.classList.add("amplifyup-selected");
1655
1720
  }
1656
1721
  /** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
1657
1722
  injectComposerHighlightStyles(highlightComponents, showZones) {
@@ -1659,16 +1724,29 @@ Available Console Commands:
1659
1724
  if (!highlightComponents && !showZones) return;
1660
1725
  const existing = document.getElementById("amplifyup-preview-highlights");
1661
1726
  if (existing) existing.remove();
1727
+ const primary = "hsl(82 92% 42%)";
1662
1728
  const lines = [];
1663
1729
  if (highlightComponents) {
1664
1730
  lines.push(
1665
1731
  "[data-amplifyup-component], [data-component-id] {",
1666
- " outline: 1px dashed rgba(59, 130, 246, 0.8) !important;",
1667
- " outline-offset: 2px !important;",
1668
1732
  " cursor: pointer !important;",
1669
1733
  "}",
1670
- "[data-amplifyup-component]:hover, [data-component-id]:hover {",
1671
- " outline-color: rgba(59, 130, 246, 1) !important;",
1734
+ "[data-amplifyup-component].amplifyup-selected, [data-component-id].amplifyup-selected {",
1735
+ ` outline: 2px solid ${primary} !important;`,
1736
+ " outline-offset: -2px !important;",
1737
+ " box-shadow: inset 0 0 0 1px hsl(82 92% 42% / 0.25) !important;",
1738
+ "}",
1739
+ "[data-amplifyup-component].amplifyup-component-hover:not(.amplifyup-selected),",
1740
+ "[data-component-id].amplifyup-component-hover:not(.amplifyup-selected) {",
1741
+ ` outline: 2px solid ${primary} !important;`,
1742
+ " outline-offset: -2px !important;",
1743
+ "}"
1744
+ );
1745
+ }
1746
+ if (highlightComponents || showZones) {
1747
+ lines.push(
1748
+ "[data-slot-id].amplifyup-selected, [data-amplifyup-slot].amplifyup-selected {",
1749
+ " background-color: rgba(245, 245, 220, 0.35) !important;",
1672
1750
  "}"
1673
1751
  );
1674
1752
  }
@@ -1803,8 +1881,9 @@ Available Console Commands:
1803
1881
  /**
1804
1882
  * Disable component highlighting
1805
1883
  */
1806
- disableHighlighting() {
1884
+ disableHighlighting(opts) {
1807
1885
  if (typeof document === "undefined") return;
1886
+ const clearSelection = opts?.clearSelection !== false;
1808
1887
  this.highlightingEnabled = false;
1809
1888
  this.teardownComposerDragDrop();
1810
1889
  if (this.mutationObserver) {
@@ -1833,10 +1912,10 @@ Available Console Commands:
1833
1912
  delete htmlEl._amplifyupSlotHandlers;
1834
1913
  htmlEl.classList.remove("amplifyup-slot-highlight");
1835
1914
  });
1915
+ if (clearSelection) {
1916
+ this.clearComposerSelection();
1917
+ }
1836
1918
  }
1837
- /**
1838
- * Build component hierarchy for ancestor selection
1839
- */
1840
1919
  buildComponentHierarchy(element) {
1841
1920
  const hierarchy = [];
1842
1921
  let current = element;
@@ -1900,6 +1979,7 @@ Available Console Commands:
1900
1979
  window.parent.postMessage(message, "*");
1901
1980
  console.log("[AmplifyUp SDK] Sent selection message:", message);
1902
1981
  }
1982
+ this.markComposerSelection(element);
1903
1983
  }
1904
1984
  /**
1905
1985
  * Send component tree to orchestrator