@amplifyup/sdk 0.1.10 → 0.1.12

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.d.mts CHANGED
@@ -37,6 +37,7 @@ declare class AmplifyUpSDK {
37
37
  private componentRegistry;
38
38
  private messageListener;
39
39
  private mutationObserver;
40
+ private composerDragHandlers;
40
41
  private isVisualEditorMode;
41
42
  private eventSelectionMode;
42
43
  private eventSelectionClickHandler;
@@ -215,10 +216,21 @@ declare class AmplifyUpSDK {
215
216
  * Generate a CSS selector for an element
216
217
  */
217
218
  private generateSelectorForElement;
219
+ /** Clear drag-over highlight state (Composer overlay path or native drag end). */
220
+ private clearComposerDragHighlight;
221
+ /**
222
+ * Hit-test a slot at iframe-local coordinates (Composer overlay drag path).
223
+ * Required for cross-origin drags: the browser blocks native drop inside the iframe.
224
+ */
225
+ private handleComposerDragAtPoint;
226
+ private handleComposerDropAtPoint;
218
227
  /**
219
228
  * Enable component highlighting
220
229
  */
221
230
  private enableHighlighting;
231
+ /** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
232
+ private setupComposerDragDrop;
233
+ private teardownComposerDragDrop;
222
234
  /** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
223
235
  private injectComposerHighlightStyles;
224
236
  /**
package/dist/index.d.ts CHANGED
@@ -37,6 +37,7 @@ declare class AmplifyUpSDK {
37
37
  private componentRegistry;
38
38
  private messageListener;
39
39
  private mutationObserver;
40
+ private composerDragHandlers;
40
41
  private isVisualEditorMode;
41
42
  private eventSelectionMode;
42
43
  private eventSelectionClickHandler;
@@ -215,10 +216,21 @@ declare class AmplifyUpSDK {
215
216
  * Generate a CSS selector for an element
216
217
  */
217
218
  private generateSelectorForElement;
219
+ /** Clear drag-over highlight state (Composer overlay path or native drag end). */
220
+ private clearComposerDragHighlight;
221
+ /**
222
+ * Hit-test a slot at iframe-local coordinates (Composer overlay drag path).
223
+ * Required for cross-origin drags: the browser blocks native drop inside the iframe.
224
+ */
225
+ private handleComposerDragAtPoint;
226
+ private handleComposerDropAtPoint;
218
227
  /**
219
228
  * Enable component highlighting
220
229
  */
221
230
  private enableHighlighting;
231
+ /** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
232
+ private setupComposerDragDrop;
233
+ private teardownComposerDragDrop;
222
234
  /** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
223
235
  private injectComposerHighlightStyles;
224
236
  /**
package/dist/index.js CHANGED
@@ -343,6 +343,7 @@ var AmplifyUpSDK = class {
343
343
  this.componentRegistry = [];
344
344
  this.messageListener = null;
345
345
  this.mutationObserver = null;
346
+ this.composerDragHandlers = null;
346
347
  this.isVisualEditorMode = false;
347
348
  this.eventSelectionMode = false;
348
349
  this.eventSelectionClickHandler = null;
@@ -1157,6 +1158,24 @@ Available Console Commands:
1157
1158
  }
1158
1159
  return;
1159
1160
  }
1161
+ if (event.data?.type === "COMPOSER_DRAG_AT_POINT") {
1162
+ const { x, y } = event.data;
1163
+ if (typeof x === "number" && typeof y === "number") {
1164
+ this.handleComposerDragAtPoint(x, y);
1165
+ }
1166
+ return;
1167
+ }
1168
+ if (event.data?.type === "COMPOSER_DROP_AT_POINT") {
1169
+ const { x, y } = event.data;
1170
+ if (typeof x === "number" && typeof y === "number") {
1171
+ this.handleComposerDropAtPoint(x, y);
1172
+ }
1173
+ return;
1174
+ }
1175
+ if (event.data?.type === "COMPOSER_DRAG_END") {
1176
+ this.clearComposerDragHighlight();
1177
+ return;
1178
+ }
1160
1179
  if (event.data?.type === "GET_ELEMENT_POSITION") {
1161
1180
  const { componentId, slotName } = event.data;
1162
1181
  const selector = slotName ? `[data-amplifyup-slot="${slotName}"], [data-slot-id="${slotName}"]` : `[data-amplifyup-component="${componentId}"], [data-component-id="${componentId}"]`;
@@ -1290,6 +1309,46 @@ Available Console Commands:
1290
1309
  }
1291
1310
  return el.tagName.toLowerCase();
1292
1311
  }
1312
+ /** Clear drag-over highlight state (Composer overlay path or native drag end). */
1313
+ clearComposerDragHighlight() {
1314
+ if (typeof document === "undefined") return;
1315
+ const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
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
+ /**
1322
+ * Hit-test a slot at iframe-local coordinates (Composer overlay drag path).
1323
+ * Required for cross-origin drags: the browser blocks native drop inside the iframe.
1324
+ */
1325
+ handleComposerDragAtPoint(x, y) {
1326
+ if (typeof document === "undefined") return;
1327
+ const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
1328
+ this.clearComposerDragHighlight();
1329
+ const el = document.elementFromPoint(x, y)?.closest?.(slotSelector);
1330
+ if (el) {
1331
+ el.classList.add("amplifyup-drag-over-slot");
1332
+ } else {
1333
+ document.body.classList.add("amplifyup-drag-no-drop");
1334
+ }
1335
+ }
1336
+ handleComposerDropAtPoint(x, y) {
1337
+ if (typeof document === "undefined") return;
1338
+ const win = window;
1339
+ const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
1340
+ this.clearComposerDragHighlight();
1341
+ const htmlEl = document.elementFromPoint(x, y)?.closest?.(slotSelector);
1342
+ if (!htmlEl || !win.parent || win.parent === win) return;
1343
+ const slotName = htmlEl.getAttribute("data-amplifyup-slot") || htmlEl.getAttribute("data-slot-id");
1344
+ if (!slotName) return;
1345
+ const isEmpty = htmlEl.getAttribute("data-slot-empty") === "true";
1346
+ win.parent.postMessage({
1347
+ type: "DROP_ON_SLOT",
1348
+ slotName,
1349
+ slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
1350
+ }, "*");
1351
+ }
1293
1352
  /**
1294
1353
  * Enable component highlighting
1295
1354
  */
@@ -1306,6 +1365,111 @@ Available Console Commands:
1306
1365
  this.applyComponentHighlights(highlightComponents, showZones);
1307
1366
  this.setupMutationObserver();
1308
1367
  }
1368
+ if (showZones) {
1369
+ this.setupComposerDragDrop();
1370
+ }
1371
+ }
1372
+ /** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
1373
+ setupComposerDragDrop() {
1374
+ if (typeof document === "undefined") return;
1375
+ this.teardownComposerDragDrop();
1376
+ const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
1377
+ const clearDragOverState = () => {
1378
+ document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
1379
+ el.classList.remove("amplifyup-drag-over-slot");
1380
+ });
1381
+ document.body.classList.remove("amplifyup-drag-no-drop");
1382
+ };
1383
+ const dragenter = (e) => {
1384
+ e.preventDefault();
1385
+ if (e.dataTransfer?.types?.length) {
1386
+ document.body.classList.add("amplifyup-drag-no-drop");
1387
+ }
1388
+ };
1389
+ const dragover = (e) => {
1390
+ e.preventDefault();
1391
+ const target = e.target;
1392
+ const slot = target?.closest?.(slotSelector);
1393
+ if (e.dataTransfer) {
1394
+ e.dataTransfer.dropEffect = slot ? "copy" : "none";
1395
+ }
1396
+ document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
1397
+ el.classList.remove("amplifyup-drag-over-slot");
1398
+ });
1399
+ if (slot) {
1400
+ slot.classList.add("amplifyup-drag-over-slot");
1401
+ document.body.classList.remove("amplifyup-drag-no-drop");
1402
+ } else {
1403
+ document.body.classList.add("amplifyup-drag-no-drop");
1404
+ }
1405
+ };
1406
+ const dragleave = (e) => {
1407
+ const related = e.relatedTarget;
1408
+ if (!related || !document.body.contains(related)) {
1409
+ clearDragOverState();
1410
+ }
1411
+ };
1412
+ const drop = (e) => {
1413
+ e.preventDefault();
1414
+ const target = e.target;
1415
+ const slot = target?.closest?.(slotSelector);
1416
+ clearDragOverState();
1417
+ if (!slot || !this.isVisualEditorMode) return;
1418
+ const slotName = slot.getAttribute("data-amplifyup-slot") || slot.getAttribute("data-slot-id");
1419
+ const isEmpty = slot.getAttribute("data-slot-empty") === "true";
1420
+ const win = window;
1421
+ if (slotName && win.parent && win.parent !== win) {
1422
+ win.parent.postMessage({
1423
+ type: "DROP_ON_SLOT",
1424
+ slotName,
1425
+ slotElement: { path: slot.getAttribute("data-slot-path"), isEmpty }
1426
+ }, "*");
1427
+ }
1428
+ };
1429
+ const mouseover = (e) => {
1430
+ if (!this.showZonesEnabled) return;
1431
+ const target = e.target;
1432
+ const slot = target?.closest?.(slotSelector);
1433
+ if (!slot) return;
1434
+ document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
1435
+ el.classList.remove("amplifyup-slot-hover");
1436
+ });
1437
+ slot.classList.add("amplifyup-slot-hover");
1438
+ };
1439
+ const mouseout = (e) => {
1440
+ if (!this.showZonesEnabled) return;
1441
+ const related = e.relatedTarget;
1442
+ if (!related?.closest?.(slotSelector)) {
1443
+ document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
1444
+ el.classList.remove("amplifyup-slot-hover");
1445
+ });
1446
+ }
1447
+ };
1448
+ document.addEventListener("dragenter", dragenter, false);
1449
+ document.addEventListener("dragover", dragover, false);
1450
+ document.addEventListener("dragleave", dragleave, false);
1451
+ document.addEventListener("drop", drop, false);
1452
+ document.addEventListener("mouseover", mouseover, true);
1453
+ document.addEventListener("mouseout", mouseout, true);
1454
+ this.composerDragHandlers = { dragenter, dragover, dragleave, drop, mouseover, mouseout };
1455
+ }
1456
+ teardownComposerDragDrop() {
1457
+ if (!this.composerDragHandlers || typeof document === "undefined") return;
1458
+ const h = this.composerDragHandlers;
1459
+ document.removeEventListener("dragenter", h.dragenter, false);
1460
+ document.removeEventListener("dragover", h.dragover, false);
1461
+ document.removeEventListener("dragleave", h.dragleave, false);
1462
+ document.removeEventListener("drop", h.drop, false);
1463
+ document.removeEventListener("mouseover", h.mouseover, true);
1464
+ document.removeEventListener("mouseout", h.mouseout, true);
1465
+ this.composerDragHandlers = null;
1466
+ document.body.classList.remove("amplifyup-drag-no-drop");
1467
+ document.querySelectorAll("[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot").forEach((el) => {
1468
+ el.classList.remove("amplifyup-drag-over-slot");
1469
+ });
1470
+ document.querySelectorAll("[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover").forEach((el) => {
1471
+ el.classList.remove("amplifyup-slot-hover");
1472
+ });
1309
1473
  }
1310
1474
  /** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
1311
1475
  injectComposerHighlightStyles(highlightComponents, showZones) {
@@ -1332,19 +1496,64 @@ Available Console Commands:
1332
1496
  " outline: 2px dotted rgba(34, 197, 94, 0.75) !important;",
1333
1497
  " outline-offset: 4px !important;",
1334
1498
  " min-height: 3rem !important;",
1499
+ " padding: 20px !important;",
1335
1500
  " box-sizing: border-box !important;",
1336
1501
  " cursor: pointer !important;",
1502
+ " position: relative !important;",
1337
1503
  "}",
1338
1504
  '[data-slot-id="main"], [data-amplifyup-slot="main"] {',
1339
1505
  " min-height: 50vh !important;",
1340
1506
  "}",
1507
+ '[data-slot-id="main"][data-slot-empty="true"]::before,',
1508
+ '[data-amplifyup-slot="main"][data-slot-empty="true"]::before {',
1509
+ ' content: "Drop components here" !important;',
1510
+ " position: absolute !important;",
1511
+ " top: 50% !important; left: 50% !important;",
1512
+ " transform: translate(-50%, -50%) !important;",
1513
+ " font-size: 14px !important; font-weight: 500 !important;",
1514
+ " color: rgba(34, 197, 94, 0.65) !important;",
1515
+ " pointer-events: none !important;",
1516
+ " white-space: nowrap !important;",
1517
+ "}",
1341
1518
  "[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover {",
1342
1519
  " outline-color: rgba(34, 197, 94, 1) !important;",
1343
1520
  " background: rgba(34, 197, 94, 0.06) !important;",
1344
1521
  "}",
1345
1522
  "[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot {",
1346
1523
  " outline: 2px solid rgba(34, 197, 94, 1) !important;",
1347
- " background: rgba(34, 197, 94, 0.1) !important;",
1524
+ " background: rgba(34, 197, 94, 0.18) !important;",
1525
+ " position: relative !important;",
1526
+ "}",
1527
+ "[data-slot-id].amplifyup-drag-over-slot::after,",
1528
+ "[data-amplifyup-slot].amplifyup-drag-over-slot::after {",
1529
+ ' content: "\\2713 Drop here" !important;',
1530
+ " position: absolute !important;",
1531
+ " top: 50% !important; left: 50% !important;",
1532
+ " transform: translate(-50%, -50%) !important;",
1533
+ " font-size: 14px !important; font-weight: 600 !important;",
1534
+ " color: rgb(22, 163, 74) !important;",
1535
+ " pointer-events: none !important;",
1536
+ " white-space: nowrap !important;",
1537
+ " z-index: 1 !important;",
1538
+ "}",
1539
+ "body.amplifyup-drag-no-drop { cursor: no-drop !important; }",
1540
+ "body.amplifyup-drag-no-drop::before {",
1541
+ ' content: "" !important;',
1542
+ " position: fixed !important; top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;",
1543
+ " background: rgba(239, 68, 68, 0.06) !important;",
1544
+ " pointer-events: none !important;",
1545
+ " z-index: 2147483646 !important;",
1546
+ "}",
1547
+ "body.amplifyup-drag-no-drop::after {",
1548
+ ' content: "\\2717 Not a drop zone" !important;',
1549
+ " position: fixed !important; bottom: 12px !important; right: 12px !important;",
1550
+ " font-size: 12px !important; font-weight: 600 !important;",
1551
+ " color: rgb(185, 28, 28) !important;",
1552
+ " background: rgba(254, 226, 226, 0.95) !important;",
1553
+ " padding: 6px 10px !important; border-radius: 6px !important;",
1554
+ " pointer-events: none !important;",
1555
+ " z-index: 2147483647 !important;",
1556
+ " box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;",
1348
1557
  "}"
1349
1558
  );
1350
1559
  }
@@ -1404,6 +1613,7 @@ Available Console Commands:
1404
1613
  disableHighlighting() {
1405
1614
  if (typeof document === "undefined") return;
1406
1615
  this.highlightingEnabled = false;
1616
+ this.teardownComposerDragDrop();
1407
1617
  if (this.mutationObserver) {
1408
1618
  this.mutationObserver.disconnect();
1409
1619
  this.mutationObserver = null;
@@ -1564,9 +1774,15 @@ Available Console Commands:
1564
1774
  e.preventDefault();
1565
1775
  e.stopPropagation();
1566
1776
  htmlEl.classList.remove("amplifyup-drag-over-slot");
1777
+ if (!win.parent || win.parent === win) return;
1778
+ win.parent.postMessage({
1779
+ type: "DROP_ON_SLOT",
1780
+ slotName,
1781
+ slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
1782
+ }, "*");
1567
1783
  try {
1568
1784
  const data = JSON.parse(e.dataTransfer.getData("application/json"));
1569
- if (data.type === "component" && win.parent && win.parent !== win) {
1785
+ if (data.type === "component") {
1570
1786
  win.parent.postMessage({
1571
1787
  type: "COMPONENT_DROPPED",
1572
1788
  componentId: data.componentId,
@@ -1574,7 +1790,6 @@ Available Console Commands:
1574
1790
  slotName,
1575
1791
  slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
1576
1792
  }, "*");
1577
- win.parent.postMessage({ type: "DROP_ON_SLOT", slotName }, "*");
1578
1793
  }
1579
1794
  } catch (_err) {
1580
1795
  }