@amplifyup/sdk 0.1.10 → 0.1.11

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/index.mjs CHANGED
@@ -339,6 +339,7 @@ var AmplifyUpSDK = class {
339
339
  this.componentRegistry = [];
340
340
  this.messageListener = null;
341
341
  this.mutationObserver = null;
342
+ this.composerDragHandlers = null;
342
343
  this.isVisualEditorMode = false;
343
344
  this.eventSelectionMode = false;
344
345
  this.eventSelectionClickHandler = null;
@@ -1302,6 +1303,111 @@ Available Console Commands:
1302
1303
  this.applyComponentHighlights(highlightComponents, showZones);
1303
1304
  this.setupMutationObserver();
1304
1305
  }
1306
+ if (showZones) {
1307
+ this.setupComposerDragDrop();
1308
+ }
1309
+ }
1310
+ /** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
1311
+ setupComposerDragDrop() {
1312
+ if (typeof document === "undefined") return;
1313
+ this.teardownComposerDragDrop();
1314
+ const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
1315
+ const clearDragOverState = () => {
1316
+ document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
1317
+ el.classList.remove("amplifyup-drag-over-slot");
1318
+ });
1319
+ document.body.classList.remove("amplifyup-drag-no-drop");
1320
+ };
1321
+ const dragenter = (e) => {
1322
+ e.preventDefault();
1323
+ if (e.dataTransfer?.types?.length) {
1324
+ document.body.classList.add("amplifyup-drag-no-drop");
1325
+ }
1326
+ };
1327
+ const dragover = (e) => {
1328
+ e.preventDefault();
1329
+ const target = e.target;
1330
+ const slot = target?.closest?.(slotSelector);
1331
+ if (e.dataTransfer) {
1332
+ e.dataTransfer.dropEffect = slot ? "copy" : "none";
1333
+ }
1334
+ document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
1335
+ el.classList.remove("amplifyup-drag-over-slot");
1336
+ });
1337
+ if (slot) {
1338
+ slot.classList.add("amplifyup-drag-over-slot");
1339
+ document.body.classList.remove("amplifyup-drag-no-drop");
1340
+ } else {
1341
+ document.body.classList.add("amplifyup-drag-no-drop");
1342
+ }
1343
+ };
1344
+ const dragleave = (e) => {
1345
+ const related = e.relatedTarget;
1346
+ if (!related || !document.body.contains(related)) {
1347
+ clearDragOverState();
1348
+ }
1349
+ };
1350
+ const drop = (e) => {
1351
+ e.preventDefault();
1352
+ const target = e.target;
1353
+ const slot = target?.closest?.(slotSelector);
1354
+ clearDragOverState();
1355
+ if (!slot || !this.isVisualEditorMode) return;
1356
+ const slotName = slot.getAttribute("data-amplifyup-slot") || slot.getAttribute("data-slot-id");
1357
+ const isEmpty = slot.getAttribute("data-slot-empty") === "true";
1358
+ const win = window;
1359
+ if (slotName && win.parent && win.parent !== win) {
1360
+ win.parent.postMessage({
1361
+ type: "DROP_ON_SLOT",
1362
+ slotName,
1363
+ slotElement: { path: slot.getAttribute("data-slot-path"), isEmpty }
1364
+ }, "*");
1365
+ }
1366
+ };
1367
+ const mouseover = (e) => {
1368
+ if (!this.showZonesEnabled) return;
1369
+ const target = e.target;
1370
+ const slot = target?.closest?.(slotSelector);
1371
+ if (!slot) return;
1372
+ document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
1373
+ el.classList.remove("amplifyup-slot-hover");
1374
+ });
1375
+ slot.classList.add("amplifyup-slot-hover");
1376
+ };
1377
+ const mouseout = (e) => {
1378
+ if (!this.showZonesEnabled) return;
1379
+ const related = e.relatedTarget;
1380
+ if (!related?.closest?.(slotSelector)) {
1381
+ document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
1382
+ el.classList.remove("amplifyup-slot-hover");
1383
+ });
1384
+ }
1385
+ };
1386
+ document.addEventListener("dragenter", dragenter, false);
1387
+ document.addEventListener("dragover", dragover, false);
1388
+ document.addEventListener("dragleave", dragleave, false);
1389
+ document.addEventListener("drop", drop, false);
1390
+ document.addEventListener("mouseover", mouseover, true);
1391
+ document.addEventListener("mouseout", mouseout, true);
1392
+ this.composerDragHandlers = { dragenter, dragover, dragleave, drop, mouseover, mouseout };
1393
+ }
1394
+ teardownComposerDragDrop() {
1395
+ if (!this.composerDragHandlers || typeof document === "undefined") return;
1396
+ const h = this.composerDragHandlers;
1397
+ document.removeEventListener("dragenter", h.dragenter, false);
1398
+ document.removeEventListener("dragover", h.dragover, false);
1399
+ document.removeEventListener("dragleave", h.dragleave, false);
1400
+ document.removeEventListener("drop", h.drop, false);
1401
+ document.removeEventListener("mouseover", h.mouseover, true);
1402
+ document.removeEventListener("mouseout", h.mouseout, true);
1403
+ this.composerDragHandlers = null;
1404
+ document.body.classList.remove("amplifyup-drag-no-drop");
1405
+ document.querySelectorAll("[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot").forEach((el) => {
1406
+ el.classList.remove("amplifyup-drag-over-slot");
1407
+ });
1408
+ document.querySelectorAll("[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover").forEach((el) => {
1409
+ el.classList.remove("amplifyup-slot-hover");
1410
+ });
1305
1411
  }
1306
1412
  /** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
1307
1413
  injectComposerHighlightStyles(highlightComponents, showZones) {
@@ -1328,19 +1434,64 @@ Available Console Commands:
1328
1434
  " outline: 2px dotted rgba(34, 197, 94, 0.75) !important;",
1329
1435
  " outline-offset: 4px !important;",
1330
1436
  " min-height: 3rem !important;",
1437
+ " padding: 20px !important;",
1331
1438
  " box-sizing: border-box !important;",
1332
1439
  " cursor: pointer !important;",
1440
+ " position: relative !important;",
1333
1441
  "}",
1334
1442
  '[data-slot-id="main"], [data-amplifyup-slot="main"] {',
1335
1443
  " min-height: 50vh !important;",
1336
1444
  "}",
1445
+ '[data-slot-id="main"][data-slot-empty="true"]::before,',
1446
+ '[data-amplifyup-slot="main"][data-slot-empty="true"]::before {',
1447
+ ' content: "Drop components here" !important;',
1448
+ " position: absolute !important;",
1449
+ " top: 50% !important; left: 50% !important;",
1450
+ " transform: translate(-50%, -50%) !important;",
1451
+ " font-size: 14px !important; font-weight: 500 !important;",
1452
+ " color: rgba(34, 197, 94, 0.65) !important;",
1453
+ " pointer-events: none !important;",
1454
+ " white-space: nowrap !important;",
1455
+ "}",
1337
1456
  "[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover {",
1338
1457
  " outline-color: rgba(34, 197, 94, 1) !important;",
1339
1458
  " background: rgba(34, 197, 94, 0.06) !important;",
1340
1459
  "}",
1341
1460
  "[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot {",
1342
1461
  " outline: 2px solid rgba(34, 197, 94, 1) !important;",
1343
- " background: rgba(34, 197, 94, 0.1) !important;",
1462
+ " background: rgba(34, 197, 94, 0.18) !important;",
1463
+ " position: relative !important;",
1464
+ "}",
1465
+ "[data-slot-id].amplifyup-drag-over-slot::after,",
1466
+ "[data-amplifyup-slot].amplifyup-drag-over-slot::after {",
1467
+ ' content: "\\2713 Drop here" !important;',
1468
+ " position: absolute !important;",
1469
+ " top: 50% !important; left: 50% !important;",
1470
+ " transform: translate(-50%, -50%) !important;",
1471
+ " font-size: 14px !important; font-weight: 600 !important;",
1472
+ " color: rgb(22, 163, 74) !important;",
1473
+ " pointer-events: none !important;",
1474
+ " white-space: nowrap !important;",
1475
+ " z-index: 1 !important;",
1476
+ "}",
1477
+ "body.amplifyup-drag-no-drop { cursor: no-drop !important; }",
1478
+ "body.amplifyup-drag-no-drop::before {",
1479
+ ' content: "" !important;',
1480
+ " position: fixed !important; top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;",
1481
+ " background: rgba(239, 68, 68, 0.06) !important;",
1482
+ " pointer-events: none !important;",
1483
+ " z-index: 2147483646 !important;",
1484
+ "}",
1485
+ "body.amplifyup-drag-no-drop::after {",
1486
+ ' content: "\\2717 Not a drop zone" !important;',
1487
+ " position: fixed !important; bottom: 12px !important; right: 12px !important;",
1488
+ " font-size: 12px !important; font-weight: 600 !important;",
1489
+ " color: rgb(185, 28, 28) !important;",
1490
+ " background: rgba(254, 226, 226, 0.95) !important;",
1491
+ " padding: 6px 10px !important; border-radius: 6px !important;",
1492
+ " pointer-events: none !important;",
1493
+ " z-index: 2147483647 !important;",
1494
+ " box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;",
1344
1495
  "}"
1345
1496
  );
1346
1497
  }
@@ -1400,6 +1551,7 @@ Available Console Commands:
1400
1551
  disableHighlighting() {
1401
1552
  if (typeof document === "undefined") return;
1402
1553
  this.highlightingEnabled = false;
1554
+ this.teardownComposerDragDrop();
1403
1555
  if (this.mutationObserver) {
1404
1556
  this.mutationObserver.disconnect();
1405
1557
  this.mutationObserver = null;
@@ -1560,9 +1712,15 @@ Available Console Commands:
1560
1712
  e.preventDefault();
1561
1713
  e.stopPropagation();
1562
1714
  htmlEl.classList.remove("amplifyup-drag-over-slot");
1715
+ if (!win.parent || win.parent === win) return;
1716
+ win.parent.postMessage({
1717
+ type: "DROP_ON_SLOT",
1718
+ slotName,
1719
+ slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
1720
+ }, "*");
1563
1721
  try {
1564
1722
  const data = JSON.parse(e.dataTransfer.getData("application/json"));
1565
- if (data.type === "component" && win.parent && win.parent !== win) {
1723
+ if (data.type === "component") {
1566
1724
  win.parent.postMessage({
1567
1725
  type: "COMPONENT_DROPPED",
1568
1726
  componentId: data.componentId,
@@ -1570,7 +1728,6 @@ Available Console Commands:
1570
1728
  slotName,
1571
1729
  slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
1572
1730
  }, "*");
1573
- win.parent.postMessage({ type: "DROP_ON_SLOT", slotName }, "*");
1574
1731
  }
1575
1732
  } catch (_err) {
1576
1733
  }