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