@amplifyup/sdk 0.1.7 → 0.1.9

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.
@@ -318,6 +318,8 @@ var AmplifyUpSDK = class {
318
318
  /** Ensures auto page() on init fires once per page load */
319
319
  this.initialPageSent = false;
320
320
  this.highlightingEnabled = false;
321
+ this.highlightComponentsEnabled = true;
322
+ this.showZonesEnabled = false;
321
323
  this.componentRegistry = [];
322
324
  this.messageListener = null;
323
325
  this.mutationObserver = null;
@@ -1112,7 +1114,7 @@ Available Console Commands:
1112
1114
  }
1113
1115
  if (event.data?.type === "GET_ELEMENT_POSITION") {
1114
1116
  const { componentId, slotName } = event.data;
1115
- const selector = slotName ? `[data-amplifyup-slot="${slotName}"]` : `[data-amplifyup-component="${componentId}"], [data-component-id="${componentId}"]`;
1117
+ const selector = slotName ? `[data-amplifyup-slot="${slotName}"], [data-slot-id="${slotName}"]` : `[data-amplifyup-component="${componentId}"], [data-component-id="${componentId}"]`;
1116
1118
  console.log("[AmplifyUp SDK] Finding element position:", { selector, componentId, slotName });
1117
1119
  const element = document.querySelector(selector);
1118
1120
  if (element) {
@@ -1250,12 +1252,62 @@ Available Console Commands:
1250
1252
  if (typeof document === "undefined") return;
1251
1253
  this.componentRegistry = componentRegistry;
1252
1254
  this.highlightingEnabled = true;
1255
+ this.highlightComponentsEnabled = highlightComponents;
1256
+ this.showZonesEnabled = showZones;
1253
1257
  this.disableHighlighting();
1254
- if (highlightComponents) {
1255
- this.applyComponentHighlights();
1258
+ this.highlightingEnabled = true;
1259
+ this.injectComposerHighlightStyles(highlightComponents, showZones);
1260
+ if (highlightComponents || showZones) {
1261
+ this.applyComponentHighlights(highlightComponents, showZones);
1256
1262
  this.setupMutationObserver();
1257
1263
  }
1258
1264
  }
1265
+ /** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
1266
+ injectComposerHighlightStyles(highlightComponents, showZones) {
1267
+ if (typeof document === "undefined") return;
1268
+ if (!highlightComponents && !showZones) return;
1269
+ const existing = document.getElementById("amplifyup-preview-highlights");
1270
+ if (existing) existing.remove();
1271
+ const lines = [];
1272
+ if (highlightComponents) {
1273
+ lines.push(
1274
+ "[data-amplifyup-component], [data-component-id] {",
1275
+ " outline: 1px dashed rgba(59, 130, 246, 0.8) !important;",
1276
+ " outline-offset: 2px !important;",
1277
+ " cursor: pointer !important;",
1278
+ "}",
1279
+ "[data-amplifyup-component]:hover, [data-component-id]:hover {",
1280
+ " outline-color: rgba(59, 130, 246, 1) !important;",
1281
+ "}"
1282
+ );
1283
+ }
1284
+ if (showZones) {
1285
+ lines.push(
1286
+ "[data-slot-id], [data-amplifyup-slot] {",
1287
+ " outline: 2px dotted rgba(34, 197, 94, 0.75) !important;",
1288
+ " outline-offset: 4px !important;",
1289
+ " min-height: 3rem !important;",
1290
+ " box-sizing: border-box !important;",
1291
+ " cursor: pointer !important;",
1292
+ "}",
1293
+ '[data-slot-id="main"], [data-amplifyup-slot="main"] {',
1294
+ " min-height: 50vh !important;",
1295
+ "}",
1296
+ "[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover {",
1297
+ " outline-color: rgba(34, 197, 94, 1) !important;",
1298
+ " background: rgba(34, 197, 94, 0.06) !important;",
1299
+ "}",
1300
+ "[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot {",
1301
+ " outline: 2px solid rgba(34, 197, 94, 1) !important;",
1302
+ " background: rgba(34, 197, 94, 0.1) !important;",
1303
+ "}"
1304
+ );
1305
+ }
1306
+ const style = document.createElement("style");
1307
+ style.id = "amplifyup-preview-highlights";
1308
+ style.textContent = lines.join("\n");
1309
+ document.head.appendChild(style);
1310
+ }
1259
1311
  /**
1260
1312
  * Set up MutationObserver to watch for new components being added
1261
1313
  */
@@ -1271,14 +1323,14 @@ Available Console Commands:
1271
1323
  mutation.addedNodes.forEach((node) => {
1272
1324
  if (node.nodeType === Node.ELEMENT_NODE) {
1273
1325
  const el = node;
1274
- 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]")) {
1326
+ 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]")) {
1275
1327
  shouldReapply = true;
1276
1328
  }
1277
1329
  }
1278
1330
  });
