@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/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;
|
|
@@ -1163,6 +1164,24 @@ Available Console Commands:
|
|
|
1163
1164
|
}
|
|
1164
1165
|
return;
|
|
1165
1166
|
}
|
|
1167
|
+
if (event.data?.type === "COMPOSER_DRAG_AT_POINT") {
|
|
1168
|
+
const { x, y } = event.data;
|
|
1169
|
+
if (typeof x === "number" && typeof y === "number") {
|
|
1170
|
+
this.handleComposerDragAtPoint(x, y);
|
|
1171
|
+
}
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
if (event.data?.type === "COMPOSER_DROP_AT_POINT") {
|
|
1175
|
+
const { x, y } = event.data;
|
|
1176
|
+
if (typeof x === "number" && typeof y === "number") {
|
|
1177
|
+
this.handleComposerDropAtPoint(x, y);
|
|
1178
|
+
}
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
if (event.data?.type === "COMPOSER_DRAG_END") {
|
|
1182
|
+
this.clearComposerDragHighlight();
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1166
1185
|
if (event.data?.type === "GET_ELEMENT_POSITION") {
|
|
1167
1186
|
const { componentId, slotName } = event.data;
|
|
1168
1187
|
const selector = slotName ? `[data-amplifyup-slot="${slotName}"], [data-slot-id="${slotName}"]` : `[data-amplifyup-component="${componentId}"], [data-component-id="${componentId}"]`;
|
|
@@ -1296,6 +1315,46 @@ Available Console Commands:
|
|
|
1296
1315
|
}
|
|
1297
1316
|
return el.tagName.toLowerCase();
|
|
1298
1317
|
}
|
|
1318
|
+
/** Clear drag-over highlight state (Composer overlay path or native drag end). */
|
|
1319
|
+
clearComposerDragHighlight() {
|
|
1320
|
+
if (typeof document === "undefined") return;
|
|
1321
|
+
const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
|
|
1322
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
|
|
1323
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1324
|
+
});
|
|
1325
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1326
|
+
}
|
|
1327
|
+
/**
|
|
1328
|
+
* Hit-test a slot at iframe-local coordinates (Composer overlay drag path).
|
|
1329
|
+
* Required for cross-origin drags: the browser blocks native drop inside the iframe.
|
|
1330
|
+
*/
|
|
1331
|
+
handleComposerDragAtPoint(x, y) {
|
|
1332
|
+
if (typeof document === "undefined") return;
|
|
1333
|
+
const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
|
|
1334
|
+
this.clearComposerDragHighlight();
|
|
1335
|
+
const el = document.elementFromPoint(x, y)?.closest?.(slotSelector);
|
|
1336
|
+
if (el) {
|
|
1337
|
+
el.classList.add("amplifyup-drag-over-slot");
|
|
1338
|
+
} else {
|
|
1339
|
+
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
handleComposerDropAtPoint(x, y) {
|
|
1343
|
+
if (typeof document === "undefined") return;
|
|
1344
|
+
const win = window;
|
|
1345
|
+
const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
|
|
1346
|
+
this.clearComposerDragHighlight();
|
|
1347
|
+
const htmlEl = document.elementFromPoint(x, y)?.closest?.(slotSelector);
|
|
1348
|
+
if (!htmlEl || !win.parent || win.parent === win) return;
|
|
1349
|
+
const slotName = htmlEl.getAttribute("data-amplifyup-slot") || htmlEl.getAttribute("data-slot-id");
|
|
1350
|
+
if (!slotName) return;
|
|
1351
|
+
const isEmpty = htmlEl.getAttribute("data-slot-empty") === "true";
|
|
1352
|
+
win.parent.postMessage({
|
|
1353
|
+
type: "DROP_ON_SLOT",
|
|
1354
|
+
slotName,
|
|
1355
|
+
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1356
|
+
}, "*");
|
|
1357
|
+
}
|
|
1299
1358
|
/**
|
|
1300
1359
|
* Enable component highlighting
|
|
1301
1360
|
*/
|
|
@@ -1312,6 +1371,111 @@ Available Console Commands:
|
|
|
1312
1371
|
this.applyComponentHighlights(highlightComponents, showZones);
|
|
1313
1372
|
this.setupMutationObserver();
|
|
1314
1373
|
}
|
|
1374
|
+
if (showZones) {
|
|
1375
|
+
this.setupComposerDragDrop();
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
/** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
|
|
1379
|
+
setupComposerDragDrop() {
|
|
1380
|
+
if (typeof document === "undefined") return;
|
|
1381
|
+
this.teardownComposerDragDrop();
|
|
1382
|
+
const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
|
|
1383
|
+
const clearDragOverState = () => {
|
|
1384
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
|
|
1385
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1386
|
+
});
|
|
1387
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1388
|
+
};
|
|
1389
|
+
const dragenter = (e) => {
|
|
1390
|
+
e.preventDefault();
|
|
1391
|
+
if (e.dataTransfer?.types?.length) {
|
|
1392
|
+
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
const dragover = (e) => {
|
|
1396
|
+
e.preventDefault();
|
|
1397
|
+
const target = e.target;
|
|
1398
|
+
const slot = target?.closest?.(slotSelector);
|
|
1399
|
+
if (e.dataTransfer) {
|
|
1400
|
+
e.dataTransfer.dropEffect = slot ? "copy" : "none";
|
|
1401
|
+
}
|
|
1402
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
|
|
1403
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1404
|
+
});
|
|
1405
|
+
if (slot) {
|
|
1406
|
+
slot.classList.add("amplifyup-drag-over-slot");
|
|
1407
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1408
|
+
} else {
|
|
1409
|
+
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1410
|
+
}
|
|
1411
|
+
};
|
|
1412
|
+
const dragleave = (e) => {
|
|
1413
|
+
const related = e.relatedTarget;
|
|
1414
|
+
if (!related || !document.body.contains(related)) {
|
|
1415
|
+
clearDragOverState();
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
const drop = (e) => {
|
|
1419
|
+
e.preventDefault();
|
|
1420
|
+
const target = e.target;
|
|
1421
|
+
const slot = target?.closest?.(slotSelector);
|
|
1422
|
+
clearDragOverState();
|
|
1423
|
+
if (!slot || !this.isVisualEditorMode) return;
|
|
1424
|
+
const slotName = slot.getAttribute("data-amplifyup-slot") || slot.getAttribute("data-slot-id");
|
|
1425
|
+
const isEmpty = slot.getAttribute("data-slot-empty") === "true";
|
|
1426
|
+
const win = window;
|
|
1427
|
+
if (slotName && win.parent && win.parent !== win) {
|
|
1428
|
+
win.parent.postMessage({
|
|
1429
|
+
type: "DROP_ON_SLOT",
|
|
1430
|
+
slotName,
|
|
1431
|
+
slotElement: { path: slot.getAttribute("data-slot-path"), isEmpty }
|
|
1432
|
+
}, "*");
|
|
1433
|
+
}
|
|
1434
|
+
};
|
|
1435
|
+
const mouseover = (e) => {
|
|
1436
|
+
if (!this.showZonesEnabled) return;
|
|
1437
|
+
const target = e.target;
|
|
1438
|
+
const slot = target?.closest?.(slotSelector);
|
|
1439
|
+
if (!slot) return;
|
|
1440
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
|
|
1441
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1442
|
+
});
|
|
1443
|
+
slot.classList.add("amplifyup-slot-hover");
|
|
1444
|
+
};
|
|
1445
|
+
const mouseout = (e) => {
|
|
1446
|
+
if (!this.showZonesEnabled) return;
|
|
1447
|
+
const related = e.relatedTarget;
|
|
1448
|
+
if (!related?.closest?.(slotSelector)) {
|
|
1449
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
|
|
1450
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1451
|
+
});
|
|
1452
|
+
}
|
|
1453
|
+
};
|
|
1454
|
+
document.addEventListener("dragenter", dragenter, false);
|
|
1455
|
+
document.addEventListener("dragover", dragover, false);
|
|
1456
|
+
document.addEventListener("dragleave", dragleave, false);
|
|
1457
|
+
document.addEventListener("drop", drop, false);
|
|
1458
|
+
document.addEventListener("mouseover", mouseover, true);
|
|
1459
|
+
document.addEventListener("mouseout", mouseout, true);
|
|
1460
|
+
this.composerDragHandlers = { dragenter, dragover, dragleave, drop, mouseover, mouseout };
|
|
1461
|
+
}
|
|
1462
|
+
teardownComposerDragDrop() {
|
|
1463
|
+
if (!this.composerDragHandlers || typeof document === "undefined") return;
|
|
1464
|
+
const h = this.composerDragHandlers;
|
|
1465
|
+
document.removeEventListener("dragenter", h.dragenter, false);
|
|
1466
|
+
document.removeEventListener("dragover", h.dragover, false);
|
|
1467
|
+
document.removeEventListener("dragleave", h.dragleave, false);
|
|
1468
|
+
document.removeEventListener("drop", h.drop, false);
|
|
1469
|
+
document.removeEventListener("mouseover", h.mouseover, true);
|
|
1470
|
+
document.removeEventListener("mouseout", h.mouseout, true);
|
|
1471
|
+
this.composerDragHandlers = null;
|
|
1472
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1473
|
+
document.querySelectorAll("[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot").forEach((el) => {
|
|
1474
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1475
|
+
});
|
|
1476
|
+
document.querySelectorAll("[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover").forEach((el) => {
|
|
1477
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1478
|
+
});
|
|
1315
1479
|
}
|
|
1316
1480
|
/** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
|
|
1317
1481
|
injectComposerHighlightStyles(highlightComponents, showZones) {
|
|
@@ -1338,19 +1502,64 @@ Available Console Commands:
|
|
|
1338
1502
|
" outline: 2px dotted rgba(34, 197, 94, 0.75) !important;",
|
|
1339
1503
|
" outline-offset: 4px !important;",
|
|
1340
1504
|
" min-height: 3rem !important;",
|
|
1505
|
+
" padding: 20px !important;",
|
|
1341
1506
|
" box-sizing: border-box !important;",
|
|
1342
1507
|
" cursor: pointer !important;",
|
|
1508
|
+
" position: relative !important;",
|
|
1343
1509
|
"}",
|
|
1344
1510
|
'[data-slot-id="main"], [data-amplifyup-slot="main"] {',
|
|
1345
1511
|
" min-height: 50vh !important;",
|
|
1346
1512
|
"}",
|
|
1513
|
+
'[data-slot-id="main"][data-slot-empty="true"]::before,',
|
|
1514
|
+
'[data-amplifyup-slot="main"][data-slot-empty="true"]::before {',
|
|
1515
|
+
' content: "Drop components here" !important;',
|
|
1516
|
+
" position: absolute !important;",
|
|
1517
|
+
" top: 50% !important; left: 50% !important;",
|
|
1518
|
+
" transform: translate(-50%, -50%) !important;",
|
|
1519
|
+
" font-size: 14px !important; font-weight: 500 !important;",
|
|
1520
|
+
" color: rgba(34, 197, 94, 0.65) !important;",
|
|
1521
|
+
" pointer-events: none !important;",
|
|
1522
|
+
" white-space: nowrap !important;",
|
|
1523
|
+
"}",
|
|
1347
1524
|
"[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover {",
|
|
1348
1525
|
" outline-color: rgba(34, 197, 94, 1) !important;",
|
|
1349
1526
|
" background: rgba(34, 197, 94, 0.06) !important;",
|
|
1350
1527
|
"}",
|
|
1351
1528
|
"[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot {",
|
|
1352
1529
|
" outline: 2px solid rgba(34, 197, 94, 1) !important;",
|
|
1353
|
-
" background: rgba(34, 197, 94, 0.
|
|
1530
|
+
" background: rgba(34, 197, 94, 0.18) !important;",
|
|
1531
|
+
" position: relative !important;",
|
|
1532
|
+
"}",
|
|
1533
|
+
"[data-slot-id].amplifyup-drag-over-slot::after,",
|
|
1534
|
+
"[data-amplifyup-slot].amplifyup-drag-over-slot::after {",
|
|
1535
|
+
' content: "\\2713 Drop here" !important;',
|
|
1536
|
+
" position: absolute !important;",
|
|
1537
|
+
" top: 50% !important; left: 50% !important;",
|
|
1538
|
+
" transform: translate(-50%, -50%) !important;",
|
|
1539
|
+
" font-size: 14px !important; font-weight: 600 !important;",
|
|
1540
|
+
" color: rgb(22, 163, 74) !important;",
|
|
1541
|
+
" pointer-events: none !important;",
|
|
1542
|
+
" white-space: nowrap !important;",
|
|
1543
|
+
" z-index: 1 !important;",
|
|
1544
|
+
"}",
|
|
1545
|
+
"body.amplifyup-drag-no-drop { cursor: no-drop !important; }",
|
|
1546
|
+
"body.amplifyup-drag-no-drop::before {",
|
|
1547
|
+
' content: "" !important;',
|
|
1548
|
+
" position: fixed !important; top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;",
|
|
1549
|
+
" background: rgba(239, 68, 68, 0.06) !important;",
|
|
1550
|
+
" pointer-events: none !important;",
|
|
1551
|
+
" z-index: 2147483646 !important;",
|
|
1552
|
+
"}",
|
|
1553
|
+
"body.amplifyup-drag-no-drop::after {",
|
|
1554
|
+
' content: "\\2717 Not a drop zone" !important;',
|
|
1555
|
+
" position: fixed !important; bottom: 12px !important; right: 12px !important;",
|
|
1556
|
+
" font-size: 12px !important; font-weight: 600 !important;",
|
|
1557
|
+
" color: rgb(185, 28, 28) !important;",
|
|
1558
|
+
" background: rgba(254, 226, 226, 0.95) !important;",
|
|
1559
|
+
" padding: 6px 10px !important; border-radius: 6px !important;",
|
|
1560
|
+
" pointer-events: none !important;",
|
|
1561
|
+
" z-index: 2147483647 !important;",
|
|
1562
|
+
" box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;",
|
|
1354
1563
|
"}"
|
|
1355
1564
|
);
|
|
1356
1565
|
}
|
|
@@ -1410,6 +1619,7 @@ Available Console Commands:
|
|
|
1410
1619
|
disableHighlighting() {
|
|
1411
1620
|
if (typeof document === "undefined") return;
|
|
1412
1621
|
this.highlightingEnabled = false;
|
|
1622
|
+
this.teardownComposerDragDrop();
|
|
1413
1623
|
if (this.mutationObserver) {
|
|
1414
1624
|
this.mutationObserver.disconnect();
|
|
1415
1625
|
this.mutationObserver = null;
|
|
@@ -1570,9 +1780,15 @@ Available Console Commands:
|
|
|
1570
1780
|
e.preventDefault();
|
|
1571
1781
|
e.stopPropagation();
|
|
1572
1782
|
htmlEl.classList.remove("amplifyup-drag-over-slot");
|
|
1783
|
+
if (!win.parent || win.parent === win) return;
|
|
1784
|
+
win.parent.postMessage({
|
|
1785
|
+
type: "DROP_ON_SLOT",
|
|
1786
|
+
slotName,
|
|
1787
|
+
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1788
|
+
}, "*");
|
|
1573
1789
|
try {
|
|
1574
1790
|
const data = JSON.parse(e.dataTransfer.getData("application/json"));
|
|
1575
|
-
if (data.type === "component"
|
|
1791
|
+
if (data.type === "component") {
|
|
1576
1792
|
win.parent.postMessage({
|
|
1577
1793
|
type: "COMPONENT_DROPPED",
|
|
1578
1794
|
componentId: data.componentId,
|
|
@@ -1580,7 +1796,6 @@ Available Console Commands:
|
|
|
1580
1796
|
slotName,
|
|
1581
1797
|
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1582
1798
|
}, "*");
|
|
1583
|
-
win.parent.postMessage({ type: "DROP_ON_SLOT", slotName }, "*");
|
|
1584
1799
|
}
|
|
1585
1800
|
} catch (_err) {
|
|
1586
1801
|
}
|
|
@@ -1951,7 +2166,7 @@ function defaultPreviewCanvas() {
|
|
|
1951
2166
|
"data-slot-id": "main",
|
|
1952
2167
|
"data-amplifyup-slot": "main",
|
|
1953
2168
|
"data-slot-empty": "true",
|
|
1954
|
-
|
|
2169
|
+
style: { minHeight: "50vh", width: "100%", display: "block" }
|
|
1955
2170
|
}
|
|
1956
2171
|
);
|
|
1957
2172
|
}
|