@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/AmplifyRenderer.js +160 -3
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +160 -3
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +160 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +160 -3
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +161 -4
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +161 -4
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -349,6 +349,7 @@ var AmplifyUpSDK = class {
|
|
|
349
349
|
this.componentRegistry = [];
|
|
350
350
|
this.messageListener = null;
|
|
351
351
|
this.mutationObserver = null;
|
|
352
|
+
this.composerDragHandlers = null;
|
|
352
353
|
this.isVisualEditorMode = false;
|
|
353
354
|
this.eventSelectionMode = false;
|
|
354
355
|
this.eventSelectionClickHandler = null;
|
|
@@ -1312,6 +1313,111 @@ Available Console Commands:
|
|
|
1312
1313
|
this.applyComponentHighlights(highlightComponents, showZones);
|
|
1313
1314
|
this.setupMutationObserver();
|
|
1314
1315
|
}
|
|
1316
|
+
if (showZones) {
|
|
1317
|
+
this.setupComposerDragDrop();
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
/** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
|
|
1321
|
+
setupComposerDragDrop() {
|
|
1322
|
+
if (typeof document === "undefined") return;
|
|
1323
|
+
this.teardownComposerDragDrop();
|
|
1324
|
+
const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
|
|
1325
|
+
const clearDragOverState = () => {
|
|
1326
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
|
|
1327
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1328
|
+
});
|
|
1329
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1330
|
+
};
|
|
1331
|
+
const dragenter = (e) => {
|
|
1332
|
+
e.preventDefault();
|
|
1333
|
+
if (e.dataTransfer?.types?.length) {
|
|
1334
|
+
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
const dragover = (e) => {
|
|
1338
|
+
e.preventDefault();
|
|
1339
|
+
const target = e.target;
|
|
1340
|
+
const slot = target?.closest?.(slotSelector);
|
|
1341
|
+
if (e.dataTransfer) {
|
|
1342
|
+
e.dataTransfer.dropEffect = slot ? "copy" : "none";
|
|
1343
|
+
}
|
|
1344
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
|
|
1345
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1346
|
+
});
|
|
1347
|
+
if (slot) {
|
|
1348
|
+
slot.classList.add("amplifyup-drag-over-slot");
|
|
1349
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1350
|
+
} else {
|
|
1351
|
+
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1352
|
+
}
|
|
1353
|
+
};
|
|
1354
|
+
const dragleave = (e) => {
|
|
1355
|
+
const related = e.relatedTarget;
|
|
1356
|
+
if (!related || !document.body.contains(related)) {
|
|
1357
|
+
clearDragOverState();
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
const drop = (e) => {
|
|
1361
|
+
e.preventDefault();
|
|
1362
|
+
const target = e.target;
|
|
1363
|
+
const slot = target?.closest?.(slotSelector);
|
|
1364
|
+
clearDragOverState();
|
|
1365
|
+
if (!slot || !this.isVisualEditorMode) return;
|
|
1366
|
+
const slotName = slot.getAttribute("data-amplifyup-slot") || slot.getAttribute("data-slot-id");
|
|
1367
|
+
const isEmpty = slot.getAttribute("data-slot-empty") === "true";
|
|
1368
|
+
const win = window;
|
|
1369
|
+
if (slotName && win.parent && win.parent !== win) {
|
|
1370
|
+
win.parent.postMessage({
|
|
1371
|
+
type: "DROP_ON_SLOT",
|
|
1372
|
+
slotName,
|
|
1373
|
+
slotElement: { path: slot.getAttribute("data-slot-path"), isEmpty }
|
|
1374
|
+
}, "*");
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1377
|
+
const mouseover = (e) => {
|
|
1378
|
+
if (!this.showZonesEnabled) return;
|
|
1379
|
+
const target = e.target;
|
|
1380
|
+
const slot = target?.closest?.(slotSelector);
|
|
1381
|
+
if (!slot) return;
|
|
1382
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
|
|
1383
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1384
|
+
});
|
|
1385
|
+
slot.classList.add("amplifyup-slot-hover");
|
|
1386
|
+
};
|
|
1387
|
+
const mouseout = (e) => {
|
|
1388
|
+
if (!this.showZonesEnabled) return;
|
|
1389
|
+
const related = e.relatedTarget;
|
|
1390
|
+
if (!related?.closest?.(slotSelector)) {
|
|
1391
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
|
|
1392
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
document.addEventListener("dragenter", dragenter, false);
|
|
1397
|
+
document.addEventListener("dragover", dragover, false);
|
|
1398
|
+
document.addEventListener("dragleave", dragleave, false);
|
|
1399
|
+
document.addEventListener("drop", drop, false);
|
|
1400
|
+
document.addEventListener("mouseover", mouseover, true);
|
|
1401
|
+
document.addEventListener("mouseout", mouseout, true);
|
|
1402
|
+
this.composerDragHandlers = { dragenter, dragover, dragleave, drop, mouseover, mouseout };
|
|
1403
|
+
}
|
|
1404
|
+
teardownComposerDragDrop() {
|
|
1405
|
+
if (!this.composerDragHandlers || typeof document === "undefined") return;
|
|
1406
|
+
const h = this.composerDragHandlers;
|
|
1407
|
+
document.removeEventListener("dragenter", h.dragenter, false);
|
|
1408
|
+
document.removeEventListener("dragover", h.dragover, false);
|
|
1409
|
+
document.removeEventListener("dragleave", h.dragleave, false);
|
|
1410
|
+
document.removeEventListener("drop", h.drop, false);
|
|
1411
|
+
document.removeEventListener("mouseover", h.mouseover, true);
|
|
1412
|
+
document.removeEventListener("mouseout", h.mouseout, true);
|
|
1413
|
+
this.composerDragHandlers = null;
|
|
1414
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1415
|
+
document.querySelectorAll("[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot").forEach((el) => {
|
|
1416
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1417
|
+
});
|
|
1418
|
+
document.querySelectorAll("[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover").forEach((el) => {
|
|
1419
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1420
|
+
});
|
|
1315
1421
|
}
|
|
1316
1422
|
/** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
|
|
1317
1423
|
injectComposerHighlightStyles(highlightComponents, showZones) {
|
|
@@ -1338,19 +1444,64 @@ Available Console Commands:
|
|
|
1338
1444
|
" outline: 2px dotted rgba(34, 197, 94, 0.75) !important;",
|
|
1339
1445
|
" outline-offset: 4px !important;",
|
|
1340
1446
|
" min-height: 3rem !important;",
|
|
1447
|
+
" padding: 20px !important;",
|
|
1341
1448
|
" box-sizing: border-box !important;",
|
|
1342
1449
|
" cursor: pointer !important;",
|
|
1450
|
+
" position: relative !important;",
|
|
1343
1451
|
"}",
|
|
1344
1452
|
'[data-slot-id="main"], [data-amplifyup-slot="main"] {',
|
|
1345
1453
|
" min-height: 50vh !important;",
|
|
1346
1454
|
"}",
|
|
1455
|
+
'[data-slot-id="main"][data-slot-empty="true"]::before,',
|
|
1456
|
+
'[data-amplifyup-slot="main"][data-slot-empty="true"]::before {',
|
|
1457
|
+
' content: "Drop components here" !important;',
|
|
1458
|
+
" position: absolute !important;",
|
|
1459
|
+
" top: 50% !important; left: 50% !important;",
|
|
1460
|
+
" transform: translate(-50%, -50%) !important;",
|
|
1461
|
+
" font-size: 14px !important; font-weight: 500 !important;",
|
|
1462
|
+
" color: rgba(34, 197, 94, 0.65) !important;",
|
|
1463
|
+
" pointer-events: none !important;",
|
|
1464
|
+
" white-space: nowrap !important;",
|
|
1465
|
+
"}",
|
|
1347
1466
|
"[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover {",
|
|
1348
1467
|
" outline-color: rgba(34, 197, 94, 1) !important;",
|
|
1349
1468
|
" background: rgba(34, 197, 94, 0.06) !important;",
|
|
1350
1469
|
"}",
|
|
1351
1470
|
"[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot {",
|
|
1352
1471
|
" outline: 2px solid rgba(34, 197, 94, 1) !important;",
|
|
1353
|
-
" background: rgba(34, 197, 94, 0.
|
|
1472
|
+
" background: rgba(34, 197, 94, 0.18) !important;",
|
|
1473
|
+
" position: relative !important;",
|
|
1474
|
+
"}",
|
|
1475
|
+
"[data-slot-id].amplifyup-drag-over-slot::after,",
|
|
1476
|
+
"[data-amplifyup-slot].amplifyup-drag-over-slot::after {",
|
|
1477
|
+
' content: "\\2713 Drop here" !important;',
|
|
1478
|
+
" position: absolute !important;",
|
|
1479
|
+
" top: 50% !important; left: 50% !important;",
|
|
1480
|
+
" transform: translate(-50%, -50%) !important;",
|
|
1481
|
+
" font-size: 14px !important; font-weight: 600 !important;",
|
|
1482
|
+
" color: rgb(22, 163, 74) !important;",
|
|
1483
|
+
" pointer-events: none !important;",
|
|
1484
|
+
" white-space: nowrap !important;",
|
|
1485
|
+
" z-index: 1 !important;",
|
|
1486
|
+
"}",
|
|
1487
|
+
"body.amplifyup-drag-no-drop { cursor: no-drop !important; }",
|
|
1488
|
+
"body.amplifyup-drag-no-drop::before {",
|
|
1489
|
+
' content: "" !important;',
|
|
1490
|
+
" position: fixed !important; top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;",
|
|
1491
|
+
" background: rgba(239, 68, 68, 0.06) !important;",
|
|
1492
|
+
" pointer-events: none !important;",
|
|
1493
|
+
" z-index: 2147483646 !important;",
|
|
1494
|
+
"}",
|
|
1495
|
+
"body.amplifyup-drag-no-drop::after {",
|
|
1496
|
+
' content: "\\2717 Not a drop zone" !important;',
|
|
1497
|
+
" position: fixed !important; bottom: 12px !important; right: 12px !important;",
|
|
1498
|
+
" font-size: 12px !important; font-weight: 600 !important;",
|
|
1499
|
+
" color: rgb(185, 28, 28) !important;",
|
|
1500
|
+
" background: rgba(254, 226, 226, 0.95) !important;",
|
|
1501
|
+
" padding: 6px 10px !important; border-radius: 6px !important;",
|
|
1502
|
+
" pointer-events: none !important;",
|
|
1503
|
+
" z-index: 2147483647 !important;",
|
|
1504
|
+
" box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;",
|
|
1354
1505
|
"}"
|
|
1355
1506
|
);
|
|
1356
1507
|
}
|
|
@@ -1410,6 +1561,7 @@ Available Console Commands:
|
|
|
1410
1561
|
disableHighlighting() {
|
|
1411
1562
|
if (typeof document === "undefined") return;
|
|
1412
1563
|
this.highlightingEnabled = false;
|
|
1564
|
+
this.teardownComposerDragDrop();
|
|
1413
1565
|
if (this.mutationObserver) {
|
|
1414
1566
|
this.mutationObserver.disconnect();
|
|
1415
1567
|
this.mutationObserver = null;
|
|
@@ -1570,9 +1722,15 @@ Available Console Commands:
|
|
|
1570
1722
|
e.preventDefault();
|
|
1571
1723
|
e.stopPropagation();
|
|
1572
1724
|
htmlEl.classList.remove("amplifyup-drag-over-slot");
|
|
1725
|
+
if (!win.parent || win.parent === win) return;
|
|
1726
|
+
win.parent.postMessage({
|
|
1727
|
+
type: "DROP_ON_SLOT",
|
|
1728
|
+
slotName,
|
|
1729
|
+
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1730
|
+
}, "*");
|
|
1573
1731
|
try {
|
|
1574
1732
|
const data = JSON.parse(e.dataTransfer.getData("application/json"));
|
|
1575
|
-
if (data.type === "component"
|
|
1733
|
+
if (data.type === "component") {
|
|
1576
1734
|
win.parent.postMessage({
|
|
1577
1735
|
type: "COMPONENT_DROPPED",
|
|
1578
1736
|
componentId: data.componentId,
|
|
@@ -1580,7 +1738,6 @@ Available Console Commands:
|
|
|
1580
1738
|
slotName,
|
|
1581
1739
|
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1582
1740
|
}, "*");
|
|
1583
|
-
win.parent.postMessage({ type: "DROP_ON_SLOT", slotName }, "*");
|
|
1584
1741
|
}
|
|
1585
1742
|
} catch (_err) {
|
|
1586
1743
|
}
|
|
@@ -1951,7 +2108,7 @@ function defaultPreviewCanvas() {
|
|
|
1951
2108
|
"data-slot-id": "main",
|
|
1952
2109
|
"data-amplifyup-slot": "main",
|
|
1953
2110
|
"data-slot-empty": "true",
|
|
1954
|
-
|
|
2111
|
+
style: { minHeight: "50vh", width: "100%", display: "block" }
|
|
1955
2112
|
}
|
|
1956
2113
|
);
|
|
1957
2114
|
}
|