1279
1331
  if (mutation.type === "attributes") {
1280
1332
  const target = mutation.target;
1281
- if (target.hasAttribute("data-amplifyup-slot") || target.hasAttribute("data-slot-empty")) {
1333
+ if (target.hasAttribute("data-amplifyup-slot") || target.hasAttribute("data-slot-id") || target.hasAttribute("data-slot-empty")) {
1282
1334
  shouldReapply = true;
1283
1335
  }
1284
1336
  }
@@ -1286,7 +1338,10 @@ Available Console Commands:
1286
1338
  if (shouldReapply && this.highlightingEnabled) {
1287
1339
  setTimeout(() => {
1288
1340
  if (this.highlightingEnabled) {
1289
- this.applyComponentHighlights();
1341
+ this.applyComponentHighlights(
1342
+ this.highlightComponentsEnabled,
1343
+ this.showZonesEnabled
1344
+ );
1290
1345
  }
1291
1346
  }, 100);
1292
1347
  }
@@ -1295,7 +1350,7 @@ Available Console Commands:
1295
1350
  childList: true,
1296
1351
  subtree: true,
1297
1352
  attributes: true,
1298
- attributeFilter: ["data-amplifyup-component", "data-component-id", "data-amplifyup-slot", "data-slot-empty"]
1353
+ attributeFilter: ["data-amplifyup-component", "data-component-id", "data-amplifyup-slot", "data-slot-id", "data-slot-empty"]
1299
1354
  });
1300
1355
  }
1301
1356
  /**
@@ -1308,6 +1363,7 @@ Available Console Commands:
1308
1363
  this.mutationObserver.disconnect();
1309
1364
  this.mutationObserver = null;
1310
1365
  }
1366
+ document.getElementById("amplifyup-preview-highlights")?.remove();
1311
1367
  document.querySelectorAll(".amplifyup-component-highlight").forEach((el) => {
1312
1368
  const htmlEl = el;
1313
1369
  const handlers = htmlEl._amplifyupHandlers;
@@ -1323,6 +1379,7 @@ Available Console Commands:
1323
1379
  if (handlers) {
1324
1380
  if (handlers.handleClick) htmlEl.removeEventListener("click", handlers.handleClick);
1325
1381
  if (handlers.handleDragOver) htmlEl.removeEventListener("dragover", handlers.handleDragOver);
1382
+ if (handlers.handleDragLeave) htmlEl.removeEventListener("dragleave", handlers.handleDragLeave);
1326
1383
  if (handlers.handleDrop) htmlEl.removeEventListener("drop", handlers.handleDrop);
1327
1384
  }
1328
1385
  delete htmlEl._amplifyupSlotHandlers;
@@ -1336,7 +1393,7 @@ Available Console Commands:
1336
1393
  const hierarchy = [];
1337
1394
  let current = element;
1338
1395
  while (current) {
1339
- if (current.hasAttribute("data-amplifyup-component") || current.hasAttribute("data-component-id") || current.hasAttribute("data-amplifyup-slot")) {
1396
+ if (current.hasAttribute("data-amplifyup-component") || current.hasAttribute("data-component-id") || current.hasAttribute("data-amplifyup-slot") || current.hasAttribute("data-slot-id")) {
1340
1397
  hierarchy.push(current);
1341
1398
  }
1342
1399
  current = current.parentElement;
@@ -1349,11 +1406,11 @@ Available Console Commands:
1349
1406
  sendSelectionMessage(element, hierarchy, isEmpty) {
1350
1407
  if (!this.isVisualEditorMode) return;
1351
1408
  const componentId = element.getAttribute("data-amplifyup-component") || element.getAttribute("data-component-id");
1352
- const slotName = element.getAttribute("data-amplifyup-slot");
1409
+ const slotName = element.getAttribute("data-amplifyup-slot") || element.getAttribute("data-slot-id");
1353
1410
  const componentName = element.getAttribute("data-component-name");
1354
1411
  const hierarchyInfo = hierarchy.map((el, index) => {
1355
1412
  const elComponentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
1356
- const elSlotName = el.getAttribute("data-amplifyup-slot");
1413
+ const elSlotName = el.getAttribute("data-amplifyup-slot") || el.getAttribute("data-slot-id");
1357
1414
  const elComponentName = el.getAttribute("data-component-name");
1358
1415
  return {
1359
1416
  index,
@@ -1391,98 +1448,116 @@ Available Console Commands:
1391
1448
  /**
1392
1449
  * Apply component highlights
1393
1450
  */
