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