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