@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.
@@ -323,6 +323,7 @@ var AmplifyUpSDK = class {
323
323
  this.componentRegistry = [];
324
324
  this.messageListener = null;
325
325
  this.mutationObserver = null;
326
+ this.composerDragHandlers = null;
326
327
  this.isVisualEditorMode = false;
327
328
  this.eventSelectionMode = false;
328
329
  this.eventSelectionClickHandler = null;
@@ -1286,6 +1287,111 @@ Available Console Commands:
1286
1287
  this.applyComponentHighlights(highlightComponents, showZones);
1287
1288
  this.setupMutationObserver();
1288
1289
  }
1290
+ if (showZones) {
1291
+ this.setupComposerDragDrop();
1292
+ }
1293
+ }
1294
+ /** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
1295
+ setupComposerDragDrop() {
1296
+ if (typeof document === "undefined") return;
1297
+ this.teardownComposerDragDrop();
1298
+ const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
1299
+ const clearDragOverState = () => {
1300
+ document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
1301
+ el.classList.remove("amplifyup-drag-over-slot");
1302
+ });
1303
+ document.body.classList.remove("amplifyup-drag-no-drop");
1304
+ };
1305
+ const dragenter = (e) => {
1306
+ e.preventDefault();
1307
+ if (e.dataTransfer?.types?.length) {
1308
+ document.body.classList.add("amplifyup-drag-no-drop");
1309
+ }
1310
+ };
1311
+ const dragover = (e) => {
1312
+ e.preventDefault();
1313
+ const target = e.target;
1314
+ const slot = target?.closest?.(slotSelector);
1315
+ if (e.dataTransfer) {
1316
+ e.dataTransfer.dropEffect = slot ? "copy" : "none";
1317
+ }
1318
+ document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
1319
+ el.classList.remove("amplifyup-drag-over-slot");
1320
+ });
1321
+ if (slot) {
1322
+ slot.classList.add("amplifyup-drag-over-slot");
1323
+ document.body.classList.remove("amplifyup-drag-no-drop");
1324
+ } else {
1325
+ document.body.classList.add("amplifyup-drag-no-drop");
1326
+ }
1327
+ };
1328
+ const dragleave = (e) => {
1329
+ const related = e.relatedTarget;
1330
+ if (!related || !document.body.contains(related)) {
1331
+ clearDragOverState();
1332
+ }
1333
+ };
1334
+ const drop = (e) => {
1335
+ e.preventDefault();
1336
+ const target = e.target;
1337
+ const slot = target?.closest?.(slotSelector);
1338
+ clearDragOverState();
1339
+ if (!slot || !this.isVisualEditorMode) return;
1340
+ const slotName = slot.getAttribute("data-amplifyup-slot") || slot.getAttribute("data-slot-id");
1341
+ const isEmpty = slot.getAttribute("data-slot-empty") === "true";
1342
+ const win = window;
1343
+ if (slotName && win.parent && win.parent !== win) {
1344
+ win.parent.postMessage({
1345
+ type: "DROP_ON_SLOT",
1346
+ slotName,
1347
+ slotElement: { path: slot.getAttribute("data-slot-path"), isEmpty }
1348
+ }, "*");
1349
+ }
1350
+ };
1351
+ const mouseover = (e) => {
1352
+ if (!this.showZonesEnabled) return;
1353
+ const target = e.target;
1354
+ const slot = target?.closest?.(slotSelector);
1355
+ if (!slot) return;
1356
+ document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
1357
+ el.classList.remove("amplifyup-slot-hover");
1358
+ });
1359
+ slot.classList.add("amplifyup-slot-hover");
1360
+ };
1361
+ const mouseout = (e) => {
1362
+ if (!this.showZonesEnabled) return;
1363
+ const related = e.relatedTarget;
1364
+ if (!related?.closest?.(slotSelector)) {
1365
+ document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
1366
+ el.classList.remove("amplifyup-slot-hover");
1367
+ });
1368
+ }
1369
+ };
1370
+ document.addEventListener("dragenter", dragenter, false);
1371
+ document.addEventListener("dragover", dragover, false);
1372
+ document.addEventListener("dragleave", dragleave, false);
1373
+ document.addEventListener("drop", drop, false);
1374
+ document.addEventListener("mouseover", mouseover, true);
1375
+ document.addEventListener("mouseout", mouseout, true);
1376
+ this.composerDragHandlers = { dragenter, dragover, dragleave, drop, mouseover, mouseout };
1377
+ }
1378
+ teardownComposerDragDrop() {
1379
+ if (!this.composerDragHandlers || typeof document === "undefined") return;
1380
+ const h = this.composerDragHandlers;
1381
+ document.removeEventListener("dragenter", h.dragenter, false);
1382
+ document.removeEventListener("dragover", h.dragover, false);
1383
+ document.removeEventListener("dragleave", h.dragleave, false);
1384
+ document.removeEventListener("drop", h.drop, false);
1385
+ document.removeEventListener("mouseover", h.mouseover, true);
1386
+ document.removeEventListener("mouseout", h.mouseout, true);
1387
+ this.composerDragHandlers = null;
1388
+ document.body.classList.remove("amplifyup-drag-no-drop");
1389
+ document.querySelectorAll("[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot").forEach((el) => {
1390
+ el.classList.remove("amplifyup-drag-over-slot");
1391
+ });
1392
+ document.querySelectorAll("[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover").forEach((el) => {
1393
+ el.classList.remove("amplifyup-slot-hover");
1394
+ });
1289
1395
  }
1290
1396
  /** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
1291
1397
  injectComposerHighlightStyles(highlightComponents, showZones) {
@@ -1312,19 +1418,64 @@ Available Console Commands:
1312
1418
  " outline: 2px dotted rgba(34, 197, 94, 0.75) !important;",
1313
1419
  " outline-offset: 4px !important;",
1314
1420
  " min-height: 3rem !important;",
1421
+ " padding: 20px !important;",
1315
1422
  " box-sizing: border-box !important;",
1316
1423
  " cursor: pointer !important;",
1424
+ " position: relative !important;",
1317
1425
  "}",
1318
1426
  '[data-slot-id="main"], [data-amplifyup-slot="main"] {',
1319
1427
  " min-height: 50vh !important;",
1320
1428
  "}",
1429
+ '[data-slot-id="main"][data-slot-empty="true"]::before,',
1430
+ '[data-amplifyup-slot="main"][data-slot-empty="true"]::before {',
1431
+ ' content: "Drop components here" !important;',
1432
+ " position: absolute !important;",
1433
+ " top: 50% !important; left: 50% !important;",
1434
+ " transform: translate(-50%, -50%) !important;",
1435
+ " font-size: 14px !important; font-weight: 500 !important;",
1436
+ " color: rgba(34, 197, 94, 0.65) !important;",
1437
+ " pointer-events: none !important;",
1438
+ " white-space: nowrap !important;",
1439
+ "}",
1321
1440
  "[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover {",
1322
1441
  " outline-color: rgba(34, 197, 94, 1) !important;",
1323
1442
  " background: rgba(34, 197, 94, 0.06) !important;",
1324
1443
  "}",
1325
1444
  "[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot {",
1326
1445
  " outline: 2px solid rgba(34, 197, 94, 1) !important;",
1327
- " background: rgba(34, 197, 94, 0.1) !important;",
1446
+ " background: rgba(34, 197, 94, 0.18) !important;",
1447
+ " position: relative !important;",
1448
+ "}",
1449
+ "[data-slot-id].amplifyup-drag-over-slot::after,",
1450
+ "[data-amplifyup-slot].amplifyup-drag-over-slot::after {",
1451
+ ' content: "\\2713 Drop here" !important;',
1452
+ " position: absolute !important;",
1453
+ " top: 50% !important; left: 50% !important;",
1454
+ " transform: translate(-50%, -50%) !important;",
1455
+ " font-size: 14px !important; font-weight: 600 !important;",
1456
+ " color: rgb(22, 163, 74) !important;",
1457
+ " pointer-events: none !important;",
1458
+ " white-space: nowrap !important;",
1459
+ " z-index: 1 !important;",
1460
+ "}",
1461
+ "body.amplifyup-drag-no-drop { cursor: no-drop !important; }",
1462
+ "body.amplifyup-drag-no-drop::before {",
1463
+ ' content: "" !important;',
1464
+ " position: fixed !important; top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;",
1465
+ " background: rgba(239, 68, 68, 0.06) !important;",
1466
+ " pointer-events: none !important;",
1467
+ " z-index: 2147483646 !important;",
1468
+ "}",
1469
+ "body.amplifyup-drag-no-drop::after {",
1470
+ ' content: "\\2717 Not a drop zone" !important;',
1471
+ " position: fixed !important; bottom: 12px !important; right: 12px !important;",
1472
+ " font-size: 12px !important; font-weight: 600 !important;",
1473
+ " color: rgb(185, 28, 28) !important;",
1474
+ " background: rgba(254, 226, 226, 0.95) !important;",
1475
+ " padding: 6px 10px !important; border-radius: 6px !important;",
1476
+ " pointer-events: none !important;",
1477
+ " z-index: 2147483647 !important;",
1478
+ " box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;",
1328
1479
  "}"
1329
1480
  );
1330
1481
  }
@@ -1384,6 +1535,7 @@ Available Console Commands:
1384
1535
  disableHighlighting() {
1385
1536
  if (typeof document === "undefined") return;
1386
1537
  this.highlightingEnabled = false;
1538
+ this.teardownComposerDragDrop();
1387
1539
  if (this.mutationObserver) {
1388
1540
  this.mutationObserver.disconnect();
1389
1541
  this.mutationObserver = null;
@@ -1544,9 +1696,15 @@ Available Console Commands:
1544
1696
  e.preventDefault();
1545
1697
  e.stopPropagation();
1546
1698
  htmlEl.classList.remove("amplifyup-drag-over-slot");
1699
+ if (!win.parent || win.parent === win) return;
1700
+ win.parent.postMessage({
1701
+ type: "DROP_ON_SLOT",
1702
+ slotName,
1703
+ slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
1704
+ }, "*");
1547
1705
  try {
1548
1706
  const data = JSON.parse(e.dataTransfer.getData("application/json"));
1549
- if (data.type === "component" && win.parent && win.parent !== win) {
1707
+ if (data.type === "component") {
1550
1708
  win.parent.postMessage({
1551
1709
  type: "COMPONENT_DROPPED",
1552
1710
  componentId: data.componentId,
@@ -1554,7 +1712,6 @@ Available Console Commands:
1554
1712
  slotName,
1555
1713
  slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
1556
1714
  }, "*");
1557
- win.parent.postMessage({ type: "DROP_ON_SLOT", slotName }, "*");
1558
1715
  }
1559
1716
  } catch (_err) {
1560
1717
  }