@amplifyup/sdk 0.1.7 → 0.1.8

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.mjs CHANGED
@@ -344,6 +344,8 @@ var AmplifyUpSDK = class {
344
344
  /** Ensures auto page() on init fires once per page load */
345
345
  this.initialPageSent = false;
346
346
  this.highlightingEnabled = false;
347
+ this.highlightComponentsEnabled = true;
348
+ this.showZonesEnabled = false;
347
349
  this.componentRegistry = [];
348
350
  this.messageListener = null;
349
351
  this.mutationObserver = null;
@@ -1138,7 +1140,7 @@ Available Console Commands:
1138
1140
  }
1139
1141
  if (event.data?.type === "GET_ELEMENT_POSITION") {
1140
1142
  const { componentId, slotName } = event.data;
1141
- const selector = slotName ? `[data-amplifyup-slot="${slotName}"]` : `[data-amplifyup-component="${componentId}"], [data-component-id="${componentId}"]`;
1143
+ const selector = slotName ? `[data-amplifyup-slot="${slotName}"], [data-slot-id="${slotName}"]` : `[data-amplifyup-component="${componentId}"], [data-component-id="${componentId}"]`;
1142
1144
  console.log("[AmplifyUp SDK] Finding element position:", { selector, componentId, slotName });
1143
1145
  const element = document.querySelector(selector);
1144
1146
  if (element) {
@@ -1276,12 +1278,62 @@ Available Console Commands:
1276
1278
  if (typeof document === "undefined") return;
1277
1279
  this.componentRegistry = componentRegistry;
1278
1280
  this.highlightingEnabled = true;
1281
+ this.highlightComponentsEnabled = highlightComponents;
1282
+ this.showZonesEnabled = showZones;
1279
1283
  this.disableHighlighting();
1280
- if (highlightComponents) {
1281
- this.applyComponentHighlights();
1284
+ this.highlightingEnabled = true;
1285
+ this.injectComposerHighlightStyles(highlightComponents, showZones);
1286
+ if (highlightComponents || showZones) {
1287
+ this.applyComponentHighlights(highlightComponents, showZones);
1282
1288
  this.setupMutationObserver();
1283
1289
  }
1284
1290
  }
1291
+ /** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
1292
+ injectComposerHighlightStyles(highlightComponents, showZones) {
1293
+ if (typeof document === "undefined") return;
1294
+ if (!highlightComponents && !showZones) return;
1295
+ const existing = document.getElementById("amplifyup-preview-highlights");
1296
+ if (existing) existing.remove();
1297
+ const lines = [];
1298
+ if (highlightComponents) {
1299
+ lines.push(
1300
+ "[data-amplifyup-component], [data-component-id] {",
1301
+ " outline: 1px dashed rgba(59, 130, 246, 0.8) !important;",
1302
+ " outline-offset: 2px !important;",
1303
+ " cursor: pointer !important;",
1304
+ "}",
1305
+ "[data-amplifyup-component]:hover, [data-component-id]:hover {",
1306
+ " outline-color: rgba(59, 130, 246, 1) !important;",
1307
+ "}"
1308
+ );
1309
+ }
1310
+ if (showZones) {
1311
+ lines.push(
1312
+ "[data-slot-id], [data-amplifyup-slot] {",
1313
+ " outline: 2px dotted rgba(34, 197, 94, 0.75) !important;",
1314
+ " outline-offset: 4px !important;",
1315
+ " min-height: 3rem !important;",
1316
+ " box-sizing: border-box !important;",
1317
+ " cursor: pointer !important;",
1318
+ "}",
1319
+ '[data-slot-id="main"], [data-amplifyup-slot="main"] {',
1320
+ " min-height: 50vh !important;",
1321
+ "}",
1322
+ "[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover {",
1323
+ " outline-color: rgba(34, 197, 94, 1) !important;",
1324
+ " background: rgba(34, 197, 94, 0.06) !important;",
1325
+ "}",
1326
+ "[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot {",
1327
+ " outline: 2px solid rgba(34, 197, 94, 1) !important;",
1328
+ " background: rgba(34, 197, 94, 0.1) !important;",
1329
+ "}"
1330
+ );
1331
+ }
1332
+ const style = document.createElement("style");
1333
+ style.id = "amplifyup-preview-highlights";
1334
+ style.textContent = lines.join("\n");
1335
+ document.head.appendChild(style);
1336
+ }
1285
1337
  /**
1286
1338
  * Set up MutationObserver to watch for new components being added
1287
1339
  */
@@ -1297,14 +1349,14 @@ Available Console Commands:
1297
1349
  mutation.addedNodes.forEach((node) => {
1298
1350
  if (node.nodeType === Node.ELEMENT_NODE) {
1299
1351
  const el = node;
1300
- if (el.hasAttribute("data-amplifyup-component") || el.hasAttribute("data-component-id") || el.hasAttribute("data-amplifyup-slot") || el.querySelector("[data-amplifyup-component], [data-component-id], [data-amplifyup-slot]")) {
1352
+ if (el.hasAttribute("data-amplifyup-component") || el.hasAttribute("data-component-id") || el.hasAttribute("data-amplifyup-slot") || el.hasAttribute("data-slot-id") || el.querySelector("[data-amplifyup-component], [data-component-id], [data-amplifyup-slot], [data-slot-id]")) {
1301
1353
  shouldReapply = true;
1302
1354
  }
1303
1355
  }
1304
1356
  });
1305
1357
  if (mutation.type === "attributes") {
1306
1358
  const target = mutation.target;
1307
- if (target.hasAttribute("data-amplifyup-slot") || target.hasAttribute("data-slot-empty")) {
1359
+ if (target.hasAttribute("data-amplifyup-slot") || target.hasAttribute("data-slot-id") || target.hasAttribute("data-slot-empty")) {
1308
1360
  shouldReapply = true;
1309
1361
  }
1310
1362
  }
@@ -1312,7 +1364,10 @@ Available Console Commands:
1312
1364
  if (shouldReapply && this.highlightingEnabled) {
1313
1365
  setTimeout(() => {
1314
1366
  if (this.highlightingEnabled) {
1315
- this.applyComponentHighlights();
1367
+ this.applyComponentHighlights(
1368
+ this.highlightComponentsEnabled,
1369
+ this.showZonesEnabled
1370
+ );
1316
1371
  }
1317
1372
  }, 100);
1318
1373
  }
@@ -1321,7 +1376,7 @@ Available Console Commands:
1321
1376
  childList: true,
1322
1377
  subtree: true,
1323
1378
  attributes: true,
1324
- attributeFilter: ["data-amplifyup-component", "data-component-id", "data-amplifyup-slot", "data-slot-empty"]
1379
+ attributeFilter: ["data-amplifyup-component", "data-component-id", "data-amplifyup-slot", "data-slot-id", "data-slot-empty"]
1325
1380
  });
1326
1381
  }
1327
1382
  /**
@@ -1334,6 +1389,7 @@ Available Console Commands:
1334
1389
  this.mutationObserver.disconnect();
1335
1390
  this.mutationObserver = null;
1336
1391
  }
1392
+ document.getElementById("amplifyup-preview-highlights")?.remove();
1337
1393
  document.querySelectorAll(".amplifyup-component-highlight").forEach((el) => {
1338
1394
  const htmlEl = el;
1339
1395
  const handlers = htmlEl._amplifyupHandlers;
@@ -1349,6 +1405,7 @@ Available Console Commands:
1349
1405
  if (handlers) {
1350
1406
  if (handlers.handleClick) htmlEl.removeEventListener("click", handlers.handleClick);
1351
1407
  if (handlers.handleDragOver) htmlEl.removeEventListener("dragover", handlers.handleDragOver);
1408
+ if (handlers.handleDragLeave) htmlEl.removeEventListener("dragleave", handlers.handleDragLeave);
1352
1409
  if (handlers.handleDrop) htmlEl.removeEventListener("drop", handlers.handleDrop);
1353
1410
  }
1354
1411
  delete htmlEl._amplifyupSlotHandlers;
@@ -1362,7 +1419,7 @@ Available Console Commands:
1362
1419
  const hierarchy = [];
1363
1420
  let current = element;
1364
1421
  while (current) {
1365
- if (current.hasAttribute("data-amplifyup-component") || current.hasAttribute("data-component-id") || current.hasAttribute("data-amplifyup-slot")) {
1422
+ if (current.hasAttribute("data-amplifyup-component") || current.hasAttribute("data-component-id") || current.hasAttribute("data-amplifyup-slot") || current.hasAttribute("data-slot-id")) {
1366
1423
  hierarchy.push(current);
1367
1424
  }
1368
1425
  current = current.parentElement;
@@ -1375,11 +1432,11 @@ Available Console Commands:
1375
1432
  sendSelectionMessage(element, hierarchy, isEmpty) {
1376
1433
  if (!this.isVisualEditorMode) return;
1377
1434
  const componentId = element.getAttribute("data-amplifyup-component") || element.getAttribute("data-component-id");
1378
- const slotName = element.getAttribute("data-amplifyup-slot");
1435
+ const slotName = element.getAttribute("data-amplifyup-slot") || element.getAttribute("data-slot-id");
1379
1436
  const componentName = element.getAttribute("data-component-name");
1380
1437
  const hierarchyInfo = hierarchy.map((el, index) => {
1381
1438
  const elComponentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
1382
- const elSlotName = el.getAttribute("data-amplifyup-slot");
1439
+ const elSlotName = el.getAttribute("data-amplifyup-slot") || el.getAttribute("data-slot-id");
1383
1440
  const elComponentName = el.getAttribute("data-component-name");
1384
1441
  return {
1385
1442
  index,
@@ -1417,98 +1474,116 @@ Available Console Commands:
1417
1474
  /**
1418
1475
  * Apply component highlights
1419
1476
  */
1420
- applyComponentHighlights() {
1477
+ applyComponentHighlights(highlightComponents = true, showZones = true) {
1421
1478
  if (typeof document === "undefined") return;
1422
1479
  if (!this.isVisualEditorMode) {
1423
1480
  return;
1424
1481
  }
1425
1482
  const doc = document;
1426
1483
  const win = window;
1427
- const componentElements = doc.querySelectorAll("[data-amplifyup-component], [data-component-id]");
1428
- console.log("[AmplifyUp SDK] Found", componentElements.length, "components to highlight");
1429
- this.sendComponentTree();
1430
- const slotElements = doc.querySelectorAll("[data-amplifyup-slot]");
1431
- console.log("[AmplifyUp SDK] Found", slotElements.length, "slots to highlight");
1432
- componentElements.forEach((el) => {
1433
- const htmlEl = el;
1434
- const componentId = htmlEl.getAttribute("data-amplifyup-component") || htmlEl.getAttribute("data-component-id");
1435
- if (!componentId) return;
1436
- if (htmlEl.classList.contains("amplifyup-component-highlight")) return;
1437
- const component = this.componentRegistry.find((c) => c.component_id === componentId);
1438
- htmlEl.classList.add("amplifyup-component-highlight");
1439
- htmlEl.setAttribute("data-component-id", componentId);
1440
- htmlEl.setAttribute("data-component-name", component?.component_name || componentId);
1441
- const hierarchy = this.buildComponentHierarchy(htmlEl);
1442
- const handleClick = (e) => {
1443
- e.stopPropagation();
1444
- this.sendSelectionMessage(htmlEl, hierarchy);
1445
- if (window.parent && window.parent !== window) {
1446
- window.parent.postMessage({ type: "CHECK_COMPONENT_DELETABLE", componentId }, "*");
1447
- }
1448
- };
1449
- htmlEl.addEventListener("click", handleClick);
1450
- htmlEl._amplifyupHandlers = { handleClick };
1451
- });
1452
- this.componentRegistry.forEach((component) => {
1453
- if (!component.data_attribute) return;
1454
- const elements = doc.querySelectorAll(`[${component.data_attribute}]`);
1455
- elements.forEach((el) => {
1484
+ if (highlightComponents) {
1485
+ const componentElements = doc.querySelectorAll("[data-amplifyup-component], [data-component-id]");
1486
+ console.log("[AmplifyUp SDK] Found", componentElements.length, "components to highlight");
1487
+ componentElements.forEach((el) => {
1456
1488
  const htmlEl = el;
1489
+ const componentId = htmlEl.getAttribute("data-amplifyup-component") || htmlEl.getAttribute("data-component-id");
1490
+ if (!componentId) return;
1457
1491
  if (htmlEl.classList.contains("amplifyup-component-highlight")) return;
1492
+ const component = this.componentRegistry.find((c) => c.component_id === componentId);
1458
1493
  htmlEl.classList.add("amplifyup-component-highlight");
1459
- htmlEl.setAttribute("data-component-id", component.component_id);
1460
- htmlEl.setAttribute("data-component-name", component.component_name);
1494
+ htmlEl.setAttribute("data-component-id", componentId);
1495
+ htmlEl.setAttribute("data-component-name", component?.component_name || componentId);
1461
1496
  const hierarchy = this.buildComponentHierarchy(htmlEl);
1462
1497
  const handleClick = (e) => {
1463
1498
  e.stopPropagation();
1464
1499
  this.sendSelectionMessage(htmlEl, hierarchy);
1465
1500
  if (window.parent && window.parent !== window) {
1466
- window.parent.postMessage({ type: "CHECK_COMPONENT_DELETABLE", componentId: component.component_id }, "*");
1501
+ window.parent.postMessage({ type: "CHECK_COMPONENT_DELETABLE", componentId }, "*");
1467
1502
  }
1468
1503
  };
1469
1504
  htmlEl.addEventListener("click", handleClick);
1470
1505
  htmlEl._amplifyupHandlers = { handleClick };
1471
1506
  });
1472
- });
1473
- slotElements.forEach((el) => {
1474
- const htmlEl = el;
1475
- const slotName = htmlEl.getAttribute("data-amplifyup-slot");
1476
- const isEmpty = htmlEl.getAttribute("data-slot-empty") === "true";
1477
- if (!slotName) return;
1478
- if (htmlEl.classList.contains("amplifyup-slot-highlight")) return;
1479
- htmlEl.classList.add("amplifyup-slot-highlight");
1480
- const hierarchy = this.buildComponentHierarchy(htmlEl);
1481
- const handleClick = (e) => {
1482
- e.stopPropagation();
1483
- this.sendSelectionMessage(htmlEl, hierarchy, isEmpty);
1484
- };
1485
- const handleDrop = (e) => {
1486
- e.preventDefault();
1487
- e.stopPropagation();
1488
- try {
1489
- const data = JSON.parse(e.dataTransfer.getData("application/json"));
1490
- if (data.type === "component" && win.parent && win.parent !== win) {
1491
- win.parent.postMessage({
1492
- type: "COMPONENT_DROPPED",
1493
- componentId: data.componentId,
1494
- componentName: data.componentName,
1495
- slotName,
1496
- slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
1497
- }, "*");
1507
+ this.componentRegistry.forEach((component) => {
1508
+ if (!component.data_attribute) return;
1509
+ const elements = doc.querySelectorAll(`[${component.data_attribute}]`);
1510
+ elements.forEach((el) => {
1511
+ const htmlEl = el;
1512
+ if (htmlEl.classList.contains("amplifyup-component-highlight")) return;
1513
+ htmlEl.classList.add("amplifyup-component-highlight");
1514
+ htmlEl.setAttribute("data-component-id", component.component_id);
1515
+ htmlEl.setAttribute("data-component-name", component.component_name);
1516
+ const hierarchy = this.buildComponentHierarchy(htmlEl);
1517
+ const handleClick = (e) => {
1518
+ e.stopPropagation();
1519
+ this.sendSelectionMessage(htmlEl, hierarchy);
1520
+ if (window.parent && window.parent !== window) {
1521
+ window.parent.postMessage({ type: "CHECK_COMPONENT_DELETABLE", componentId: component.component_id }, "*");
1522
+ }
1523
+ };
1524
+ htmlEl.addEventListener("click", handleClick);
1525
+ htmlEl._amplifyupHandlers = { handleClick };
1526
+ });
1527
+ });
1528
+ }
1529
+ if (showZones) {
1530
+ const slotElements = doc.querySelectorAll("[data-amplifyup-slot], [data-slot-id]");
1531
+ console.log("[AmplifyUp SDK] Found", slotElements.length, "slots to highlight");
1532
+ slotElements.forEach((el) => {
1533
+ const htmlEl = el;
1534
+ const slotName = htmlEl.getAttribute("data-amplifyup-slot") || htmlEl.getAttribute("data-slot-id");
1535
+ const isEmpty = htmlEl.getAttribute("data-slot-empty") === "true";
1536
+ if (!slotName) return;
1537
+ if (htmlEl.classList.contains("amplifyup-slot-highlight")) return;
1538
+ htmlEl.classList.add("amplifyup-slot-highlight");
1539
+ const hierarchy = this.buildComponentHierarchy(htmlEl);
1540
+ const handleClick = (e) => {
1541
+ e.stopPropagation();
1542
+ this.sendSelectionMessage(htmlEl, hierarchy, isEmpty);
1543
+ };
1544
+ const handleDrop = (e) => {
1545
+ e.preventDefault();
1546
+ e.stopPropagation();
1547
+ htmlEl.classList.remove("amplifyup-drag-over-slot");
1548
+ try {
1549
+ const data = JSON.parse(e.dataTransfer.getData("application/json"));
1550
+ if (data.type === "component" && win.parent && win.parent !== win) {
1551
+ win.parent.postMessage({
1552
+ type: "COMPONENT_DROPPED",
1553
+ componentId: data.componentId,
1554
+ componentName: data.componentName,
1555
+ slotName,
1556
+ slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
1557
+ }, "*");
1558
+ win.parent.postMessage({ type: "DROP_ON_SLOT", slotName }, "*");
1559
+ }
1560
+ } catch (_err) {
1498
1561
  }
1499
- } catch (_err) {
1500
- }
1501
- };
1502
- const handleDragOver = (e) => {
1503
- e.preventDefault();
1504
- e.stopPropagation();
1505
- e.dataTransfer.dropEffect = "copy";
1506
- };
1507
- htmlEl.addEventListener("click", handleClick);
1508
- htmlEl.addEventListener("dragover", handleDragOver);
1509
- htmlEl.addEventListener("drop", handleDrop);
1510
- htmlEl._amplifyupSlotHandlers = { handleClick, handleDragOver, handleDrop };
1511
- });
1562
+ };
1563
+ const handleDragOver = (e) => {
1564
+ e.preventDefault();
1565
+ e.stopPropagation();
1566
+ e.dataTransfer.dropEffect = "copy";
1567
+ htmlEl.classList.add("amplifyup-drag-over-slot");
1568
+ };
1569
+ const handleDragLeave = (e) => {
1570
+ const related = e.relatedTarget;
1571
+ if (!related || !htmlEl.contains(related)) {
1572
+ htmlEl.classList.remove("amplifyup-drag-over-slot");
1573
+ }
1574
+ };
1575
+ htmlEl.addEventListener("click", handleClick);
1576
+ htmlEl.addEventListener("dragover", handleDragOver);
1577
+ htmlEl.addEventListener("dragleave", handleDragLeave);
1578
+ htmlEl.addEventListener("drop", handleDrop);
1579
+ htmlEl._amplifyupSlotHandlers = {
1580
+ handleClick,
1581
+ handleDragOver,
1582
+ handleDragLeave,
1583
+ handleDrop
1584
+ };
1585
+ });
1586
+ }
1512
1587
  }
1513
1588
  /**
1514
1589
  * Cleanup: Remove message listener and observers
@@ -1811,7 +1886,16 @@ function AmplifyRenderer({
1811
1886
  childrenCount: childrenToRender.length
1812
1887
  });
1813
1888
  }
1814
- slotChildren[slot.slotId] = /* @__PURE__ */ jsx("div", { "data-slot-id": slot.slotId, "data-zone-id": slot.zoneId || void 0, children: childrenToRender.map((child) => renderNode(child)) }, slot.slotId);
1889
+ slotChildren[slot.slotId] = /* @__PURE__ */ jsx(
1890
+ "div",
1891
+ {
1892
+ "data-slot-id": slot.slotId,
1893
+ "data-amplifyup-slot": slot.slotId,
1894
+ "data-zone-id": slot.zoneId || void 0,
1895
+ children: childrenToRender.map((child) => renderNode(child))
1896
+ },
1897
+ slot.slotId
1898
+ );
1815
1899
  console.log(`[AmplifyRenderer] Created slot content for ${slot.slotId}`, {
1816
1900
  slotId: slot.slotId,
1817
1901
  renderedChildrenCount: childrenToRender.length
@@ -1836,7 +1920,15 @@ function AmplifyRenderer({
1836
1920
  return /* @__PURE__ */ jsx("main", { children: layoutTree.map((node) => /* @__PURE__ */ jsx("div", { children: renderNode(node) }, node.id)) });
1837
1921
  }
1838
1922
  function defaultPreviewCanvas() {
1839
- return /* @__PURE__ */ jsx("main", { className: "min-h-[50vh]", "data-amplifyup-composer-canvas": true });
1923
+ return /* @__PURE__ */ jsx("main", { className: "min-h-[50vh] w-full", children: /* @__PURE__ */ jsx(
1924
+ "div",
1925
+ {
1926
+ "data-slot-id": "main",
1927
+ "data-amplifyup-slot": "main",
1928
+ "data-slot-empty": "true",
1929
+ className: "min-h-[50vh] w-full"
1930
+ }
1931
+ ) });
1840
1932
  }
1841
1933
  function hasAmplifyLayout(pageConfig) {
1842
1934
  return !!(pageConfig && pageConfig.id !== "default" && Array.isArray(pageConfig.layoutTree) && pageConfig.layoutTree.length > 0);