1394
- applyComponentHighlights() {
1451
+ applyComponentHighlights(highlightComponents = true, showZones = true) {
1395
1452
  if (typeof document === "undefined") return;
1396
1453
  if (!this.isVisualEditorMode) {
1397
1454
  return;
1398
1455
  }
1399
1456
  const doc = document;
1400
1457
  const win = window;
1401
- const componentElements = doc.querySelectorAll("[data-amplifyup-component], [data-component-id]");
1402
- console.log("[AmplifyUp SDK] Found", componentElements.length, "components to highlight");
1403
- this.sendComponentTree();
1404
- const slotElements = doc.querySelectorAll("[data-amplifyup-slot]");
1405
- console.log("[AmplifyUp SDK] Found", slotElements.length, "slots to highlight");
1406
- componentElements.forEach((el) => {
1407
- const htmlEl = el;
1408
- const componentId = htmlEl.getAttribute("data-amplifyup-component") || htmlEl.getAttribute("data-component-id");
1409
- if (!componentId) return;
1410
- if (htmlEl.classList.contains("amplifyup-component-highlight")) return;
1411
- const component = this.componentRegistry.find((c) => c.component_id === componentId);
1412
- htmlEl.classList.add("amplifyup-component-highlight");
1413
- htmlEl.setAttribute("data-component-id", componentId);
1414
- htmlEl.setAttribute("data-component-name", component?.component_name || componentId);
1415
- const hierarchy = this.buildComponentHierarchy(htmlEl);
1416
- const handleClick = (e) => {
1417
- e.stopPropagation();
1418
- this.sendSelectionMessage(htmlEl, hierarchy);
1419
- if (window.parent && window.parent !== window) {
1420
- window.parent.postMessage({ type: "CHECK_COMPONENT_DELETABLE", componentId }, "*");
1421
- }
1422
- };
1423
- htmlEl.addEventListener("click", handleClick);
1424
- htmlEl._amplifyupHandlers = { handleClick };
1425
- });
1426
- this.componentRegistry.forEach((component) => {
1427
- if (!component.data_attribute) return;
1428
- const elements = doc.querySelectorAll(`[${component.data_attribute}]`);
1429
- elements.forEach((el) => {
1458
+ if (highlightComponents) {
1459
+ const componentElements = doc.querySelectorAll("[data-amplifyup-component], [data-component-id]");
1460
+ console.log("[AmplifyUp SDK] Found", componentElements.length, "components to highlight");
1461
+ componentElements.forEach((el) => {
1430
1462
  const htmlEl = el;
1463
+ const componentId = htmlEl.getAttribute("data-amplifyup-component") || htmlEl.getAttribute("data-component-id");
1464
+ if (!componentId) return;
1431
1465
  if (htmlEl.classList.contains("amplifyup-component-highlight")) return;
1466
+ const component = this.componentRegistry.find((c) => c.component_id === componentId);
1432
1467
  htmlEl.classList.add("amplifyup-component-highlight");
1433
- htmlEl.setAttribute("data-component-id", component.component_id);
1434
- htmlEl.setAttribute("data-component-name", component.component_name);
1468
+ htmlEl.setAttribute("data-component-id", componentId);
1469
+ htmlEl.setAttribute("data-component-name", component?.component_name || componentId);
1435
1470
  const hierarchy = this.buildComponentHierarchy(htmlEl);
1436
1471
  const handleClick = (e) => {
1437
1472
  e.stopPropagation();
1438
1473
  this.sendSelectionMessage(htmlEl, hierarchy);
1439
1474
  if (window.parent && window.parent !== window) {
1440
- window.parent.postMessage({ type: "CHECK_COMPONENT_DELETABLE", componentId: component.component_id }, "*");
1475
+ window.parent.postMessage({ type: "CHECK_COMPONENT_DELETABLE", componentId }, "*");
1441
1476
  }
1442
1477
  };
1443
1478
  htmlEl.addEventListener("click", handleClick);
1444
1479
  htmlEl._amplifyupHandlers = { handleClick };
1445
1480
  });
1446
- });
1447
- slotElements.forEach((el) => {
1448
- const htmlEl = el;
1449
- const slotName = htmlEl.getAttribute("data-amplifyup-slot");
1450
- const isEmpty = htmlEl.getAttribute("data-slot-empty") === "true";
1451
- if (!slotName) return;
1452
- if (htmlEl.classList.contains("amplifyup-slot-highlight")) return;
1453
- htmlEl.classList.add("amplifyup-slot-highlight");
1454
- const hierarchy = this.buildComponentHierarchy(htmlEl);
1455
- const handleClick = (e) => {
1456
- e.stopPropagation();
1457
- this.sendSelectionMessage(htmlEl, hierarchy, isEmpty);
1458
- };
1459
- const handleDrop = (e) => {
1460
- e.preventDefault();
1461
- e.stopPropagation();
1462
- try {
1463
- const data = JSON.parse(e.dataTransfer.getData("application/json"));
1464
- if (data.type === "component" && win.parent && win.parent !== win) {
1465
- win.parent.postMessage({
1466
- type: "COMPONENT_DROPPED",
1467
- componentId: data.componentId,
1468
- componentName: data.componentName,
1469
- slotName,
1470
- slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
1471
- }, "*");
1481
+ this.componentRegistry.forEach((component) => {
1482
+ if (!component.data_attribute) return;
1483
+ const elements = doc.querySelectorAll(`[${component.data_attribute}]`);
1484
+ elements.forEach((el) => {
1485
+ const htmlEl = el;
1486
+ if (htmlEl.classList.contains("amplifyup-component-highlight")) return;
1487
+ htmlEl.classList.add("amplifyup-component-highlight");
1488
+ htmlEl.setAttribute("data-component-id", component.component_id);
1489
+ htmlEl.setAttribute("data-component-name", component.component_name);
1490
+ const hierarchy = this.buildComponentHierarchy(htmlEl);
1491
+ const handleClick = (e) => {
1492
+ e.stopPropagation();
1493
+ this.sendSelectionMessage(htmlEl, hierarchy);
1494
+ if (window.parent && window.parent !== window) {
1495
+ window.parent.postMessage({ type: "CHECK_COMPONENT_DELETABLE", componentId: component.component_id }, "*");
1496
+ }
1497
+ };
1498
+ htmlEl.addEventListener("click", handleClick);
1499
+ htmlEl._amplifyupHandlers = { handleClick };
1500
+ });
1501
+ });
1502
+ }
1503
+ if (showZones) {
1504
+ const slotElements = doc.querySelectorAll("[data-amplifyup-slot], [data-slot-id]");
1505
+ console.log("[AmplifyUp SDK] Found", slotElements.length, "slots to highlight");
1506
+ slotElements.forEach((el) => {
1507
+ const htmlEl = el;
1508
+ const slotName = htmlEl.getAttribute("data-amplifyup-slot") || htmlEl.getAttribute("data-slot-id");
1509
+ const isEmpty = htmlEl.getAttribute("data-slot-empty") === "true";
1510
+ if (!slotName) return;
1511
+ if (htmlEl.classList.contains("amplifyup-slot-highlight")) return;
1512
+ htmlEl.classList.add("amplifyup-slot-highlight");
1513
+ const hierarchy = this.buildComponentHierarchy(htmlEl);
1514
+ const handleClick = (e) => {
1515
+ e.stopPropagation();
1516
+ this.sendSelectionMessage(htmlEl, hierarchy, isEmpty);
1517
+ };
1518
+ const handleDrop = (e) => {
1519
+ e.preventDefault();
1520
+ e.stopPropagation();
1521
+ htmlEl.classList.remove("amplifyup-drag-over-slot");
1522
+ try {
1523
+ const data = JSON.parse(e.dataTransfer.getData("application/json"));
1524
+ if (data.type === "component" && win.parent && win.parent !== win) {
1525
+ win.parent.postMessage({
1526
+ type: "COMPONENT_DROPPED",
1527
+ componentId: data.componentId,
1528
+ componentName: data.componentName,
1529
+ slotName,
1530
+ slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
1531
+ }, "*");
1532
+ win.parent.postMessage({ type: "DROP_ON_SLOT", slotName }, "*");
1533
+ }
1534
+ } catch (_err) {
1472
1535
  }
1473
- } catch (_err) {
1474
- }
1475
- };
1476
- const handleDragOver = (e) => {
1477
- e.preventDefault();
1478
- e.stopPropagation();
1479
- e.dataTransfer.dropEffect = "copy";
1480
- };
1481
- htmlEl.addEventListener("click", handleClick);
1482
- htmlEl.addEventListener("dragover", handleDragOver);
1483
- htmlEl.addEventListener("drop", handleDrop);
1484
- htmlEl._amplifyupSlotHandlers = { handleClick, handleDragOver, handleDrop };
1485
- });
1536
+ };
1537
+ const handleDragOver = (e) => {
1538
+ e.preventDefault();
1539
+ e.stopPropagation();
1540
+ e.dataTransfer.dropEffect = "copy";
1541
+ htmlEl.classList.add("amplifyup-drag-over-slot");
1542
+ };
1543
+ const handleDragLeave = (e) => {
1544
+ const related = e.relatedTarget;
1545
+ if (!related || !htmlEl.contains(related)) {
1546
+ htmlEl.classList.remove("amplifyup-drag-over-slot");
1547
+ }
1548
+ };
1549
+ htmlEl.addEventListener("click", handleClick);
1550
+ htmlEl.addEventListener("dragover", handleDragOver);
1551
+ htmlEl.addEventListener("dragleave", handleDragLeave);
1552
+ htmlEl.addEventListener("drop", handleDrop);
1553
+ htmlEl._amplifyupSlotHandlers = {
1554
+ handleClick,
1555
+ handleDragOver,
1556
+ handleDragLeave,
1557
+ handleDrop
1558
+ };
1559
+ });
1560
+ }
1486
1561
  }
1487
1562
  /**
1488
1563
  * Cleanup: Remove message listener and observers
@@ -1804,7 +1879,16 @@ function AmplifyRenderer({
1804
1879
  childrenCount: childrenToRender.length
1805
1880
  });
1806
1881
  }
1807
- 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);
1882
+ slotChildren[slot.slotId] = /* @__PURE__ */ jsx(
1883
+ "div",
1884
+ {
1885
+ "data-slot-id": slot.slotId,
1886
+ "data-amplifyup-slot": slot.slotId,
1887
+ "data-zone-id": slot.zoneId || void 0,
1888
+ children: childrenToRender.map((child) => renderNode(child))
1889
+ },
1890
+ slot.slotId
1891
+ );
1808
1892
  console.log(`[AmplifyRenderer] Created slot content for ${slot.slotId}`, {
1809
1893
  slotId: slot.slotId,
1810
1894
  renderedChildrenCount: childrenToRender.length