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